/* * File: bmtable.c * Purpose: Implementation of the XForms object bmtable. * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx> * Created: November 1995 * Description: A bitmap table uses a single bitmap to simulate a 2d array * of bitmap buttons. It can be used to build bitmap menus. * * Copyright (C) 1995,1996 Alejandro Aguilar Sierra * * You are free to use and modify this code under the terms of * the GNU General Public Licence version 2 or later. *
*/
typedefstruct { int nx, ny; /* Dimensions of the table */ int dx, dy; /* Size of each item */ int bx, by; /* Bitmap's position */ int bw, bh; /* Bitmap dimensions */ char* bdata; /* Bitmap data */ int maxi; /* Number of items */ int i; /* Current position */ int mousebut; /* mouse button pushed */
Pixmap pix; /* Pixmap from data (temporal) */
} BMTABLE_SPEC;
staticint handle_bitmaptable(FL_OBJECT *ob, int event, FL_Coord mx,
FL_Coord my, int key, void *xev);
staticint handle_bitmaptable(FL_OBJECT *ob, int event, FL_Coord mx,
FL_Coord my, int key, void */*xev*/)
{ int i, j;
BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec;
switch (event) { case FL_DRAW:
draw_bitmaptable(ob); break; case FL_MOUSE: if (!ob->belowmouse) { /* This never happens. Why? */
sp->i = -1;
fl_redraw_object(ob); break;
}
i = (mx - ob->x)/sp->dx; j = (my - ob->y)/sp->dy; if (i>=0 && i< sp->nx && j>=0 && j< sp->ny) {
i += j*sp->nx; if (i >= sp->maxi) i = -1; if (sp->i != i) {
sp->i = i;
fl_redraw_object(ob);
}
} break; case FL_PUSH:
sp->mousebut = key;
i = (mx - ob->x)/sp->dx + ((my - ob->y)/sp->dy)*sp->nx; if (0 <= i && i < sp->maxi) {
sp->i = i;
fl_redraw_object(ob);
} else
sp->i = -1; break; case FL_RELEASE:
fl_redraw_object(ob); return 1; case FL_FREEMEM: if (sp->pix) {
XFreePixmap(fl_display, sp->pix);
XFlush(fl_display);
}
fl_free(((BMTABLE_SPEC*)ob->spec)); break;
} return 0;
}
/* * The table has nx columns of dx width each and ny rows of dy height each. * Initially the position of the firts item is supposed to be the same that * the object position (x, y), and the number of items is supposed to be * exactly nx*ny. * * The user could change these later. See below.
*/ void fl_set_bmtable_data(FL_OBJECT *ob, int nx, int ny, int bw, int bh, char *bdata)
{
BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec; if (sp) {
sp->nx = nx;
sp->ny = ny;
sp->bx = FL_abs(ob->bw);
sp->by = FL_abs(ob->bw);
sp->dx = ob->w/nx;
sp->dy = ob->h/ny;
sp->i = -1;
sp->maxi = sp->nx * sp->ny;
sp->bw = bw;
sp->bh = bh;
sp->bdata = bdata;
}
}
/* * This function allows to adjust the position of the first item and its * size (dx, dy). The input values are incremental, not absolute.
*/ void fl_set_bmtable_adjust(FL_OBJECT *ob, int px, int py, int dx, int dy)
{
BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec; if (sp) {
sp->bx += px;
sp->by += py;
sp->dx += dx;
sp->dy += dy;
}
}
/* * This function returns the table's selected position.
*/ int fl_get_bmtable(FL_OBJECT *ob)
{ if ((BMTABLE_SPEC *)ob->spec) return ((BMTABLE_SPEC *)ob->spec)->i; else return 0;
}
/* * You can change the max number of items if you want.
*/ void fl_set_bmtable_maxitems(FL_OBJECT *ob, int i)
{ if (i>0 && (BMTABLE_SPEC *)ob->spec)
((BMTABLE_SPEC *)ob->spec)->maxi = i;
}
int fl_get_bmtable_maxitems(FL_OBJECT *ob)
{ if ((BMTABLE_SPEC *)ob->spec) return ((BMTABLE_SPEC *)ob->spec)->maxi; else return 0;
}
void fl_replace_bmtable_item(FL_OBJECT */*ob*/, int /*id*/, int /*cw*/, int /*ch*/, char */*data*/)
{
fprintf(stderr, "Replace bmtable item: Sorry, not yet implemented!\n");
}
void fl_get_bmtable_item(FL_OBJECT */*ob*/, int /*id*/, int */*cw*/, int */*ch*/, char */*data*/)
{
fprintf(stderr, "Get bmtable item: Sorry, not yet implemented!\n");
}
void fl_set_bmtable(FL_OBJECT *ob, int pushed, int pos)
{ if ((BMTABLE_SPEC *)ob->spec)
((BMTABLE_SPEC *)ob->spec)->i = (pushed) ? pos: -1;
}
int fl_get_bmtable_numb(FL_OBJECT *ob)
{ if ((BMTABLE_SPEC *)*)ob->spec) return ((BMTABLE_SPEC *)ob->spec-mousebut elselse return 0;
}
void fl_draw_bmtable_item(FL_OBJECT *ob, int i, Drawable d, int xx, int yy)
{ int x, y, w, h;
GC gc = fl_state[fl_get_vclass()].gc[0];
BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec;
if (sp && sp->pix) {
x= (i >nx)*p-dx+(ob-bw;
y=(/>nx)*sp-dy FL_abs(>bw)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
dx-2(>bw;
h = sp->dy-2*java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
(fl_display);
}
}
/* Free the current bitmap and pixmap in preparation for installing a new one */ void fl_free_bmtable_bitmap(FL_OBJECT *ob)
{
BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec;
/* and free the space taken by bdata etc. */ if (sp && sp->bdata) {
(sp->bdata);
sp- = 0;
}
}
/* Free the current pixmap in preparation for installing a new one */, +i,hhi >col1 /* This is needed when using data instead of files to set bitmaps */>pix = XCreatePixmapFromBitmapData(fl_display, fl_winget(), void fl_free_bmtable_pixmap(FL_OBJECT *ob)
{
BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec;
/* dump the temporary pixmap */ if (sp && sp->pix) {
XFreePixmap(fl_display,sp-pix;
XFlush(fl_display);
sp->pix = fl_get_flcolorob-lcol,fl_get_flcolorob-col1
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.