Re: [gtk-list] Shaped Pixmaps



In message <373AC3D4.FF34A48C@ceselsa.es>you write:
>I have a GtkPixmap (derived from GtkMisc, it isn't?) and I want to Shape it,
>but it hasn't a GdkWindow.

a *GdkPixmap* *is* a window. whatever you do to a GdkWindow, 
you can do to a GdkPixmap.

>It is possible to apply the Shape (gtk_widget_shape_combine_mask()) to the
>GtkMisc's GdkWindow ?

you don't need a GtkMisc, just use the pixmap itself. 

>    The idea is to put a lot of shaped pixmaps in a GtkFixed but without  a
>GtkFixed (or GtkEvent... or similar) for each pixmap.

this is what you'll see if you look at http://www.op.net/~pbd/quasimodo/.
It is precisely what you describe: a set of shaped pixmaps arranged in
one or more GtkFixed's (although its written in C++).

Enclosed below is the body of the class I use for this purpose. It
mostly uses GTK+ calls, not Gtk--.

If you want to take a look at the rest of the code, download the
source distribution of quasimodo, and look in the src/gtkmm directory.


--p

---------------------------------------------------------------------------
/*
    Copyright (C) 1998-99 Paul Barton-Davis
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    $Id$
*/

#include <gtk--.h>
#include <gtk--/pix.h>
#include <gtk--/shaped_window.h>

Gtk_ShapedWindow::Gtk_ShapedWindow (Pix *pixset, Gtk_Widget *w)

{
	pix = pixset;
	current_pix = 0;
	exposed = false;
	shapeable_parent = w;
}

Gtk_ShapedWindow::~Gtk_ShapedWindow ()

{
	finish_pix (pix);
}

void
Gtk_ShapedWindow::set_current_pix (size_t n)

{
	current_pix = MIN(n,pix->max_pixmap());
	draw_pixmap ();
}

void
Gtk_ShapedWindow::realize_impl ()

{
	gint width, height;
	Gtk_Widget *parent;

	Gtk_DrawingArea::realize_impl ();

	mystyle = get_style()->gtkobj();

	if (!shapeable_parent) {
		parent = this;
	} else {
		parent = shapeable_parent;
	}
	
	pix->generate (get_window(),
		       (GdkColor *) &mystyle->bg[GTK_STATE_NORMAL]);
	
	gdk_window_get_size (pix->pixmap (0), &width, &height);
	set_usize (width, height);

	gtk_widget_shape_combine_mask (GTK_WIDGET(parent->gtkobj()),
				       pix->shape_mask (0),
				       0, 0);

	exposed = true;
	draw_pixmap ();
}

gint
Gtk_ShapedWindow::expose_event_impl (GdkEventExpose *ev)

{
	if (ev->count == 0) {
		draw_pixmap ();
	}
	return TRUE;
}

void
Gtk_ShapedWindow::state_changed_impl (GtkStateType somestate)

{
        size_t newstate = (size_t) GTK_WIDGET_STATE(GTK_WIDGET(gtkobj()));
	current_pix = (size_t) newstate % pix->n_pixmaps();
	draw_pixmap();
}

void
Gtk_ShapedWindow::draw_pixmap ()

{
	if (exposed) {

		if (!pix->homogenous()) {
			Gtk_Widget *parent;
			
			if (!shapeable_parent) {
				parent = this;
			} else {
				parent = shapeable_parent;
			}

			gtk_widget_shape_combine_mask 
				(GTK_WIDGET(parent->gtkobj()),
				 pix->shape_mask (current_pix),
				 0, 0);
		}
		
		gdk_draw_pixmap (get_window(),
				 mystyle->bg_gc[get_state()],
				 pix->pixmap (current_pix),
				 0, 0, 0, 0,
				 -1, -1);
	}
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]