void PanelButton::draw() { Fl_Boxtype box = up; Fl_Flags flags; Fl_Color color; if (belowmouse()) { // Highlight button when below mouse flags = FL_HIGHLIGHT; color = highlight_color(); if (!color) color = this->color(); // box = down; } else { flags = 0; color = this->color(); } if (value()) box=down; // Push down button when pressed if(!box->fills_rectangle()) { fl_push_clip(0, 0, this->w(), this->h()); parent()->draw_group_box(); fl_pop_clip(); } box->draw(0, 0, this->w(), this->h(), color, flags); int x,y,w,h; x = y = 0; w = this->w(); h = this->h(); box->inset(x,y,w,h); draw_inside_label(x,y,w,h,flags); }
void PanelMenu::draw() { Fl_Boxtype box = up; Fl_Flags flags; Fl_Color color; if (!active_r()) { // Button is disabled flags = FL_INACTIVE; color = this->color(); } else if (m_open) { // Menu is open, make the button pushed and highlighted flags = FL_HIGHLIGHT; color = highlight_color(); if (!color) color = this->color(); box = down; } else if (belowmouse()) { // Menu is not open, but button is below mouse - highlight flags = FL_HIGHLIGHT; color = highlight_color(); if (!color) color = this->color(); } else { // Plain flags = 0; color = this->color(); } if(!box->fills_rectangle()) { fl_push_clip(0, 0, this->w(), this->h()); parent()->draw_group_box(); fl_pop_clip(); } box->draw(0, 0, this->w(), this->h(), color, flags); int x,y,w,h; x = y = 0; w = this->w(); h = this->h(); box->inset(x,y,w,h); draw_inside_label(x,y,w,h,flags); }
/* Construct a Port on an existing module. */ Port::Port(Module& module, const std::string& name, bool is_input, uint32_t color) : Box(module.canvas(), GANV_BOX( ganv_port_new(module.gobj(), is_input, "fill-color", color, "border-color", highlight_color(color, 0x20), "label", name.c_str(), NULL))) { g_signal_connect(gobj(), "value-changed", G_CALLBACK(on_value_changed), this); }
int Fl_Input_Browser::handle(int e) { int TX, TY = 0, TW, TH = h(); if(type()&NONEDITABLE) { TX = 0; TW = w(); } else { TX = input()->x()+input()->w(); TW = w()-(input()->x()+input()->w()); } if (Fl::event_inside(TX, TY, TW, TH)) over_now = 1; else over_now = 0; if((over_now != over_last) && highlight_color()) redraw(FL_DAMAGE_HIGHLIGHT); if(e == FL_FOCUS) Fl::focus(input()); if((Fl::event_inside(input()->x(), input()->y(), input()->w(), input()->h()) || e == FL_KEY) && !(type()&NONEDITABLE) && Fl::pushed() != this) { if(e == FL_PUSH) { Fl::pushed(input()); Fl::focus(input()); } return input()->send(e);//handle(e); } switch (e) { case FL_PUSH: { if(!win || !win->visible()) popup(); return 1; } case FL_FOCUS: case FL_UNFOCUS: if (type()&NONEDITABLE) break; return input()->handle(e); case FL_ENTER: case FL_MOVE: return 1; } return 0; }
int Fl_Scrollbar::handle(int event) { // area of scrollbar: int X=0; int Y=0; int W=w(); int H=h(); box()->inset(X,Y,W,H); // adjust slider area to be inside the arrow buttons: if (vertical()) { if (H >= 3*W) {Y += W; H -= 2*W;} } else { if (W >= 3*H) {X += H; W -= 2*H;} } // which widget part is highlighted? int mx = Fl::event_x(); int my = Fl::event_y(); int which_part; if (!Fl::event_inside(0, 0, w(), h())) which_part = NOTHING; else if (vertical()) { if (my < Y) which_part = UP_ARROW; else if (my >= Y+H) which_part = DOWN_ARROW; else { int slidery = slider_position(value(), H); if (my < Y+slidery) which_part = ABOVE_SLIDER; else if (my >= Y+slidery+slider_size()) which_part = BELOW_SLIDER; else which_part = SLIDER; } } // horizontal else { if (mx < X) which_part = UP_ARROW; else if (mx >= X+W) which_part = DOWN_ARROW; else { int sliderx = slider_position(value(), W); if (mx < X+sliderx) which_part = ABOVE_SLIDER; else if (mx >= X+sliderx+slider_size()) which_part = BELOW_SLIDER; else which_part = SLIDER; } } switch (event) { case FL_FOCUS: return 0; case FL_ENTER: case FL_MOVE: if (!highlight_color()) return 1; if (which_part != which_highlight) { which_highlight = which_part; redraw(FL_DAMAGE_HIGHLIGHT); } return 1; case FL_LEAVE: if (which_highlight) { which_highlight = 0; redraw(FL_DAMAGE_HIGHLIGHT); } return 1; case FL_PUSH: // Clicking on the slider or middle or right click on the trough // gives us normal slider behavior: if (which_part == SLIDER || Fl::event_button() > 1 && which_part > DOWN_ARROW) { which_pushed = SLIDER; return Fl_Slider::handle(event, X,Y,W,H); } handle_push(); goto J1; case FL_DRAG: if (which_pushed==SLIDER) return Fl_Slider::handle(event, X,Y,W,H); if (which_part == SLIDER) which_part = NOTHING; // it is okay to switch between arrows and nothing, but no other // changes are allowed: if (!which_pushed && which_part <= DOWN_ARROW) ; else if (!which_part && which_pushed <= DOWN_ARROW) ; else which_part = which_pushed; J1: if (which_part != which_pushed) { Fl::remove_timeout(timeout_cb, this); which_highlight = which_pushed = which_part; redraw(FL_DAMAGE_HIGHLIGHT); if (which_part) { Fl::add_timeout(INITIALREPEAT, timeout_cb, this); increment_cb(); } } return 1; case FL_RELEASE: if (which_pushed == SLIDER) { Fl_Slider::handle(event, X,Y,W,H); } else if (which_pushed) { Fl::remove_timeout(timeout_cb, this); handle_release(); redraw(FL_DAMAGE_HIGHLIGHT); } which_pushed = NOTHING; return 1; case FL_MOUSEWHEEL: { float n = (vertical() ? Fl::event_dy() : Fl::event_dx()) * Fl_Style::wheel_scroll_lines * linesize(); if (fabsf(n) > pagesize()) n = (n<0)?-pagesize():pagesize(); handle_drag(value()+n); return 1; } case FL_KEY: if (vertical()) switch(Fl::event_key()) { case FL_Home: handle_drag(maximum()); return 1; case FL_End: handle_drag(minimum()); return 1; case FL_Page_Up: handle_drag(value()-pagesize()); return 1; case FL_Page_Down: handle_drag(value()+pagesize()); return 1; } // else fall through... default: return Fl_Slider::handle(event); } }
void _SeqIndexMetric::DrawOn( BView* view, BRect clip, SeqSongWinPropertiesI& props, float fontHeight) { BRect b(0, mFrame.top, clip.right, mFrame.bottom); float borderL = 1, borderR = 0; float bottomIndent = 5; float stringIndent = 4; float bot = mFrame.top + fontHeight + 2 + bottomIndent + stringIndent; if (bot < mFrame.bottom) b.bottom = bot; rgb_color bgc = background_color(); /* Drawn this way just to get pixel-perfect: The very right edge of * the view should always be drawn with the background color, regardless * of whether or not the track is selected, because a couple pixels * show through behind the mode buttons. */ if (props.Selections() && props.Selections()->IncludesTrack(mTrackId) ) { if (props.IsRecording() ) bgc = recording_highlight_color(); else bgc = highlight_color(); draw_background(view, b, bgc, borderL, borderR, bottomIndent); draw_background(view, BRect(b.right - 4, b.top, b.right, b.bottom), background_color(), borderL, borderR, bottomIndent); } else draw_background(view, b, bgc, borderL, borderR, bottomIndent); /* Clean up the cap */ float absBottom = b.bottom - bottomIndent + 2; view->SetHighColor(0, 0, 0); view->StrokeLine( BPoint(0, b.top + 3), BPoint(0, absBottom) ); /* Cap off if I'm larger then normal. */ float fullBottom = mFrame.bottom - bottomIndent + 2; if (fullBottom > absBottom && clip.right >= mFrame.right) { view->StrokeLine(BPoint(mFrame.right, absBottom), BPoint(mFrame.right, fullBottom)); } /* Draw the label */ view->SetLowColor(bgc); view->SetHighColor( Prefs().Color(AM_ARRANGE_FG_C) ); if (mLabel.Length() > 0) view->DrawString(mLabel.String(), BPoint( b.left + borderL + 2, b.bottom - bottomIndent - stringIndent) ); /* Draw the group indicator. */ if (mGroups > 0) { const char* gname = group_name_from(mGroups); if (gname) { BPoint mutePt = MuteRect().LeftTop(); float w = view->StringWidth("G9"); view->DrawString(gname, BPoint(mutePt.x - w - 1, b.bottom - bottomIndent - stringIndent)); // view->FillRect(BRect(b.left + borderL + 2, mFrame.top, b.left + borderL + 8, mFrame.bottom)); } } /* Draw the mode buttons. */ if (mModeW > 0 && clip.right >= mFrame.right - mModeW) { BPoint mutePt = MuteRect().LeftTop(), soloPt = SoloRect().LeftTop(); drawing_mode mode = view->DrawingMode(); view->SetDrawingMode(B_OP_ALPHA); view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); if (mModeFlags&AmTrack::MUTE_MODE && gMuteOn) view->DrawBitmapAsync(gMuteOn, mutePt); else if (gMuteOff) view->DrawBitmapAsync(gMuteOff, mutePt); if (mModeFlags&AmTrack::SOLO_MODE && gSoloOn) view->DrawBitmapAsync(gSoloOn, soloPt); else if (gSoloOff) view->DrawBitmapAsync(gSoloOff, soloPt); view->SetDrawingMode(mode); } }
int Fl_Button::handle(int event) { static bool oldval; static bool already_pushed=false; bool newval; switch (event) { case FL_LEAVE: case FL_ENTER: if (highlight_color() && takesevents()) redraw(FL_DAMAGE_HIGHLIGHT); case FL_MOVE: return 1; case FL_PUSH: if(!already_pushed) oldval = value(); already_pushed = true; case FL_DRAG: if (Fl::event_inside(0,0,w(),h())) { held_down = this; if (type() == RADIO) newval = true; else newval = !oldval; } else { held_down = 0; newval = oldval; } if (value(newval) && when()&FL_WHEN_CHANGED) do_callback((void*)value()); return 1; case FL_RELEASE: redraw(FL_DAMAGE_VALUE); held_down = 0; already_pushed = false; if (value() == oldval) return 1; if (type() == RADIO) setonly(); else if (type()) // TOGGLE ; // leave it as set else { value(oldval); if (when() & FL_WHEN_CHANGED) do_callback((void*)value()); } if (when() & FL_WHEN_RELEASE) do_callback((void*)value()); else set_changed(); return 1; case FL_UNFOCUS: case FL_FOCUS: redraw(FL_DAMAGE_HIGHLIGHT); // grab initial focus if we are an Fl_Return_Button: return shortcut()=='\r' ? 2 : 1; case FL_SHORTCUT: case FL_KEY: if(event==FL_SHORTCUT && !test_shortcut()) return 0; if(event==FL_KEY && Fl::event_key() != ' ' && Fl::event_key() != FL_Enter ) return 0; if (type() == RADIO/* && !value()*/) { setonly(); if (when() & FL_WHEN_CHANGED) do_callback((void*)value()); } // TOGGLE else if (type()) { value(!value()); if (when() & FL_WHEN_CHANGED) do_callback((void*)value()); } if (when() & FL_WHEN_RELEASE) do_callback((void*)value()); else set_changed(); return 1; default: break; } return Fl_Widget::handle(event); }
// Draw button-like widgets with an optional glyph. The glyph is given // a size (negative to put it on the right) void Fl_Button::draw(int glyph, int glyph_width) const { // Figure out the colors to use. The flags are used by the label and // glyph functions to figure out their colors: Fl_Flags flags; Fl_Color color; if (!active_r()) { flags = FL_INACTIVE; color = this->color(); } else if (belowmouse()) { flags = FL_HIGHLIGHT; color = highlight_color(); if (!color) color = this->color(); } else { flags = 0; color = this->color(); } Fl_Flags glyph_flags = flags; if (glyph_width) { if (this == held_down) flags.set(FL_VALUE); if (value()) glyph_flags.set(FL_VALUE); } else if (value()) { flags.set(FL_VALUE); // Use the pushed-in color if the user has explicitly set it // on this widget: if (style()->selection_color) { color = style()->selection_color; flags.set(FL_SELECTED); // this makes label use selected_text_color() } } bool draw_label = true; int x = 0, y = 0, w = this->w(), h = this->h(); if (box() == FL_NO_BOX) { // If the box is FL_NO_BOX we need to avoid drawing the label so // that it does not blink and does not draw multiple times (which // will make it look bold if antialiasing is on). /* if (!label()) { // don't do anything if no label, so buttons that are an image // only will redraw correctly and with minimum blinking. } else */ if ((damage()&FL_DAMAGE_EXPOSE) || (damage()&FL_DAMAGE_HIGHLIGHT) && !focused()) { // erase the background behind where the label will draw: fl_push_clip(0, 0, w, h); parent()->draw_group_box(); fl_pop_clip(); } else { // Don't draw the label unnecessarily: draw_label = false; } } else { bool drawed = false; if(image() && !image()->get_mask()) { if((align()&FL_ALIGN_TILED || align()&FL_ALIGN_SCALE) && ( !(align()&(FL_ALIGN_LEFT|FL_ALIGN_RIGHT|FL_ALIGN_TOP|FL_ALIGN_BOTTOM)) || (align()&FL_ALIGN_INSIDE) ) ) { // We can draw only frame, if drawing image tiled or scale // And no mask defined to image... draw_frame(); drawed = true; } } if(!drawed) { if (damage()&FL_DAMAGE_EXPOSE && !box()->fills_rectangle()) { fl_push_clip(0, 0, w, h); parent()->draw_group_box(); fl_pop_clip(); } // Draw the box: box()->draw(0, 0, w, h, color, flags); } box()->inset(x,y,w,h); } if (glyph_width < 0) { int g = -glyph_width; draw_glyph(glyph, x+w-g-3, y+((h-g)>>1), g, g, glyph_flags); if (draw_label) draw_inside_label(x, y, w-g-3, h, flags); }
void Fl_Dial::draw() { int X = 0; int Y = 0; int W = w(); int H = h(); if (!(type() == FILL && box() == FL_OVAL_BOX)) { if (damage()&FL_DAMAGE_ALL) draw_box(); box()->inset(X,Y,W,H); } Fl_Color fillcolor = selection_color(); Fl_Color linecolor = highlight_color(); if (!active_r()) { fillcolor = fl_inactive(fillcolor); linecolor = fl_inactive(linecolor); } double angle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1; if (type() == FILL) { if (damage()&FL_DAMAGE_EXPOSE && box() == FL_OVAL_BOX) { fl_push_clip(0, 0, w(), h()); parent()->draw_group_box(); fl_pop_clip(); } fl_color(color()); fl_pie(X, Y, W-1, H-1, 270-a1, angle > a1 ? 360+270-angle : 270-360-angle); fl_color(fillcolor); fl_pie(X, Y, W-1, H-1, 270-angle, 270-a1); if (box() == FL_OVAL_BOX) { fl_ellipse(X, Y, W-1, H-1); fl_color(linecolor); fl_stroke(); } } else { if (!(damage()&FL_DAMAGE_ALL)) { fl_ellipse(X+1, Y+1, W-2, H-2); fl_color(color()); fl_fill(); } fl_push_matrix(); fl_translate(X+W/2-.5, Y+H/2-.5); fl_scale(W-1, H-1); fl_rotate(45-angle); if (type() == LINE) { fl_vertex(0.0, 0.0); fl_vertex(-0.04, 0.0); fl_vertex(-0.25, 0.25); fl_vertex(0.0, 0.04); } else { fl_circle(-0.20, 0.20, 0.07); } fl_color(fillcolor); fl_fill_stroke(linecolor); fl_pop_matrix(); } if (focused()) { fl_ellipse(X+2, Y+2, W-5, H-5); fl_color(linecolor); fl_line_style(FL_DASH); fl_stroke(); fl_line_style(0); } }