|
//
// (с)Котик
//
#include // #define TRUE 1 // unsigned char x = 2, y = 2; // void Item0Action() void Item1Action() void Item2Action() void Item3Action() // struct TItem typedef struct TItem TMenuItem; void RepaintItem(struct TItem *Self) TMenuItem MainMenu[4] = { unsigned char SelectedItemN = 0; void DisplayMainMenu() for(i = 0; i < 4; i++) void ProcessMainMenu() for(i = 0; i < 4; i++) // int main(void) while(1)
E-mail:
info@telesys.ru
//
//
#define FALSE 0
//
//
unsigned char ExitFlag = FALSE;
unsigned char KeyPressed = 0;
//
//
{
attron(COLOR_PAIR(1));
mvprintw(20,10,"Item0 action applied");
attroff(COLOR_PAIR(1));
refresh();
}
{
attron(COLOR_PAIR(1));
mvprintw(20,10,"Item1 action applied");
attroff(COLOR_PAIR(1));
refresh();
}
{
attron(COLOR_PAIR(1));
mvprintw(20,10,"Item2 action applied");
attroff(COLOR_PAIR(1));
refresh();
}
{
attron(COLOR_PAIR(1));
mvprintw(20,10,"Item3 action applied");
attroff(COLOR_PAIR(1));
refresh();
}
//
//
{
char *ItemCaption;
unsigned char Index;
unsigned char IsSelected;
unsigned char XPos;
unsigned char YPos;
void(*PaintFunction)(struct TItem *Self);
void(*ActionFunction)();
};
{
unsigned char SelectedColorPair;
if(Self->IsSelected)SelectedColorPair = 2;
else SelectedColorPair = 1;
attron(COLOR_PAIR(SelectedColorPair));
mvprintw(Self->YPos, Self->XPos, Self->ItemCaption);
attroff(COLOR_PAIR(SelectedColorPair));
};
{" assa 0 ", 0, TRUE, 10, 10, RepaintItem, Item0Action},
{" assa 1 ", 0, FALSE, 10, 11, RepaintItem, Item1Action},
{" assa 2 ", 0, FALSE, 10, 12, RepaintItem, Item2Action},
{" assa 3 ", 0, FALSE, 10, 13, RepaintItem, Item3Action},
};
unsigned char MainMenuItemsN = 4;
{
unsigned char i;
(*MainMenu[i].PaintFunction)(&MainMenu[i]);
};
{
unsigned char i;
if(i == SelectedItemN)MainMenu[i].IsSelected = TRUE;
else MainMenu[i].IsSelected = FALSE;
};
//
//
{
initscr();
start_color();
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_BLACK, COLOR_GREEN);
noecho();
curs_set(0); // set cursor invisible
box(stdscr, ACS_VLINE, ACS_HLINE);
attron(COLOR_PAIR(1));
mvprintw(0,23," Simple one-level menu sample ");
mvprintw(24,13," Use numpad arrow keys to move '*', 'q' - to quit :) ");
attroff(COLOR_PAIR(2));
DisplayMainMenu();
refresh();
{
KeyPressed = getch();
switch(KeyPressed)
{
case('-'):
{
if(SelectedItemN)SelectedItemN--;
break;
};
case('+'):
{
if(SelectedItemN < MainMenuItemsN - 1)SelectedItemN++;
break;
}
case('q'):ExitFlag = TRUE;break;
case(10):
{
(*MainMenu[SelectedItemN].ActionFunction)();
break;
}
default: break;
};
if(ExitFlag)break;
ProcessMainMenu();
DisplayMainMenu();
refresh();
};
curs_set(1); // set cursor visible
clear();
refresh();
endwin();
return 0;
}
Ответы