#19171 Missing Code Review changes - part 2

This commit is contained in:
vincent 2013-04-11 00:47:53 +02:00
parent b43475a34e
commit ebc5874441
4 changed files with 37 additions and 36 deletions

View file

@ -9,9 +9,9 @@
#include "Menu.h" #include "Menu.h"
const int lineHeight = 30; const int LINE_HEIGHT = 30;
const int menuHeight = 30; const int MENU_HEIGHT = 30;
const int yOffset = 8; // under windows we have 8 vertical pixels offset. In 2D an object with y=8, the object is displayed at y=0 const int MENU_Y_OFFSET = 8; // under windows we have 8 vertical pixels offset. In 2D an object with y=8, the object is displayed at y=0
// change the value in the other platforms (if required). // change the value in the other platforms (if required).
@ -28,29 +28,29 @@ Menu::~Menu() {
columns.clear(); columns.clear();
} }
void Menu::mouseClickColumn(int iColumnIndex) { void Menu::mouseClickColumn(int columnIndex) {
if (currentColumn == iColumnIndex) { if (currentColumn == columnIndex) {
currentColumn = -1; currentColumn = -1;
} else { } else {
currentColumn = iColumnIndex; currentColumn = columnIndex;
} }
} }
void Menu::setMouseOver(int leftPosition, int rightPosition, int yTop, int yBottom) { void Menu::setMouseOver(int leftPosition, int rightPosition, int top, int bottom) {
leftMouseOver = leftPosition; leftMouseOver = leftPosition;
rightMouseOver = rightPosition; rightMouseOver = rightPosition;
topMouseOver = yTop; topMouseOver = top;
bottomMouseOver = yBottom; bottomMouseOver = bottom;
} }
void Menu::renderMouseOver() { void Menu::renderMouseOver() {
if (leftMouseOver != 0 || topMouseOver != 0 || rightMouseOver != 0 ||& bottomMouseOver != 0) { if (leftMouseOver != 0 || topMouseOver != 0 || rightMouseOver != 0 ||& bottomMouseOver != 0) {
glColor4f(0, 0, 0, 0.1); glColor4f(0, 0, 0, 0.1);
glBegin(GL_QUADS); { glBegin(GL_QUADS); {
glVertex2f(leftMouseOver, yOffset + topMouseOver); glVertex2f(leftMouseOver, MENU_Y_OFFSET + topMouseOver);
glVertex2f(rightMouseOver, yOffset + topMouseOver); glVertex2f(rightMouseOver, MENU_Y_OFFSET + topMouseOver);
glVertex2f(rightMouseOver, yOffset + bottomMouseOver); glVertex2f(rightMouseOver, MENU_Y_OFFSET + bottomMouseOver);
glVertex2f(leftMouseOver, yOffset + bottomMouseOver); glVertex2f(leftMouseOver, MENU_Y_OFFSET + bottomMouseOver);
} }
glEnd(); glEnd();
} }
@ -64,12 +64,12 @@ bool Menu::mouseClick(int x, int y) {
for (unsigned int i = 0; i < columns.size(); ++i) { for (unsigned int i = 0; i < columns.size(); ++i) {
columnWidth = columns[i].getWidth(); columnWidth = columns[i].getWidth();
rightPosition = leftPosition + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS; rightPosition = leftPosition + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS;
if (x > leftPosition && x < rightPosition && y > 0 && y < menuHeight) { if (x > leftPosition && x < rightPosition && y > 0 && y < MENU_HEIGHT) {
mouseClickColumn(i); mouseClickColumn(i);
menuFound = true; menuFound = true;
break; break;
} else if (currentColumn == i) { } else if (currentColumn == i) {
menuFound = columns[i].mouseClick(x, y, leftPosition, menuHeight, lineHeight); menuFound = columns[i].mouseClick(x, y, leftPosition, MENU_HEIGHT, LINE_HEIGHT);
if (menuFound) { if (menuFound) {
currentColumn = -1; currentColumn = -1;
} }
@ -87,8 +87,8 @@ bool Menu::mouseOver(int x, int y) {
for (unsigned int i = 0; i < columns.size(); ++i) { for (unsigned int i = 0; i < columns.size(); ++i) {
columnWidth = columns[i].getWidth(); columnWidth = columns[i].getWidth();
rightPosition = leftPosition + columnWidth + SPACE_BETWEEN_COLUMNS; rightPosition = leftPosition + columnWidth + SPACE_BETWEEN_COLUMNS;
if (x > leftPosition && x < rightPosition && y > 0 && y < menuHeight) { if (x > leftPosition && x < rightPosition && y > 0 && y < MENU_HEIGHT) {
setMouseOver(leftPosition, rightPosition, 0, menuHeight); setMouseOver(leftPosition, rightPosition, 0, MENU_HEIGHT);
overMenu = true; overMenu = true;
if (currentColumn >= 0) { if (currentColumn >= 0) {
columns[currentColumn].setMouseOver(0, 0, 0, 0); columns[currentColumn].setMouseOver(0, 0, 0, 0);
@ -96,7 +96,7 @@ bool Menu::mouseOver(int x, int y) {
} }
break; break;
} else if (currentColumn == i) { } else if (currentColumn == i) {
columns[i].mouseOver(x, y, leftPosition, menuHeight, lineHeight); columns[i].mouseOver(x, y, leftPosition, MENU_HEIGHT, LINE_HEIGHT);
} }
leftPosition = rightPosition; leftPosition = rightPosition;
} }
@ -113,10 +113,10 @@ void Menu::render(int screenWidth, int screenHeight) {
int width = screenWidth; int width = screenWidth;
int height = screenHeight; int height = screenHeight;
glBegin(GL_QUADS); { glBegin(GL_QUADS); {
glVertex2f(0, yOffset); glVertex2f(0, MENU_Y_OFFSET);
glVertex2f(width, yOffset); glVertex2f(width, MENU_Y_OFFSET);
glVertex2f(width, menuHeight + yOffset); glVertex2f(width, MENU_HEIGHT + MENU_Y_OFFSET);
glVertex2f(0 , menuHeight + yOffset); glVertex2f(0 , MENU_HEIGHT + MENU_Y_OFFSET);
} }
glEnd(); glEnd();
int xPosition = SPACE_BETWEEN_COLUMNS; int xPosition = SPACE_BETWEEN_COLUMNS;
@ -125,10 +125,10 @@ void Menu::render(int screenWidth, int screenHeight) {
for (unsigned int i = 0; i < columns.size(); ++i) { for (unsigned int i = 0; i < columns.size(); ++i) {
columnName = columns[i].getName(); columnName = columns[i].getName();
columnWidth = columns[i].getWidth(scale, mono, xPosition - 0.5 * SPACE_BETWEEN_COLUMNS); columnWidth = columns[i].getWidth(scale, mono, xPosition - 0.5 * SPACE_BETWEEN_COLUMNS);
drawtext(xPosition, 18 + yOffset, scale, 0, 1.0, mono, columnName, 0, 0, 0); drawtext(xPosition, 18 + MENU_Y_OFFSET, scale, 0, 1.0, mono, columnName, 0, 0, 0);
xPosition += columnWidth + SPACE_BETWEEN_COLUMNS; xPosition += columnWidth + SPACE_BETWEEN_COLUMNS;
if (currentColumn == i) { if (currentColumn == i) {
columns[i].render(yOffset, menuHeight, lineHeight); columns[i].render(MENU_Y_OFFSET, MENU_HEIGHT, LINE_HEIGHT);
} }
} }
renderMouseOver(); renderMouseOver();

View file

@ -38,18 +38,18 @@ bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int
int topPosition = menuHeight; int topPosition = menuHeight;
int bottomPosition = menuHeight; int bottomPosition = menuHeight;
int columnWidth = 0; int columnWidth = 0;
bool bRet = false; bool menuFound = false;
for (unsigned int i = 0; i < rows.size(); ++i) { for (unsigned int i = 0; i < rows.size(); ++i) {
columnWidth = rows[i].getWidth(); 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) {
mouseClickRow(i); mouseClickRow(i);
bRet = true; menuFound = true;
break; break;
} }
bottomPosition = topPosition; bottomPosition = topPosition;
} }
return bRet; return menuFound;
} }
void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPosition, int bottomPosition) { void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPosition, int bottomPosition) {
@ -64,21 +64,21 @@ bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int l
int topPosition = menuHeight; int topPosition = menuHeight;
int bottomPosition = menuHeight; int bottomPosition = menuHeight;
int columnWidth = 0; int columnWidth = 0;
bool bRet = 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(); 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);
bRet = true; overMenu = true;
break; break;
} }
bottomPosition = topPosition; bottomPosition = topPosition;
} }
if (!bRet) { if (!overMenu) {
setMouseOver(0, 0, 0, 0); setMouseOver(0, 0, 0, 0);
} }
return bRet; return overMenu;
} }
char* MenuColumn::getName() { char* MenuColumn::getName() {
@ -102,10 +102,10 @@ int MenuColumn::getLeftPosition() {
} }
int MenuColumn::addRow(char * rowName, PFNRowCallback callback) { int MenuColumn::addRow(char * rowName, PFNRowCallback callback) {
MenuRow* pRow; MenuRow* row;
pRow = new MenuRow(rowName, callback); row = new MenuRow(rowName, callback);
rows.push_back(*pRow); rows.push_back(*row);
delete pRow; delete row;
return 0; return 0;
} }

View file

@ -11,7 +11,7 @@ public:
bool mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight); bool mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight);
void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); void setMouseOver(int xLeft, int xRight, int yTop, int yBottom);
bool mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight); bool mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight);
char * getName(); char* getName();
int getWidth(float scale, int mono, int leftPosition); int getWidth(float scale, int mono, int leftPosition);
int getWidth(); int getWidth();
int getLeftPosition(); int getLeftPosition();

View file

@ -11,6 +11,7 @@
MenuRow::MenuRow() { MenuRow::MenuRow() {
} }
MenuRow::MenuRow(char * columnName, PFNRowCallback callback) { MenuRow::MenuRow(char * columnName, PFNRowCallback callback) {
int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName));
strncpy(this->rowName, columnName, length); strncpy(this->rowName, columnName, length);