diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2001-08-05 23:58:54 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2001-08-05 23:58:54 +0000 |
| commit | 7ebaf77cdcbcadb4706c87f1662730a4687caf20 (patch) | |
| tree | 07340f24b863b23f716b9cf9f657026c76c62fbf /src/Fl_Pixmap.cxx | |
| parent | 208cf399a6ab801951bf28a82a0e07adefc60028 (diff) | |
Image labels!
image() method to set active image, deimage() method to set inactive image.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1560 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Pixmap.cxx')
| -rw-r--r-- | src/Fl_Pixmap.cxx | 74 |
1 files changed, 29 insertions, 45 deletions
diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index 846383b55..df0e029a6 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Pixmap.cxx,v 1.9.2.4 2001/01/22 15:13:40 easysw Exp $" +// "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.1 2001/08/05 23:58:54 easysw Exp $" // // Pixmap drawing code for the Fast Light Tool Kit (FLTK). // @@ -42,25 +42,35 @@ extern uchar **fl_mask_bitmap; // used by fl_draw_pixmap.C to store mask void fl_restore_clip(); // in fl_rect.C +void Fl_Pixmap::measure() { + int W, H; + + // ignore empty or bad pixmap data: + if (w()<0) { + fl_measure_pixmap(data, W, H); + w(W); h(H); + } +} + void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { // ignore empty or bad pixmap data: - if (w<0) { - fl_measure_pixmap(data, w, h); - if (WP==-1) { WP = w; HP = h; } + if (w()<0) { + measure(); + if (WP==-1) { WP = w(); HP = h(); } } - if (!w) return; + if (!w()) return; // account for current clip region (faster on Irix): int X,Y,W,H; fl_clip_box(XP,YP,WP,HP,X,Y,W,H); cx += X-XP; cy += Y-YP; // clip the box down to the size of image, quit if empty: if (cx < 0) {W += cx; X -= cx; cx = 0;} - if (cx+W > w) W = w-cx; + if (cx+W > w()) W = w()-cx; if (W <= 0) return; if (cy < 0) {H += cy; Y -= cy; cy = 0;} - if (cy+H > h) H = h-cy; + if (cy+H > h()) H = h()-cy; if (H <= 0) return; if (!id) { - id = (ulong)fl_create_offscreen(w, h); + id = (ulong)fl_create_offscreen(w(), h()); fl_begin_offscreen((Fl_Offscreen)id); uchar *bitmap = 0; fl_mask_bitmap = &bitmap; @@ -78,11 +88,11 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { 0x01, 0x09, 0x05, 0x0d, 0x03, 0x0b, 0x07, 0x0f }; int np = GetDeviceCaps(fl_gc, PLANES); //: was always one on sample machines int bpp = GetDeviceCaps(fl_gc, BITSPIXEL);//: 1,4,8,16,24,32 and more odd stuff? - int Bpr = (bpp*w+7)/8; //: bytes per row - int pad = Bpr&1, w1 = (w+7)/8, shr = ((w-1)&7)+1; + int Bpr = (bpp*w()+7)/8; //: bytes per row + int pad = Bpr&1, w1 = (w()+7)/8, shr = ((w()-1)&7)+1; if (bpp==4) shr = (shr+1)/2; uchar *newarray = new uchar[(Bpr+pad)*h], *dst = newarray, *src = bitmap; - for (int i=0; i<h; i++) { + for (int i=0; i<h(); i++) { //: this is slooow, but we do it only once per pixmap for (int j=w1; j>0; j--) { uchar b = *src++; @@ -112,11 +122,11 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { } dst += pad; } - mask = (ulong)CreateBitmap(w, h, np, bpp, newarray); + mask = (ulong)CreateBitmap(w(), h(), np, bpp, newarray); delete[] newarray; #else mask = XCreateBitmapFromData(fl_display, fl_window, - (const char*)bitmap, (w+7)&-8, h); + (const char*)bitmap, (w()+7)&-8, h()); #endif delete[] bitmap; } @@ -142,8 +152,8 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { cy += ny-Y; Y = ny; // make X use the bitmap as a mask: XSetClipMask(fl_display, fl_gc, mask); - int ox = X-cx; if (ox < 0) ox += w; - int oy = Y-cy; if (oy < 0) oy += h; + int ox = X-cx; if (ox < 0) ox += w(); + int oy = Y-cy; if (oy < 0) oy += h(); XSetClipOrigin(fl_display, fl_gc, X-cx, Y-cy); } fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy); @@ -160,39 +170,13 @@ Fl_Pixmap::~Fl_Pixmap() { if (mask) fl_delete_offscreen((Fl_Offscreen)mask); } -static void pixmap_labeltype( - const Fl_Label* o, int x, int y, int w, int h, Fl_Align a) -{ - Fl_Pixmap* b = (Fl_Pixmap*)(o->value); - if (b->w<0) fl_measure_pixmap(b->data, b->w, b->h); - int cx; - if (a & FL_ALIGN_LEFT) cx = 0; - else if (a & FL_ALIGN_RIGHT) cx = b->w-w; - else cx = (b->w-w)/2; - int cy; - if (a & FL_ALIGN_TOP) cy = 0; - else if (a & FL_ALIGN_BOTTOM) cy = b->h-h; - else cy = (b->h-h)/2; - b->draw(x,y,w,h,cx,cy); -} - -static void pixmap_measure(const Fl_Label* o, int& w, int& h) { - Fl_Pixmap* b = (Fl_Pixmap*)(o->value); - if (b->w<0) fl_measure_pixmap(b->data, b->w, b->h); - w = b->w; - h = b->h; -} - -void Fl_Pixmap::label(Fl_Widget* o) { - Fl::set_labeltype(_FL_PIXMAP_LABEL, pixmap_labeltype, pixmap_measure); - o->label(_FL_PIXMAP_LABEL, (const char*)this); +void Fl_Pixmap::label(Fl_Widget* w) { + w->image(this); } -void Fl_Pixmap::label(Fl_Menu_Item* o) { - Fl::set_labeltype(_FL_PIXMAP_LABEL, pixmap_labeltype, pixmap_measure); - o->label(_FL_PIXMAP_LABEL, (const char*)this); +void Fl_Pixmap::label(Fl_Menu_Item* m) { } // -// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4 2001/01/22 15:13:40 easysw Exp $". +// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.1 2001/08/05 23:58:54 easysw Exp $". // |
