static IPTR mLampAskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg) { struct lampData *data = INST_DATA(cl,obj); struct RastPort rp; struct TextExtent te; UWORD w, h, d; DoSuperMethodA(cl,obj,(APTR)msg); CopyMem(&_screen(obj)->RastPort,&rp,sizeof(rp)); /* Don't ask or modify ! */ SetFont(&rp,_font(obj)); TextExtent(&rp," ",2,&te); w = te.te_Width; h = te.te_Height; if (w>=h) d = w; else d = h; data->delta = te.te_Extent.MinY; msg->MinMaxInfo->MinWidth += d; msg->MinMaxInfo->MinHeight += h; msg->MinMaxInfo->DefWidth += d; msg->MinMaxInfo->DefHeight += h; msg->MinMaxInfo->MaxWidth += d; msg->MinMaxInfo->MaxHeight += h; return 0; }
void DrawYTickLabel(Graph *graph, int sx, int sy, float val, float scale, int left, int right) { char format[80]; char label[80]; int tw, th; if (right < 0) { sprintf(format, "%%%dg", -right); } else { sprintf(format, "%%%d.%df", left, right); } /* * Change tick values that are almost zero to zero. * Otherwise adjust them to the scale value. */ if (fabs(val / graph->yaxis_tickinc) < 0.001) val = 0.0; else val *= scale; sprintf(label, format, val); TextExtent(label, &tw, &th); Text((BasicWindow *)graph, sx - tw - 2 * graph->ticksize + graph->yticklabel_offset, sy + th / 2, label); }
IPTR MenuDecorClass__MDM_GETDEFSIZE_SYSIMAGE(Class *cl, Object *obj, struct mdpGetDefSizeSysImage *msg) { switch(msg->mdp_Which) { case SUBMENUIMAGE: *msg->mdp_Width = 0; *msg->mdp_Height = 0; struct RastPort *rp = CreateRastPort(); if (rp) { struct TextExtent TextExt; SetFont(rp, msg->mdp_ReferenceFont); TextExtent(rp, ">>", 2, &TextExt); *msg->mdp_Width = TextExt.te_Width; *msg->mdp_Height = TextExt.te_Height; FreeRastPort(rp); } break; case MENUCHECK: *msg->mdp_Width = REFWIDTH / 2 + 4; // reffont->tf_XSize * 3 / 2; *msg->mdp_Height= REFHEIGHT; break; default: *msg->mdp_Width = DEFSIZE_WIDTH; *msg->mdp_Height = DEFSIZE_HEIGHT; break; } return TRUE; }
uint16 GUI_Font::get_center(const char *text, uint16 width) { int w,h; TextExtent(text, &w, &h); if(w < width) return ((width - w) / 2); else return 0; }
// Update toolbar cache BOOL GetToolBarCache(ToolBarInfo *toolbar,BOOL real) { short depth,width,height,num,x,y; short last_width=0,last_height=0; Cfg_Button *button; struct TagItem tags[4]; struct Rectangle rect; // Invalid toolbar? if (!toolbar) return 0; // Free existing cache FreeToolBarCache(toolbar); // Remap toolbar if this is for real if (real && !toolbar->done_remap) { // Do remap RemapToolBar(toolbar); toolbar->done_remap=1; } // Initialise tags tags[0].ti_Tag=IM_Depth; tags[0].ti_Data=1; tags[1].ti_Tag=IM_Width; tags[1].ti_Data=0; tags[2].ti_Tag=IM_Height; tags[2].ti_Data=0; tags[3].ti_Tag=TAG_DONE; // Minimum depth depth=1; // Count items in toolbar for (button=(Cfg_Button *)toolbar->buttons->buttons.lh_Head,toolbar->count=0; button->node.ln_Succ; button=(Cfg_Button *)button->node.ln_Succ,toolbar->count++); // Allocate position array if (!(toolbar->button_array=AllocVec(sizeof(struct Rectangle)*(toolbar->count+2),MEMF_CLEAR))) { FreeToolBarCache(toolbar); return 0; } // Go through buttons again for (button=(Cfg_Button *)toolbar->buttons->buttons.lh_Head,num=0,toolbar->max_width=0; button->node.ln_Succ; button=(Cfg_Button *)button->node.ln_Succ,num++) { Cfg_ButtonFunction *func; short width,height,x; // Get left button image if ((func=(Cfg_ButtonFunction *) FindFunctionType((struct List *)&button->function_list,FTYPE_LEFT_BUTTON)) && func->image) { // Get depth and other info GetImageAttrs(func->image,tags); // Biggest depth so far? if (tags[0].ti_Data>depth) depth=tags[0].ti_Data; // Get size width=tags[1].ti_Data; height=tags[2].ti_Data; } // Or textual button? else if (!(button->button.flags&BUTNF_GRAPHIC) && func) { struct TextExtent extent; // Get length of label TextExtent(&GUI->screen_pointer->RastPort,func->label,strlen(func->label),&extent); // Get size width=extent.te_Width; height=extent.te_Height; } // Use last size else { width=last_width; height=last_height; } // Minimum size if (width<2) width=8; if (height<2) height=8; // Save size last_width=width; last_height=height; // Increase size for border if (!(toolbar->buttons->window.flags&BTNWF_BORDERLESS)) { width+=2; height+=2; } // Biggest width so far? if (width>toolbar->max_width) toolbar->max_width=width; // Get last position x=(num>0)?toolbar->button_array[num-1].MaxX+1:0; // Store position in array toolbar->button_array[num].MinX=x; toolbar->button_array[num].MinY=0; toolbar->button_array[num].MaxX=x+width-1; toolbar->button_array[num].MaxY=height-1; } // No actual buttons? if (toolbar->count<1 || depth<1) { FreeToolBarCache(toolbar); return 0; } // Store rows/cols toolbar->cols=toolbar->count; toolbar->rows=1; // Valid toolbar arrow? if (GUI->toolbar_arrow_image) { short width,height; // Get size of the arrow button GetImageAttrs(GUI->toolbar_arrow_image,tags); // Biggest depth so far? if (tags[0].ti_Data>depth) depth=tags[0].ti_Data; // Get size width=tags[1].ti_Data; height=tags[2].ti_Data; // Increase size for border if (!(toolbar->buttons->window.flags&BTNWF_BORDERLESS)) { width+=2; height+=2; } // Store size in array toolbar->button_array[toolbar->count].MaxX=width-1; toolbar->button_array[toolbar->count].MaxY=height-1; // Add to maximum width toolbar->max_width+=width; } // Get height of toolbar for (num=0,height=0;num<=toolbar->count;num++) { if ((width=RECTHEIGHT(&toolbar->button_array[num]))>height) height=width; } // Store toolbar height toolbar->button_height=height; // Get cache size toolbar->width=toolbar->button_array[toolbar->count-1].MaxX+1; toolbar->height=toolbar->button_height; // Don't want cache? if (!real) return 1; // Allocate cache bitmap if (!(toolbar->bitmap= NewBitMap( toolbar->width, toolbar->height, depth, BMF_CLEAR, GUI->screen_pointer->RastPort.BitMap))) // 0))) { // Failed FreeToolBarCache(toolbar); return 0; } // Initialise RastPort InitRastPort(&toolbar->rp); toolbar->rp.BitMap=toolbar->bitmap; // Got cache successfully toolbar->cache=1; // Set pens and font SetAPen(&toolbar->rp,1); SetBPen(&toolbar->rp,0); SetFont(&toolbar->rp,GUI->screen_pointer->RastPort.Font); // Initialise draw tags tags[0].ti_Tag=IM_Rectangle; tags[0].ti_Data=(ULONG)▭ tags[1].ti_Tag=IM_ClipBoundary; tags[1].ti_Data=(toolbar->buttons->window.flags&BTNWF_BORDERLESS)?0:2; tags[2].ti_Tag=IM_NoIconRemap; tags[2].ti_Data=(environment->env->desktop_flags&DESKTOPF_NO_REMAP)?TRUE:FALSE; tags[3].ti_Tag=TAG_DONE; // Go through buttons for (button=(Cfg_Button *)toolbar->buttons->buttons.lh_Head,x=0,y=0,num=0; button->node.ln_Succ; button=(Cfg_Button *)button->node.ln_Succ,num++) { Cfg_ButtonFunction *func; BOOL ok=0; // Get button rectangle rect=toolbar->button_array[num]; // Get left button image if ((func=(Cfg_ButtonFunction *)FindFunctionType((struct List *)&button->function_list,FTYPE_LEFT_BUTTON)) && func->image) { // Draw button image RenderImage(&toolbar->rp,func->image,0,0,tags); ok=1; } // Or textual button? else if (!(button->button.flags&BUTNF_GRAPHIC) && func && func->label && *func->label) { // Draw label Move(&toolbar->rp,x,y+toolbar->rp.TxBaseline); Text(&toolbar->rp,func->label,strlen(func->label)); ok=1; } // Draw button border if (!ok || !(toolbar->buttons->window.flags&BTNWF_BORDERLESS)) DrawBox(&toolbar->rp,&rect,GUI->draw_info,0); } return 1; }
void shutdownwnd_open(void) { if ((scr = LockPubScreen(NULL))) { char *filename; /* get a white pen for the color of our text */ pen = ObtainBestPenA(scr->ViewPort.ColorMap,0xffffffff,0xffffffff,0xffffffff,NULL); if ((filename = mycombinepath(gui_get_images_directory(),"shutdown"))) { if ((obj = LoadAndMapPicture("PROGDIR:Images/shutdown",scr))) { struct BitMapHeader *bmhd = NULL; struct BitMap *bitmap = NULL; GetDTAttrs(obj,PDTA_BitMapHeader,&bmhd,TAG_DONE); GetDTAttrs(obj,PDTA_DestBitMap,&bitmap,TAG_DONE); if (!bitmap) GetDTAttrs(obj,PDTA_BitMap,&bitmap,TAG_DONE); if (bmhd && bitmap) { int width = bmhd->bmh_Width; int height = bmhd->bmh_Height; int wndleft,wndtop; wndleft = (scr->Width - width)/2; wndtop = (scr->Height - height)/2; if ((shutdown_wnd = OpenWindowTags(NULL, WA_SmartRefresh, TRUE, WA_NoCareRefresh, TRUE, WA_Borderless, TRUE, WA_Width, width, WA_Height, height, WA_PubScreen, scr, WA_Left, wndleft, WA_Top, wndtop, WA_BackFill, LAYERS_NOBACKFILL, TAG_DONE))) { BltBitMapRastPort(bitmap,0,0, shutdown_wnd->RPort, 0, 0, width, height, 0xc0); if (!user.config.dont_show_shutdown_text) { struct TextExtent te; const char *txt = _("Shutting down..."); SetDrMd(shutdown_wnd->RPort,JAM1); SetAPen(shutdown_wnd->RPort,pen); TextExtent(shutdown_wnd->RPort,txt,strlen(txt),&te); if ((te.te_Width < width) && (te.te_Height < height)) { /* only draw the text if there is enought space for it */ Move(shutdown_wnd->RPort,(width - te.te_Width)/2, height - te.te_Height - 4 + shutdown_wnd->RPort->TxBaseline); Text(shutdown_wnd->RPort,txt,strlen(txt)); } } } } } free(filename); } } }
Att_List *build_text_display(struct Window *window,ObjectList *objlist,char *text) { Att_List *list; struct TextExtent extent; short want_len,max_len,textlen=0,width; char *textpos=0; struct Rectangle rect; char old; // Allocate a new list list=Att_NewList(0); // Get list object size GetObjectRect(objlist,GAD_TEXT_DISPLAY,&rect); width=RECTWIDTH(&rect)-28; // Go through text FOREVER { // No current line? if (!textpos) textpos=text; // Move on from current line else { // Were we on a newline? if (textlen==0) ++textpos; // No else { // Bump pointer textpos+=textlen; // If this leaves us on a newline or space, skip over it if (*textpos=='\n' || *textpos=='\t') ++textpos; } } // End of text? if (!*textpos) break; // If we're on a space, skip over it if (*textpos==' ') ++textpos; // Calculate desired length of the line for (want_len=0;textpos[want_len] && textpos[want_len]!='\n';++want_len); // Blank line? if (want_len==0) { textlen=0; } // Not blank else { // Get maximum length that will actually fit max_len=TextFit( window->RPort, textpos, want_len, &extent, 0,1, width,window->RPort->TxHeight); // Go from here to end of current word want_len=max_len; while ( textpos[want_len] && textpos[want_len]!='\n' && textpos[want_len]!=' ') ++want_len; // Loop until successful do { // Get text size TextExtent(window->RPort,textpos,want_len,&extent); // Will it fit? if (extent.te_Width<=width) { // Save size textlen=want_len; break; } // Come backwards to word break for (--want_len;want_len>0 && textpos[want_len]!=' ';--want_len); // Didn't find one? if (want_len<1) { // Get maximum length want_len=max_len; } } while(1); } // Null out break temporarily old=textpos[textlen]; textpos[textlen]=0; // Add node Att_NewNode(list,textpos,0,0); // Restore character textpos[textlen]=old; } // Add list to display SetGadgetChoices(objlist,GAD_TEXT_DISPLAY,list); return list; }
void TextMultiLine( struct RastPort *rp, char *text, short text_len, short max_width, short flags, struct TextExtent *extent) { short x,startx,y,first=1; // No text? if (!text) return; // Get length if (text_len==-1) text_len=strlen(text); // Get current position x=rp->cp_x; y=rp->cp_y; startx=x; // No maximum width? if (max_width<=rp->Font->tf_XSize) { struct TextExtent ex; // Get extent TextExtent(rp,text,text_len,&ex); // Center? if (flags&TMLF_CENTER) { // Center horizontally x-=ex.te_Width>>1; // Position for text if (!(flags&TMLF_EXTENT)) Move(rp,x,y); } // User wants extent if (extent) { // Fix rectangle ex.te_Extent.MinX=x; ex.te_Extent.MinY=y-rp->TxBaseline; ex.te_Extent.MaxX=x+ex.te_Width-1; ex.te_Extent.MaxY=ex.te_Extent.MinY+ex.te_Height-1; // Get extent *extent=ex; } // Draw if not just getting extent if (!(flags&TMLF_EXTENT)) { Text(rp,text,text_len); } return; }