void cross(graphics& graph, int x, int y, uint32_t size, uint32_t thickness, nana::color_t color) { if(thickness + 2 <= size) { int gap = (size - thickness) / 2; nana::point ps[12]; ps[0].x = x + gap; ps[1].x = ps[0].x + thickness - 1; ps[1].y = ps[0].y = y; ps[2].x = ps[1].x; ps[2].y = y + gap; ps[3].x = ps[2].x + gap; ps[3].y = ps[2].y; ps[4].x = ps[3].x; ps[4].y = ps[3].y + thickness - 1; ps[5].x = ps[1].x; ps[5].y = ps[4].y; ps[6].x = ps[5].x; ps[6].y = ps[5].y + gap; ps[7].x = x + gap; ps[7].y = ps[6].y; ps[8].x = ps[7].x; ps[8].y = ps[4].y; ps[9].x = x; ps[9].y = ps[4].y; ps[10].x = x; ps[10].y = y + gap; ps[11].x = x + gap; ps[11].y = y + gap; nana::color_t dkcolor = graph.mix(color, 0x0, 0.5); for(int i = 0; i < 11; ++i) graph.line(ps[i], ps[i + 1], dkcolor); graph.line(ps[11], ps[0], dkcolor); graph.rectangle(ps[10].x + 1, ps[10].y + 1, (gap << 1) + thickness - 2, thickness - 2, color, true); graph.rectangle(ps[0].x + 1, ps[0].y + 1, thickness - 2, (gap << 1) + thickness - 2, color, true); } }
// canvas::draw overridable virtual void draw( HELEMENT he, graphics& gx, UINT width, UINT height ) { if( !data.is_array() ) { draw_message( gx, width, height, const_wchars(L"Data not found") ); return; } color black(0,0,0); // x axis gx.line_cap(LINE_CAP_BUTT); gx.line_color(black); gx.line( 0.5, height - 0.5, width - 0.5, height - 0.5 ); // 0.5 - to draw line in the middle of the pixel for( int n = 0; n < data.length(); ++n ) { json::value bar_def = data[n]; json::value color_v = bar_def.k2v(L"color"); json::value value_v = bar_def.k2v(L"value"); if( color_v.is_undefined() || value_v.is_undefined()) { draw_message( gx, width, height, const_wchars(L"Bad data structure") ); return; } draw_bar(gx, width, height, n, data.length(), color(color_v.get(0)), value_v.get(1.0)); } }
void draw_clock_hand( HELEMENT he, graphics& gx, UINT sx, UINT sy, double angle_degree, int hand ) { dom::element self(he); color c(255,0,0,0); int hand_width_px; double radians = (2.0 * PI * (angle_degree - 90.0)) / 360.0 ; int radius = min( sy, sx ) / 2 - 16; gx.line_cap(LINE_CAP_ROUND); switch(hand) { case 0: // hours radius -= 24 ; c = self.attribute("-hand-hours", c); if(c.transparent()) return; hand_width_px = self.attribute("-hand-hours-width", 5); gx.line_color(c); gx.line_width( hand_width_px ); break; case 1: // minutes radius -= 12 ; c = self.attribute("-hand-minutes", c); if(c.transparent()) return; hand_width_px = self.attribute("-hand-minutes-width", 3); gx.line_color(c); gx.line_width( hand_width_px ); break; case 2: // seconds c = self.attribute("-hand-seconds", c); if(c.transparent()) return; hand_width_px = self.attribute("-hand-seconds-width", 1); gx.line_color( c ); gx.line_width( hand_width_px ); break; default: assert(false); } double y = (sy / 2) + 0.5; // + 0.5 is to move it to the center of the pixel. double x = (sy / 2) + 0.5; double xe = x + int(cos(radians) * radius) + 0.5; double ye = y + int(sin(radians) * radius) + 0.5; gx.line( x, y, xe, ye ); if( hand == 2 ) { // circle on the end of seconds hand if(pimage) { int w = pimage->width(); int h = pimage->height(); gx.draw_image(pimage,xe - double(w)/2,ye - double(h)/2,w,h,0,0,w,h); } else // no image gx.circle( xe, ye, 4 ); } }