gameui
view src/widget.cc @ 1:54ffb1765d39
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 11 Mar 2014 23:04:11 +0200 |
parents | 3aa12cdb9925 |
children | e5b1525084f7 |
line source
1 #include <string>
2 #include <stringstream>
3 #include "widget.h"
5 using namespace gameui;
7 class WidgetImpl {
8 public:
9 std::string name_prefix;
10 std::string name;
11 BBox box;
12 VisState vis_st;
13 ActiveState act_st;
15 float vis, act;
17 long vis_start_time, act_start_time;
18 };
21 Widget::Widget()
22 : name_prefix("widget")
23 {
24 static int widget_count;
26 std::stringstream sstr;
27 sstr << name_prefix << widget_count++;
28 name = sstr.str();
30 box.bmin = Vec2(0, 0);
31 box.bmax = Vec2(1, 1);
33 vis_st = VST_VISIBLE;
34 act_st = AST_ACTIVE;
36 vis = act = 1.0;
37 }
39 Widget::~Widget()
40 {
41 }
43 void Widget::show()
44 {
45 if(vis_st == VST_EASEVISIBLE || vis_st == VST_EASEIN) {
46 return;
47 }
49 vis_st = VST_EASEIN;
50 vis_start_time = get_cur_time();
51 }
53 void Widget::hide()
54 {
55 if(vis_st == VST_EASEHIDDEN || vis_st == VST_EASEOUT) {
56 return;
57 }
59 vis_st = VST_EASEOUT;
60 vis_start_time = get_cur_time();
61 }
63 float Widget::get_visibility() const
64 {
65 switch(vis_st) {
66 case VST_EASEIN:
67 vis = (get_cur_time() - vis_start_time) / gameui::ease_time;
68 if(vis < 0.0) vis = 0.0;
69 if(vis > 1.0) vis = 1.0;
70 break;
72 case VST_EASEOUT:
73 vis = 1.0 - (get_cur_time() - vis_start_time) / gameui::ease_time;
74 if(vis < 0.0) vis = 0.0;
75 if(vis > 1.0) vis = 1.0;
76 break;
78 case VST_HIDDEN:
79 vis = 0.0;
80 break;
82 case VST_VISIBLE:
83 vis = 1.0;
84 break;
85 }
87 return vis;
88 }
90 void Widget::activate()
91 {
92 }
94 #ifdef WIN32
95 long gameui::get_cur_time()
96 {
97 return GetTickCount();
98 }
99 #endif
101 #if defined(__unix__) || defined(__APPLE__)
102 long gameui::get_cur_time()
103 {
104 struct timeval tv;
105 static struct timeval tv0;
107 gettimeofday(&tv, 0);
108 if(tv0.tv_sec == 0 && tv0.tv_msec == 0) {
109 tv0 = tv;
110 return 0;
111 }
112 return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
113 }
114 #endif