summaryrefslogtreecommitdiff
path: root/src/ui/indicatorwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2022-02-06 15:07:17 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2022-02-06 15:07:17 +0200
commit076e34aa8d1e57cbf3142abdc91c8e88d21b75d6 (patch)
tree3ee91315ee1a083b74d84637af28252f039fa084 /src/ui/indicatorwidget.c
parentedb260848a42de2e1af44cab93dbf267d20e1f6f (diff)
parent53ab74c3a25521faa6f41b40b1969a3b8e8ad027 (diff)
Merge branch 'dev' into work/v1.11
# Conflicts: # CMakeLists.txt # res/fonts/SmolEmoji-Regular.ttf # res/lang/gl.bin # src/app.c
Diffstat (limited to 'src/ui/indicatorwidget.c')
-rw-r--r--src/ui/indicatorwidget.c66
1 files changed, 15 insertions, 51 deletions
diff --git a/src/ui/indicatorwidget.c b/src/ui/indicatorwidget.c
index bc0bd0fa..e16550ff 100644
--- a/src/ui/indicatorwidget.c
+++ b/src/ui/indicatorwidget.c
@@ -28,32 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 28
29#include <SDL_timer.h> 29#include <SDL_timer.h>
30 30
31static int timerId_; /* common timer for all indicators */ 31struct Impl_IndicatorWidget {
32static int animCount_; /* number of animating indicators */
33
34static uint32_t postRefresh_(uint32_t interval, void *context) {
35 iUnused(context);
36 postRefresh_App();
37 return interval;
38}
39
40static void startTimer_(void) {
41 animCount_++;
42 if (!timerId_) {
43 timerId_ = SDL_AddTimer(1000 / 60, postRefresh_, NULL);
44 }
45}
46
47static void stopTimer_(void) {
48 iAssert(animCount_ > 0);
49 if (--animCount_ == 0) {
50 iAssert(timerId_);
51 SDL_RemoveTimer(timerId_);
52 timerId_ = 0;
53 }
54}
55
56struct Impl_IndicatorWidget{
57 iWidget widget; 32 iWidget widget;
58 iAnim pos; 33 iAnim pos;
59}; 34};
@@ -64,6 +39,14 @@ iLocalDef iBool isActive_IndicatorWidget_(const iIndicatorWidget *d) {
64 return isSelected_Widget(d); 39 return isSelected_Widget(d);
65} 40}
66 41
42static void animate_IndicatorWidget_(void *ptr) {
43 iIndicatorWidget *d = ptr;
44 if (!isFinished_Anim(&d->pos)) {
45 addTickerRoot_App(animate_IndicatorWidget_, d->widget.root, ptr);
46 }
47 postRefresh_App();
48}
49
67static void setActive_IndicatorWidget_(iIndicatorWidget *d, iBool set) { 50static void setActive_IndicatorWidget_(iIndicatorWidget *d, iBool set) {
68 setFlags_Widget(as_Widget(d), selected_WidgetFlag, set); 51 setFlags_Widget(as_Widget(d), selected_WidgetFlag, set);
69} 52}
@@ -75,22 +58,8 @@ void init_IndicatorWidget(iIndicatorWidget *d) {
75 setFlags_Widget(w, unhittable_WidgetFlag, iTrue); 58 setFlags_Widget(w, unhittable_WidgetFlag, iTrue);
76} 59}
77 60
78static void startTimer_IndicatorWidget_(iIndicatorWidget *d) {
79 if (!isActive_IndicatorWidget_(d)) {
80 startTimer_();
81 setActive_IndicatorWidget_(d, iTrue);
82 }
83}
84
85static void stopTimer_IndicatorWidget_(iIndicatorWidget *d) {
86 if (isActive_IndicatorWidget_(d)) {
87 stopTimer_();
88 setActive_IndicatorWidget_(d, iFalse);
89 }
90}
91
92void deinit_IndicatorWidget(iIndicatorWidget *d) { 61void deinit_IndicatorWidget(iIndicatorWidget *d) {
93 stopTimer_IndicatorWidget_(d); 62 removeTicker_App(animate_IndicatorWidget_, d);
94} 63}
95 64
96static iBool isCompleted_IndicatorWidget_(const iIndicatorWidget *d) { 65static iBool isCompleted_IndicatorWidget_(const iIndicatorWidget *d) {
@@ -116,12 +85,7 @@ void draw_IndicatorWidget_(const iIndicatorWidget *d) {
116 85
117iBool processEvent_IndicatorWidget_(iIndicatorWidget *d, const SDL_Event *ev) { 86iBool processEvent_IndicatorWidget_(iIndicatorWidget *d, const SDL_Event *ev) {
118 iWidget *w = &d->widget; 87 iWidget *w = &d->widget;
119 if (ev->type == SDL_USEREVENT && ev->user.code == refresh_UserEventCode) { 88 if (isCommand_SDLEvent(ev)) {
120 if (isFinished_Anim(&d->pos)) {
121 stopTimer_IndicatorWidget_(d);
122 }
123 }
124 else if (isCommand_SDLEvent(ev)) {
125 const char *cmd = command_UserEvent(ev); 89 const char *cmd = command_UserEvent(ev);
126 if (startsWith_CStr(cmd, "document.request.")) { 90 if (startsWith_CStr(cmd, "document.request.")) {
127 if (pointerLabel_Command(cmd, "doc") == parent_Widget(w)) { 91 if (pointerLabel_Command(cmd, "doc") == parent_Widget(w)) {
@@ -130,23 +94,23 @@ iBool processEvent_IndicatorWidget_(iIndicatorWidget *d, const SDL_Event *ev) {
130 setValue_Anim(&d->pos, 0, 0); 94 setValue_Anim(&d->pos, 0, 0);
131 setValue_Anim(&d->pos, 0.75f, 4000); 95 setValue_Anim(&d->pos, 0.75f, 4000);
132 setFlags_Anim(&d->pos, easeOut_AnimFlag, iTrue); 96 setFlags_Anim(&d->pos, easeOut_AnimFlag, iTrue);
133 startTimer_IndicatorWidget_(d); 97 animate_IndicatorWidget_(d);
134 } 98 }
135 else if (equal_Command(cmd, "finished")) { 99 else if (equal_Command(cmd, "finished")) {
136 if (value_Anim(&d->pos) > 0.01f) { 100 if (value_Anim(&d->pos) > 0.01f) {
137 setValue_Anim(&d->pos, 1.0f, 250); 101 setValue_Anim(&d->pos, 1.0f, 250);
138 setFlags_Anim(&d->pos, easeOut_AnimFlag, iFalse); 102 setFlags_Anim(&d->pos, easeOut_AnimFlag, iFalse);
139 startTimer_IndicatorWidget_(d); 103 animate_IndicatorWidget_(d);
140 } 104 }
141 else { 105 else {
142 setValue_Anim(&d->pos, 0, 0); 106 setValue_Anim(&d->pos, 0, 0);
143 stopTimer_IndicatorWidget_(d); 107 animate_IndicatorWidget_(d);
144 refresh_Widget(d); 108 refresh_Widget(d);
145 } 109 }
146 } 110 }
147 else if (equal_Command(cmd, "cancelled")) { 111 else if (equal_Command(cmd, "cancelled")) {
148 setValue_Anim(&d->pos, 0, 0); 112 setValue_Anim(&d->pos, 0, 0);
149 stopTimer_IndicatorWidget_(d); 113 animate_IndicatorWidget_(d);
150 refresh_Widget(d); 114 refresh_Widget(d);
151 } 115 }
152 } 116 }