Skip to content

Commit 973dc2c

Browse files
committed
[app-dreameye] Add slide input event handling for photo navigation.
1 parent ede5108 commit 973dc2c

File tree

3 files changed

+151
-7
lines changed

3 files changed

+151
-7
lines changed

applications/dreameye/app.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
</input>
295295
</panel>
296296
</panel>
297-
<panel width="100%" height="285" y="60" name="gallery-grid">
297+
<panel width="100%" height="270" y="55" name="gallery-grid">
298298
<panel x="90" y="15" width="140" height="110" name="thumb-0">
299299
<input type="button" width="140" height="110" name="thumb-button-0"
300300
onclick="export:DreameyeApp_ViewPhoto()"
@@ -338,6 +338,9 @@
338338
</input>
339339
</panel>
340340
</panel>
341+
<panel width="100%" height="25">
342+
<label font="comic-14" color="#444444" align="center" text="Use L/R buttons to navigate through photos" />
343+
</panel>
341344
<panel height="65" width="50%">
342345
<input type="button" width="280" height="60"
343346
onclick="export:DreameyeApp_ShowPhotoPage()" align="center">

applications/dreameye/modules/app_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void DreameyeApp_ExportPhoto(GUI_Widget *widget);
2020

2121
void DreameyeApp_ErasePhoto(GUI_Widget *widget);
2222

23-
void DreameyeApp_FileBrowserItemClick(GUI_Widget *widget);
23+
void DreameyeApp_FileBrowserItemClick(dirent_fm_t *fm_ent);
2424

2525
void DreameyeApp_FileBrowserConfirm(GUI_Widget *widget);
2626

applications/dreameye/modules/module.c

Lines changed: 146 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
*/
66

77
#include <ds.h>
8+
#include <sfx.h>
89
#include <kos.h>
910
#include <dc/maple.h>
1011
#include <drivers/dreameye.h>
1112
#include <stdbool.h>
1213
#include "qr_code.h"
1314
#include "photo.h"
1415
#include "gallery.h"
16+
#include "app_module.h"
1517

1618
DEFAULT_MODULE_EXPORTS(app_dreameye);
1719

@@ -78,6 +80,8 @@ static struct {
7880
GUI_Surface *default_thumb_surface;
7981
GUI_Surface *default_thumb_hl_surface;
8082

83+
Event_t *slide_input_event;
84+
8185
} self;
8286

8387
#define NO_QR_CODE_TEXT "QR code is not detected"
@@ -214,6 +218,95 @@ static void LoadPhotoIntoViewer(int photo_index) {
214218
gallery_load_photo(photo_index, 380, 280, on_photo_loaded);
215219
}
216220

