#include "pandora.hpp" using namespace std; using namespace net::lliurex::lgi::toolkit::pandora; /* Helper drawing funcs*/ /** * draw a rounded corner square **/ 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); //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(const char * text,float x,float y) { this->x=x; this->y=y; //provisional size this->width=5; this->height=5; this->name="Pandora::Button"; this->text=string(text); 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, 1.0, 0.78, 0.19); else cairo_set_source_rgb(cairo, 0.72, 0.72, 0.72); draw_round_square(cairo,x,y,width,height); cairo_fill(cairo); cairo_set_source_rgb(cairo, 0.2, 0.2, 0.2); cairo_set_line_width (cairo, 2.0); draw_round_square(cairo,x,y,width,height); cairo_stroke(cairo); cairo_pattern_t *pat; pat = cairo_pattern_create_linear (x, y,x , y+height); cairo_pattern_add_color_stop_rgb(pat, 0,1.0,1.0,1.0f); cairo_pattern_add_color_stop_rgb(pat, 1,0.0f,0.0f,0.0f); cairo_set_source (cairo, pat); cairo_set_line_width (cairo, 1.0); draw_round_square(cairo,x+1,y+2,width-2,height-1); cairo_stroke(cairo); cairo_pattern_destroy (pat); cairo_set_source_rgb (cairo, 0.05, 0.05, 0.05); 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()); cairo_set_source_rgb (cairo, 0.95, 0.95, 0.95); cairo_move_to (cairo, x+((width-te.width)/2.0),y+(height)-((height-fe.height)/2.0)-fe.descent); cairo_show_text (cairo, text.c_str()); } CheckBox::CheckBox(bool state,float x,float y) { this->x=x; this->y=y; this->state=state; this->width=24.0f; this->height=24.0f; this->name="Pandora::CheckBox"; this->mouse_over=false; this->mouse_press=false; this->focus=false; } void CheckBox::Draw(cairo_t * cairo) { cairo_pattern_t *pat; if(state) cairo_set_source_rgb(cairo, 1.0, 0.78, 0.19); else cairo_set_source_rgb(cairo, 0.72, 0.72, 0.72); draw_round_square(cairo,x,y,width,height); cairo_fill(cairo); pat = cairo_pattern_create_linear (x, y,x , y+height); cairo_pattern_add_color_stop_rgb(pat, 0,1.0,1.0,1.0f); cairo_pattern_add_color_stop_rgb(pat, 1,0.0f,0.0f,0.0f); cairo_set_source (cairo, pat); cairo_set_line_width (cairo, 1.0); draw_round_square(cairo,x+1,y+2,width-2,height-1); cairo_stroke(cairo); cairo_pattern_destroy (pat); cairo_set_source_rgb(cairo, 0.2, 0.2, 0.2); cairo_set_line_width (cairo, 2.0); draw_round_square(cairo,x,y,width,height); cairo_stroke(cairo); } Label::Label(const char * text,float x,float y) { this->x=x; this->y=y; //provisional size this->width=5; this->height=5; this->name="Pandora::Label"; this->text=string(text); this->mouse_over=false; this->mouse_press=false; this->focus=false; } void Label::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.95, 0.88, 0.29); else cairo_set_source_rgb(cairo, 0.95, 0.95, 0.95); draw_round_square(cairo,x,y,width,height); cairo_fill(cairo); if(focus) cairo_set_source_rgb(cairo, 1.0, 0.78, 0.19); else cairo_set_source_rgb(cairo, 0.2, 0.2, 0.2); cairo_set_line_width (cairo, 2.0); draw_round_square(cairo,x,y,width,height); cairo_stroke(cairo); cairo_set_source_rgb (cairo, 0.2, 0.2, 0.2); cairo_move_to (cairo, x+((width-te.width)/2.0),y+(height)-((height-fe.height)/2.0)-fe.descent); cairo_show_text (cairo, text.c_str()); }