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 );
       }
    }
예제 #2
0
파일: behavior_chart.cpp 프로젝트: txe/ieml
    void draw_bar( graphics& gx, UINT width, UINT height, int n_bar, int total_bars, color c, double val )
    {
        double bar_width = double(width) / (2*total_bars);
        double bar_height = double(height - 2) * val * (double(step)/double(steps-1));

        double bar_x1 = bar_width/2 + n_bar * 2 * bar_width;
        double bar_x2 = bar_x1 + bar_width;
        double bar_y2 = height - 0.5;
        double bar_y1 = bar_y2 - bar_height;

        color c_outline(0,0,0,0);

        gx.line_color(c_outline);
        gx.line_width(3);
        
        COLOR_STOP cs[3] = 
        {
          { gcolor(c) , 0.0f },
          { gcolor(0xff,0xff,0xff), 0.33f },
          { gcolor(c), 1.0f }
        };
        gx.fill_linear_gradient( bar_x1,bar_y1,bar_x2,bar_y1, cs, 3);

        gx.rectangle(bar_x1,bar_y1,bar_x2,bar_y2,6,6,0,0);
    }
예제 #3
0
파일: behavior_chart.cpp 프로젝트: txe/ieml
    // 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));
      }
    }