Пример #1
0
static void GProgressDraw(GProgress *p,GWindow pixmap,GRect *rect) {
    GRect r, old;
    int width, amount;

    GDrawPushClip(pixmap,rect,&old);
    GDrawSetFont(pixmap,p->font);
    if ( p->line1!=NULL )
	GDrawDrawText(pixmap, (p->width-p->l1width)/2, p->l1y, p->line1, -1,
		progress_foreground );
    if ( p->line2!=NULL )
	GDrawDrawText(pixmap, (p->width-p->l2width)/2, p->l2y, p->line2, -1,
		progress_foreground );

    r.x = GDrawPointsToPixels(pixmap,10);
    r.y = p->boxy;
    r.height = r.x;
    width = p->width-2*r.x;
    
    if ( p->tot==0 )
	amount = 0;
    else
	amount = width * (p->stage*p->tot + p->sofar)/(p->stages*p->tot);
    if ( amount>0 ) {
	r.width = amount;
	GDrawFillRect(pixmap,&r,progress_fillcol);
    } else if ( p->tot==0 ) {
	r.width = width;
	GDrawSetStippled(pixmap,1,0,0);
	GDrawFillRect(pixmap,&r,progress_fillcol);
	GDrawSetStippled(pixmap,0,0,0);
    }
    r.width = width;
    GDrawDrawRect(pixmap,&r,progress_foreground);
    GDrawPopClip(pixmap,&old);
}
Пример #2
0
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,&gts->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 );
}
Пример #3
0
static int splash_e_h(GWindow gw, GEvent *event) {
    static int splash_cnt;
    GRect old;
    int i, y, x;
    static char *foolishness[] = {
/* GT: These strings are for fun. If they are offensive or incomprehensible */
/* GT: simply translate them as something dull like: "FontForge" */
/* GT: This is a spoof of political slogans, designed to point out how foolish they are */
	    N_("A free press discriminates\nagainst the illiterate."),
	    N_("A free press discriminates\nagainst the illiterate."),
/* GT: This is a pun on the old latin drinking song "Gaudeamus igature!" */
	    N_("Gaudeamus Ligature!"),
	    N_("Gaudeamus Ligature!"),
/* GT: Spoof on the bible */
	    N_("In the beginning was the letter..."),
/* GT: Some wit at MIT came up with this ("ontology recapitulates phylogony" is the original) */
	    N_("fontology recapitulates file-ogeny")
    };

    switch ( event->type ) {
      case et_create:
	GDrawGrabSelection(gw,sn_user1);
      break;
      case et_expose:
	GDrawPushClip(gw,&event->u.expose.rect,&old);
	GDrawDrawImage(gw,&splashimage,NULL,0,0);
	GDrawSetFont(gw,splash_font);
	y = splashimage.u.image->height + as + fh/2;
	for ( i=1; i<linecnt; ++i ) {
	    if ( is>=lines[i-1]+1 && is<lines[i] ) {
		x = 8+GDrawDrawText(gw,8,y,lines[i-1]+1,is-lines[i-1]-1,0x000000);
		GDrawSetFont(gw,splash_italic);
		GDrawDrawText(gw,x,y,is,lines[i]-is,0x000000);
	    } else if ( ie>=lines[i-1]+1 && ie<lines[i] ) {
		x = 8+GDrawDrawText(gw,8,y,lines[i-1]+1,ie-lines[i-1]-1,0x000000);
		GDrawSetFont(gw,splash_font);
		GDrawDrawText(gw,x,y,ie,lines[i]-ie,0x000000);
	    } else
		GDrawDrawText(gw,8,y,lines[i-1]+1,lines[i]-lines[i-1]-1,0x000000);
	    y += fh;
	}
	GDrawPopClip(gw,&old);
      break;
      case et_map:
	splash_cnt = 0;
      break;
      case et_timer:
	if ( event->u.timer.timer==autosave_timer ) {
	    DoAutoSaves();
	} else if ( event->u.timer.timer==splasht ) {
	    if ( ++splash_cnt==1 )
		GDrawResize(gw,splashimage.u.image->width,splashimage.u.image->height-30);
	    else if ( splash_cnt==2 )
		GDrawResize(gw,splashimage.u.image->width,splashimage.u.image->height);
	    else if ( splash_cnt>=7 ) {
		GGadgetEndPopup();
		GDrawSetVisible(gw,false);
		GDrawCancelTimer(splasht);
		splasht = NULL;
	    }
	} else {
	    DoDelayedEvents(event);
	}
      break;
      case et_char:
      case et_mousedown:
      case et_close:
	GGadgetEndPopup();
	GDrawSetVisible(gw,false);
      break;
      case et_mousemove:
	GGadgetPreparePopup8(gw,_(foolishness[rand()%(sizeof(foolishness)/sizeof(foolishness[0]))]) );
      break;
      case et_selclear:
	/* If this happens, it means someone wants to send us a message with a*/
	/*  filename to open. So we need to ask for it, process it, and then  */
	/*  take the selection back again */
	if ( event->u.selclear.sel == sn_user1 ) {
	    int len;
	    char *arg;
	    arg = GDrawRequestSelection(splashw,sn_user1,"STRING",&len);
	    if ( arg==NULL )
return( true );
	    if ( strcmp(arg,"-new")==0 || strcmp(arg,"--new")==0 )
		FontNew();
	    else if ( strcmp(arg,"-open")==0 || strcmp(arg,"--open")==0 )
		_FVMenuOpen(NULL);
	    else if ( strcmp(arg,"-quit")==0 || strcmp(arg,"--quit")==0 )
		MenuExit(NULL,NULL,NULL);
	    else
		ViewPostScriptFont(arg,0);
	    free(arg);
	    GDrawGrabSelection(splashw,sn_user1);
	}
      break;
      case et_destroy:
	IError("Who killed the splash screen?");
      break;
    }
return( true );
}
Пример #4
0
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 );
}
Пример #5
0
/* 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 );
}