History

#19171 split of menu.cpp in menuColumn.cpp and menuRow.cpp

vincent committed 13 years ago

Commit eb646ad1 parent d6189697 files · +263 −231Browse files

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

Unified · Split

interface/src/MenuColumn.cpp+150−0
@@ -0,0 +1,150 @@
1+
2+#include <algorithm>
3+#include "InterfaceConfig.h"
4+#include "MenuRow.h"
5+#include "MenuColumn.h"
6+#include "Menu.h"
7+#include "Util.h"
8+
9+
10+
11+MenuColumn::MenuColumn()
12+{
13+}
14+MenuColumn::MenuColumn(char * columnName)
15+{
16+ int length = std::min(MAX_COLUMN_NAME - 1,(int) strlen(columnName));
17+ strncpy(this->columnName, columnName, length);
18+ this->columnName[length] = '\0';
19+ columnWidth = 0;
20+ leftPosition = 0;
21+ xLeftMouseOver = 0;
22+ xRightMouseOver = 0;
23+ yTopMouseOver = 0;
24+ yBottomMouseOver = 0;
25+}
26+
27+MenuColumn::~MenuColumn()
28+{
29+}
30+
31+void MenuColumn::mouseClickRow(int iRowIndex) {
32+ rows[iRowIndex].call();
33+}
34+
35+bool MenuColumn::mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight) {
36+ int xRight = xLeft + 200;
37+ int yTop = menuHeight;
38+ int yBottom = menuHeight;
39+ int columnWidth;
40+ bool bRet = false;
41+ for (unsigned int i = 0; i < rows.size(); ++i) {
42+ columnWidth = rows[i].getWidth();
43+ yTop = yBottom + lineHeight;
44+ if (x > xLeft && x < xRight && y > yBottom && y < yTop) {
45+ mouseClickRow(i);
46+ bRet = true;
47+ break;
48+ }
49+ yBottom = yTop;
50+ }
51+ return bRet;
52+}
53+
54+void MenuColumn::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) {
55+ xLeftMouseOver = xLeft;
56+ xRightMouseOver = xRight;
57+ yTopMouseOver = yTop;
58+ yBottomMouseOver = yBottom;
59+}
60+
61+bool MenuColumn::mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight) {
62+ int xRight = xLeft + 100;
63+ int yTop = menuHeight;
64+ int yBottom = menuHeight;
65+ int columnWidth;
66+ bool bRet = false;
67+ for (unsigned int i = 0; i < rows.size(); ++i) {
68+ columnWidth = rows[i].getWidth();
69+ yTop = yBottom + lineHeight ;
70+ if (x > xLeft && x < xRight && y > yBottom && y < yTop) {
71+ setMouseOver(xLeft, xRight, yBottom, yTop);
72+ bRet = true;
73+ break;
74+ }
75+ yBottom = yTop;
76+ }
77+ if (!bRet) {
78+ setMouseOver(0, 0, 0, 0);
79+ }
80+ return bRet;
81+}
82+
83+char * MenuColumn::getName() {
84+ return this->columnName;
85+}
86+
87+int MenuColumn::getWidth(float scale, int mono, int leftPosition){
88+ if (columnWidth == 0) {
89+ columnWidth = widthText( scale, mono, this->columnName);
90+ this->leftPosition = leftPosition;
91+ }
92+ return columnWidth;
93+}
94+
95+int MenuColumn::getWidth(){
96+ return columnWidth;
97+}
98+
99+int MenuColumn::getLeftPosition(){
100+ return leftPosition;
101+}
102+
103+int MenuColumn::addRow(char * rowName, PFNRowCallback callback){
104+ MenuRow * pRow;
105+ pRow = new MenuRow(rowName, callback);
106+ rows.push_back(*pRow);
107+ delete pRow;
108+ return 0;
109+
110+}
111+
112+void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) {
113+ int iRow = rows.size();
114+ if (iRow > 0) {
115+ glColor3f(0.9,0.9,0.9);
116+ glBegin(GL_QUADS); {
117+ glVertex2f(leftPosition, yOffset + menuHeight);
118+ glVertex2f(leftPosition+100, yOffset + menuHeight);
119+ glVertex2f(leftPosition+100, yOffset + menuHeight + iRow*lineHeight);
120+ glVertex2f(leftPosition , yOffset + menuHeight + iRow* lineHeight);
121+ }
122+ glEnd();
123+ }
124+ float scale = 0.10;
125+ int mono = 0;
126+ int y = menuHeight + lineHeight / 2 ;
127+ char * rowName;
128+ int columnWidth;
129+ for (unsigned int i = 0; i < rows.size(); ++i)
130+ {
131+ rowName = rows[i].getName();
132+ columnWidth = rows[i].getWidth(scale, mono, 0);
133+ drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0);
134+ y += lineHeight;
135+ }
136+ renderMouseOver(yOffset);
137+}
138+
139+void MenuColumn::renderMouseOver(int yOffset) {
140+ if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 0){
141+ glColor4f(0,0,0,0.1);
142+ glBegin(GL_QUADS); {
143+ glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver);
144+ glVertex2f(xRightMouseOver, yOffset + yTopMouseOver);
145+ glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver);
146+ glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver);
147+ }
148+ glEnd();
149+ }
150+}