PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
pge_menu.h
1 /*
2  * Platformer Game Engine by Wohlstand, a free platform for game making
3  * Copyright (c) 2015 Vitaly Novichkov <admin@wohlnet.ru>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef PGE_MENU_H
20 #define PGE_MENU_H
21 
22 #include <QString>
23 #include <QList>
24 #include <QPair>
25 #include <common_features/pge_texture.h>
26 #include <common_features/rect.h>
27 #include <common_features/size.h>
28 #include <common_features/point.h>
29 #include <functional>
30 
31 #include "menu/_pge_menuitem.h"
32 
33 #include "menu/pge_bool_menuitem.h"
34 #include "menu/pge_int_menuitem.h"
35 #include "menu/pge_int_named_menuitem.h"
36 #include "menu/pge_keygrab_menuitem.h"
37 
38 struct KM_Key;
39 
40 class PGE_Menu
41 {
42 friend class PGE_KeyGrabMenuItem;
43 public:
44  enum menuAlignment { HORIZONTAL, VERTICLE };
45 
46  PGE_Menu(menuAlignment align=VERTICLE, int itemGap=0);
47  PGE_Menu(const PGE_Menu&menu);
48  ~PGE_Menu();
49 
50  void addMenuItem(QString value, QString title="",
51  std::function<void()> _extAction=([]()->void{}));
52  void addBoolMenuItem(bool *flag, QString value, QString title="",
53  std::function<void()> _extAction=([]()->void{}));
54  void addIntMenuItem(int *intvalue, int min, int max, QString value, QString title, bool rotate=false,
55  std::function<void()> _extAction=([]()->void{}) );
56  void addNamedIntMenuItem(int *intvalue, QList<NamedIntItem > _items, QString value, QString title, bool rotate=false,
57  std::function<void()> _extAction=([]()->void{}) );
58  void addKeyGrabMenuItem(KM_Key *key, QString value, QString title, SDL_Joystick *joystick_device=NULL);
59 
60  void setValueOffset(int offset);
61  void setItemWidth(int width);
62 
63  void clear();
64 
65  void selectUp();
66  void selectDown();
67  void scrollUp();
68  void scrollDown();
69  void selectLeft();
70  void selectRight();
71  void acceptItem();
72  void rejectItem();
73  void resetState();
74  void setMouseHoverPos(int x, int y);
77  void setMouseClickPos(int x, int y);
78  int findItem(int x, int y);
79 
80  void reset();
81 
82  void setItemsNumber(int q);
83 
84  void sort();
85  void render();
86 
87  bool isSelected();
88  bool isAccepted();
89  bool isKeyGrabbing();
90  bool processJoystickBinder();
91  void storeKey(int scancode);
92  menuAlignment getAlignment();
93  const PGE_Menuitem currentItem();
94  int currentItemI();
95  void setCurrentItem(int i);
96  int line();
97  void setLine(int ln);
98  int offset();
99  void setOffset(int of);
100 
101  //Position and size Rectangle
102  PGE_Rect rect();
103  PGE_Rect rectFull();
104  int topOffset();
105  void setPos(int x, int y);
106  void setPos(PGE_Point p);
107  void setSize(int w, int h);
108  void setSize(PGE_Size s);
109  void setTextLenLimit(int maxlen, bool strict=false);
110  int getMenuItemGap();
111 
112  bool isKeygrabViaKey() const;
113  void setKeygrabViaKey(bool value);
114 
115 private:
116  void refreshRect();
117  PGE_Rect menuRect;
118 
119  /*******Key grabbing********/
120  PGE_KeyGrabMenuItem *m_item;
121  bool is_keygrab;
122  //This is needed, because the first inital keypress should not be prossesed.
123  bool is_keygrabViaKey;
124  /*******Key grabbing********/
125 
126  menuAlignment alignment;
127  int _itemsOnScreen;
128  int _currentItem;
129  int _line;
130  int _offset;
131  bool arrowUpViz;
132  bool arrowDownViz;
133  bool _EndSelection;
134  bool _accept;
135  QList<PGE_BoolMenuItem > _items_bool;
136  QList<PGE_IntMenuItem > _items_int;
137  QList<PGE_NamedIntMenuItem > _items_named_int;
138  QList<PGE_Menuitem > _items_normal;
139  QList<PGE_KeyGrabMenuItem > _items_keygrabs;
140 
141  QList<PGE_Menuitem *> _items;
142  bool namefileLessThan(const PGE_Menuitem *d1, const PGE_Menuitem *d2);
143  bool namefileMoreThan(const PGE_Menuitem *d1, const PGE_Menuitem *d2);
144  void autoOffset();
145  PGE_Texture _selector;
146  PGE_Texture _scroll_up;
147  PGE_Texture _scroll_down;
148  int _item_height;
149  int _width_limit;
150  int _text_len_limit;
151  bool _text_len_limit_strict;
152  int menuItemGap;
153 
154  int _font_id;
155  int _font_offset;
156 };
157 
158 #endif // PGE_MENU_H
void selectLeft()
switch to left (for lists)
Definition: pge_menu.cpp:348
void clear()
Clean all menuitems.
Definition: pge_menu.cpp:272
void scrollDown()
Scroll by mousewheel.
Definition: pge_menu.cpp:337
void selectDown()
move selection cursor down
Definition: pge_menu.cpp:307
void reset()
Reset menu to initial state.
Definition: pge_menu.cpp:489
void setPos(int x, int y)
Sets current position of menu box.
Definition: pge_menu.cpp:640
Definition: pge_texture.h:32
Definition: rect.h:26
void setOffset(int of)
Sets scrolling offset from begin of menu list.
Definition: pge_menu.cpp:592
Definition: size.h:23
void scrollUp()
Scroll by mousewheel.
Definition: pge_menu.cpp:327
int topOffset()
Offset.
Definition: pge_menu.cpp:763
bool processJoystickBinder()
Is a joystick key grabbing mode.
Definition: pge_menu.cpp:473
void resetState()
Reset state after acception or rejection.
Definition: pge_menu.cpp:499
void selectUp()
move selection cursor up
Definition: pge_menu.cpp:285
void selectRight()
switch to right (for lists)
Definition: pge_menu.cpp:354
void setSize(int w, int h)
Sets size of menu box.
Definition: pge_menu.cpp:654
int offset()
Returns scrolling offset from begin of menu list.
Definition: pge_menu.cpp:587
void sort()
Sort menu items in alphabetic order.
Definition: pge_menu.cpp:406
Definition: pge_keygrab_menuitem.h:29
int line()
Returns number of current line where cursor is located on screen.
Definition: pge_menu.cpp:574
void setMouseHoverPos(int x, int y)
Definition: pge_menu.cpp:505
int currentItemI()
Returns index of current menu item.
Definition: pge_menu.cpp:559
bool isKeyGrabbing()
Is a key grabbing mode.
Definition: pge_menu.cpp:468
Definition: controller_key_map.h:4
void render()
Draw menu on screen.
Definition: pge_menu.cpp:772
PGE_Rect rect()
Returns rectangle of menu box.
Definition: pge_menu.cpp:730
void setLine(int ln)
Sets current line number.
Definition: pge_menu.cpp:579
Definition: point.h:23
void setItemsNumber(int q)
Set number of item which will show on screen.
Definition: pge_menu.cpp:397
PGE_Menu(menuAlignment align=VERTICLE, int itemGap=0)
Definition: pge_menu.cpp:30
bool isAccepted()
Is menu was accepted, else rejected.
Definition: pge_menu.cpp:463
void acceptItem()
Accept currently selected item.
Definition: pge_menu.cpp:360
void rejectItem()
Reject menu.
Definition: pge_menu.cpp:390
bool isSelected()
Is menu was accepted or rejected.
Definition: pge_menu.cpp:458
const PGE_Menuitem currentItem()
Returns current menu item entry.
Definition: pge_menu.cpp:546
PGE_Rect rectFull()
Returns rectangle of menu box include sliders.
Definition: pge_menu.cpp:735
Definition: _pge_menuitem.h:27
void setCurrentItem(int i)
Sets current index of menuitem.
Definition: pge_menu.cpp:564
Definition: pge_menu.h:40