-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_item_grid.cpp
More file actions
113 lines (101 loc) · 2.25 KB
/
list_item_grid.cpp
File metadata and controls
113 lines (101 loc) · 2.25 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
#include "list_item_grid.h"
#include "list_item.h"
#include "linmath.h"
/* class for creating a grid of items starting at init_x.
each new item is width long with margin between */
list_item_grid::list_item_grid
(
int set_num_list_items,
float set_init_x,
float set_y,
float set_width,
float set_margin,
api_source* set_api
)
{
num_list_items = set_num_list_items;
list_items = new list_item[num_list_items];
init_x = set_init_x;
y = set_y;
width = set_width;
margin = set_margin;
tot_width = width + margin;
onscreen_cnt = (int)floor((2.0f - (init_x + 1.0f))/(tot_width));
api = set_api;
this->init_list_items(0);
list_items[0].select(true);
selected = 0;
}
void list_item_grid::init_list_items(int start)
{
int i;
for (i = 0; i < num_list_items; i++)
{
list_items[i].set_values(init_x + ((width + margin) * (i - start)), y, width, api->get_versus(i), api->get_blurb(i), api->create_image(i));
}
}
void list_item_grid::shift_list_items(int start)
{
int i;
for (i = 0; i < num_list_items; i++)
{
list_items[i].set_values(init_x + ((width + margin) * (i - start)), y, width);
}
}
void list_item_grid::draw()
{
int i;
for (i = 0; i < num_list_items; i++)
{
list_items[i].draw();
}
}
void list_item_grid::set_selected(int i)
{
list_items[i].select(true);
}
void list_item_grid::select_next()
{
list_items[selected].select(false);
if (selected == num_list_items - 1)
{
selected = 0;
this->shift_list_items(0);
}
else
{
selected++;
if(selected > (onscreen_cnt / 2) && (num_list_items - selected + 1) > (onscreen_cnt / 2))
{
this->shift_list_items(selected - (int)(onscreen_cnt / 2));
}
}
list_items[selected].select(true);
}
void list_item_grid::select_prev()
{
list_items[selected].select(false);
if (selected == 0)
{
selected = num_list_items - 1;
this->shift_list_items(num_list_items - onscreen_cnt);
}
else
{
selected--;
if(selected < num_list_items - (onscreen_cnt / 2) && (selected + 1) > (onscreen_cnt / 2))
{
this->shift_list_items(selected - (onscreen_cnt / 2));
}
}
list_items[selected].select(true);
}
/* class clean up function to remove associated texture files */
void list_item_grid::remove_files()
{
int i;
for (i = 0; i < num_list_items; i++)
{
list_items[i].remove_files();
}
}