void BitmapButton::draw(const Point& p_pos,const Size& p_size,const Rect& p_exposed) { switch( get_draw_mode() ) { case DRAW_NORMAL: { if (normal) get_painter()->draw_bitmap( normal, Point() ); } break; case DRAW_PRESSED: { BitmapID bm = pressed>=0 ? pressed : normal; if (bm) get_painter()->draw_bitmap( bm, Point() ); } break; case DRAW_HOVER: { BitmapID bm = hover>=0 ? hover : normal; if (bm) get_painter()->draw_bitmap( bm, Point() ); } break; } if (icon>=0) get_painter()->draw_bitmap( icon, (p_size-get_painter()->get_bitmap_size(icon))/2 ); }
void OptionButton::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { if (!has_icon("arrow")) return; RID ci = get_canvas_item(); Ref<Texture> arrow = Control::get_icon("arrow"); Ref<StyleBox> normal = get_stylebox("normal"); Color clr = Color(1, 1, 1); if (get_constant("modulate_arrow")) { switch (get_draw_mode()) { case DRAW_PRESSED: clr = get_color("font_color_pressed"); break; case DRAW_HOVER: clr = get_color("font_color_hover"); break; case DRAW_DISABLED: clr = get_color("font_color_disabled"); break; default: clr = get_color("font_color"); } } Size2 size = get_size(); Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2))); arrow->draw(ci, ofs, clr); } }
void Button::draw(const Point& p_pos,const Size& p_size,const Rect& p_exposed) { Painter *p=get_painter(); /* Draw Outline */ //if disabled... bool draw_displaced=false; DrawMode draw_mode=get_draw_mode(); if (draw_mode==DRAW_HOVER) { //optative, otherwise draw normal if (stylebox( SB_BUTTON_HOVER ).mode!=StyleBox::MODE_NONE && (!is_toggle_mode() || (is_toggle_mode() && !is_pressed()))) { p->draw_stylebox( stylebox( SB_BUTTON_HOVER ) , Point() , p_size, p_exposed ); } else draw_mode=is_pressed()?DRAW_PRESSED:DRAW_NORMAL; } ; if (draw_mode==DRAW_NORMAL) { p->draw_stylebox( stylebox( SB_BUTTON_NORMAL ) , Point() , p_size, p_exposed ); } if (draw_mode==DRAW_PRESSED) { p->draw_stylebox( stylebox( SB_BUTTON_PRESSED ) , Point() , p_size, p_exposed ); draw_displaced=true; } Rect area_rect=Rect( p_pos, p_size ); area_rect.pos.x=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_LEFT ); area_rect.pos.y=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_TOP ); area_rect.size-=area_rect.pos; area_rect.size.x-=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_RIGHT ); area_rect.size.y-=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_BOTTOM ); area_rect.size.x-=constant( C_BUTTON_EXTRA_MARGIN )*2; area_rect.pos.x+=constant( C_BUTTON_EXTRA_MARGIN ); area_rect.size.y-=constant( C_BUTTON_EXTRA_MARGIN )*2; area_rect.pos.y+=constant( C_BUTTON_EXTRA_MARGIN ); area_rect.size.x-=constant( C_BUTTON_DISPLACEMENT ); area_rect.size.y-=constant( C_BUTTON_DISPLACEMENT ); if (draw_displaced) area_rect.pos+=Point( constant( C_BUTTON_DISPLACEMENT ), constant( C_BUTTON_DISPLACEMENT ) ); if (constant(C_BUTTON_HAS_CHECKBOX)) { Size cbsize; if ( constant( C_BUTTON_CHECKBOX_SIZE )>0 ) { cbsize.width+=constant( C_BUTTON_CHECKBOX_SIZE ); cbsize.height+=constant( C_BUTTON_CHECKBOX_SIZE ); } else { cbsize=p->get_bitmap_size( bitmap( BITMAP_BUTTON_UNCHECKED ) ); } Point check_pos=area_rect.pos; check_pos.y+=(area_rect.size.height-cbsize.height)/2; if ( constant( C_BUTTON_CHECKBOX_SIZE )>0 ) { p->draw_stylebox( stylebox( is_pressed() ? SB_BUTTON_CHECKED : SB_BUTTON_UNCHECKED ) , check_pos , cbsize); } else { p->draw_bitmap( bitmap( is_pressed() ? BITMAP_BUTTON_CHECKED : BITMAP_BUTTON_UNCHECKED ), check_pos ); } area_rect.pos.x+=cbsize.x+constant( C_BUTTON_SEPARATION ); area_rect.size.x-=cbsize.x+constant( C_BUTTON_SEPARATION ); } if (get_icon() >=0 && p->is_bitmap_valid( get_icon() )) { Size icon_size=p->get_bitmap_size( get_icon() ); Point icon_pos=area_rect.pos; icon_pos.y+=(area_rect.size.height-icon_size.height)/2; p->draw_bitmap( get_icon(), icon_pos ); area_rect.pos.x+=icon_size.width; area_rect.size.x-=icon_size.width; if (label_text!="") { area_rect.pos.x+=constant( C_BUTTON_SEPARATION ); //separation for the label area_rect.size.x-=constant( C_BUTTON_SEPARATION ); //separation for the label } } if (shortcut!=0) { String s_str = Keyboard::get_code_name( shortcut ); int w = p->get_font_string_width( font(FONT_BUTTON), s_str ); Point shrc_ofs= area_rect.pos; shrc_ofs.y+=(area_rect.size.height-p->get_font_height( font( FONT_BUTTON ) ))/2+p->get_font_ascent( font( FONT_BUTTON ) ); shrc_ofs.x = (area_rect.pos.x+area_rect.size.x)-w; p->draw_text( font( FONT_BUTTON ) , shrc_ofs, s_str, color(COLOR_BUTTON_SHORTCUT_FONT) ); area_rect.size.x-=w; } Point label_ofs=area_rect.pos; if (constant(C_BUTTON_LABEL_ALIGN_CENTER)) { label_ofs.x+=(area_rect.size.width-p->get_font_string_width( font( FONT_BUTTON ) , label_text ))/2; } label_ofs.y+=(area_rect.size.height-p->get_font_height( font( FONT_BUTTON ) ))/2+p->get_font_ascent( font( FONT_BUTTON ) ); p->draw_text( font( FONT_BUTTON ) , label_ofs, label_text, color(draw_mode==DRAW_HOVER?COLOR_BUTTON_FONT_HOVER:COLOR_BUTTON_FONT) ); if (accel_char >= 0) { int width = 0; for (int i=0; i<accel_char; i++) { width += p->get_font_char_width(font( FONT_BUTTON ), label_text[i]); }; p->draw_text( font( FONT_BUTTON ) , label_ofs + Point(width, 0), "_", color(COLOR_BUTTON_FONT) ); }; if (has_focus()) p->draw_stylebox( stylebox( SB_BUTTON_FOCUS ) , Point() , p_size, p_exposed); }
void TextureButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { DrawMode draw_mode = get_draw_mode(); Ref<Texture> texdraw; switch (draw_mode) { case DRAW_NORMAL: { if (normal.is_valid()) texdraw = normal; } break; case DRAW_PRESSED: { if (pressed.is_null()) { if (hover.is_null()) { if (normal.is_valid()) texdraw = normal; } else texdraw = hover; } else texdraw = pressed; } break; case DRAW_HOVER: { if (hover.is_null()) { if (pressed.is_valid() && is_pressed()) texdraw = pressed; else if (normal.is_valid()) texdraw = normal; } else texdraw = hover; } break; case DRAW_DISABLED: { if (disabled.is_null()) { if (normal.is_valid()) texdraw = normal; } else texdraw = disabled; } break; } if (texdraw.is_valid()) { Point2 ofs; Size2 size = texdraw->get_size(); Rect2 tex_regin = Rect2(Point2(), texdraw->get_size()); bool tile = false; if (expand) { switch (stretch_mode) { case STRETCH_KEEP: size = texdraw->get_size(); break; case STRETCH_SCALE: size = get_size(); break; case STRETCH_TILE: size = get_size(); tile = true; break; case STRETCH_KEEP_CENTERED: ofs = (get_size() - texdraw->get_size()) / 2; size = texdraw->get_size(); break; case STRETCH_KEEP_ASPECT_CENTERED: case STRETCH_KEEP_ASPECT: { Size2 _size = get_size(); float tex_width = texdraw->get_width() * _size.height / texdraw->get_height(); float tex_height = _size.height; if (tex_width > _size.width) { tex_width = _size.width; tex_height = texdraw->get_height() * tex_width / texdraw->get_width(); } if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) { ofs.x = (_size.width - tex_width) / 2; ofs.y = (_size.height - tex_height) / 2; } size.width = tex_width; size.height = tex_height; } break; case STRETCH_KEEP_ASPECT_COVERED: { size = get_size(); Size2 tex_size = texdraw->get_size(); Size2 scaleSize(size.width / tex_size.width, size.height / tex_size.height); float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height; Size2 scaledTexSize = tex_size * scale; Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f; tex_regin = Rect2(ofs, size / scale); } break; } } if (tile) draw_texture_rect(texdraw, Rect2(ofs, size), tile); else draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin); } if (has_focus() && focused.is_valid()) { Rect2 drect(Point2(), get_size()); draw_texture_rect(focused, drect, false); }; } break; } }
void LinkButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Size2 size = get_size(); Color color; bool do_underline = false; //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode())); switch (get_draw_mode()) { case DRAW_NORMAL: { color = get_color("font_color"); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; case DRAW_PRESSED: { if (has_color("font_color_pressed")) color = get_color("font_color_pressed"); else color = get_color("font_color"); do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_HOVER: { color = get_color("font_color_hover"); do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_DISABLED: { color = get_color("font_color_disabled"); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; } if (has_focus()) { Ref<StyleBox> style = get_stylebox("focus"); style->draw(ci, Rect2(Point2(), size)); } Ref<Font> font = get_font("font"); draw_string(font, Vector2(0, font->get_ascent()), text, color); if (do_underline) { int underline_spacing = get_constant("underline_spacing"); int width = font->get_string_size(text).width; int y = font->get_ascent() + underline_spacing; draw_line(Vector2(0, y), Vector2(width, y), color); } } break; } }
void Button::_notification(int p_what) { if (p_what==NOTIFICATION_DRAW) { RID ci = get_canvas_item(); Size2 size=get_size(); Color color; //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode())); switch( get_draw_mode() ) { case DRAW_NORMAL: { if (!flat) get_stylebox("normal" )->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color"); } break; case DRAW_PRESSED: { get_stylebox("pressed" )->draw( ci, Rect2(Point2(0,0), size) ); if (has_color("font_color_pressed")) color=get_color("font_color_pressed"); else color=get_color("font_color"); } break; case DRAW_HOVER: { get_stylebox("hover" )->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_hover"); } break; case DRAW_DISABLED: { get_stylebox("disabled" )->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_disabled"); } break; } if (has_focus()) { Ref<StyleBox> style = get_stylebox("focus"); style->draw(ci,Rect2(Point2(),size)); } Ref<StyleBox> style = get_stylebox("normal" ); Ref<Font> font=get_font("font"); Ref<Texture> _icon; if (icon.is_null() && has_icon("icon")) _icon=Control::get_icon("icon"); else _icon=icon; Point2 icon_ofs = (!_icon.is_null())?Point2( _icon->get_width() + get_constant("hseparation"), 0):Point2(); int text_clip=size.width - style->get_minimum_size().width - icon_ofs.width; Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size( text ) )/2.0; switch(align) { case ALIGN_LEFT: { text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x; text_ofs.y+=style->get_offset().y; } break; case ALIGN_CENTER: { if (text_ofs.x<0) text_ofs.x=0; text_ofs+=icon_ofs; text_ofs+=style->get_offset(); } break; case ALIGN_RIGHT: { text_ofs.x=size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size( text ).x; text_ofs.y+=style->get_offset().y; } break; } text_ofs.y+=font->get_ascent(); font->draw( ci, text_ofs.floor(), text, color,clip_text?text_clip:-1); if (!_icon.is_null()) { int valign = size.height-style->get_minimum_size().y; _icon->draw(ci,style->get_offset()+Point2(0, Math::floor( (valign-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) ); } } }
void PlaybackButton::draw(const Point& p_pos,const Size& p_size,const Rect& p_exposed) { Painter *p=get_painter(); /* Draw Outline */ //if disabled... bool draw_displaced=false; switch( get_draw_mode() ) { case DRAW_HOVER: { //optative, otherwise draw normal if (stylebox( SB_PLAYBACK_BUTTON_HOVER ).mode!=StyleBox::MODE_NONE) { p->draw_stylebox( stylebox( SB_PLAYBACK_BUTTON_HOVER ) , Point() , p_size, p_exposed ); break; } } case DRAW_NORMAL: { p->draw_stylebox( stylebox( SB_PLAYBACK_BUTTON_NORMAL ) , Point() , p_size, p_exposed ); } break; case DRAW_PRESSED: { p->draw_stylebox( stylebox( SB_PLAYBACK_BUTTON_PRESSED ) , Point() , p_size, p_exposed ); draw_displaced=true; } break; } Rect area_rect=Rect( p_pos, p_size ); area_rect.pos.x=p->get_stylebox_margin( stylebox( SB_PLAYBACK_BUTTON_NORMAL ), MARGIN_LEFT ); area_rect.pos.y=p->get_stylebox_margin( stylebox( SB_PLAYBACK_BUTTON_NORMAL ), MARGIN_TOP ); area_rect.size-=area_rect.pos; area_rect.size.x-=p->get_stylebox_margin( stylebox( SB_PLAYBACK_BUTTON_NORMAL ), MARGIN_RIGHT ); area_rect.size.y-=p->get_stylebox_margin( stylebox( SB_PLAYBACK_BUTTON_NORMAL ), MARGIN_BOTTOM ); area_rect.size.x-=constant( C_PLAYBACK_BUTTON_DISPLACEMENT ); area_rect.size.y-=constant( C_PLAYBACK_BUTTON_DISPLACEMENT ); if (draw_displaced) area_rect.pos+=Point( constant( C_PLAYBACK_BUTTON_DISPLACEMENT ), constant( C_PLAYBACK_BUTTON_DISPLACEMENT ) ); if (constant( C_PLAYBACK_BUTTON_ARROW_SIZE )>0) { Point pos=area_rect.pos; Size size=area_rect.size; switch(type) { case TYPE_REWIND: { size.x/=2; get_painter()->draw_arrow( pos, size, LEFT, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ) ); pos.x+=size.x; get_painter()->draw_arrow( pos, size, LEFT, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ) ); } break; case TYPE_PLAY: { get_painter()->draw_arrow( pos, size, RIGHT, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ), false ); } break; case TYPE_STOP: { int ofs=size.width/8; size.width-=ofs*2; size.height-=ofs*2; pos.x+=ofs; pos.y+=ofs; get_painter()->draw_fill_rect( pos, size, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ) ); } break; case TYPE_FORWARD: { size.x/=2; get_painter()->draw_arrow( pos, size, RIGHT, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ) ); pos.x+=size.x; get_painter()->draw_arrow( pos, size, RIGHT, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ) ); } break; case TYPE_PLAY_PATTERN: { get_painter()->draw_arrow( pos, size, DOWN, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ), false ); } break; case TYPE_PLAY_CURSOR: { get_painter()->draw_arrow( pos, Size(size.x,size.y/2), DOWN, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ), false ); get_painter()->draw_arrow( pos+Point(0,size.y/2), Size(size.x,size.y/2), DOWN, color( COLOR_PLAYBACK_BUTTON_ARROW_COLOR ), false ); } break; } } else { //draw some pixmap } if (has_focus()) p->draw_stylebox( stylebox( SB_PLAYBACK_BUTTON_FOCUS ) , Point() , p_size, p_exposed); }
void ArrowButton::draw(const Point& p_pos,const Size& p_size,const Rect& p_exposed) { Painter *p=get_painter(); /* Draw Outline */ //if disabled... bool draw_displaced=false; switch( get_draw_mode() ) { case DRAW_HOVER: { //optative, otherwise draw normal if (stylebox( SB_ARROWBUTTON_HOVER ).mode!=StyleBox::MODE_NONE) { p->draw_stylebox( stylebox( SB_ARROWBUTTON_HOVER ) , Point() , p_size, p_exposed ); break; } } case DRAW_NORMAL: { p->draw_stylebox( stylebox( SB_ARROWBUTTON_NORMAL ) , Point() , p_size, p_exposed ); } break; case DRAW_PRESSED: { p->draw_stylebox( stylebox( SB_ARROWBUTTON_PRESSED ) , Point() , p_size, p_exposed ); draw_displaced=true; } break; } Rect area_rect=Rect( p_pos, p_size ); area_rect.pos.x=p->get_stylebox_margin( stylebox( SB_ARROWBUTTON_NORMAL ), MARGIN_LEFT ); area_rect.pos.y=p->get_stylebox_margin( stylebox( SB_ARROWBUTTON_NORMAL ), MARGIN_TOP ); area_rect.size-=area_rect.pos; area_rect.size.x-=p->get_stylebox_margin( stylebox( SB_ARROWBUTTON_NORMAL ), MARGIN_RIGHT ); area_rect.size.y-=p->get_stylebox_margin( stylebox( SB_ARROWBUTTON_NORMAL ), MARGIN_BOTTOM ); area_rect.size.x-=constant( C_ARROWBUTTON_DISPLACEMENT ); area_rect.size.y-=constant( C_ARROWBUTTON_DISPLACEMENT ); if (draw_displaced) area_rect.pos+=Point( constant( C_ARROWBUTTON_DISPLACEMENT ), constant( C_ARROWBUTTON_DISPLACEMENT ) ); if (constant( C_ARROWBUTTON_ARROW_SIZE )>0) { get_painter()->draw_arrow( area_rect.pos, area_rect.size, dir, color( COLOR_ARROWBUTTON_ARROW_COLOR ) ); } else { //draw some pixmap } if (has_focus()) p->draw_stylebox( stylebox( SB_ARROWBUTTON_FOCUS ) , Point() , p_size, p_exposed ); }
void TextureButton::_notification(int p_what) { switch( p_what ) { case NOTIFICATION_DRAW: { RID canvas_item = get_canvas_item(); DrawMode draw_mode = get_draw_mode(); // if (normal.is_null()) // break; Ref<Texture> texdraw; switch (draw_mode) { case DRAW_NORMAL: { if (normal.is_valid()) texdraw=normal; } break; case DRAW_PRESSED: { if (pressed.is_null()) { if (hover.is_null()) { if (normal.is_valid()) texdraw=normal; } else texdraw=hover; } else texdraw=pressed; } break; case DRAW_HOVER: { if (hover.is_null()) { if (pressed.is_valid() && is_pressed()) texdraw=pressed; else if (normal.is_valid()) texdraw=normal; } else texdraw=hover; } break; case DRAW_DISABLED: { if (disabled.is_null()) { if (normal.is_valid()) texdraw=normal; } else texdraw=disabled; } break; } if (texdraw.is_valid()) { Rect2 drect(Point2(),texdraw->get_size()*scale); draw_texture_rect(texdraw,drect,false,modulate); } if (has_focus() && focused.is_valid()) { Rect2 drect(Point2(),focused->get_size()*scale); draw_texture_rect(focused,drect,false,modulate); }; } break; } }