Skip to content

Commit 6154d36

Browse files
committed
navigation cycle review to support loop menus
also made hilite texte color to be bgColor, providing beter support for monochrom
1 parent 82b02bd commit 6154d36

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

menu.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ menuNode* menuNode::activeNode=NULL;
2828

2929
bool menuOut::needRedraw(menu& m,int i) {return (drawn!=&m)||(top!=lastTop)||(m.sel!=lastSel&&((i==m.sel)||(i==lastSel)));}
3030

31+
#ifndef LOOP_MENU
32+
#define LOOP_MENU false
33+
#endif
34+
3135
//menu navigation engine
3236
//iteract with input until a selection is done, return the selection
3337
int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
@@ -36,18 +40,27 @@ int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
3640
int ch=c.read();
3741
if (ch!=menu::enterCode) {
3842
if (ch==menu::downCode) {
39-
if (sel>0) {
40-
sel--;
41-
if (sel+1>=p.maxY) p.top=sel-p.maxY;
42-
} else
43-
sel = sz-(canExit?0:1); // infinite loop menu
43+
sel--;
44+
if (sel<0) {
45+
#if LOOP_MENU
46+
sel=sz-(canExit?0:1);
47+
if (sel+1>=p.maxY) p.top=sel-p.maxY+1;
48+
#else
49+
sel=0;
50+
#endif
51+
}
52+
if (p.top>sel) p.top=sel;
4453
} else if (ch==menu::upCode) {
45-
if (sel<(sz-(canExit?0:1))) {
46-
sel++;
47-
if ((sz-sel+(canExit?1:0))>=p.maxY) p.top=sel-(canExit?1:0);
48-
} else
49-
sel = 0; // infinite loop menu
50-
54+
sel++;
55+
if (sel>(sz-(canExit?0:1))) {
56+
#if LOOP_MENU
57+
sel=0;
58+
p.top=0;
59+
#else
60+
sel=sz-(canExit?0:1);
61+
#endif
62+
}
63+
if (sel+1>p.maxY) p.top=sel-p.maxY+1;
5164
} else if (ch==menu::escCode) {
5265
op=-1;
5366
} else

menuGFX.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ www.r-site.net
5252
enabledColor(enabledColor),
5353
disabledColor(disabledColor),
5454
hiliteColor(hiliteColor),
55-
enabledColorHi(enabledColor),
56-
disabledColorHi(disabledColor),
55+
enabledColorHi(bgColor),
56+
disabledColorHi(bgColor),
5757
menuOut(gfx.width()/resX,gfx.height()/resY,resX,resY) {}
5858

5959
virtual void clearLine(int ln) {

0 commit comments

Comments
 (0)