History

Moved menu, chat entry field to ui subdirectory.

Andrzej Kapolka committed 13 years ago

Commit a24f2151 parent d4fbe909 files · +5 −4Browse files

Showing the changes to interface/src/Menu.cpp (1 of 9 files). Show all

Unified · Split

interface/src/Menu.cpp+0−158
@@ -1,158 +0,0 @@
1//
2// Menu.cpp
3// hifi
4//
5// Created by Dominque Vincent on 4/10/13.
6//
7//
8
9#include <algorithm>
10
11#include "InterfaceConfig.h"
12#include "Util.h"
13
14#include "MenuRow.h"
15#include "MenuColumn.h"
16#include "Menu.h"
17
18
19const int LINE_HEIGHT = 30;
20const int MENU_HEIGHT = 30;
21
22#ifdef _WIN32
23const int MENU_Y_OFFSET = 8; // under windows we have 8 vertical pixels offset.
24 // In 2D an object with y=8, the object is displayed at y=0
25 // change the value in the other platforms (if required).
26#else
27const int MENU_Y_OFFSET = 0;
28#endif
29
30Menu::Menu() {
31 currentColumn = -1;
32 leftMouseOver = 0;
33 rightMouseOver = 0;
34 topMouseOver = 0;
35 bottomMouseOver = 0;
36}
37
38
39Menu::~Menu() {
40 columns.clear();
41}
42
43void Menu::mouseClickColumn(int columnIndex) {
44 if (currentColumn == columnIndex) {
45 currentColumn = -1;
46 } else {
47 currentColumn = columnIndex;
48 }
49}
50
51void Menu::setMouseOver(int leftPosition, int rightPosition, int top, int bottom) {
52 leftMouseOver = leftPosition;
53 rightMouseOver = rightPosition;
54 topMouseOver = top;
55 bottomMouseOver = bottom;
56}
57
58void Menu::renderMouseOver() {
59 if (leftMouseOver != 0 || topMouseOver != 0 || rightMouseOver != 0 ||& bottomMouseOver != 0) {
60 glColor4f(0, 0, 0, 0.1);
61 glBegin(GL_QUADS); {
62 glVertex2f(leftMouseOver, MENU_Y_OFFSET + topMouseOver);
63 glVertex2f(rightMouseOver, MENU_Y_OFFSET + topMouseOver);
64 glVertex2f(rightMouseOver, MENU_Y_OFFSET + bottomMouseOver);
65 glVertex2f(leftMouseOver, MENU_Y_OFFSET + bottomMouseOver);
66 }
67 glEnd();
68 }
69}
70
71bool Menu::mouseClick(int x, int y) {
72 int leftPosition = 0.5 * SPACE_BETWEEN_COLUMNS;
73 int rightPosition = 0;
74 int columnWidth = 0;
75 bool menuFound = false;
76 for (unsigned int i = 0; i < columns.size(); ++i) {
77 columnWidth = columns[i].getWidth();
78 rightPosition = leftPosition + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS;
79 if (x > leftPosition && x < rightPosition && y > 0 && y < MENU_HEIGHT) {
80 mouseClickColumn(i);
81 menuFound = true;
82 break;
83 } else if (currentColumn == i) {
84 menuFound = columns[i].mouseClick(x, y, leftPosition, MENU_HEIGHT, LINE_HEIGHT);
85 if (menuFound) {
86 currentColumn = -1;
87 }
88 }
89 leftPosition = rightPosition;
90 }
91 return menuFound;
92}
93
94bool Menu::mouseOver(int x, int y) {
95 int leftPosition = 0.5 * SPACE_BETWEEN_COLUMNS;
96 int rightPosition;
97 int columnWidth;
98 bool overMenu = false;
99 for (unsigned int i = 0; i < columns.size(); ++i) {
100 columnWidth = columns[i].getWidth();
101 rightPosition = leftPosition + columnWidth + SPACE_BETWEEN_COLUMNS;
102 if (x > leftPosition && x < rightPosition && y > 0 && y < MENU_HEIGHT) {
103 setMouseOver(leftPosition, rightPosition, 0, MENU_HEIGHT);
104 overMenu = true;
105 if (currentColumn >= 0) {
106 columns[currentColumn].setMouseOver(0, 0, 0, 0);
107 currentColumn = i;
108 }
109 break;
110 } else if (currentColumn == i) {
111 columns[i].mouseOver(x, y, leftPosition, MENU_HEIGHT, LINE_HEIGHT);
112 }
113 leftPosition = rightPosition;
114 }
115 if (!overMenu) {
116 setMouseOver(0, 0, 0, 0);
117 }
118 return overMenu;
119}
120
121const float MENU_COLOR[3] = {0.75, 0.75, 0.75};
122
123void Menu::render(int screenWidth, int screenHeight) {
124 float scale = 0.10;
125 int mono = 0;
126 glColor3fv(MENU_COLOR);
127 int width = screenWidth;
128 glEnable(GL_LINE_SMOOTH);
129 glBegin(GL_QUADS); {
130 glVertex2f(0, MENU_Y_OFFSET);
131 glVertex2f(width, MENU_Y_OFFSET);
132 glVertex2f(width, MENU_HEIGHT + MENU_Y_OFFSET);
133 glVertex2f(0 , MENU_HEIGHT + MENU_Y_OFFSET);
134 }
135 glEnd();
136 int xPosition = SPACE_BETWEEN_COLUMNS;
137 char* columnName;
138 int columnWidth;
139 for (unsigned int i = 0; i < columns.size(); ++i) {
140 columnName = columns[i].getName();
141 columnWidth = columns[i].getWidth(scale, mono, xPosition - 0.5 * SPACE_BETWEEN_COLUMNS);
142 drawtext(xPosition, 18 + MENU_Y_OFFSET, scale, 0, 1.0, mono, columnName, 0, 0, 0);
143 xPosition += columnWidth + SPACE_BETWEEN_COLUMNS;
144 if (currentColumn == i) {
145 columns[i].render(MENU_Y_OFFSET, MENU_HEIGHT, LINE_HEIGHT);
146 }
147 }
148 renderMouseOver();
149 }
150
151
152MenuColumn* Menu::addColumn(const char *columnName) {
153 MenuColumn* pColumn;
154 pColumn = new MenuColumn(columnName);
155 columns.push_back(*pColumn);
156 delete pColumn;
157 return &columns[columns.size() - 1];
158}