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); }
void MainMenu::draw() { Fl_Boxtype box = this->box(); Fl_Flags flags; Fl_Color color = this->color(); Fl_Color lcolor = label_color(); if (!active_r()) flags = FL_INACTIVE; else if (m_open) flags = FL_VALUE; else flags = 0; if (belowmouse()) { flags = flags|FL_HIGHLIGHT; color = fl_lighter(color); lcolor = fl_lighter(label_color()); if(!color) color = this->color(); if(!lcolor) color = this->label_color(); } box->draw(0, 0, this->w(), this->h(), color, flags); int X=0, Y=0, W=w(), H=h(); box->inset(X,Y,W,H); if(image()) { int imY = (h()/2)-(image()->height()/2); image()->draw(6, imY, image()->width(), image()->height(), flags); X+=image()->width()+6; } else { X += 4; W -= 4; } fl_font(label_font(), label_size()); label_type()->draw(label(), X, Y, W-X, H, lcolor, flags|FL_ALIGN_LEFT); }
void Fl_Slider::draw() { // figure out the inner size of the box: Fl_Boxtype box = this->box(); int ix = 0, iy = 0, iw = w(), ih = h(); box->inset(ix,iy,iw,ih); // figure out where to draw the slider, leaving room for tick marks: int sx = ix, sy = iy, sw = iw, sh = ih; if (tick_size_ && (type()&TICK_BOTH)) { if (horizontal()) { sh -= tick_size_; switch (type()&TICK_BOTH) { case TICK_BOTH: sy += tick_size_/2; break; case TICK_ABOVE: sy += tick_size_; break; } } else { sw -= tick_size_; switch (type()&TICK_BOTH) { case TICK_BOTH: sx += tick_size_/2; break; case TICK_ABOVE: sx += tick_size_; break; } } } Fl_Flags flags = 0; if (!active_r()) { flags.set(FL_INACTIVE); } else { if (Fl::pushed() == this) flags.set(FL_VALUE); if (belowmouse()) flags.set(FL_HIGHLIGHT); } if(!(fl_current_dev->capabilities() & Fl_Device::CAN_CLIPOUT)) { // draw the box or the visible parts of the window if (!box->fills_rectangle()) parent()->draw_group_box(); box->draw(0, 0, w(), h(), color(), flags); } // minimal-update the slider, if it indicates the background needs // to be drawn, draw that. We draw the slot if the current box type // has no border: if (draw(sx, sy, sw, sh, flags, iy==0)) { if(fl_current_dev->capabilities() & Fl_Device::CAN_CLIPOUT) { // draw the box or the visible parts of the window if (!box->fills_rectangle()) parent()->draw_group_box(); box->draw(0, 0, w(), h(), color(), flags); } // draw the focus indicator inside the box: if (focused()) { focus_box()->draw(ix+1, iy+1, iw-2, ih-2, label_color(), FL_INVISIBLE); } if (type() & TICK_BOTH) { if (horizontal()) { switch (type()&TICK_BOTH) { case TICK_ABOVE: ih = sy+sh/2-iy; break; case TICK_BELOW: ih += iy; iy = sy+sh/2+(iy?0:3); ih -= iy; break; } } else { switch (type()&TICK_BOTH) { case TICK_ABOVE: iw = sx+sw/2-ix; break; case TICK_BELOW: iw += ix; ix = sx+sw/2+(iy?0:3); iw -= ix; break; } } Fl_Color color = text_color(); if (!active_r()) color = fl_inactive(color); fl_color(color); draw_ticks(ix, iy, iw, ih, (slider_size_+1)/2); } fl_pop_clip(); } }
bool Fl::dnd() { // Remember any user presets for the action and types: Atom* types; Atom action; Atom local_source_types[2] = {fl_textplain, 0}; if (fl_dnd_source_types == fl_incoming_dnd_source_types) { types = local_source_types; action = fl_XdndActionCopy; } else { types = fl_dnd_source_types; action = fl_dnd_source_action; } Fl_Window* source_fl_window = Fl::first_window(); Window source_window = fl_xid(source_fl_window); fl_local_grab = grabfunc; Window target_window = 0; Fl_Window* local_window = 0; int version = 4; int dest_x, dest_y; XSetSelectionOwner(fl_display, fl_XdndSelection, fl_message_window, fl_event_time); Fl_Cursor oldcursor = FL_CURSOR_DEFAULT; drop_ok = true; moved = true; while (Fl::pushed()) { // figure out what window we are pointing at: Window new_window = 0; int new_version = 0; Fl_Window* new_local_window = 0; for (Window child = RootWindow(fl_display, fl_screen);;) { Window root; unsigned int junk3; XQueryPointer(fl_display, child, &root, &child, &e_x_root, &e_y_root, &dest_x, &dest_y, &junk3); if (!child) { if (!new_window && (new_version = dnd_aware(root))) new_window = root; break; } new_window = child; if ((new_local_window = fl_find(child))) break; if ((new_version = dnd_aware(new_window))) break; } if (new_window != target_window) { if (local_window) { fl_dnd_source_window = 0; local_handle(FL_DND_LEAVE, local_window); } else if (version) { fl_sendClientMessage(target_window, fl_XdndLeave, source_window); } version = new_version; target_window = new_window; local_window = new_local_window; if (local_window) { fl_dnd_source_window = source_window; fl_dnd_source_types = types; fl_dnd_type = fl_textplain; local_handle(FL_DND_ENTER, local_window); } else if (version) { fl_sendClientMessage(target_window, fl_XdndEnter, source_window, version<<24, types[0], types[1], types[1] ? types[2] : 0); } } if (local_window) { fl_dnd_source_window = source_window; // ?? is this needed? fl_dnd_source_types = types; fl_dnd_action = fl_XdndActionCopy; drop_ok = local_handle(FL_DND_DRAG, local_window); } else if (version) { if (moved) fl_sendClientMessage(target_window, fl_XdndPosition, source_window, 0, (e_x_root<<16)|e_y_root, fl_event_time, fl_dnd_source_action); } else { // Windows that don't support DnD are reported as ok because // we are going to try the middle-mouse click on them: drop_ok = types[0]==fl_textplain; } Fl_Cursor cursor = Fl_Cursor(drop_ok ? 21 : FL_CURSOR_NO); if (cursor != oldcursor) { oldcursor = cursor; source_fl_window->cursor(cursor); } moved = false; Fl::wait(); } if (!drop_ok) ; else if (local_window) { fl_i_own_selection[0] = true; if (local_handle(FL_DND_RELEASE, local_window)) paste(*belowmouse(),false); } else if (version) { fl_sendClientMessage(target_window, fl_XdndDrop, source_window, 0, fl_event_time); } else if (target_window) { // fake a drop by clicking the middle mouse button: XButtonEvent msg; msg.type = ButtonPress; msg.window = target_window; msg.root = RootWindow(fl_display, fl_screen); msg.subwindow = 0; msg.time = fl_event_time+1; msg.x = dest_x; msg.y = dest_y; msg.x_root = Fl::e_x_root; msg.y_root = Fl::e_y_root; msg.state = 0x0; msg.button = Button2; XSendEvent(fl_display, target_window, False, 0L, (XEvent*)&msg); msg.time++; msg.state = 0x200; msg.type = ButtonRelease; XSendEvent(fl_display, target_window, False, 0L, (XEvent*)&msg); } fl_local_grab = 0; if (oldcursor) source_fl_window->cursor(FL_CURSOR_DEFAULT); // reset the action and type: fl_dnd_source_types = fl_incoming_dnd_source_types; return drop_ok; }
// 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); }