Re: [gtk-list] Re: clip origin, and **clip mask origion** ??



I don't think you know my question yet but I really think you know the
answer!

The large xpm contains lots of little images that a single game tile is
built with possibly a pit, a wall and a couple lasers. Each picture is
drawn on a transparent xpm so they each need their own mask. I select
where to start copying the drawing and where to draw to and that is what I
do and it works out nicely copying but it will not use the appropriate
mask. For instance: If I copy a picture from location 150x75 and it is
75x75 it will copy that information but still use the mask located at 0x0
and be 75x75. I need to be able to specify the location 150x75 to specify
the mask.

If this isn't possible it really should be, there should be a command for
it.

Your answer of window_shaped_mask doesn't seem to work for me because I'm
just copying and drawing ... in this case to a 900x900 pixmap.

I was thinking that a bitmap is just a pixmap with 2 different colors so I
figured I could just use the command I was shapeing the pixmap to start
out with to just shape the bitmap to but that isn't possible.

If I could even figure out how to copy out of the bitmap to a pixmap my
75x75 square I could then use the gdk_draw_pixmap using the new pixmap to
create the mask I need and could then use with the origional copy.

I've converted from single xpm files to the method of useing only one xpm
for many reasons ... and I expect there has to be a simple method to this
problem as I'm sure many people have tried... including you.


