1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <GUI.h>
#include <time.h>
#include <iostream>
using namespace Graph_lib;
//---------------------------------
class Dynamic_clock : public Window {
public:
Dynamic_clock(Point p, int w, int h, const string& title):
Window(p, w, h, title),
quit_button(Point(x_max()-90,20), 60, 20, "Quit", cb_quit),
l1(Point (p.x+100,p.y), Point(p.x+120,p.y)),
l2(Point (p.x-100,p.y), Point(p.x-120,p.y)),
l3(Point (p.x,p.y-100), Point(p.x,p.y-120)),
l4(Point (p.x,p.y+100), Point(p.x,p.y+120)),
hour1(Point(300,250), Point(300,155)),
hour2(Point(300,250), Point(310,165)),
c(Point(p), 120) {
attach(c);
attach(l1);
attach(l2);
attach(l3);
attach(l4);
attach(quit_button);
clock_hands();
}
private:
Button quit_button;
Circle c;
Line l1, l2, l3, l4, hour1, hour2;
double h, m, s;
void quit() { hide(); }
void clock_hands() {
get_current_time();
hour1.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 3));
attach(hour1);
Sleep(1000);
detach(hour1);
attach(hour2);
}
void get_current_time() {
time_t t = time(0);
t -= 1421526600;
double h = t/3600;
t -= h*3600;
double m = t/60;
t -= m*60;
double s = t;
}
static void cb_quit(Address, Address pw) {reference_to<Dynamic_clock>(pw).quit();}
};
//------------------
int main() {
Dynamic_clock dc(Point(300,250), 800, 600, "Dynamic_clock");
return gui_main();
}
|