forked from keirf/flashfloppy-hxc-file-selector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.c
More file actions
144 lines (118 loc) · 3.5 KB
/
menu.c
File metadata and controls
144 lines (118 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
//
// Copyright (C) 2009-2017 Jean-François DEL NERO
//
// This file is part of the HxCFloppyEmulator file selector.
//
// HxCFloppyEmulator file selector may be used and distributed without restriction
// provided that this copyright statement is not removed from the file and that any
// derivative work contains the original copyright notice and the associated
// disclaimer.
//
// HxCFloppyEmulator file selector is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// HxCFloppyEmulator file selector is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with HxCFloppyEmulator file selector; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "keysfunc_defs.h"
#include "conf.h"
#include "cfg_file.h"
#include "ui_context.h"
#include "gui_utils.h"
#include "hal.h"
#include "fectrl.h"
#include "menu.h"
int menu_draw(ui_context * ctx, const menu * submenu, int *max_len)
{
int i,t;
clear_list(ctx);
*max_len = 0;
i = 0;
while( submenu[i].text )
{
t = strlen((char*)submenu[i].text);
if(*max_len<t)
*max_len = t;
i++;
}
// Center & align the parameters if possible...
if( *max_len < ctx->screen_txt_xsize / 2 )
*max_len = ctx->screen_txt_xsize / 2;
i = 0;
while( submenu[i].text )
{
hxc_print(ctx,submenu[i].align,0,FILELIST_Y_POS + i, (char*)submenu[i].text);
if(submenu[i].menu_cb)
{
submenu[i].menu_cb(ctx,0,*max_len,FILELIST_Y_POS + i,submenu[i].cb_parameter);
}
i++;
}
return i;
}
int enter_menu(ui_context * ctx, const menu * submenu)
{
int i,item_count,max_len;
int cb_return;
unsigned char c;
item_count = menu_draw(ctx, submenu, &max_len);
i = 0;
invert_line(ctx, FILELIST_Y_POS + i);
do
{
cb_return = MENU_STAYINMENU;
c=wait_function_key();
switch(c)
{
case FCT_UP_KEY:
invert_line( ctx, FILELIST_Y_POS + i );
if(i)
i--;
invert_line( ctx, FILELIST_Y_POS + i );
break;
case FCT_DOWN_KEY:
invert_line( ctx, FILELIST_Y_POS + i );
if( i < item_count - 1 )
i++;
invert_line( ctx, FILELIST_Y_POS + i );
break;
case FCT_SELECT_FILE_DRIVEA:
case FCT_LEFT_KEY:
case FCT_RIGHT_KEY:
// call callback.
invert_line( ctx, FILELIST_Y_POS + i );
if(submenu[i].menu_cb)
{
cb_return = submenu[i].menu_cb(ctx,c,max_len,FILELIST_Y_POS + i,submenu[i].cb_parameter);
if(cb_return == MENU_REDRAWMENU)
{
menu_draw(ctx, submenu, &max_len);
}
}
if(c == FCT_SELECT_FILE_DRIVEA)
{
if(submenu[i].submenu && submenu[i].submenu != (struct menu *)-1)
{
enter_menu(ctx, (menu *)submenu[i].submenu);
menu_draw(ctx, submenu, &max_len);
}
}
invert_line( ctx, FILELIST_Y_POS + i );
break;
}
}while( (( c != FCT_SELECT_FILE_DRIVEA ) || (submenu[i].submenu != (struct menu *)-1)) && (cb_return != MENU_LEAVEMENU) );
return (int)submenu[i].cb_parameter;
}