Travis Loyd
[email: lelandg@usa.net				Encrypt your email too: ]
[other: s201635@mail.nwmissouri.edu		     http://www.pgp.com	]
[  pgp: send email with subject: sendmepgp				]

On Fri, 14 May 1999, Paul Barton-Davis wrote:

> In message <Pine.LNX.4.05.9905131200320.3105-100000@trundle.elephant.com>you wr
> ite:
> >I looked a 'gsyn' in response to where the information was originating from
> >the last answer I received via this mailing list. That program is not
> >using transparencies as I am. There for the mask wouldn't be an issue
> >with their program.
> >
> >The actual code to my program is located at http://roborally.linuxguru.net
> >
> >Anyone else know how to specify the origin on a mask to use? I'm not
> >actually even sure why gtk_set_clip_origin is necessary.
> 
> Me neither. Is the mask different for each section of the pixmap you
> want to display ? If so, then you can to create an independent
> mask for each one, and use gtk_window_shape_combine_mask() to shape
> the window that you draw the pixmap in.
> 
> to be honest, i gave up on the "lots-of-images-in-one-pixmap" approach
> for reasons similar the the problems you're having. Instead, I use a
> C++ object called a Pix, which is a series of pixmaps and masks, used
> in combination with another called ShapedWindow (code posted earlier
> today). I use these two to implement lots of things, including buttons
> that change shape depending on their state, sliders that have no
> "background", etc. etc. See the screenshot at
> http://www.op.net/~pbd/quasimodo/ for more.
> 
> --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: pix.h,v 1.3 1999/05/13 14:50:49 pbd Exp $
> */
> 
> #ifndef __pbd_gtkmm_pix_h__
> #define __pbd_gtkmm_pix_h__
> 
> #include <map>
> #include <gtk--.h>
> 
> class Pix
> {
> 	typedef map<string, Pix *> PixCache;
> 	static PixCache cache;
> 
> 	PixCache::iterator cache_position;
> 	int refcnt;
>         bool generated;
> 	vector<string *> *files;
> 	size_t pixmap_count;
> 	size_t last_pixmap;
> 	GdkPixmap **pixmaps;
> 	GdkBitmap **bitmaps;
> 	size_t max_pixwidth;
> 	size_t max_pixheight;
> 	bool _homegenous;
> 
>         Pix (const string &dirpath, const string &regexp, 
> 	     bool homogenous = true);
>         virtual ~Pix();
> 
> 	friend  Pix *get_pix (const string &dirpath, 
> 			      const string &regexp,
> 			      bool homogenous);
> 	friend  void finish_pix (Pix *);
> 
>   protected:
> 	void ref () { refcnt++; }
> 	void unref () { if (refcnt) refcnt--; }
> 	friend class UI;
> 
>   public:      
> 	Pix (bool homogenous = true);
> 
>         void generate (GdkWindow *, GdkColor *);
> 	size_t n_pixmaps() { return pixmap_count; }
> 	size_t max_pixmap() { return last_pixmap; }
> 	bool homogenous () { return _homegenous; }
> 
>         GdkBitmap *shape_mask (size_t n) {
> 		if (n < pixmap_count) {
> 			return bitmaps[n];
> 		} 
> 		return NULL;
> 	}
> 
> 	GdkPixmap *pixmap(size_t n) {
> 		if (n < pixmap_count) {
> 			return pixmaps[n];
> 		} 
> 		return NULL;
> 	}
> 
> 	size_t max_width() { return max_pixwidth; }
> 	size_t max_height() { return max_pixheight; }
> };
> 
> extern Pix *get_pix (const string &dirpath, 
> 		     const string &regexp, 
> 		     bool homog = false);
> extern void finish_pix (Pix *);
> 
> #endif  __pbd_gtkmm_pix_h__
> 
> /*
>     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: pix.cc,v 1.3 1999/05/13 14:50:49 pbd Exp $
> */
> 
> #include <algo.h>
> 
> #include <gdk/gdk.h>
> 
> #include "pathscanner.h"
> #include "stl_delete.h"
> #include "stl_functors.h"
> #include "pix.h"
> #include "error.h"
> 
> Pix::PixCache Pix::cache;
> 
> Pix::Pix (bool homog)
> 
> {
> 	pixmap_count = 0;
> 	_homegenous = homog;
> }
> 
> Pix::Pix (const string &dirpath, const string &regexp, bool homog)
> 
> {
> 	PathScanner scanner;
> 	less<string *> cmp;
> 
> 	pixmap_count = 0;
> 	last_pixmap = 0;
> 	refcnt = 0;
> 	generated = false;
> 	max_pixwidth = 0;
> 	max_pixheight = 0;
> 	_homegenous = homog;
> 
> 	pixmaps = NULL;
> 	bitmaps = NULL;
> 	
> 	files = scanner (dirpath, regexp, false, true);
> 
> 	sort (files->begin(), files->end(), cmp);
> 
> 	if (files == NULL) {
> 		return;
> 	}
> 
> 	/* create handy reference */
> 
> 	if ((pixmap_count = files->size()) == 0) {
> 		error ("No pixmaps found to match \"%s\" in path %s",
> 		       regexp.c_str(), dirpath.c_str());
> 		return;
> 	}
> 
> 	pixmaps = new GdkPixmap * [pixmap_count];
> 	bitmaps = new GdkBitmap * [pixmap_count];
> 	memset (pixmaps, 0, sizeof (GdkPixmap *) * pixmap_count);
> 	memset (bitmaps, 0, sizeof (GdkBitmap *) * pixmap_count);
> 
> 	last_pixmap = pixmap_count - 1;
> }
> 
> Pix::~Pix ()
> 
> {
> 	size_t i;
> 
> 	for (i = 0; i < pixmap_count; i++) {
> 		if (pixmaps[i] != NULL) {
> 			gdk_pixmap_unref (pixmaps[i]);
> 			gdk_bitmap_unref (bitmaps[i]);
> 		}
> 	}
> 
> 	vector_delete (files);
> 	if (pixmap_count) delete [] pixmaps;
> 	if (pixmap_count) delete [] bitmaps;
> }
> 
> void
> Pix::generate (GdkWindow *win, GdkColor *transparent)
> 
> {
> 	size_t i;
> 	size_t w, h;
> 
> 	if (generated) {
> 		return;
> 	}
> 
> 	for (i = 0; i < pixmap_count; i++) {
> 		string *strp;
> 		
> 		strp = (*files)[i];
> 
> 		if (win == NULL) {
> 			GtkWidget *widget = (GtkWidget *) transparent;
> 
> 			pixmaps[i] = gdk_pixmap_colormap_create_from_xpm 
> 				(NULL, gtk_widget_get_colormap (widget),
> 				 &bitmaps[i], NULL, strp->c_str());
> 		} else {
> 			pixmaps[i] = gdk_pixmap_create_from_xpm 
> 				(win, &bitmaps[i], transparent, strp->c_str());
> 		}
> 
> 		gdk_window_get_size (pixmaps[i],  (gint *) &w, (gint *) &h);
> 		if (w > max_pixwidth) max_pixwidth = w;
> 		if (h > max_pixheight) max_pixheight = h;
> 	}
> 
> 	generated = true;
> }
> 
> Pix *
> get_pix (const string &dirpath, const string &regexp, bool homog)
> 
> {
> 	Pix *ret = NULL;
> 	Pix::PixCache::iterator iter;
> 	pair<string, Pix *> newpair;
> 
> 	if ((iter = Pix::cache.find (regexp)) == Pix::cache.end()) {
> 		ret = new Pix (dirpath, regexp, homog);
> 		if (ret->pixmap_count == 0) {
> 			delete ret;
> 			return NULL;
> 		}
> 		newpair.first = regexp;
> 		newpair.second = ret;
> 		ret->cache_position = (Pix::cache.insert (newpair)).first;
> 		ret->refcnt++;
> 		return ret;
> 	} else {
> 		(*iter).second->refcnt++;
> 		return (*iter).second;
> 	}
> }
> 
> void 
> finish_pix (Pix *pix)
> 
> {
> 	pix->refcnt--;
> 	if (pix->refcnt == 0) {
> 		Pix::cache.erase (pix->cache_position);
> 		delete pix;
> 	}
> }
>                                                              
> 
> -- 
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
> 



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