summaryrefslogtreecommitdiff
path: root/src/ui/banner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/banner.c')
-rw-r--r--src/ui/banner.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/ui/banner.c b/src/ui/banner.c
index 5ec3c9f0..d1ed470c 100644
--- a/src/ui/banner.c
+++ b/src/ui/banner.c
@@ -53,6 +53,7 @@ struct Impl_Banner {
53 iString site; 53 iString site;
54 iString icon; 54 iString icon;
55 iArray items; 55 iArray items;
56 iBool isClick;
56}; 57};
57 58
58iDefineTypeConstruction(Banner) 59iDefineTypeConstruction(Banner)
@@ -70,6 +71,7 @@ void init_Banner(iBanner *d) {
70 init_String(&d->site); 71 init_String(&d->site);
71 init_String(&d->icon); 72 init_String(&d->icon);
72 init_Array(&d->items, sizeof(iBannerItem)); 73 init_Array(&d->items, sizeof(iBannerItem));
74 d->isClick = iFalse;
73} 75}
74 76
75void deinit_Banner(iBanner *d) { 77void deinit_Banner(iBanner *d) {
@@ -96,6 +98,10 @@ int height_Banner(const iBanner *d) {
96 return d->rect.size.y; 98 return d->rect.size.y;
97} 99}
98 100
101iBool contains_Banner(const iBanner *d, iInt2 coord) {
102 return contains_Rect(d->rect, coord);
103}
104
99void clear_Banner(iBanner *d) { 105void clear_Banner(iBanner *d) {
100 iForEach(Array, i, &d->items) { 106 iForEach(Array, i, &d->items) {
101 deinit_BannerItem(i.value); 107 deinit_BannerItem(i.value);
@@ -139,8 +145,36 @@ void remove_Banner(iBanner *d, enum iGmStatusCode code) {
139 145
140iBool processEvent_Banner(iBanner *d, const SDL_Event *ev) { 146iBool processEvent_Banner(iBanner *d, const SDL_Event *ev) {
141 iWidget *w = as_Widget(d->doc); 147 iWidget *w = as_Widget(d->doc);
142 /* on motion: */ 148 switch (ev->type) {
143// setCursor_Window(window_Widget(w), SDL_SYSTEM_CURSOR_HAND); 149 case SDL_MOUSEMOTION:
150 if (contains_Rect(d->rect, init_I2(ev->motion.x, ev->motion.y))) {
151 setCursor_Window(window_Widget(w), SDL_SYSTEM_CURSOR_HAND);
152 }
153 break;
154 case SDL_MOUSEBUTTONDOWN:
155 case SDL_MOUSEBUTTONUP:
156 /* Clicking on the top/side banner navigates to site root. */
157 if (ev->button.button == SDL_BUTTON_LEFT) {
158 const iBool isInside = contains_Rect(d->rect, init_I2(ev->button.x, ev->button.y));
159 if (isInside && ev->button.state == SDL_PRESSED) {
160 d->isClick = iTrue;
161 return iTrue;
162 }
163 else if (ev->button.state == SDL_RELEASED) {
164 if (d->isClick && isInside) {
165 postCommand_Widget(d->doc, "navigate.root");
166 }
167 d->isClick = iFalse;
168 }
169 /* Clicking on a warning? */
170// if (bannerType_DocumentWidget_(d) == certificateWarning_GmDocumentBanner &&
171// pos_Click(&d->click).y - top_Rect(banRect) >
172// lineHeight_Text(banner_FontId) * 2) {
173// postCommand_Widget(d, "document.info");
174// }
175 }
176 break;
177 }
144 return iFalse; 178 return iFalse;
145} 179}
146 180