1 #include "stdafx.h"
5 #include <time.h>
6
8 {
9 /*
10 BEHAVIOR: native-clock
11 - draws content layer using sciter-x-graphics.hpp primitives.
12
13 SAMPLE:
14 See: samples/behaviors/native-drawing.htm
15 */
16
18 {
19 // ctor
22
24 {
27 return true;
28 }
29
31 {
33 }
35
36
38 {
40 return true; // keep ticking
41 }
42
44 {
45 if( params.
cmd !=
DRAW_CONTENT )
return false;
// drawing only content layer 46
47 const float PI = 3.141592653f;
48
49 float w = float(params.
area.right - params.
area.left);
50 float h = float(params.
area.bottom - params.
area.top);
51
52 float scale = w < h? w / 300.0f: h / 300.0f;
53
54 time_t rawtime;
55 time (&rawtime);
56 struct tm timeinfo = *localtime (&rawtime);
57
58 sciter::graphics gfx(params.
gfx);
59 gfx.state_save();
60
61 gfx.translate(params.
area.left + w / 2.0f,params.
area.top + h / 2.0f);
62 gfx.scale(scale,scale);
63 gfx.rotate(-PI/2);
64 gfx.line_color(0);
65 gfx.line_width(8.f);
67
68 // Hour marks
69 gfx.state_save();
70 gfx.line_color(gcolor(0x32,0x5F,0xA2));
71 for (int i = 0; i < 12; ++i) {
72 gfx.rotate(PI/6);
73 gfx.line(137.f,0,144.f,0);
74 }
75 gfx.state_restore();
76
77 // Minute marks
78 gfx.state_save();
79 gfx.line_width(3.f);
80 gfx.line_color(gcolor(0xA5,0x2A, 0x2A));
81 for (int i = 0; i < 60; ++i) {
82 if ( i % 5 != 0)
83 gfx.line(143,0,146,0);
84 gfx.rotate(PI/30.f);
85 }
86 gfx.state_restore();
87
88 int sec = timeinfo.tm_sec;
89 int min = timeinfo.tm_min;
90 int hr = timeinfo.tm_hour;
91 hr = hr >= 12 ? hr - 12 : hr;
92
93 // draw Hours
94 gfx.state_save();
95 gfx.rotate( hr*(PI/6) + (PI/360)*min + (PI/21600)*sec );
96 gfx.line_width(14);
97 gfx.line_color(gcolor(0x32,0x5F,0xA2));
98 gfx.line(-20,0,70,0);
99 gfx.state_restore();
100
101 // draw Minutes
102 gfx.state_save();
103 gfx.rotate( (PI/30)*min + (PI/1800)*sec );
104 gfx.line_width(10);
105 gfx.line_color(gcolor(0x32,0x5F,0xA2));
106 gfx.line(-28,0,100,0);
107 gfx.state_restore();
108
109 // draw seconds
110 gfx.state_save();
111 gfx.rotate(sec * PI/30);
112 gfx.line_color(gcolor(0xD4,0,0));
113 gfx.fill_color(gcolor(0xD4,0,0));
114 gfx.line_width(6);
115 gfx.line(-30,0,83,0);
116 gfx.ellipse(0,0,10,10);
117
118 gfx.fill_color(0);
119 gfx.ellipse(95,0,10,10);
120 gfx.state_restore();
121
122 gfx.state_restore();
123
124 return false;
125
126 }
127
128 };
129
131
133
134 // the only behavior_factory method:
137 }
138
139 };
140
141 // instantiating and attaching it to the global list
143
144
145 }
Behaiviors support (a.k.a windowless scriptable controls)
virtual bool handle_draw(HELEMENT he, DRAW_PARAMS ¶ms)
void start_timer(unsigned int ms, void *timer_id=0)
virtual event_handler * create(HELEMENT he)
native_clock_factory native_clock_factory_instance
virtual bool subscription(HELEMENT he, UINT &event_groups)
virtual bool handle_timer(HELEMENT he, TIMER_PARAMS ¶ms)
virtual void detached(HELEMENT he)
void refresh(RECT rc) const
virtual void attached(HELEMENT he)