#include "Widgets.hpp" using namespace std; using namespace net::lliurex::drumroll; void draw_round_square(cairo_t * cairo,float x,float y,float width,float height) { float w=3.0f; float v=5.0f; float rwidth = width - (w*2.0f) - (v*2.0f); float rheight = height - (w*2.0f) - (v*2.0f); if(width<6.0)return; //top cairo_move_to(cairo,x,y+w+v); cairo_curve_to(cairo,x,y+w,x+w,y,x+w+v,y); cairo_line_to(cairo,x+w+v+rwidth,y); cairo_curve_to(cairo,x+w+v+rwidth+v,y,x+width,y+w,x+width,y+w+v); //right side cairo_line_to(cairo,x+width,y+w+v+rheight); //bottom cairo_curve_to(cairo,x+width,y+w+v+rheight+v,x+w+v+rwidth+w,y+height,x+w+v+rwidth,y+height); cairo_line_to(cairo,x+w+v,y+height); cairo_curve_to(cairo,x+w,y+height,x,y+w+v+rheight+v,x,y+w+v+rheight); //left side cairo_line_to(cairo,x,y+w+v); } Button::Button(string text) { this->text=text; this->name="drumroll::Button"; this->width=5; this->height=5; this->x=0.0f; this->y=0.0f; this->mouse_over=false; this->mouse_press=false; this->focus=false; } void Button::Draw(cairo_t * cairo) { cairo_text_extents_t te; cairo_font_extents_t fe; cairo_select_font_face (cairo, "Ubuntu", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cairo, 16.0); cairo_text_extents (cairo, text.c_str(), &te); cairo_font_extents (cairo, &fe); width=te.width; height=(fe.height); width+=20.0f; // 10+10 margins height+=(height*0.8f); if(mouse_over) cairo_set_source_rgb(cairo, 0.45,0.43,0.33); else cairo_set_source_rgb(cairo, 0.35,0.33,0.23); cairo_set_line_width (cairo, 2.0); draw_round_square(cairo,x,y,width,height); cairo_stroke(cairo); cairo_move_to (cairo, x+((width-te.width)/2.0)+1,y+(height)-((height-fe.height)/2.0)-fe.descent+1); cairo_show_text (cairo, text.c_str()); } void Button::SetText(string text) { this->text=text; }