forked from catmirrors/xlvns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LvnsMenu.c
158 lines (138 loc) · 3.18 KB
/
LvnsMenu.c
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
145
146
147
148
149
150
151
152
153
154
155
/*
* $Id: LvnsMenu.c,v 1.12 2001/08/12 11:35:44 tf Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include "Lvns.h"
/**
* デフォルトの表示処理
*/
void
LvnsDefaultMenuDisp(Lvns *lvns, MenuData *data)
{
MenuLine *line = data->line;
while (line->str != NULL) {
LvnsDrawString(lvns, line->xpos, line->ypos, line->str,
line->attr == lvns->text_cursor_state ? 0 : 1);
line++;
}
}
/**
* ポインタの位置チェック
*/
static int
check_pos(Lvns *lvns, MenuData *data)
{
Bool changed = False;
MenuLine *line = data->line;
while (line->str != NULL) {
if (lvns->motion_x >= line->xpos &&
lvns->motion_y >= line->ypos &&
lvns->motion_x < line->xpos + line->width &&
lvns->motion_y < line->ypos + line->height) {
lvns->text_cursor_state = line->attr;
changed = True;
break;
}
line++;
}
return changed;
}
/**
* メニュー処理
*/
int
LvnsMenu(Lvns *lvns, MenuData *data, int cancelok)
{
int ret;
int demo_cnt;
Bool changed;
lvns->inside_state = LVNS_WAIT_MENU;
start:
lvns->latitude = lvns->latitude_dark;
demo_cnt = 0;
lvns->text_cursor_state = 0;
lvns->select = False;
lvns->cancel = False;
lvns->cursor_up = False;
lvns->cursor_down = False;
lvns->motion = False;
lvns->number = 0;
LvnsSetDispFunc(lvns, data->disp ? data->disp: LvnsDefaultMenuDisp, data);
check_pos(lvns, data);
LvnsDispWindow(lvns);
changed = False;
while (1) {
LvnsFlip(lvns, True);
if ((!lvns->effect_back || !lvns->enable_effect_back)
&& changed) {
/* 再描画処理 */
LvnsDispWindow(lvns);
changed = False;
}
if (lvns->select) {
if (lvns->text_cursor_state)
break;
else
lvns->select = False;
} else if (lvns->cancel) {
if (cancelok) {
lvns->text_cursor_state = 0;
break;
} else
lvns->cancel = False;
} else if (lvns->motion) {
if (check_pos(lvns, data))
changed = True;
lvns->motion = False;
} else if (lvns->cursor_up) {
if (lvns->text_cursor_state == 0) {
lvns->text_cursor_state = data->select_num;
} else if (lvns->text_cursor_state > 1) {
lvns->text_cursor_state--;
}
changed = True;
lvns->cursor_up = False;
} else if (lvns->cursor_down) {
if (lvns->text_cursor_state < data->select_num) {
lvns->text_cursor_state++;
}
changed = True;
lvns->cursor_down = False;
} else if (lvns->number > 0) {
if (lvns->number <= data->select_num) {
lvns->text_cursor_state = lvns->number;
changed = True;
break;
} else {
lvns->number = 0;
}
} else if (lvns->demo_mode) {
demo_cnt++;
if (demo_cnt == 30) {
lvns->text_cursor_state = data->demo_choice;
changed = True;
} else if (demo_cnt > 120) {
break;
}
}
}
// 表示処理解除
LvnsSetDispFunc(lvns, NULL, NULL);
LvnsDispWindow(lvns);
if (!lvns->text_cursor_state) {
/* キャンセル */
ret = -1;
} else if (data->menu) {
ret = data->menu(lvns, lvns->text_cursor_state);
if (ret == 0)
goto start;
} else
ret = lvns->text_cursor_state;
lvns->select = False;
lvns->cancel = False;
lvns->cursor_up = False;
lvns->cursor_down = False;
lvns->motion = False;
return ret;
}