221+
static void DreameyeApp_FullscreenPrevPhoto(void);
222+
static void DreameyeApp_FullscreenNextPhoto(void);
223+
224+
static void Slide_EventHandler(void *ds_event, void *param, int action) {
225+
SDL_Event *event = (SDL_Event *) param;
226+
switch(event->type) {
227+
case SDL_JOYBUTTONDOWN:
228+
switch(event->jbutton.button) {
229+
case SDL_DC_L:
230+
if (IsVirtKeyboardVisible()) {
231+
break;
232+
}
233+
switch(GUI_CardStackGetIndex(self.pages)) {
234+
case APP_PAGE_GALLERY:
235+
DreameyeApp_GalleryPrevPage(NULL);
236+
break;
237+
case APP_PAGE_PHOTO_VIEWER:
238+
DreameyeApp_ViewPrevPhoto(NULL);
239+
break;
240+
case APP_PAGE_FULLSCREEN_VIEWER:
241+
DreameyeApp_FullscreenPrevPhoto();
242+
break;
243+
default:
244+
break;
245+
}
246+
break;
247+
case SDL_DC_R:
248+
if (IsVirtKeyboardVisible()) {
249+
break;
250+
}
251+
switch(GUI_CardStackGetIndex(self.pages)) {
252+
case APP_PAGE_GALLERY:
253+
DreameyeApp_GalleryNextPage(NULL);
254+
break;
255+
case APP_PAGE_PHOTO_VIEWER:
256+
DreameyeApp_ViewNextPhoto(NULL);
257+
break;
258+
case APP_PAGE_FULLSCREEN_VIEWER:
259+
DreameyeApp_FullscreenNextPhoto();
260+
break;
261+
default:
262+
break;
263+
}
264+
break;
265+
default:
266+
break;
267+
}
268+
break;
269+
case SDL_KEYDOWN:
270+
switch (event->key.keysym.sym) {
271+
case SDLK_COMMA:
272+
switch(GUI_CardStackGetIndex(self.pages)) {
273+
case APP_PAGE_GALLERY:
274+
DreameyeApp_GalleryPrevPage(NULL);
275+
break;
276+
case APP_PAGE_PHOTO_VIEWER:
277+
DreameyeApp_ViewPrevPhoto(NULL);
278+
break;
279+
case APP_PAGE_FULLSCREEN_VIEWER:
280+
DreameyeApp_FullscreenPrevPhoto();
281+
break;
282+
default:
283+
break;
284+
}
285+
break;
286+
case SDLK_PERIOD:
287+
switch(GUI_CardStackGetIndex(self.pages)) {
288+
case APP_PAGE_GALLERY:
289+
DreameyeApp_GalleryNextPage(NULL);
290+
break;
291+
case APP_PAGE_PHOTO_VIEWER:
292+
DreameyeApp_ViewNextPhoto(NULL);
293+
break;
294+
case APP_PAGE_FULLSCREEN_VIEWER:
295+
DreameyeApp_FullscreenNextPhoto();
296+
break;
297+
default:
298+
break;
299+
}
300+
break;
301+
default:
302+
break;
303+
}
304+
break;
305+
default:
306+
break;
307+
}
308+
}
309+
217310
void DreameyeApp_Init(App_t *app) {
218311
self.app = app;
219312
self.action = APP_ACTION_IDLE;
@@ -283,6 +376,14 @@ void DreameyeApp_Init(App_t *app) {
283376

284377
self.default_thumb_hl_surface = GUI_ButtonGetHighlightImage(self.thumb_buttons[0]);
285378
GUI_ObjectIncRef((GUI_Object *)self.default_thumb_hl_surface);
379+
380+
self.slide_input_event = AddEvent(
381+
"Slide_Input",
382+
EVENT_TYPE_INPUT,
383+
EVENT_PRIO_DEFAULT,
384+
Slide_EventHandler,
385+
NULL
386+
);
286387
}
287388

288389
void DreameyeApp_Shutdown(App_t *app) {
@@ -292,6 +393,8 @@ void DreameyeApp_Shutdown(App_t *app) {
292393

293394
GUI_ObjectDecRef((GUI_Object *)self.default_thumb_surface);
294395
GUI_ObjectDecRef((GUI_Object *)self.default_thumb_hl_surface);
396+
397+
RemoveEvent(self.slide_input_event);
295398
}
296399

297400
void DreameyeApp_Open(App_t *app) {
@@ -642,7 +745,9 @@ void DreameyeApp_ShowGalleryPage(GUI_Widget *widget) {
642745
}
643746

644747
void DreameyeApp_GalleryPrevPage(GUI_Widget *widget) {
645-
(void)widget;
748+
if(widget == NULL) {
749+
ds_sfx_play(DS_SFX_SLIDE);
750+
}
646751

647752
gallery_state_t *state = gallery_get_state();
648753
if (state->current_page > 0 && !state->loading) {
@@ -651,7 +756,9 @@ void DreameyeApp_GalleryPrevPage(GUI_Widget *widget) {
651756
}
652757

653758
void DreameyeApp_GalleryNextPage(GUI_Widget *widget) {
654-
(void)widget;
759+
if(widget == NULL) {
760+
ds_sfx_play(DS_SFX_SLIDE);
761+
}
655762

656763
gallery_state_t *state = gallery_get_state();
657764
if (state->current_page < state->total_pages - 1 && !state->loading) {
@@ -685,7 +792,9 @@ void DreameyeApp_ViewPhoto(GUI_Widget *widget) {
685792
}
686793

687794
void DreameyeApp_ViewPrevPhoto(GUI_Widget *widget) {
688-
(void)widget;
795+
if(widget == NULL) {
796+
ds_sfx_play(DS_SFX_SLIDE);
797+
}
689798

690799
gallery_state_t *state = gallery_get_state();
691800
if (state->current_photo > 0 && !state->loading) {
@@ -694,7 +803,9 @@ void DreameyeApp_ViewPrevPhoto(GUI_Widget *widget) {
694803
}
695804

696805
void DreameyeApp_ViewNextPhoto(GUI_Widget *widget) {
697-
(void)widget;
806+
if(widget == NULL) {
807+
ds_sfx_play(DS_SFX_SLIDE);
808+
}
698809

699810
gallery_state_t *state = gallery_get_state();
700811
if (state->current_photo < (int)self.photo_count - 1 && !state->loading) {
@@ -819,11 +930,41 @@ void DreameyeApp_ExitFullscreen(GUI_Widget *widget) {
819930
(void)widget;
820931

821932
LockVideo();
822-
GUI_WidgetSetPosition(self.pages, 0, 45);
823933
GUI_ContainerRemove(self.app->body, self.pages);
824934
GUI_ContainerAdd(self.app->body, self.header_panel);
825935
GUI_ContainerAdd(self.app->body, self.pages);
936+
GUI_WidgetSetPosition(self.pages, 0, 45);
826937
GUI_CardStackShowIndex(self.pages, APP_PAGE_PHOTO_VIEWER);
827938
GUI_WidgetMarkChanged(self.app->body);
828939
UnlockVideo();
829940
}
941+
942+
static void DreameyeApp_FullscreenPrevPhoto(void) {
943+
gallery_state_t *state = gallery_get_state();
944+
945+
if (state->current_photo > 0 && !state->loading) {
946+
947+
ds_sfx_play(DS_SFX_SLIDE);
948+
state->current_photo--;
949+
950+
GUI_WidgetSetEnabled(self.fullscreen_photo, 0);
951+
GUI_LabelSetText(self.fullscreen_status, "Loading...");
952+
953+
gallery_load_photo(state->current_photo, 0, 0, on_fullscreen_loaded);
954+
}
955+
}
956+
957+
static void DreameyeApp_FullscreenNextPhoto(void) {
958+
gallery_state_t *state = gallery_get_state();
959+
960+
if (state->current_photo < (int)self.photo_count - 1 && !state->loading) {
961+
962+
ds_sfx_play(DS_SFX_SLIDE);
963+
state->current_photo++;
964+
965+
GUI_WidgetSetEnabled(self.fullscreen_photo, 0);
966+
GUI_LabelSetText(self.fullscreen_status, "Loading...");
967+
968+
gallery_load_photo(state->current_photo, 0, 0, on_fullscreen_loaded);
969+
}
970+
}

0 commit comments

Comments
 (0)