Re: [gtk-list] Re: clip origin, and **clip mask origion** ??
- From: Paul Barton-Davis <pbd op net>
- To: gtk-list redhat com
- Cc: Travis Loyd <lelandg usa net>
- Subject: Re: [gtk-list] Re: clip origin, and **clip mask origion** ??
- Date: Fri, 14 May 1999 00:59:01 -0400
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 ®exp,
bool homogenous = true);
virtual ~Pix();
friend Pix *get_pix (const string &dirpath,
const string ®exp,
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 ®exp,
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 ®exp, 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 ®exp, 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;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]