diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-04 15:12:59 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-04 15:12:59 +0200 |
commit | 69541c037e67635787b334b326a4850f1703a763 (patch) | |
tree | 9d3f590d955c7f87f47a1bdc6ca33a67086630f3 | |
parent | 74d4343beb74424b400f5f65e620abf98b8c1562 (diff) |
IndicatorWidget: Use the normal animation method
This old timer-based animation predates the ticker convention.
-rw-r--r-- | src/ui/indicatorwidget.c | 66 |
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 | ||
31 | static int timerId_; /* common timer for all indicators */ | 31 | struct Impl_IndicatorWidget { |
32 | static int animCount_; /* number of animating indicators */ | ||
33 | |||
34 | static uint32_t postRefresh_(uint32_t interval, void *context) { | ||
35 | iUnused(context); | ||
36 | postRefresh_App(); | ||
37 | return interval; | ||
38 | } | ||
39 | |||
40 | static void startTimer_(void) { | ||
41 | animCount_++; | ||
42 | if (!timerId_) { | ||
43 | timerId_ = SDL_AddTimer(1000 / 60, postRefresh_, NULL); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | static void stopTimer_(void) { | ||
48 | iAssert(animCount_ > 0); | ||
49 | if (--animCount_ == 0) { | ||
50 | iAssert(timerId_); | ||
51 | SDL_RemoveTimer(timerId_); | ||
52 | timerId_ = 0; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | struct 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 | ||
42 | static 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 | |||
67 | static void setActive_IndicatorWidget_(iIndicatorWidget *d, iBool set) { | 50 | static 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 | ||
78 | static void startTimer_IndicatorWidget_(iIndicatorWidget *d) { | ||
79 | if (!isActive_IndicatorWidget_(d)) { | ||
80 | startTimer_(); | ||
81 | setActive_IndicatorWidget_(d, iTrue); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | static void stopTimer_IndicatorWidget_(iIndicatorWidget *d) { | ||
86 | if (isActive_IndicatorWidget_(d)) { | ||
87 | stopTimer_(); | ||
88 | setActive_IndicatorWidget_(d, iFalse); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | void deinit_IndicatorWidget(iIndicatorWidget *d) { | 61 | void deinit_IndicatorWidget(iIndicatorWidget *d) { |
93 | stopTimer_IndicatorWidget_(d); | 62 | removeTicker_App(animate_IndicatorWidget_, d); |
94 | } | 63 | } |
95 | 64 | ||
96 | static iBool isCompleted_IndicatorWidget_(const iIndicatorWidget *d) { | 65 | static iBool isCompleted_IndicatorWidget_(const iIndicatorWidget *d) { |
@@ -116,12 +85,7 @@ void draw_IndicatorWidget_(const iIndicatorWidget *d) { | |||
116 | 85 | ||
117 | iBool processEvent_IndicatorWidget_(iIndicatorWidget *d, const SDL_Event *ev) { | 86 | iBool 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 | } |