make menu columns render properly for menu items wider than 100 pixels

This commit is contained in:
ZappoMan 2013-04-13 13:07:02 -07:00
parent ff1095a1e7
commit 093f489520
2 changed files with 25 additions and 9 deletions

View file

@ -41,7 +41,7 @@ void MenuColumn::mouseClickRow(int numberOfRowsIndex) {
} }
bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) { bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) {
int rightPosition = leftPosition + 200; int rightPosition = leftPosition + 200; // XXXBHG - this looks like a hack?
int topPosition = menuHeight; int topPosition = menuHeight;
int bottomPosition = menuHeight; int bottomPosition = menuHeight;
int columnWidth = 0; int columnWidth = 0;
@ -67,13 +67,14 @@ void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPositi
} }
bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int lineHeight) { bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int lineHeight) {
int rightPosition = leftPosition + 100;
int maxColumnWidth = this->getMaxRowWidth();
int rightPosition = leftPosition + maxColumnWidth;
int topPosition = menuHeight; int topPosition = menuHeight;
int bottomPosition = menuHeight; int bottomPosition = menuHeight;
int columnWidth = 0;
bool overMenu = false; bool overMenu = false;
for (unsigned int i = 0; i < rows.size(); ++i) { for (unsigned int i = 0; i < rows.size(); ++i) {
columnWidth = rows[i].getWidth();
topPosition = bottomPosition + lineHeight ; topPosition = bottomPosition + lineHeight ;
if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) { if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) {
setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition); setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition);
@ -116,26 +117,40 @@ int MenuColumn::addRow(const char* rowName, MenuRowCallback callback) {
return 0; return 0;
} }
int MenuColumn::getMaxRowWidth() {
float scale = 0.09;
int mono = 0;
int maxColumnWidth = 100 - (SPACE_BEFORE_ROW_NAME*2); // the minimum size we want
for (unsigned int i = 0; i < rows.size(); ++i) {
maxColumnWidth = std::max(maxColumnWidth,rows[i].getWidth(scale, mono, 0));
}
maxColumnWidth += SPACE_BEFORE_ROW_NAME*2; // space before and after!!
return maxColumnWidth;
}
void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) {
float scale = 0.09;
int mono = 0;
int numberOfRows = rows.size(); int numberOfRows = rows.size();
if (numberOfRows > 0) { if (numberOfRows > 0) {
int maxColumnWidth = this->getMaxRowWidth();
glColor3f(0.9,0.9,0.9); glColor3f(0.9,0.9,0.9);
glBegin(GL_QUADS); { glBegin(GL_QUADS); {
glVertex2f(leftPosition, yOffset + menuHeight); glVertex2f(leftPosition, yOffset + menuHeight);
glVertex2f(leftPosition+100, yOffset + menuHeight); glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight);
glVertex2f(leftPosition+100, yOffset + menuHeight + numberOfRows*lineHeight); glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight + numberOfRows*lineHeight);
glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight); glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight);
} }
glEnd(); glEnd();
} }
float scale = 0.09;
int mono = 0;
int y = menuHeight + lineHeight / 2 ; int y = menuHeight + lineHeight / 2 ;
char* rowName; char* rowName;
int columnWidth = 0; int columnWidth = 0;
for (unsigned int i = 0; i < rows.size(); ++i) { for (unsigned int i = 0; i < rows.size(); ++i) {
rowName = rows[i].getName(); rowName = rows[i].getName();
columnWidth = rows[i].getWidth(scale, mono, 0);
drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0); drawtext(leftPosition + SPACE_BEFORE_ROW_NAME, y+5 + yOffset, scale, 0, 1.0, mono, rowName, 0, 0, 0);
y += lineHeight; y += lineHeight;
} }

View file

@ -27,6 +27,7 @@ public:
void render(int yOffset, int menuHeight, int lineHeight); void render(int yOffset, int menuHeight, int lineHeight);
void renderMouseOver(int yOffset); void renderMouseOver(int yOffset);
int addRow(const char* rowName, MenuRowCallback callback); int addRow(const char* rowName, MenuRowCallback callback);
int getMaxRowWidth();
private: private:
char columnName[MAX_COLUMN_NAME]; char columnName[MAX_COLUMN_NAME];
int columnWidth; int columnWidth;