void MessageBox::add_button(Fl_Button* b, MessageBoxButtonType bt) { E_RETURN_IF_FAIL(nbuttons < MSGBOX_MAX_BUTTONS); E_RETURN_IF_FAIL(b != NULL); int W = 0, H = 0; fl_font(b->labelfont(), b->labelsize()); fl_measure(b->label(), W, H); if(W > 90) { W += 10; // some spaces between label an button edges if(bt == MSGBOX_BUTTON_RETURN) W += 30; // increase again since Fl_Return_Button have that stupid marker else W += 10; // ordinary button b_start -= W; } else { W = 90; b_start -= W; } b->resize(b_start, 75, W, 25); b_start -= 5; // space between buttons gr->add(b); buttons[nbuttons] = b; nbuttons++; }
void Icon::update_all() { Fl_Config &iconConfig = *cfg; iconConfig.read_file(false); iconConfig.set_section("Desktop Entry"); // Icon Label: icon_name = get_localized_name(iconConfig); tooltip(icon_name); label(icon_name); label_color(label_foreground); label_size(label_fontsize); lwidth = label_maxwidth; // This is a bit strange, but otherwise we get mysterious crashes... lheight= 0; fl_font(label_font(), label_size()); fl_measure(icon_name, lwidth, lheight, FL_ALIGN_WRAP); lwidth += 4; // height+= 4; // Icon file: iconConfig.read("Icon", icon_file, "folder.png"); update_icon(); redraw(); //desktop->redraw(); }
void CInstaller::SetTitle(const std::string &t) { int w = m_pTitle->w(), h = 0; int minheaderh = (m_pLogoBox) ? (m_pLogoBox->y() + m_pLogoBox->h() + HeaderSpacing()) : 50; fl_font(m_pTitle->labelfont(), m_pTitle->labelsize()); fl_measure(t.c_str(), w, h); minheaderh = std::max(minheaderh, h); m_pTitle->size(m_pTitle->w(), minheaderh); m_pTitle->label(MakeCString(t)); if (m_pHeaderGroup->h() != minheaderh) { // Center logo (if any) if (m_pLogoBox) { const int y = ((minheaderh - m_pLogoBox->h()) / 2); m_pLogoBox->position(m_pLogoBox->x(), y); } m_pHeaderGroup->size(m_pHeaderGroup->w(), minheaderh); m_pWizard->size(m_pWizard->w(), m_pCancelButton->y()-minheaderh-ButtonHSpacing()); } }
void Fl_TooltipBox::layout() { fl_font(label_font(), label_size()); int ww, hh; ww = MAX_WIDTH; fl_measure(tip, ww, hh, FL_ALIGN_LEFT|FL_ALIGN_WRAP|FL_ALIGN_INSIDE); ww += 6; hh += 6; // find position on the screen of the widget: int ox = Fl::event_x_root(); //int ox = X+W/2; int oy = Y + H+2; for (Fl_Widget* p = widget; p; p = p->parent()) { //ox += p->x(); oy += p->y(); } if (ox+ww > Fl::w()) ox = Fl::w() - ww; if (ox < 0) ox = 0; if (H > 30) { oy = Fl::event_y_root()+13; if (oy+hh > Fl::h()) oy -= 23+hh; } else { if (oy+hh > Fl::h()) oy -= (4+hh+H); } if (oy < 0) oy = 0; resize(ox, oy, ww, hh); Fl_Menu_Window::layout(); }
void SetButtonWidth(Fl_Button *button) { const int spacing = 50; int w = 0, h = 0; fl_font(button->labelfont(), button->labelsize()); fl_measure(button->label(), w, h); button->size(w+spacing, button->h()); }
void Flu_Choice_Group :: draw() { int i; // make sure the selected child is still a child bool found = false; for( i = 1; i < children(); i++ ) if( child(i) == selected ) { found = true; break; } if( !found ) selected = NULL; if( !selected && children() > 1 ) value( child(1) ); int lblW = 0, lblH = 0, X; for( i = 1; i < children(); i++ ) { int W = 0, H; fl_measure( child(i)->label(), W, H ); if( W > lblW ) lblW = W; if( H > lblH ) lblH = H; } lblW += 26; lblH += 6; // align the label if( align() & FL_ALIGN_LEFT ) X = 4; else if( align() & FL_ALIGN_RIGHT ) X = w() - lblW - 8; else X = w()/2 - lblW/2 - 2; // draw the main group box if( damage() & ~FL_DAMAGE_CHILD ) fl_draw_box( box(), x(), y()+lblH/2, w(), h()-lblH/2, color() ); // clip and draw the children choice->resize( choice->x(), choice->y(), 0, 0 ); fl_clip( x()+2, y()+lblH+1, w()-4, h()-lblH-3 ); draw_children(); fl_pop_clip(); // clear behind the button and draw it fl_color( color() ); fl_rectf( x()+X, y(), lblW+4, lblH ); fl_color( labelcolor() ); choice->resize( x()+X+2, y(), lblW, lblH ); draw_child( *choice ); }
static void label_measure(const Fl_Label* o, int& W, int& H) { fl_font(o->font, o->size); fl_measure(o->value, W, H); W += MENU_ICON_W+3; if (W > MAX_MENU_WIDTH) W = MAX_MENU_WIDTH; if (H < MENU_ICON_H) H = MENU_ICON_H; }
void value(float f) { sprintf(tip, "%.2f", f); // Recalc size of window fl_font(labelfont(), labelsize()); int W = w(), H = h(); fl_measure(tip, W, H, 0); W += 8; size(W, H); redraw(); }
void NotifyBox::update_label_size(void) { lwidth = MAX_LABEL_WIDTH; lheight= 0; fl_font(txt_box->labelfont(), txt_box->labelsize()); fl_measure(txt_box->label(), lwidth, lheight, txt_box->align()); lwidth += 10; lheight += 10; }
void Icon::update_label_size(void) { lwidth = globals->label_maxwidth; lheight= 0; fl_font(label_font(), label_size()); fl_measure(label(), lwidth, lheight, FL_ALIGN_WRAP); lwidth += 8; lheight += 4; }
void MapsWindow::MapArea::MapInfoWin::info(std::string const& info) { info_ = info; fl_font(Fl_Tooltip::font(), Fl_Tooltip::size()); int W = 0; int H = 0; fl_measure(info_.c_str(), W, H, 0); size(W + 2*MARGIN, H + 2*MARGIN); redraw(); }
static void frame_label_measure(const Fl_Label* o, int& W, int& H) { Frame* f = (Frame*)(o->value); if (window_deleted(f)) {W = MENU_ICON_W+3; H = MENU_ICON_H; return;} const char* l = f->label(); if (!l) l = "unnamed"; fl_font(o->font, o->size); fl_measure(l, W, H); W += MENU_ICON_W+3; if (W > MAX_MENU_WIDTH) W = MAX_MENU_WIDTH; if (H < MENU_ICON_H) H = MENU_ICON_H; }
void Flu_Collapsable_Group :: draw() { int X; FluSimpleString l = open() ? "- " : "+ "; l += label(); button.label( l.c_str() ); // force fit the button if necessary if( _fit ) button.size( w()-12, button.labelsize()+6 ); else { // otherwise make it as big as its label int W = 0, H = 0; fl_font( button.labelfont(), button.labelsize() ); fl_measure( button.label(), W, H ); button.size( W+6, button.h() ); } // align the button if( align() & FL_ALIGN_LEFT ) X = 4; else if( align() & FL_ALIGN_RIGHT ) X = w() - button.w() - 8; else X = w()/2 - button.w()/2 - 2; // draw the main group box if( damage() & ~FL_DAMAGE_CHILD ) fl_draw_box( box(), x(), y()+button.h()/2, w(), h()-button.h()/2, color() ); // clip and draw the internal group fl_clip( x()+2, y()+button.h()+1, w()-4, h()-button.h()-3 ); if( _changing ) { if( !_open ) group.resize( x(), y()-_originalHeight+(int)_currentHeight+_BUTTON_HEIGHT, w(), _originalHeight ); else group.resize( x(), y()-_newHeight+(int)_currentHeight+_BUTTON_HEIGHT, w(), _newHeight ); } draw_child( group ); fl_pop_clip(); // clear behind the button, resize, and draw fl_color( color() ); fl_rectf( x()+X, y(), button.w()+4, button.h() ); button.position( x()+X+2, y() ); draw_child( button ); button.label( 0 ); }
// FLTK.measure(text) // Get the width and height of a string, according to the last call to FLTK.font. mrb_value mrb_fltk_measure_module_method( mrb_state *mrb, mrb_value self ) { int width = 0; int height = 0; char *text; mrb_get_args( mrb, "z", &text ); fl_measure( text, width, height ); mrb_value result = mrb_hash_new( mrb ); mrb_hash_set( mrb, result, mrb_symbol_value( mrb_intern_cstr( mrb, "width" ) ), mrb_fixnum_value( width ) ); mrb_hash_set( mrb, result, mrb_symbol_value( mrb_intern_cstr( mrb, "height" ) ), mrb_fixnum_value( height ) ); return result; }
void Fl_Rotated_Text::set(const char *text, Fl_Font font, int size, uchar align, int rotation){ uncache(); if(alloc_array) delete[] ar2; ar2 = 0; array = 0; alloc_array = 0; delete[] text_; text_=0; font_ = font; size_ = size; align_ = align; if(!text || !(*text)){ w(0); h(0); return; } text_ = new char[strlen(text) + 1]; strcpy(text_, text); if(rotation >9) rot_ = (uchar)(((rotation+45)/90) % 4); else rot_ = (uchar) (rotation & 3); int w_ = 0; int h_ = 0; int old_font = fl_font(); int old_size = fl_size(); fl_font(font,size); fl_measure(text_,w_,h_,0); // assure that w() and h() are always available fl_font(old_font,old_size); h_ += fl_height()/2; if(rot_ & 1){ w(h_); h(w_); }else{ w(w_); h(h_); } };
void MessageBox::fix_sizes(void) { int W = MAX_TXT_W, H = 0, step = 0; int xdiff = 0, ydiff = 0; // This means that last added button goes beyond X=10 (in negative). if(b_start < 10) step = -b_start + 5; // 5 is addition as diff from edge fl_font(txt->labelfont(), txt->labelsize()); fl_measure(txt->label(), W, H); if(W > txt->w()) xdiff = W - txt->w(); else W = txt->w(); // use MIN_TXT_W if(H > img->h()) { ydiff = H - img->h(); if(inpt) ydiff += 30; // uh... } else { // use size from img if(!inpt) H = img->h(); else H = txt->h(); // or default size, so it can nice lay with inpt } if(inpt) inpt->resize(inpt->x(), inpt->y() + ydiff, W + step, inpt->h()); txt->size(W + step, H); // force group to not resize any children or will mess everything up gr->resizable(0); gr->size(w() + xdiff + step, h() + ydiff); size(w() + xdiff + step, h() + ydiff); for(int n = 0; n < nbuttons; n++) buttons[n]->position(buttons[n]->x() + xdiff + step, buttons[n]->y() + ydiff); }
void DesktopIcon::update_label_size(void) { labelsize(gsettings->label_fontsize); lwidth = gsettings->label_maxwidth; lheight= 0; /* * make sure current font size/type is set (internaly to fltk) * so fl_measure() can correctly calculate label width and height */ int old = fl_font(); int old_sz = fl_size(); fl_font(labelfont(), labelsize()); fl_measure(label(), lwidth, lheight, align()); fl_font(old, old_sz); lwidth += 12; lheight += 5; }
void IconBox::set_icon_path(const String& s) { char* ptr; int W = 0, H = 0, len; iconpth.assign(s); /* get basename without extension */ ptr = strrchr(s.c_str(), E_DIR_SEPARATOR); if(ptr) { ptr += 1; char* ptr2 = strrchr(ptr, '.'); if(ptr2) *ptr2 = '\0'; } else { ptr = _("(unknown)"); } iconname = strdup(ptr); len = strlen(iconname); fl_measure(iconname, W, H); if(W > w() && len > 10) { /* copy as label so we can modify it */ copy_label(iconname); ptr = (char*)(label() + 10); /* end label string with '...' */ *ptr = '\0'; *(ptr - 1) = '.'; *(ptr - 2) = '.'; *(ptr - 3) = '.'; } else { label(iconname); } align(FL_ALIGN_INSIDE); tooltip(iconname); }
void TaskButton::draw(void) { Fl_Color col = value() ? selection_color() : color(); draw_box(value() ? (down_box() ? down_box() : fl_down(box())) : box(), col); if(image()) { int X, Y, lw, lh; X = x() + 5; Y = (y() + h() / 2) - (image()->h() / 2); image()->draw(X, Y); X += image()->w() + 5; if(label()) { fl_font(labelfont(), labelsize()); fl_color(labelcolor()); lw = lh = 0; fl_measure(label(), lw, lh, 0); /* use clipping so long labels do not be drawn on the right border, which looks ugly */ fl_push_clip(x() + Fl::box_dx(box()), y() + Fl::box_dy(box()), w() - Fl::box_dw(box()) - 5, h() - Fl::box_dh(box())); Y = (y() + h() / 2) - (lh / 2); fl_draw(label(), X, Y, lw, lh, align(), 0, 0); fl_pop_clip(); } } else { draw_label(); } if(Fl::focus() == this) draw_focus(); }
void CInstaller::CreateHeader() { m_pHeaderGroup = new Fl_Group(0, 0, WindowW(), 50); // Dummy height, real height is set at the end m_pHeaderGroup->color(FL_WHITE); m_pHeaderGroup->box(FL_FLAT_BOX); m_pHeaderGroup->resizable(NULL); /* Fl_Shared_Image *img = Fl_Shared_Image::get(GetLogoFName()); if (img) { m_pLogoBox = new Fl_Box(HeaderSpacing(), HeaderSpacing(), img->w()+HeaderSpacing(), img->h()); m_pLogoBox->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE); m_pLogoBox->image(img); }*/ int w = 0, h = 0; const char *text = GetTranslation("About"); m_pAboutBox = new CFLTKHyperLink(0, 0, 0, 0, text); m_pAboutBox->labelsize(10); m_pAboutBox->callback(ShowAboutCB, this); m_pAboutBox->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE); fl_font(m_pAboutBox->labelfont(), m_pAboutBox->labelsize()); fl_measure(text, w, h); m_pAboutBox->resize(WindowW() - w - HeaderSpacing(), 0, w, h); int x = (m_pLogoBox) ? m_pLogoBox->x() + m_pLogoBox->w() : 0; x += HeaderSpacing(); w = m_pAboutBox->x() - x - HeaderSpacing(); m_pTitle = new Fl_Box(x, 0, w, 0); // Height is set when title is set m_pTitle->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_WRAP); m_pTitle->labelsize(18); m_pHeaderGroup->end(); h = (m_pLogoBox) ? (m_pLogoBox->y() + m_pLogoBox->h() + HeaderSpacing()) : 50; m_pHeaderGroup->size(m_pHeaderGroup->w(), h); }
/* * The layout() was modified from original Fl_Tooltip, as y coordinate is not remembered any more * and mouse y position is used as referent point. This is because remembered y would dump tooltip * window around, since originally, the tooltip was shown on the same place as possible; with menus * this isn't possible. */ void TooltipWin::layout() { fl_font(Fl_Tooltip::font(), Fl_Tooltip::size()); int ww, hh; ww = MAX_WIDTH; fl_measure(tip, ww, hh, FL_ALIGN_LEFT|FL_ALIGN_WRAP|FL_ALIGN_INSIDE); ww += 6; hh += 6; int ox = Fl::event_x_root() + 10; int oy = Fl::event_y_root() + 10; int scr_x, scr_y, scr_w, scr_h; Fl::screen_xywh(scr_x, scr_y, scr_w, scr_h); if (ox+ww > scr_x+scr_w) ox = scr_x+scr_w - ww; if (ox < scr_x) ox = scr_x; if (H > 30) { oy = Fl::event_y_root()+13; if (oy+hh > scr_y+scr_h) oy -= 23+hh; } else { if (oy+hh > scr_y+scr_h) oy -= (4+hh+H); } if (oy < scr_y) oy = scr_y; resize(ox, oy, ww, hh); }
FL_EXPORT_C(void,flc_measure)(const char* str,int* x,int* y){ *x = 0; *y = 0; fl_measure(str,*x,*y); }
void tabbar::draw() { const u32 startx = x(); const u32 endx = x() + w() - 1; const u32 gradarea = h() - 2; u32 i, j; // bg u32 r1 = 63, g1 = 72, b1 = 81; u32 r2 = 38, g2 = 48, b2 = 59; for (i = 0; i <= gradarea; i++) { const float pos = i / (float) gradarea; fl_color(mix(r1, r2, pos), mix(g1, g2, pos), mix(b1, b2, pos)); const u32 posy = y() + 1 + i; fl_line(startx, posy, endx, posy); } // Borders fl_color(37, 46, 52); fl_line(startx, y(), endx, y()); fl_line(startx, y() + h() - 1, endx, y() + h() - 1); // Tabs u32 max; u32 tabw = calctabw(&max, w()); bool highborder = false; if ((mousex - x()) % tabw > tabw / 2) highborder = true; u32 posx = x(); const u32 lowy = y(); const u32 highy = y() + h() - 1; for (i = 0; i < max; i++) { bool hover = false; // Borders fl_color(FL_BLACK); if (!i) fl_line(posx, lowy, posx, highy); fl_line(posx + tabw, lowy, posx + tabw, highy); // Bg r1 = 83, g1 = 92, b1 = 101; r2 = 58, g2 = 68, b2 = 79; if (i == g->curtab) { r1 = 100, g1 = 160, b1 = 191; r2 = 42, g2 = 100, b2 = 125; } else if ((mousein && mousex >= posx && mousex <= (posx + tabw - 1)) || (!firstpress && longorder.size() && longorder[longpress] == i)) { r1 = 150, g1 = 150, b1 = 191; r2 = 100, g2 = 100, b2 = 155; hover = true; } if (dragging && mousein && mousex >= posx && mousex <= (posx + tabw - 1)) { fl_color(FL_WHITE); if (!highborder) fl_line(posx, lowy, posx, highy); else fl_line(posx + tabw, lowy, posx + tabw, highy); } for (j = 0; j <= gradarea; j++) { const float pos = j / (float) gradarea; fl_color(mix(r1, r2, pos), mix(g1, g2, pos), mix(b1, b2, pos)); const u32 posy = y() + 1 + j; fl_line(posx + 1, posy, posx + tabw - 1, posy); } // Icon Fl_Image *img = g->tabs[i].icon; if (!img) img = Fl_Shared_Image::get("newtab.png"); const u32 imgy = y() + (h() - 16) / 2; img->draw(posx + 4, imgy, 16, 16); // Text fl_color(200, 200, 200); if (i == g->curtab) fl_color(FL_WHITE); else if (hover) fl_color(230, 230, 230); fl_font(labelfont(), labelsize()); char tmp[80]; memset(tmp, 0, 80); strncpy(tmp, g->tabs[i].title(), 79); int textw = 0, texth = 0; fl_measure(tmp, textw, texth, 0); const u32 textarea = tabw - 2 - 8 - 16 - 4; while ((u32) textw >= textarea) { // Shorten it until it fits const u32 len = strlen(tmp) - 1; tmp[len] = '\0'; tmp[len - 1] = '.'; tmp[len - 2] = '.'; tmp[len - 3] = '.'; textw = texth = 0; fl_measure(tmp, textw, texth, 0); } const u32 texty = y() - fl_descent() + fl_height() + (h() - fl_height())/2; fl_draw(tmp, posx + 2 + 8 + 16, texty); posx += tabw; } }
static void measure_cb(const Fl_Label *o, int &w, int &h) { fl_font(o->font, o->size); fl_measure(o->value, w, h, 0); }
// Anybody can call this to force the label to draw anywhere, this is // used by Fl_Group and Fl_Tabs to draw outside labels: void Fl_Widget::draw_label(int X, int Y, int W, int H, Fl_Flags flags) const { fl_font(label_font(), float(label_size())); if (!active_r()) flags.set(FL_INACTIVE); Fl_Color color; // Figure out if alignment puts the label inside the widget: if (!(this->flags()&15) || (this->flags() & FL_ALIGN_INSIDE)) { // yes, inside label is affected by selection or highlight: if (flags&FL_SELECTED) color = selection_text_color(); else if (flags&FL_HIGHLIGHT && highlight_label_color()) color = highlight_label_color(); else color = label_color(); if (focused()) flags.set(FL_SELECTED); } else { color = label_color(); } if (flags & FL_ALIGN_CLIP) fl_push_clip(X, Y, W, H); if (image_) { fl_color(fl_inactive(color, flags)); if(flags & FL_ALIGN_TILED || flags & FL_ALIGN_SCALE) { image_->draw(X, Y, W, H, flags); } else { int w = W; int h = H; image_->measure(w, h); // If all the flags are off, draw the image and label centered "nicely" // by measuring their total size and centering that rectangle: if (!(flags & (FL_ALIGN_LEFT|FL_ALIGN_RIGHT|FL_ALIGN_TOP|FL_ALIGN_BOTTOM| FL_ALIGN_INSIDE)) && !label_.empty()) { int d = (H-int(h+fl_height()))>>1; if (d >= 0) { // put the image atop the text Y += d; H -= d; flags.set(FL_ALIGN_TOP); } else { // put image to left int text_w = W; int text_h = H; fl_measure(label_.c_str(), text_w, text_h, flags); int d = (W-(h+text_w))>>1; if (d > 0) {X += d; W -= d;} flags.set(FL_ALIGN_LEFT); } } int cx,cy; // point in image to put at X,Y if (flags & FL_ALIGN_RIGHT) { cx = w-W; if (flags & FL_ALIGN_LEFT && cx < 0) cx = 0; } else if (flags & FL_ALIGN_LEFT) cx = 0; else cx = w/2-W/2; if (flags & FL_ALIGN_BOTTOM) { cy = h-H; if (flags & FL_ALIGN_TOP && cy < 0) cy = 0; } else if (flags & FL_ALIGN_TOP) cy = 0; else cy = h/2-H/2; image_->draw(X-cx, Y-cy, W, H, 0,0,0,0,flags); // figure out the rectangle that remains for text: if (flags & FL_ALIGN_LEFT) { X += (w+2); W -= (w+4); } else if (flags & FL_ALIGN_RIGHT) W -= (w+4); else if (flags & FL_ALIGN_TOP) {Y += h; H -= h;} else if (flags & FL_ALIGN_BOTTOM) H -= h; else { /*flags |= FL_ALIGN_TOP;*/ Y += (h-cy); H -= (h-cy); } } }
void Fl_Align_Group::layout() { Fl_Widget::layout(); if(!children()) return; int i; int n_lines = n_to_break() ? (children() / n_to_break() + (children() % n_to_break()?1:0)) : 1; bool variable_is_y = (align() & (FL_ALIGN_TOP|FL_ALIGN_BOTTOM)) != 0; int nx = vertical() ? n_lines : n_to_break() ? n_to_break() : children(); int ny = vertical() ? n_to_break() ? n_to_break() : children() : n_lines; int n_variable = variable_is_y ? ny : nx; uchar label_space[256]; memset(label_space,0,n_variable*sizeof(uchar)); int u=0, v=0; int total_label_space=0; int numchildren = children(); if (align()) { for (i = 0; i < numchildren; i++) { Fl_Widget* o = child(i); fl_font(o->label_font(), o->label_size()); int w = this->w()-o->w(),h = this->h()-o->h(); fl_measure(o->label().c_str() ,w,h,o->flags()); if (variable_is_y) w = h; int which = (variable_is_y == vertical()) ? u : v; if (label_space[which] < w) label_space[which] = w; if (++u == n_to_break()) {u = 0; v++;} } for (i = 0; i<n_variable; i++) total_label_space+=label_space[i]; } int W = (w() - (variable_is_y ? 0:total_label_space) - (nx + 1)*dw()) / nx; int H = (h() - (variable_is_y ? total_label_space:0) - (ny + 1)*dh()) / ny; int cx = dw(), cy = dh(); int icx = cx, icy = cy; u = v = 0; for (i = 0; i < numchildren; i++) { Fl_Widget* o = child(i); int which = (variable_is_y == vertical()) ? u : v; int X = cx, Y = cy; if (align() & FL_ALIGN_TOP) Y += label_space[which]; else if (!variable_is_y && align() & FL_ALIGN_LEFT) X += label_space[which]; o->resize(X,Y,W,H); o->align(align()); o->layout(); if (++u == n_to_break()) { u = 0; v++; if (vertical()) { cx += W+dw(); cy = icy; if (!variable_is_y) cx += label_space[which]; } else { cy += H+dh(); cx = icx; if (variable_is_y) cy += label_space[which]; } } else { if (vertical()) { cy += H+dh(); if (variable_is_y) cy += label_space[which]; } else { cx += W+dw(); if (!variable_is_y) cx += label_space[which]; } } } init_sizes(); }
/// Draw this item and its children. void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, const Fl_Tree_Prefs &prefs, int lastchild) { if ( ! _visible ) return; fl_font(_labelfont, _labelsize); int H = _labelsize + fl_descent() + prefs.linespacing(); // Colors, fonts Fl_Color fg = _selected ? prefs.bgcolor() : _labelfgcolor; Fl_Color bg = _selected ? prefs.selectcolor() : _labelbgcolor; if ( ! _active ) { fg = fl_inactive(fg); if ( _selected ) bg = fl_inactive(bg); } // Update the xywh of this item _xywh[0] = X; _xywh[1] = Y; _xywh[2] = W; _xywh[3] = H; // Text size int textw=0, texth=0; fl_measure(_label, textw, texth, 0); int textycenter = Y+(H/2); int &icon_x = _collapse_xywh[0] = X-1; int &icon_y = _collapse_xywh[1] = textycenter - (prefs.openicon()->h()/2); int &icon_w = _collapse_xywh[2] = prefs.openicon()->w(); _collapse_xywh[3] = prefs.openicon()->h(); // Horizontal connector values int hstartx = X+icon_w/2-1; int hendx = hstartx + prefs.connectorwidth(); int hcenterx = X + icon_w + ((hendx - (X + icon_w)) / 2); // See if we should draw this item // If this item is root, and showroot() is disabled, don't draw. // char drawthis = ( is_root() && prefs.showroot() == 0 ) ? 0 : 1; if ( drawthis ) { // Draw connectors if ( prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) { // Horiz connector between center of icon and text draw_horizontal_connector(hstartx, hendx, textycenter, prefs); if ( has_children() && is_open() ) { // Small vertical line down to children draw_vertical_connector(hcenterx, textycenter, Y+H, prefs); } // Connectors for last child if ( ! is_root() ) { if ( lastchild ) { draw_vertical_connector(hstartx, Y, textycenter, prefs); } else { draw_vertical_connector(hstartx, Y, Y+H, prefs); } } } // Draw collapse icon if ( has_children() && prefs.showcollapse() ) { // Draw icon image if ( is_open() ) { prefs.closeicon()->draw(icon_x,icon_y); } else { prefs.openicon()->draw(icon_x,icon_y); } } // Background for this item int &bx = _label_xywh[0] = X+(icon_w/2-1+prefs.connectorwidth()); int &by = _label_xywh[1] = Y; int &bw = _label_xywh[2] = W-(icon_w/2-1+prefs.connectorwidth()); int &bh = _label_xywh[3] = texth; // Draw bg only if different from tree's bg if ( bg != tree->color() || is_selected() ) { if ( is_selected() ) { // Selected? Use selectbox() style fl_draw_box(prefs.selectbox(), bx, by, bw, bh, bg); } else { // Not Selected? use plain filled rectangle fl_color(bg); fl_rectf(bx, by, bw, bh); } } // Draw user icon (if any) int useroff = (icon_w/2-1+prefs.connectorwidth()); if ( usericon() ) { // Item has user icon? Use it useroff += prefs.usericonmarginleft(); usericon()->draw(X+useroff,icon_y); useroff += usericon()->w(); } else if ( prefs.usericon() ) { // Prefs has user icon? Use it useroff += prefs.usericonmarginleft(); prefs.usericon()->draw(X+useroff,icon_y); useroff += prefs.usericon()->w(); } useroff += prefs.labelmarginleft(); // Draw label if ( widget() ) { // Widget? Draw it int lx = X+useroff; int ly = by; int lw = widget()->w(); int lh = bh; if ( widget()->x() != lx || widget()->y() != ly || widget()->w() != lw || widget()->h() != lh ) { widget()->resize(lx, ly, lw, lh); // fltk will handle drawing this } } else { // No label widget? Draw text label if ( _label ) { fl_color(fg); fl_draw(_label, X+useroff, Y+H-fl_descent()-1); } } Y += H; } // end drawthis // Draw children if ( has_children() && is_open() ) { int child_x = drawthis ? // offset children to right, (hcenterx - (icon_w/2) + 1) : X; // unless didn't drawthis int child_w = W - (child_x-X); int child_y_start = Y; for ( int t=0; t<children(); t++ ) { int lchild = ((t+1)==children()) ? 1 : 0; _children[t]->draw(child_x, Y, child_w, tree, prefs, lchild); } if ( has_children() && is_open() ) { Y += prefs.openchild_marginbottom(); // offset below open child tree } if ( ! lastchild ) { draw_vertical_connector(hstartx, child_y_start, Y, prefs); } } }
void Ca_Y_Axis::draw(){ if(min_==max_) return; int BD = 0; Fl_Widget * W_ = this; if(canvas_){ BD = canvas_->border(); W_ = canvas_; }else if(widget_){ W_ = widget_; } int tick_index=-1; double tick_value; int tick_order;//,tick_number; double _interval=0; const char * label_format=label_format_; // if(damage()|FL_DAMAGE_ALL) // draw_label(); if (damage()&(FL_DAMAGE_ALL|CA_DAMAGE_ALL)){ update(); if (box()==FL_NO_BOX){ fl_color(parent()->color()); fl_rectf(x(),y(),w(),h()); }else draw_box(); if(!valid_) return; fl_font(label_font_face_,label_font_size_); int l1=0; int l2=0; int m1=0; int m2=0; int l=0; int _x=0; int _w,_h; //temporary coordinates for ticks double _pos,_y; //fl_clip(x()+Fl::box_dx(box()),y()+Fl::box_dy(box()),w()-Fl::box_dw(box()),h()-Fl::box_dh(box())); fl_color(axis_color_); int a=x()+Fl::box_dx(box())+border_; int b=a+w()-Fl::box_dw(box())-2*border_; switch(axis_align_ & CA_ALIGNMENT){ case CA_RIGHT: l=l1=m1=a; if(axis_align_&CA_NO_TICS) m2=m1; else if (tick_length_) m2=m1+tick_length_; else m2=m1+label_font_size_; l2=(l1+m2)/2; break; case CA_LEFT: l=l2=m2=b-1; if(axis_align_&CA_NO_TICS) m1=m2; else if (tick_length_) m1=m2-tick_length_; else m1=m2-label_font_size_; l1=(m1+m2)/2; break; case CA_CENTER: m1=a; m2=b; l=(a+b)/2; l1=(a+l)/2; l2=(l+b)/2; break; } fl_line_style(FL_SOLID|FL_CAP_FLAT,tick_width_); // double minp,maxp; double start_tick; double end_tick; bool tick_not_started = 1; while(next_tick(tick_index, tick_value, tick_order, _interval)){ _pos=position(tick_value); if(scale_&CA_REV){ if((_pos+1)<min_pos_-BD) continue; if((_pos-1)>max_pos_+BD) break; }else{ if((_pos+1)<max_pos_-BD) break; if((_pos-1)>min_pos_+BD) continue; } if(!(axis_align_&CA_NO_TICS)){ fl_begin_loop(); if(tick_index % major_step_){ fl_vertex(l1,_pos); fl_vertex(l2,_pos); }else{ fl_vertex(m1,_pos); fl_vertex(m2,_pos); } fl_end_loop(); if(tick_not_started){ tick_not_started = 0; start_tick = _pos; } end_tick = _pos; } if(!((tick_index % label_step_)|(axis_align_&CA_NO_LABELS))){ char label[MAX_LABEL_LENGTH]; char _label_format[MAX_LABEL_FORMAT]; if(!label_format){ int _tick_order; if (tick_order>=0) _tick_order=0; else _tick_order=-tick_order - 1; sprintf(_label_format,"%s.%if","%",_tick_order); } else strcpy(_label_format,label_format); sprintf(label, _label_format,tick_value); fl_measure(label,_w,_h); _y=_pos+_h/3; switch (axis_align_ & CA_ALIGNMENT){ case CA_LEFT: _x=m1-_h/3-_w; break; case CA_RIGHT: _x=m2+_h/3; break; case CA_CENTER: _x=(m1+m2)/2-_w/2; Fl_Color _color=fl_color(); fl_color(color()); ca_rectf(_x-_h/6,_pos-_h/2,_w+_h/3,_h); fl_color(_color); break; } ca_text(label,_x,_y); } } if((axis_align_ & CA_LINE) && !tick_not_started){ fl_begin_line(); fl_vertex(l,start_tick); fl_vertex(l,end_tick); //fl_vertex(l,W_->y()+Fl::box_dy(W_->box())); //fl_vertex(l,W_->y()+W_->h()+Fl::box_dy(W_->box())-Fl::box_dh(W_->box())); fl_end_line(); } fl_line_style(0); //fl_pop_clip(); } };
// modified explicitly from Fl_Return_Button.cpp void Flu_Button :: draw() { if( type() == FL_HIDDEN_BUTTON ) return; if( !active() ) Fl_Button::color( col ); // draw the link text if( linkBtn ) { fl_draw_box( box(), x(), y(), w(), h(), color() ); labelSize[0] = labelSize[1] = labelSize[2] = labelSize[3] = 0; fl_font( labelfont(), labelsize() ); fl_measure( label(), labelSize[2], labelSize[3], 1 ); labelSize[0] += 2; labelSize[1] += h()/2 - labelsize()/2 - 2; fl_color( labelcolor() ); fl_draw( label(), x()+labelSize[0], y()+labelSize[1], labelSize[2], labelSize[3], FL_ALIGN_LEFT ); if( !overLink || ( overLink && hover ) ) { fl_line_style( FL_SOLID ); fl_line( x()+labelSize[0], y()+labelSize[1]+labelSize[3]-2, x()+labelSize[0]+labelSize[2], y()+labelSize[1]+labelSize[3]-2 ); fl_line_style( 0 ); } return; } Fl_Image *tmp = 0; if( active() && image_follows_value() ) { if( !value() ) { tmp = Fl_Button::image(); Fl_Button::image( Fl_Button::deimage() ); } } else if( active() && value() && downImg ) { tmp = Fl_Button::image(); Fl_Button::image( downImg ); } const char *lbl = label(); if( retBtn ) label(""); if( eBox != FL_NO_BOX && Fl::belowmouse() == this && active() ) { Fl_Boxtype oldbox = box(); box( eBox ); Fl_Button::draw(); box( oldbox ); } else Fl_Button::draw(); if( retBtn ) { int W = h(); if (w()/3 < W) W = w()/3; flu_return_arrow(x()+w()-W-4, y(), W, h()); label( lbl ); draw_label(x(), y(), w()-W+4, h()); } if( tmp ) Fl_Button::image( tmp ); }
FL_EXPORT_C(void,flc_measure_with_draw_symbols)(const char* str,int* x,int* y,int draw_symbols){ *x = 0; *y = 0; fl_measure(str,*x,*y,draw_symbols); }