diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-16 13:19:39 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-16 13:19:39 +0300 |
commit | 2eddc6ee320204c7791ef23e6a4bbea67f151796 (patch) | |
tree | 9f75a85a89c1ff719fbc5d387bb77a5529c77562 /src/ui/widget.c | |
parent | a9fe4cc0bfacb3ab003e269576ec74e9e09fe52a (diff) |
Widget: Fade opacity based on area covering root
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r-- | src/ui/widget.c | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c index 310522ce..23c701e4 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -61,23 +61,12 @@ void init_Widget(iWidget *d) { | |||
61 | d->bgColor = none_ColorId; | 61 | d->bgColor = none_ColorId; |
62 | d->frameColor = none_ColorId; | 62 | d->frameColor = none_ColorId; |
63 | init_Anim(&d->visualOffset, 0.0f); | 63 | init_Anim(&d->visualOffset, 0.0f); |
64 | // init_Anim(&d->fadeOpacity, 0.0f); | ||
65 | d->children = NULL; | 64 | d->children = NULL; |
66 | d->parent = NULL; | 65 | d->parent = NULL; |
67 | d->commandHandler = NULL; | 66 | d->commandHandler = NULL; |
68 | iZap(d->padding); | 67 | iZap(d->padding); |
69 | } | 68 | } |
70 | 69 | ||
71 | #if 0 | ||
72 | static void animateFadeOpacity_Widget_(void *ptr) { | ||
73 | iWidget *d = ptr; | ||
74 | postRefresh_App(); | ||
75 | if (!isFinished_Anim(&d->fadeOpacity)) { | ||
76 | addTicker_App(animateFadeOpacity_Widget_, ptr); | ||
77 | } | ||
78 | } | ||
79 | #endif | ||
80 | |||
81 | static void visualOffsetAnimation_Widget_(void *ptr) { | 70 | static void visualOffsetAnimation_Widget_(void *ptr) { |
82 | iWidget *d = ptr; | 71 | iWidget *d = ptr; |
83 | postRefresh_App(); | 72 | postRefresh_App(); |
@@ -102,7 +91,6 @@ void deinit_Widget(iWidget *d) { | |||
102 | if (d->flags & visualOffset_WidgetFlag) { | 91 | if (d->flags & visualOffset_WidgetFlag) { |
103 | removeTicker_App(visualOffsetAnimation_Widget_, d); | 92 | removeTicker_App(visualOffsetAnimation_Widget_, d); |
104 | } | 93 | } |
105 | // removeTicker_App(animateFadeOpacity_Widget_, d); | ||
106 | widgetDestroyed_Touch(d); | 94 | widgetDestroyed_Touch(d); |
107 | } | 95 | } |
108 | 96 | ||
@@ -1077,7 +1065,6 @@ void drawBackground_Widget(const iWidget *d) { | |||
1077 | if (d->flags & noBackground_WidgetFlag) { | 1065 | if (d->flags & noBackground_WidgetFlag) { |
1078 | return; | 1066 | return; |
1079 | } | 1067 | } |
1080 | // iAnim *fadeOpacity = (iAnim *) &d->fadeOpacity; | ||
1081 | if (d->flags & hidden_WidgetFlag && ~d->flags & visualOffset_WidgetFlag) { | 1068 | if (d->flags & hidden_WidgetFlag && ~d->flags & visualOffset_WidgetFlag) { |
1082 | return; | 1069 | return; |
1083 | } | 1070 | } |
@@ -1098,22 +1085,15 @@ void drawBackground_Widget(const iWidget *d) { | |||
1098 | const iBool isFaded = fadeBackground && | 1085 | const iBool isFaded = fadeBackground && |
1099 | ~d->flags & noFadeBackground_WidgetFlag && | 1086 | ~d->flags & noFadeBackground_WidgetFlag && |
1100 | ~d->flags & destroyPending_WidgetFlag; | 1087 | ~d->flags & destroyPending_WidgetFlag; |
1101 | #if 0 | ||
1102 | if (isFaded && fadeOpacity->to != 1.0f) { | ||
1103 | setValue_Anim(fadeOpacity, 1.0f, 150); | ||
1104 | animateFadeOpacity_Widget_((void *) d); | ||
1105 | } | ||
1106 | else if (!isFaded && fadeOpacity->to != 0.0f) { | ||
1107 | setValue_Anim(fadeOpacity, 0.0f, 150); | ||
1108 | animateFadeOpacity_Widget_((void *) d); | ||
1109 | } | ||
1110 | if (value_Anim(fadeOpacity) > 0.0f) { | ||
1111 | #endif | ||
1112 | if (isFaded) { | 1088 | if (isFaded) { |
1113 | iPaint p; | 1089 | iPaint p; |
1114 | init_Paint(&p); | 1090 | init_Paint(&p); |
1115 | // p.alpha = (uint8_t) (2 * 0x50 * value_Anim(&d->fadeOpacity)); | ||
1116 | p.alpha = 0x50; | 1091 | p.alpha = 0x50; |
1092 | if (flags_Widget(d) & visualOffset_WidgetFlag) { | ||
1093 | const float area = d->rect.size.x * d->rect.size.y; | ||
1094 | const float visibleArea = area_Rect(intersect_Rect(bounds_Widget(d), rect_Root(d->root))); | ||
1095 | p.alpha *= (area > 0 ? visibleArea / area : 0.0f); | ||
1096 | } | ||
1117 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); | 1097 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); |
1118 | int fadeColor; | 1098 | int fadeColor; |
1119 | switch (colorTheme_App()) { | 1099 | switch (colorTheme_App()) { |