static void GProgressResInit(void) { if ( !progress_init ) { progress_foreground = GResourceFindColor("GProgress.Foreground", GDrawGetDefaultForeground(NULL)); progress_background = GResourceFindColor("GProgress.Background", GDrawGetDefaultBackground(NULL)); progress_fillcol = GResourceFindColor("GProgress.FillColor", progress_fillcol); progress_font = GResourceFindFont("GProgress.Font",NULL); progress_init = true; } }
static int DrawTab(GWindow pixmap, GTabSet *gts, int i, int x, int y ) { Color fg = gts->tabs[i].disabled?gts->g.box->disabled_foreground:gts->g.box->main_foreground; if ( fg==COLOR_DEFAULT ) fg = GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)); GBoxDrawTabOutline(pixmap,>s->g,x,y,gts->tabs[i].width,gts->rowh,i==gts->sel); if ( (i==gts->sel) && (gts->g.box->flags&box_active_border_inner) ) { GRect r; r.x = x+2; r.y = y+1; r.width = gts->tabs[i].width-4; r.height = gts->rowh-2; GDrawFillRect(pixmap,&r,gts->g.box->active_border); } GDrawDrawText(pixmap,x+(gts->tabs[i].width-gts->tabs[i].tw)/2,y+gts->rowh-gts->ds, gts->tabs[i].name,-1,fg); gts->tabs[i].x = x; x += gts->tabs[i].width; return( x ); }
static int DrawRightArrowTab(GWindow pixmap, GTabSet *gts, int x, int y ) { Color fg = gts->g.box->main_foreground; GPoint pts[5]; int retx = x + gts->arrow_width, cnt; if ( fg==COLOR_DEFAULT ) fg = GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)); GBoxDrawTabOutline(pixmap,>s->g,x,y,gts->arrow_width,gts->rowh,false); gts->hasrarrow = true; y += (gts->rowh-gts->arrow_size)/2; x += (gts->arrow_width-gts->arrow_size/2)/2; cnt = 4; pts[0].y = (y+(gts->arrow_size-1)/2); pts[0].x = x + (gts->arrow_size-1)/2; pts[1].y = y; pts[1].x = x; pts[2].y = y+gts->arrow_size-1; pts[2].x = pts[1].x; pts[3] = pts[0]; if ( !(gts->arrow_size&1 )) { ++pts[3].y; pts[4] = pts[0]; cnt = 5; } GDrawFillPoly(pixmap,pts,cnt,fg); return( retx ); }
static int gradio_expose(GWindow pixmap, GGadget *g, GEvent *event) { GRadio *gr = (GRadio *) g; int x; GImage *img = gr->image; GResImage *mark; GRect old1, old2, old3; int yoff = (g->inner.height-(gr->fh))/2; if ( g->state == gs_invisible ) return( false ); GDrawPushClip(pixmap,&g->r,&old1); GBoxDrawBackground(pixmap,&g->r,g->box, g->state==gs_enabled? gs_pressedactive: g->state,false); GBoxDrawBorder(pixmap,&g->r,g->box,g->state,false); GDrawPushClip(pixmap,&gr->onoffrect,&old2); GBoxDrawBackground(pixmap,&gr->onoffrect,gr->ison?gr->onbox:gr->offbox, gs_pressedactive,false); GBoxDrawBorder(pixmap,&gr->onoffrect,gr->ison?gr->onbox:gr->offbox, gs_pressedactive,false); mark = NULL; if ( g->state == gs_disabled ) mark = gr->ison ? gr->ondis : gr->offdis; if ( mark==NULL || mark->image==NULL ) mark = gr->ison ? gr->on : gr->off; if ( mark!=NULL && mark->image==NULL ) mark = NULL; if ( mark!=NULL ) { GDrawPushClip(pixmap,&gr->onoffinner,&old3); GDrawDrawScaledImage(pixmap,mark->image, gr->onoffinner.x,gr->onoffinner.y); GDrawPopClip(pixmap,&old3); } else if ( gr->ison && gr->onbox == &checkbox_on_box ) { Color fg = g->state==gs_disabled?g->box->disabled_foreground: g->box->main_foreground==COLOR_DEFAULT?GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)): g->box->main_foreground; int bp = GDrawPointsToPixels(pixmap,gr->onbox->border_width); GDrawDrawLine(pixmap, gr->onoffrect.x+bp,gr->onoffrect.y+bp, gr->onoffrect.x+gr->onoffrect.width-1-bp,gr->onoffrect.y+gr->onoffrect.height-1-bp, fg); GDrawDrawLine(pixmap, gr->onoffrect.x+gr->onoffrect.width-1-bp,gr->onoffrect.y+bp, gr->onoffrect.x+bp,gr->onoffrect.y+gr->onoffrect.height-1-bp, fg); } GDrawPopClip(pixmap,&old2); x = gr->onoffrect.x + gr->onoffrect.width + GDrawPointsToPixels(pixmap,4); GDrawPushClip(pixmap,&g->inner,&old2); if ( gr->font!=NULL ) GDrawSetFont(pixmap,gr->font); if ( gr->image_precedes && img!=NULL ) { GDrawDrawScaledImage(pixmap,img,x,g->inner.y); x += GImageGetScaledWidth(pixmap,img) + GDrawPointsToPixels(pixmap,_GGadget_TextImageSkip); } if ( gr->label!=NULL ) { Color fg = g->state==gs_disabled?g->box->disabled_foreground: g->box->main_foreground==COLOR_DEFAULT?GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)): g->box->main_foreground; int lcnt = gradio_linecount(gr); if ( lcnt>1 ) yoff = (g->inner.height-lcnt*gr->fh)/2; _ggadget_underlineMnemonic(pixmap,x,g->inner.y + gr->as + yoff,gr->label, g->mnemonic,fg,g->inner.y+g->inner.height); x += GDrawDrawBiText(pixmap,x,g->inner.y + gr->as + yoff,gr->label,-1,NULL, fg ); x += GDrawPointsToPixels(pixmap,_GGadget_TextImageSkip); } if ( !gr->image_precedes && img!=NULL ) GDrawDrawScaledImage(pixmap,img,x,g->inner.y); GDrawPopClip(pixmap,&old2); GDrawPopClip(pixmap,&old1); return( true ); }
static int gtabset_expose(GWindow pixmap, GGadget *g, GEvent *event) { GTabSet *gts = (GTabSet *) g; int x,y,i,rd, dsel; GRect old1, bounds; int bw = GBoxBorderWidth(pixmap,g->box); int yoff = ( gts->rcnt==1 ? bw : 0 ); Color fg; int ni = GDrawPointsToPixels(pixmap,NEST_INDENT); if ( g->state == gs_invisible ) return( false ); GDrawPushClip(pixmap,&g->r,&old1); GBoxDrawBackground(pixmap,&g->r,g->box,g->state,false); bounds = g->r; if ( !gts->vertical ) { /* make room for tabs */ bounds.y += gts->rcnt*gts->rowh+yoff-1; bounds.height -= gts->rcnt*gts->rowh+yoff-1; /* draw border around horizontal tabs only */ GBoxDrawBorder(pixmap,&bounds,g->box,g->state,false); } else if ( g->state==gs_enabled ) { /* background for labels */ GRect old2, vertListRect = g->r; vertListRect.width = gts->vert_list_width+bw-1; GDrawPushClip(pixmap,&vertListRect,&old2); GBoxDrawBackground(pixmap,&g->r,g->box,gs_pressedactive,false); GDrawPopClip(pixmap,&old2); } GDrawSetFont(pixmap,gts->font); if ( gts->vertical ) { x = g->r.x + bw + 3; y = g->r.y + bw + 3; for ( i=gts->offtop; i<gts->tabcnt; ++i ) { fg = gts->tabs[i].disabled?gts->g.box->disabled_foreground:gts->g.box->main_foreground; if ( fg==COLOR_DEFAULT ) fg = GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)); if ( i==gts->sel ) { GRect r; r.x = x; r.y = y; r.width = gts->vert_list_width-10; r.height = gts->fh; GDrawFillRect(pixmap,&r,gts->g.box->active_border); } GDrawDrawText(pixmap,x+gts->tabs[i].nesting*ni,y + gts->as,gts->tabs[i].name,-1,fg); y += gts->fh; } fg = gts->g.box->main_foreground; if ( fg==COLOR_DEFAULT ) fg = GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)); GDrawDrawLine(pixmap,x + gts->vert_list_width-4, g->r.y + bw, x + gts->vert_list_width-4, g->r.y + g->r.height - (bw+1), fg); if ( gts->vsb != NULL ) gts->vsb->funcs->handle_expose(pixmap,gts->vsb,event); } else { gts->haslarrow = gts->hasrarrow = false; if ( gts->scrolled ) { x = g->r.x + GBoxBorderWidth(pixmap,gts->g.box); y = g->r.y+yoff; dsel = 0; if ( gts->toff!=0 ) x = DrawLeftArrowTab(pixmap,gts,x,y); for ( i=gts->toff; (i==gts->tabcnt-1 && x+gts->tabs[i].width < g->r.width) || (i<gts->tabcnt-1 && x+gts->tabs[i].width < g->r.width-gts->arrow_width ) ; ++i ) { if ( i!=gts->sel ) x = DrawTab(pixmap,gts,i,x,y); else { gts->tabs[i].x = x; x += gts->tabs[i].width; dsel = 1; } } if ( i!=gts->tabcnt ) { int p = gts->g.inner.x+gts->g.inner.width - gts->arrow_width; if ( p>x ) x=p; x = DrawRightArrowTab(pixmap,gts,x,y); gts->tabs[i].x = 0x7fff; } /* This one draws on top of the others, must come last */ if ( dsel ) DrawTab(pixmap,gts,gts->sel,gts->tabs[gts->sel].x, g->r.y + (gts->rcnt-1) * gts->rowh + yoff ); } else { /* r is real row, rd is drawn pos */ /* rd is 0 at the top of the ggadget */ /* r is 0 when it contains tabs[0], (the index in the rowstarts array) */ for ( rd = 0; rd<gts->rcnt; ++rd ) { int r = (gts->rcnt-1-rd+gts->active_row)%gts->rcnt; y = g->r.y + rd * gts->rowh + yoff; x = g->r.x + (gts->rcnt-1-rd) * gts->offset_per_row + GBoxBorderWidth(pixmap,gts->g.box); for ( i = gts->rowstarts[r]; i<gts->rowstarts[r+1]; ++i ) if ( i==gts->sel ) { gts->tabs[i].x = x; x += gts->tabs[i].width; } else x = DrawTab(pixmap,gts,i,x,y); } /* This one draws on top of the others, must come last */ DrawTab(pixmap,gts,gts->sel,gts->tabs[gts->sel].x, g->r.y + (gts->rcnt-1) * gts->rowh + yoff ); } } if ( gts->nested_expose ) (gts->nested_expose)(pixmap,g,event); GDrawPopClip(pixmap,&old1); return( true ); }
static void draw_arrow(GWindow pixmap, GScrollBar *gsb, int which) { GPoint pts[5]; int point = GDrawPointsToPixels(gsb->g.base,1); int cnt = 4; Color fill = gsb->thumbbox->main_foreground; if ( fill == COLOR_DEFAULT ) fill = GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)); switch ( which ) { case 0: /* Horizontal left arrow */ pts[0].y = (gsb->g.r.y+(gsb->g.r.height-1)/2); pts[0].x = gsb->g.r.x + 2*point; pts[1].y = gsb->g.r.y + point; pts[1].x = pts[0].x + (gsb->g.r.height-1)/2-point ; pts[2].y = gsb->g.r.y+gsb->g.r.height-1 - point; pts[2].x = pts[1].x; pts[3] = pts[0]; if ( !(gsb->g.inner.height&1 )) { ++pts[3].y; pts[4] = pts[0]; cnt = 5; } GDrawFillPoly(pixmap,pts,cnt,fill); GDrawDrawLine(pixmap,pts[0].x,pts[0].y,pts[1].x,pts[1].y, gsb->thumbbox->border_brightest); GDrawDrawLine(pixmap,pts[2].x,pts[2].y,pts[3].x,pts[3].y, gsb->thumbbox->border_darker); GDrawDrawLine(pixmap,pts[1].x,pts[1].y,pts[2].x,pts[2].y, gsb->thumbbox->border_darkest); break; case 1: /* Vertical up arrow */ pts[0].x = (gsb->g.r.x+(gsb->g.r.width-1)/2); pts[0].y = gsb->g.r.y + 2*point; pts[1].x = gsb->g.r.x + point; pts[1].y = pts[0].y + (gsb->g.r.width-1)/2-point ; pts[2].x = gsb->g.r.x+gsb->g.r.width-1 - point; pts[2].y = pts[1].y; pts[3] = pts[0]; if ( !(gsb->g.inner.width&1 )) { ++pts[3].x; pts[4] = pts[0]; cnt = 5; } GDrawFillPoly(pixmap,pts,cnt,fill); GDrawDrawLine(pixmap,pts[0].x,pts[0].y,pts[1].x,pts[1].y, gsb->thumbbox->border_brightest); GDrawDrawLine(pixmap,pts[2].x,pts[2].y,pts[3].x,pts[3].y, gsb->thumbbox->border_darker); GDrawDrawLine(pixmap,pts[1].x,pts[1].y,pts[2].x,pts[2].y, gsb->thumbbox->border_darkest); break; case 2: /* Horizontal right arrow */ pts[0].y = (gsb->g.r.y+(gsb->g.r.height-1)/2); pts[0].x = gsb->g.r.x + gsb->g.r.width-1 - 2*point; pts[1].y = gsb->g.r.y + point; pts[1].x = pts[0].x - ((gsb->g.r.height-1)/2-point); pts[2].y = gsb->g.r.y+gsb->g.r.height-1 - point; pts[2].x = pts[1].x; pts[3] = pts[0]; if ( !(gsb->g.inner.height&1 )) { ++pts[3].y; pts[4] = pts[0]; cnt = 5; } GDrawFillPoly(pixmap,pts,cnt,fill); GDrawDrawLine(pixmap,pts[0].x,pts[0].y,pts[1].x,pts[1].y, gsb->thumbbox->border_darkest); GDrawDrawLine(pixmap,pts[2].x,pts[2].y,pts[3].x,pts[3].y, gsb->thumbbox->border_darker); GDrawDrawLine(pixmap,pts[1].x,pts[1].y,pts[2].x,pts[2].y, gsb->thumbbox->border_brightest); break; case 3: /* Vertical down arrow */ pts[0].x = (gsb->g.r.x+(gsb->g.r.width-1)/2); pts[0].y = gsb->g.r.y + gsb->g.r.height-1 - 2*point; pts[1].x = gsb->g.r.x + point; pts[1].y = pts[0].y - ((gsb->g.r.width-1)/2-point); pts[2].x = gsb->g.r.x+gsb->g.r.width-1 - point; pts[2].y = pts[1].y; pts[3] = pts[0]; if ( !(gsb->g.inner.width&1 )) { ++pts[3].x; pts[4] = pts[0]; cnt = 5; } GDrawFillPoly(pixmap,pts,cnt,fill); GDrawDrawLine(pixmap,pts[0].x,pts[0].y,pts[1].x,pts[1].y, gsb->thumbbox->border_darkest); GDrawDrawLine(pixmap,pts[2].x,pts[2].y,pts[3].x,pts[3].y, gsb->thumbbox->border_darker); GDrawDrawLine(pixmap,pts[1].x,pts[1].y,pts[2].x,pts[2].y, gsb->thumbbox->border_brightest); break; } }
/* Called on expose events, this renders the button. */ static int gradio_expose(GWindow pixmap, GGadget *g, GEvent *event) { GRadio *gr = (GRadio *) g; int x; GImage *img = gr->image; /* the optional image tied to the label */ GResImage *mark; GRect old1, old2, old3; int yoff = (g->inner.height-(gr->fh))/2; if ( g->state == gs_invisible ) return( false ); /* First blank out the button area. */ GDrawPushClip(pixmap,&g->r,&old1); GBoxDrawBackground(pixmap,&g->r,g->box, g->state==gs_enabled? gs_pressedactive: g->state,false); GBoxDrawBorder(pixmap,&g->r,g->box,g->state,false); GDrawPushClip(pixmap,&gr->onoffrect,&old2); GBoxDrawBackground(pixmap,&gr->onoffrect,gr->ison?gr->onbox:gr->offbox, gs_pressedactive,false); if (gr->ison && gr->onbox->border_type!=bt_none) GBoxDrawBorder(pixmap,&gr->onoffrect,gr->onbox, gs_pressedactive,false); else if (!gr->ison && gr->offbox->border_type!=bt_none) GBoxDrawBorder(pixmap,&gr->onoffrect,gr->offbox,gs_pressedactive,false); /* Next draw either the right image or draw in an on or off indicator. */ mark = NULL; if ( g->state == gs_disabled ) mark = gr->ison ? gr->ondis : gr->offdis; /* note: ondis or offdis may be NULL! */ if ( mark==NULL || mark->image==NULL ) mark = gr->ison ? gr->on : gr->off; /* note: on or off may be NULL! */ if ( mark!=NULL && mark->image==NULL ) /* when there's a reference to a special image, but no actual image */ mark = NULL; if ( mark!=NULL ) { GDrawPushClip(pixmap,&gr->onoffinner,&old3); GDrawDrawScaledImage(pixmap,mark->image, gr->onoffinner.x,gr->onoffinner.y); GDrawPopClip(pixmap,&old3); } else if ( gr->ison && gr->onbox == &checkbox_on_box ) { /* for radio buttons where the on is a checkbox style, draw an X */ Color fg = g->state==gs_disabled?g->box->disabled_foreground: g->box->main_foreground==COLOR_DEFAULT?GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)): g->box->main_foreground; int bp = GDrawPointsToPixels(pixmap,gr->onbox->border_width); GDrawDrawLine(pixmap, gr->onoffrect.x+bp,gr->onoffrect.y+bp, gr->onoffrect.x+gr->onoffrect.width-1-bp,gr->onoffrect.y+gr->onoffrect.height-1-bp, fg); GDrawDrawLine(pixmap, gr->onoffrect.x+gr->onoffrect.width-1-bp,gr->onoffrect.y+bp, gr->onoffrect.x+bp,gr->onoffrect.y+gr->onoffrect.height-1-bp, fg); } else if ( gr->ison && gr->onbox == &visibility_on_box ) { /* draw open white of eye */ GPoint pts[15]; Color fg; double angle; int c,i; int bp = gr->onbox->border_type==bt_none ? 0 : GDrawPointsToPixels(pixmap,gr->onbox->border_width); int x=gr->onoffrect.x+bp; int y=gr->onoffrect.y+bp; int w=gr->onoffrect.width -1-2*bp; int h=gr->onoffrect.height-1-2*bp; GRect rect; for (c=0, i=0; c<7; c++) { angle=(30+c/6.*120)*M_PI/180; pts[i].x=.5*w*cos(angle)+x+w/2; pts[i].y=.5*h*sin(angle)+y+h/4; ++i; } for (c=1; c<6; c++) { angle=(180+30+c/6.*120)*M_PI/180; pts[i].x=.5*w*cos(angle)+x+w/2; pts[i].y=.5*h*sin(angle)+y+h*3/4; ++i; } pts[i].x=pts[0].x; pts[i].y=pts[0].y; ++i; fg=0x00ffffff; /* white */ GDrawFillPoly(pixmap, pts, i, fg); fg = g->state==gs_disabled?g->box->disabled_foreground: g->box->main_foreground==COLOR_DEFAULT?GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)): g->box->main_foreground; GDrawDrawPoly(pixmap, pts, i, fg); /* draw pupil */ rect.x=gr->onoffrect.x+bp+w*.3; rect.y=gr->onoffrect.y+bp+h*.3; rect.width =.4*w; rect.height=.4*h; fg=0; /* black */ GDrawFillElipse(pixmap, &rect, fg); } else if ( (!gr->ison) && gr->onbox == &visibility_on_box ) { /* draw closed eye */ GPoint pts[6]; int c,i; double angle; int bp = gr->onbox->border_type==bt_none ? 0 : GDrawPointsToPixels(pixmap,gr->onbox->border_width); int x=gr->onoffrect.x+bp; int y=gr->onoffrect.y+bp; int w=gr->onoffrect.width -1-2*bp; int h=gr->onoffrect.height-1-2*bp; Color fg = g->state==gs_disabled?g->box->disabled_foreground: g->box->main_foreground==COLOR_DEFAULT?GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)): g->box->main_foreground; for (c=0, i=0; c<=6; c++) { angle=(30+c/6.*120)*M_PI/180; pts[i].x=.5*w*cos(angle)+x+w/2; pts[i].y=.5*h*sin(angle)+y+h/4; /* draw lashes */ if (i>0 && i<5) GDrawDrawLine(pixmap, pts[i].x,pts[i].y, .75*w*cos(angle)+x+w/2, .75*h*sin(angle)+y+h/4, fg); ++i; } GDrawDrawPoly(pixmap, pts, i, fg); } GDrawPopClip(pixmap,&old2); x = gr->onoffrect.x + gr->onoffrect.width + GDrawPointsToPixels(pixmap,4); /* Finally write out the label if any. */ GDrawPushClip(pixmap,&g->inner,&old2); if ( gr->font!=NULL ) GDrawSetFont(pixmap,gr->font); if ( gr->image_precedes && img!=NULL ) { GDrawDrawScaledImage(pixmap,img,x,g->inner.y); x += GImageGetScaledWidth(pixmap,img) + GDrawPointsToPixels(pixmap,_GGadget_TextImageSkip); } if ( gr->label!=NULL ) { Color fg = g->state==gs_disabled?g->box->disabled_foreground: g->box->main_foreground==COLOR_DEFAULT?GDrawGetDefaultForeground(GDrawGetDisplayOfWindow(pixmap)): g->box->main_foreground; int lcnt = gradio_linecount(gr); if ( lcnt>1 ) yoff = (g->inner.height-lcnt*gr->fh)/2; _ggadget_underlineMnemonic(pixmap,x,g->inner.y + gr->as + yoff,gr->label, g->mnemonic,fg,g->inner.y+g->inner.height); x += GDrawDrawText(pixmap,x,g->inner.y + gr->as + yoff,gr->label,-1,fg); x += GDrawPointsToPixels(pixmap,_GGadget_TextImageSkip); } if ( !gr->image_precedes && img!=NULL ) GDrawDrawScaledImage(pixmap,img,x,g->inner.y); GDrawPopClip(pixmap,&old2); GDrawPopClip(pixmap,&old1); return( true ); }