Snoke
Main Page
Related Pages
Classes
Files
File List
File Members
menu.cpp
Go to the documentation of this file.
1
#include "
menu.h
"
2
6
void
MenuItem::draw
()
7
{
8
mvaddstr(
y
,
x
,
name
);
9
}
10
14
MenuItem::MenuItem
(
const
char
*
name
,
int
x
,
int
y
,
int
width
,
int
height
) :
Widget
(), x(x), y(y), width(width), height(height), name(name)
15
{}
16
21
void
Menu::add
(
const
char
*
name
)
22
{
23
MenuItem
* item =
new
MenuItem
(name,
x
+ (
width
- strlen(name)) / 2,
y
+ this->
childLength
() * 2, strlen(name), 1);
24
item->
listener
(
EVENT_FOCUS
, std::bind(&
Menu::focus
,
this
, this->
childLength
()));
25
item->
listener
(
EVENT_UNFOCUS
, std::bind(&
Menu::unfocus
,
this
, this->
childLength
()));
26
this->
add
(item);
27
}
28
35
void
Menu::focus
(
int
index)
36
{
37
mvaddch(
y
+ index * 2,
x
,
'>'
);
38
refresh();
39
}
40
47
void
Menu::unfocus
(
int
index)
48
{
49
mvaddch(
y
+ index * 2,
x
,
' '
);
50
refresh();
51
}
52
56
void
Menu::draw
()
57
{
58
Widget
* current =
firstChild
();
59
while
(current)
60
{
61
current->
draw
();
62
current = current->
next
();
63
}
64
}
65
73
Menu::Menu
(
int
x
,
int
y
,
int
width
,
int
height
) :
Widget
(), x(x), y(y), width(width), height(height)
74
{}
MenuItem
Definition:
menu.h:12
MenuItem::x
int x
Definition:
menu.h:15
MenuItem::width
int width
Definition:
menu.h:15
MenuItem::y
int y
Definition:
menu.h:15
MenuItem::MenuItem
MenuItem(const char *name, int x, int y, int width, int height)
Definition:
menu.cpp:14
EVENT_FOCUS
#define EVENT_FOCUS
Definition:
widget.h:14
Menu::add
void add(const char *name)
Definition:
menu.cpp:21
Menu::draw
void draw()
Definition:
menu.cpp:56
Menu::Menu
Menu(int x, int y, int width, int height)
Definition:
menu.cpp:73
Widget::childLength
unsigned short childLength()
Definition:
widget.cpp:112
Menu::unfocus
void unfocus(int index)
Definition:
menu.cpp:47
Widget::draw
virtual void draw()
Definition:
widget.cpp:7
EVENT_UNFOCUS
#define EVENT_UNFOCUS
Definition:
widget.h:15
Widget::listener
void listener(unsigned char name, Listener function)
Definition:
widget.cpp:150
MenuItem::height
int height
Definition:
menu.h:15
Widget
Definition:
widget.h:36
menu.h
Widget::add
void add(Widget *child)
Definition:
widget.cpp:86
Widget::next
Widget * next()
Definition:
widget.cpp:59
MenuItem::name
const char * name
Definition:
menu.h:16
MenuItem::draw
void draw()
Definition:
menu.cpp:6
Menu::focus
void focus(int index)
Definition:
menu.cpp:35
Widget::firstChild
Widget * firstChild()
Definition:
widget.cpp:32
app
Widgets
menu.cpp
Generated by
1.8.11