From 6a5c51bc693ff1872f88d81ce19a6a026435fdb6 Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 10 Apr 2013 21:31:29 +0200 Subject: [PATCH 1/6] #19171 Add a simple openGL menu that will work x-platform --- interface/src/Menu.cpp | 330 +++++++++++++++++++++++++++++++++++++++++ interface/src/Menu.h | 72 +++++++++ interface/src/Util.cpp | 11 ++ interface/src/Util.h | 1 + interface/src/main.cpp | 112 +++++++++++--- 5 files changed, 508 insertions(+), 18 deletions(-) create mode 100644 interface/src/Menu.cpp create mode 100644 interface/src/Menu.h diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp new file mode 100644 index 0000000000..160b59fae7 --- /dev/null +++ b/interface/src/Menu.cpp @@ -0,0 +1,330 @@ + +#include +#include "InterfaceConfig.h" +#include "Menu.h" +#include "Util.h" + +int menuHeight = 30; +int lineHeight = 30; +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 + // change the value in the other platforms (if required). + +MenuRow::MenuRow() +{ +} +MenuRow::MenuRow(char * columnName, PFNRowCallback callback) +{ + int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); + strncpy(this->rowName, columnName, length); + memcpy(this->rowName + length, " \0", 5); + this->callback = callback; + rowWidth = 0; +} + +MenuRow::~MenuRow() +{ +} + +void MenuRow::call() { + callback(-2); +} + +char * MenuRow::getName() { + int length = (int) strlen(this->rowName) - 4; + int currentValue = callback(-1); + if (currentValue == 0) { + memcpy(this->rowName + length, " OFF\0", 5); + } else if (currentValue == 1) { + memcpy(this->rowName + length, " ON \0", 5); + } else { + memcpy(this->rowName + length, " \0", 5); + } + return this->rowName; +} + +int MenuRow::getWidth(float scale, int mono, int leftPosition){ + if (rowWidth == 0) { + rowWidth = widthText( scale, mono, this->rowName); + } + return rowWidth; +} + +int MenuRow::getWidth(){ + return rowWidth; +} + + +MenuColumn::MenuColumn() +{ +} +MenuColumn::MenuColumn(char * columnName) +{ + int length = std::min(MAX_COLUMN_NAME - 1,(int) strlen(columnName)); + strncpy(this->columnName, columnName, length); + this->columnName[length] = '\0'; + columnWidth = 0; + leftPosition = 0; + xLeftMouseOver = 0; + xRightMouseOver = 0; + yTopMouseOver = 0; + yBottomMouseOver = 0; +} + +MenuColumn::~MenuColumn() +{ +} + +void MenuColumn::mouseClickRow(int iRowIndex) { + rows[iRowIndex].call(); +} + +bool MenuColumn::mouseClick(int x, int y, int xLeft) { + int xRight = xLeft + 200; + int yTop = menuHeight; + int yBottom = menuHeight; + int columnWidth; + bool bRet = false; + for (unsigned int i = 0; i < rows.size(); ++i) { + columnWidth = rows[i].getWidth(); + yTop = yBottom + lineHeight; + if (x > xLeft && x < xRight && y > yBottom && y < yTop) { + mouseClickRow(i); + bRet = true; + break; + } + yBottom = yTop; + } + return bRet; +} + +void MenuColumn::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) { + xLeftMouseOver = xLeft; + xRightMouseOver = xRight; + yTopMouseOver = yTop; + yBottomMouseOver = yBottom; +} + +bool MenuColumn::mouseOver(int x, int y, int xLeft) { + int xRight = xLeft + 100; + int yTop = menuHeight; + int yBottom = menuHeight; + int columnWidth; + bool bRet = false; + for (unsigned int i = 0; i < rows.size(); ++i) { + columnWidth = rows[i].getWidth(); + yTop = yBottom + lineHeight ; + if (x > xLeft && x < xRight && y > yBottom && y < yTop) { + setMouseOver(xLeft, xRight, yBottom, yTop); + bRet = true; + break; + } + yBottom = yTop; + } + if (!bRet) { + setMouseOver(0, 0, 0, 0); + } + return bRet; +} + +char * MenuColumn::getName() { + return this->columnName; +} + +int MenuColumn::getWidth(float scale, int mono, int leftPosition){ + if (columnWidth == 0) { + columnWidth = widthText( scale, mono, this->columnName); + this->leftPosition = leftPosition; + } + return columnWidth; +} + +int MenuColumn::getWidth(){ + return columnWidth; +} + +int MenuColumn::getLeftPosition(){ + return leftPosition; +} + +int MenuColumn::addRow(char * rowName, PFNRowCallback callback){ + MenuRow * pRow; + pRow = new MenuRow(rowName, callback); + rows.push_back(*pRow); + delete pRow; + return 0; + +} + +void MenuColumn::render() { + int iRow = rows.size(); + if (iRow > 0) { + glColor3f(0.9,0.9,0.9); + glBegin(GL_QUADS); { + glVertex2f(leftPosition, yOffset + menuHeight); + glVertex2f(leftPosition+100, yOffset + menuHeight); + glVertex2f(leftPosition+100, yOffset + menuHeight + iRow*lineHeight); + glVertex2f(leftPosition , yOffset + menuHeight + iRow* lineHeight); + } + glEnd(); + } + float scale = 0.10; + int mono = 0; + int y = menuHeight + lineHeight / 2 ; + char * rowName; + int columnWidth; + for (unsigned int i = 0; i < rows.size(); ++i) + { + 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); + y += lineHeight; + } + renderMouseOver(); +} + +void MenuColumn::renderMouseOver() { + if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 0){ + glColor4f(0,0,0,0.1); + glBegin(GL_QUADS); { + glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver); + glVertex2f(xRightMouseOver, yOffset + yTopMouseOver); + glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver); + glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver); + } + glEnd(); + } +} + +Menu::Menu(){ + iCurrentColumn = -1; + xLeftMouseOver = 0; + xRightMouseOver = 0; + yTopMouseOver = 0; + yBottomMouseOver = 0; +} + + +Menu::~Menu(){ + columns.clear(); +} + +void Menu::mouseClickColumn(int iColumnIndex) { + if (iCurrentColumn == iColumnIndex) { + iCurrentColumn = -1; + } else { + iCurrentColumn = iColumnIndex; + } +} + +void Menu::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) { + xLeftMouseOver = xLeft; + xRightMouseOver = xRight; + yTopMouseOver = yTop; + yBottomMouseOver = yBottom; +} + +void Menu::renderMouseOver() { + if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 0){ + glColor4f(0,0,0,0.1); + glBegin(GL_QUADS); { + glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver); + glVertex2f(xRightMouseOver, yOffset + yTopMouseOver); + glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver); + glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver); + } + glEnd(); + } +} + +bool Menu::mouseClick(int x, int y) { + int xLeft = 0.5 * SPACE_BETWEEN_COLUMNS; + int xRight; + int columnWidth; + bool bRet = false; + for (unsigned int i = 0; i < columns.size(); ++i) + { + columnWidth = columns[i].getWidth(); + xRight = xLeft + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS; + if (x > xLeft && x < xRight && y > 0 && y < menuHeight){ + mouseClickColumn(i); + bRet = true; + break; + } + if (iCurrentColumn == i) { + bRet = columns[i].mouseClick(x, y, xLeft); + if (bRet) { + iCurrentColumn = -1; + } + } + xLeft = xRight; + } + return bRet; +} + +bool Menu::mouseOver(int x, int y) { + int xLeft = 0.5 * SPACE_BETWEEN_COLUMNS; + int xRight; + int columnWidth; + bool bRet = false; + for (unsigned int i = 0; i < columns.size(); ++i) + { + columnWidth = columns[i].getWidth(); + xRight = xLeft + columnWidth + SPACE_BETWEEN_COLUMNS; + if (x > xLeft && x < xRight && y > 0 && y < menuHeight){ + printf("Mouse Over: %d %d", x, y); + + setMouseOver(xLeft, xRight, 0, menuHeight); + bRet = true; + if (iCurrentColumn >= 0) { + columns[iCurrentColumn].setMouseOver(0, 0, 0, 0); + iCurrentColumn = i; + } + break; + } else if (iCurrentColumn == i) { + columns[i].mouseOver(x, y, xLeft); + } + xLeft = xRight; + } + if (!bRet) { + setMouseOver(0, 0, 0, 0); + } + return bRet; +} + +void Menu::render(int screenwidth, int screenheight) { + float scale = 0.10; + int mono = 0; + glColor3f(0.9,0.9,0.9); + int width = screenwidth; + int height = screenheight; + glBegin(GL_QUADS); { + glVertex2f(0, yOffset); + glVertex2f(width, yOffset); + glVertex2f( width, menuHeight + yOffset); + glVertex2f(0 , menuHeight + yOffset); + } + glEnd(); + int x = SPACE_BETWEEN_COLUMNS; + char * columnName; + int columnWidth; + for (unsigned int i = 0; i < columns.size(); ++i) + { + columnName = columns[i].getName(); + columnWidth = columns[i].getWidth(scale, mono, x- 0.5 * SPACE_BETWEEN_COLUMNS); + drawtext(x,18 + yOffset, scale, 0, 1.0, mono, columnName, 0, 0, 0); + x += columnWidth + SPACE_BETWEEN_COLUMNS; + if (iCurrentColumn == i) { + columns[i].render(); + } + } + renderMouseOver(); + } + + +MenuColumn* Menu::addColumn(char *columnName) { + MenuColumn * pColumn; + pColumn = new MenuColumn(columnName); + columns.push_back(*pColumn); + delete pColumn; + return &columns[columns.size()-1]; +} \ No newline at end of file diff --git a/interface/src/Menu.h b/interface/src/Menu.h new file mode 100644 index 0000000000..7b8eb9bad6 --- /dev/null +++ b/interface/src/Menu.h @@ -0,0 +1,72 @@ + +#include + +#define MAX_COLUMN_NAME 50 +#define SPACE_BETWEEN_COLUMNS 20 +#define SPACE_BEFORE_ROW_NAME 10 +typedef int(CALLBACK * PFNRowCallback)(int); + + +class MenuRow { + public: + MenuRow(); + MenuRow(char * rowName, PFNRowCallback); + ~MenuRow(); + void call(); + char * getName(); + int getWidth(float scale, int mono, int leftPosition); + int getWidth(); +private: + char rowName[MAX_COLUMN_NAME]; + int rowWidth; + PFNRowCallback callback; +}; + + +class MenuColumn { + public: + MenuColumn(); + MenuColumn(char * columnName); + ~MenuColumn(); + void mouseClickRow(int iColumnIndex); + bool mouseClick(int x, int y, int xLeft); + void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); + bool mouseOver(int x, int y, int xLeft); + char * getName(); + int getWidth(float scale, int mono, int leftPosition); + int getWidth(); + int getLeftPosition(); + void render(); + void MenuColumn::renderMouseOver(); + int addRow(char * rowName, PFNRowCallback callback); +private: + char columnName[MAX_COLUMN_NAME]; + int columnWidth; + int leftPosition; + std::vector rows; + int xLeftMouseOver; + int xRightMouseOver; + int yTopMouseOver; + int yBottomMouseOver; +}; + +class Menu { + public: + Menu(); + ~Menu(); + void mouseClickColumn(int iColumnIndex); + void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); + void renderMouseOver(); + bool mouseClick(int x, int y); + bool mouseOver(int x, int y); + void render(int screenwidth, int screenheight); + void renderColumn(int i); + MenuColumn* addColumn(char *columnName); +private: + std::vector columns; + int iCurrentColumn; + int xLeftMouseOver; + int xRightMouseOver; + int yTopMouseOver; + int yBottomMouseOver; +}; \ No newline at end of file diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index a670f48f9e..46f0398a36 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -90,6 +90,17 @@ double diffclock(timeval *clock1,timeval *clock2) return diffms; } +int widthText(float scale, int mono, char *string) { + int width = 0; + if (!mono) { + width =scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string); + } + else { + width =scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string); + } + return width; +} + void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char const* string, float r, float g, float b) { diff --git a/interface/src/Util.h b/interface/src/Util.h index 8efe6f549e..766b094f8c 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -41,6 +41,7 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float float randFloat(); void render_world_box(); void render_vector(glm::vec3 * vec); +int widthText(float scale, int mono, char *string); void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char const* string, float r=1.0, float g=1.0, float b=1.0); void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec, diff --git a/interface/src/main.cpp b/interface/src/main.cpp index c2d8c1fc73..b1e69d749c 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -57,6 +57,7 @@ #include "FieldOfView.h" #include "Stars.h" +#include "Menu.h" #include "Head.h" #include "Hand.h" #include "Camera.h" @@ -168,6 +169,9 @@ int mouseX, mouseY; // Where is the mouse int mouseStartX, mouseStartY; // Mouse location at start of last down click int mousePressed = 0; // true if mouse has been pressed (clear when finished) +Menu menu; // main menu +int menuOn = 0; // Whether to show onscreen menu + // // Serial USB Variables // @@ -233,23 +237,27 @@ void Timer(int extra) void displayStats(void) { + int statsVerticalOffset = 50; + if (menuOn == 0) { + statsVerticalOffset = 8; + } // bitmap chars are about 10 pels high char legend[] = "/ - toggle this display, Q - exit, H - show head, M - show hand, T - test audio"; - drawtext(10, 15, 0.10f, 0, 1.0, 0, legend); + drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, legend); char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene"; - drawtext(10, 32, 0.10f, 0, 1.0, 0, legend2); + drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2); glm::vec3 headPos = myHead.getPos(); char stats[200]; sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)=( %f , %f , %f )", FPS, packetsPerSecond, bytesPerSecond, headPos.x,headPos.y,headPos.z); - drawtext(10, 49, 0.10f, 0, 1.0, 0, stats); + drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats); if (serialPort.active) { sprintf(stats, "ADC samples = %d, LED = %d", serialPort.getNumSamples(), serialPort.getLED()); - drawtext(300, 30, 0.10f, 0, 1.0, 0, stats); + drawtext(300, statsVerticalOffset + 30, 0.10f, 0, 1.0, 0, stats); } // Output the ping times to the various agents @@ -262,22 +270,22 @@ void displayStats(void) std::stringstream voxelStats; voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered(); - drawtext(10,70,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); + drawtext(10, statsVerticalOffset + 70, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); voxelStats << "Voxels Created: " << voxels.getVoxelsCreated() << " (" << voxels.getVoxelsCreatedRunningAverage() << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) "; - drawtext(10,250,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); + drawtext(10, statsVerticalOffset + 250, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); voxelStats << "Voxels Colored: " << voxels.getVoxelsColored() << " (" << voxels.getVoxelsColoredRunningAverage() << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) "; - drawtext(10,270,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); + drawtext(10, statsVerticalOffset + 270, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); voxelStats << "Voxels Bytes Read: " << voxels.getVoxelsBytesRead() << " (" << voxels.getVoxelsBytesReadRunningAverage() << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) "; - drawtext(10,290,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); + drawtext(10, statsVerticalOffset + 290,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); long int voxelsBytesPerColored = voxels.getVoxelsColored() ? voxels.getVoxelsBytesRead()/voxels.getVoxelsColored() : 0; @@ -286,7 +294,7 @@ void displayStats(void) voxelStats << "Voxels Bytes per Colored: " << voxelsBytesPerColored << " (" << voxelsBytesPerColoredAvg << "/sec in last "<< COUNTETSTATS_TIME_FRAME << " seconds) "; - drawtext(10,310,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); + drawtext(10, statsVerticalOffset + 310, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); if (::perfStatsOn) { @@ -295,7 +303,7 @@ void displayStats(void) int lines = PerfStat::DumpStats(perfStatLinesArray); int atZ = 150; // arbitrary place on screen that looks good for (int line=0; line < lines; line++) { - drawtext(10,atZ,0.10f, 0, 1.0, 0, perfStatLinesArray[line]); + drawtext(10, statsVerticalOffset + atZ, 0.10f, 0, 1.0, 0, perfStatLinesArray[line]); delete perfStatLinesArray[line]; // we're responsible for cleanup perfStatLinesArray[line]=NULL; atZ+=20; // height of a line @@ -828,6 +836,13 @@ void display(void) glPointSize(1.0f); displayStats(); } + + // Show menu + if (menuOn) { + glLineWidth(1.0f); + glPointSize(1.0f); + menu.render(WIDTH,HEIGHT); + } // Draw number of nearby people always glPointSize(1.0f); @@ -851,6 +866,62 @@ void display(void) frameCount++; } +int CALLBACK setValue(int state, int *value) { + if (state == -2) { + *value = !(*value); + } else if (state == -1) { + return *value; + } else { + *value = state; + } + return *value; +} + +int CALLBACK setHead(int state) { + return setValue(state, &displayHead); +} + +int CALLBACK setField(int state) { + return setValue(state, &displayField); +} + +int CALLBACK setNoise(int state) { + int iRet = setValue(state, &noiseOn); + if (noiseOn) + { + myHead.setNoise(noise); + } + else + { + myHead.setNoise(0); + } + return iRet; +} + +int CALLBACK setStats(int state) { + return setValue(state, &statsOn); +} + +int CALLBACK setMenu(int state) { + return setValue(state, &menuOn); +} + +int CALLBACK setMirror(int state) { + return setValue(state, &headMirror); +} + +void initMenu() { + MenuColumn *menuColumnOptions, *menuColumnTools; + menuColumnOptions = menu.addColumn("Options"); + menuColumnOptions->addRow("Head", setHead); + menuColumnOptions->addRow("Field", setField); + menuColumnOptions->addRow("Noise", setNoise); + menuColumnOptions->addRow("Mirror", setMirror); + menuColumnTools = menu.addColumn("Tools"); + menuColumnTools->addRow("Stats", setStats); + menuColumnTools->addRow("Menu", setMenu); +} + void testPointToVoxel() { float y=0; @@ -1022,7 +1093,8 @@ void key(unsigned char k, int x, int y) #endif } - if (k == 'm') headMirror = !headMirror; +// if (k == 'm') headMirror = !headMirror; // move in the menu + if (k == 'm') setMenu(-2); if (k == 'f') displayField = !displayField; if (k == 'l') displayLevels = !displayLevels; @@ -1166,12 +1238,14 @@ void mouseFunc( int button, int state, int x, int y ) { if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { - mouseX = x; - mouseY = y; - mousePressed = 1; - lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT); - mouseStartX = x; - mouseStartY = y; + if (menu.mouseClick(x, y) == false) { + mouseX = x; + mouseY = y; + mousePressed = 1; + lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT); + mouseStartX = x; + mouseStartY = y; + } } if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) { @@ -1192,6 +1266,7 @@ void motionFunc( int x, int y) void mouseoverFunc( int x, int y) { + menu.mouseOver(x, y); mouseX = x; mouseY = y; if (mousePressed == 0) @@ -1255,7 +1330,8 @@ int main(int argc, const char * argv[]) #endif printf( "Created Display Window.\n" ); - + + initMenu(); initDisplay(); printf( "Initialized Display.\n" ); From d6189694c82ac19bf0e518541e882043a50bc2bf Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 10 Apr 2013 21:55:29 +0200 Subject: [PATCH 2/6] #19171 move of usleep function to SharedUtil.cpp --- shared/src/AgentList.cpp | 12 ------------ shared/src/SharedUtil.cpp | 20 ++++++++++++++++++++ shared/src/SharedUtil.h | 4 ++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 76626db04a..1add03d6ff 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -311,18 +311,6 @@ void AgentList::stopSilentAgentRemovalThread() { pthread_join(removeSilentAgentsThread, NULL); } -#ifdef _WIN32 - void usleep(int waitTime) { - __int64 time1 = 0, time2 = 0, sysFreq = 0; - - QueryPerformanceCounter((LARGE_INTEGER *)&time1); - QueryPerformanceFrequency((LARGE_INTEGER *)&sysFreq); - do { - QueryPerformanceCounter((LARGE_INTEGER *)&time2); - } while( (time2 - time1) < waitTime); - } -#endif - void *checkInWithDomainServer(void *args) { AgentList *parentAgentList = (AgentList *)args; diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index 60d3b1559f..7a8ae3772f 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -9,6 +9,9 @@ #include #include #include +#ifdef _WIN32 +#include "Syssocket.h" +#endif #include "SharedUtil.h" #include "OctalCode.h" @@ -16,6 +19,11 @@ #include #endif + +#ifdef _WIN32 +#endif + + double usecTimestamp(timeval *time) { return (time->tv_sec * 1000000.0 + time->tv_usec); } @@ -336,3 +344,15 @@ void printVoxelCode(unsigned char* voxelCode) { outputBits(voxelCode[i]); } } + +#ifdef _WIN32 + void usleep(int waitTime) { + __int64 time1 = 0, time2 = 0, sysFreq = 0; + + QueryPerformanceCounter((LARGE_INTEGER *)&time1); + QueryPerformanceFrequency((LARGE_INTEGER *)&sysFreq); + do { + QueryPerformanceCounter((LARGE_INTEGER *)&time2); + } while( (time2 - time1) < waitTime); + } +#endif diff --git a/shared/src/SharedUtil.h b/shared/src/SharedUtil.h index 8468a5601a..34ac6d8b86 100644 --- a/shared/src/SharedUtil.h +++ b/shared/src/SharedUtil.h @@ -50,4 +50,8 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, bool createVoxelEditMessage(unsigned char command, short int sequence, int voxelCount, VoxelDetail* voxelDetails, unsigned char*& bufferOut, int& sizeOut); +#ifdef _WIN32 +void usleep(int waitTime); +#endif + #endif /* defined(__hifi__SharedUtil__) */ From eb646ade8450e2db0be4fcaaaa01defd207a4237 Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 10 Apr 2013 22:39:01 +0200 Subject: [PATCH 3/6] #19171 split of menu.cpp in menuColumn.cpp and menuRow.cpp --- interface/src/Menu.cpp | 196 ++--------------------------------- interface/src/Menu.h | 42 -------- interface/src/MenuColumn.cpp | 150 +++++++++++++++++++++++++++ interface/src/MenuColumn.h | 28 +++++ interface/src/MenuRow.cpp | 53 ++++++++++ interface/src/MenuRow.h | 23 ++++ interface/src/main.cpp | 2 + 7 files changed, 263 insertions(+), 231 deletions(-) create mode 100644 interface/src/MenuColumn.cpp create mode 100644 interface/src/MenuColumn.h create mode 100644 interface/src/MenuRow.cpp create mode 100644 interface/src/MenuRow.h diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 160b59fae7..730b2e27c1 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1,199 +1,17 @@ #include #include "InterfaceConfig.h" +#include "MenuRow.h" +#include "MenuColumn.h" #include "Menu.h" #include "Util.h" -int menuHeight = 30; + int lineHeight = 30; +int menuHeight = 30; 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 // change the value in the other platforms (if required). -MenuRow::MenuRow() -{ -} -MenuRow::MenuRow(char * columnName, PFNRowCallback callback) -{ - int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); - strncpy(this->rowName, columnName, length); - memcpy(this->rowName + length, " \0", 5); - this->callback = callback; - rowWidth = 0; -} - -MenuRow::~MenuRow() -{ -} - -void MenuRow::call() { - callback(-2); -} - -char * MenuRow::getName() { - int length = (int) strlen(this->rowName) - 4; - int currentValue = callback(-1); - if (currentValue == 0) { - memcpy(this->rowName + length, " OFF\0", 5); - } else if (currentValue == 1) { - memcpy(this->rowName + length, " ON \0", 5); - } else { - memcpy(this->rowName + length, " \0", 5); - } - return this->rowName; -} - -int MenuRow::getWidth(float scale, int mono, int leftPosition){ - if (rowWidth == 0) { - rowWidth = widthText( scale, mono, this->rowName); - } - return rowWidth; -} - -int MenuRow::getWidth(){ - return rowWidth; -} - - -MenuColumn::MenuColumn() -{ -} -MenuColumn::MenuColumn(char * columnName) -{ - int length = std::min(MAX_COLUMN_NAME - 1,(int) strlen(columnName)); - strncpy(this->columnName, columnName, length); - this->columnName[length] = '\0'; - columnWidth = 0; - leftPosition = 0; - xLeftMouseOver = 0; - xRightMouseOver = 0; - yTopMouseOver = 0; - yBottomMouseOver = 0; -} - -MenuColumn::~MenuColumn() -{ -} - -void MenuColumn::mouseClickRow(int iRowIndex) { - rows[iRowIndex].call(); -} - -bool MenuColumn::mouseClick(int x, int y, int xLeft) { - int xRight = xLeft + 200; - int yTop = menuHeight; - int yBottom = menuHeight; - int columnWidth; - bool bRet = false; - for (unsigned int i = 0; i < rows.size(); ++i) { - columnWidth = rows[i].getWidth(); - yTop = yBottom + lineHeight; - if (x > xLeft && x < xRight && y > yBottom && y < yTop) { - mouseClickRow(i); - bRet = true; - break; - } - yBottom = yTop; - } - return bRet; -} - -void MenuColumn::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) { - xLeftMouseOver = xLeft; - xRightMouseOver = xRight; - yTopMouseOver = yTop; - yBottomMouseOver = yBottom; -} - -bool MenuColumn::mouseOver(int x, int y, int xLeft) { - int xRight = xLeft + 100; - int yTop = menuHeight; - int yBottom = menuHeight; - int columnWidth; - bool bRet = false; - for (unsigned int i = 0; i < rows.size(); ++i) { - columnWidth = rows[i].getWidth(); - yTop = yBottom + lineHeight ; - if (x > xLeft && x < xRight && y > yBottom && y < yTop) { - setMouseOver(xLeft, xRight, yBottom, yTop); - bRet = true; - break; - } - yBottom = yTop; - } - if (!bRet) { - setMouseOver(0, 0, 0, 0); - } - return bRet; -} - -char * MenuColumn::getName() { - return this->columnName; -} - -int MenuColumn::getWidth(float scale, int mono, int leftPosition){ - if (columnWidth == 0) { - columnWidth = widthText( scale, mono, this->columnName); - this->leftPosition = leftPosition; - } - return columnWidth; -} - -int MenuColumn::getWidth(){ - return columnWidth; -} - -int MenuColumn::getLeftPosition(){ - return leftPosition; -} - -int MenuColumn::addRow(char * rowName, PFNRowCallback callback){ - MenuRow * pRow; - pRow = new MenuRow(rowName, callback); - rows.push_back(*pRow); - delete pRow; - return 0; - -} - -void MenuColumn::render() { - int iRow = rows.size(); - if (iRow > 0) { - glColor3f(0.9,0.9,0.9); - glBegin(GL_QUADS); { - glVertex2f(leftPosition, yOffset + menuHeight); - glVertex2f(leftPosition+100, yOffset + menuHeight); - glVertex2f(leftPosition+100, yOffset + menuHeight + iRow*lineHeight); - glVertex2f(leftPosition , yOffset + menuHeight + iRow* lineHeight); - } - glEnd(); - } - float scale = 0.10; - int mono = 0; - int y = menuHeight + lineHeight / 2 ; - char * rowName; - int columnWidth; - for (unsigned int i = 0; i < rows.size(); ++i) - { - 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); - y += lineHeight; - } - renderMouseOver(); -} - -void MenuColumn::renderMouseOver() { - if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 0){ - glColor4f(0,0,0,0.1); - glBegin(GL_QUADS); { - glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver); - glVertex2f(xRightMouseOver, yOffset + yTopMouseOver); - glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver); - glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver); - } - glEnd(); - } -} Menu::Menu(){ iCurrentColumn = -1; @@ -251,7 +69,7 @@ bool Menu::mouseClick(int x, int y) { break; } if (iCurrentColumn == i) { - bRet = columns[i].mouseClick(x, y, xLeft); + bRet = columns[i].mouseClick(x, y, xLeft, menuHeight, lineHeight); if (bRet) { iCurrentColumn = -1; } @@ -281,7 +99,7 @@ bool Menu::mouseOver(int x, int y) { } break; } else if (iCurrentColumn == i) { - columns[i].mouseOver(x, y, xLeft); + columns[i].mouseOver(x, y, xLeft, menuHeight, lineHeight); } xLeft = xRight; } @@ -314,7 +132,7 @@ void Menu::render(int screenwidth, int screenheight) { drawtext(x,18 + yOffset, scale, 0, 1.0, mono, columnName, 0, 0, 0); x += columnWidth + SPACE_BETWEEN_COLUMNS; if (iCurrentColumn == i) { - columns[i].render(); + columns[i].render(yOffset, menuHeight, lineHeight); } } renderMouseOver(); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 7b8eb9bad6..c5b6b995f3 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -7,48 +7,6 @@ typedef int(CALLBACK * PFNRowCallback)(int); -class MenuRow { - public: - MenuRow(); - MenuRow(char * rowName, PFNRowCallback); - ~MenuRow(); - void call(); - char * getName(); - int getWidth(float scale, int mono, int leftPosition); - int getWidth(); -private: - char rowName[MAX_COLUMN_NAME]; - int rowWidth; - PFNRowCallback callback; -}; - - -class MenuColumn { - public: - MenuColumn(); - MenuColumn(char * columnName); - ~MenuColumn(); - void mouseClickRow(int iColumnIndex); - bool mouseClick(int x, int y, int xLeft); - void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); - bool mouseOver(int x, int y, int xLeft); - char * getName(); - int getWidth(float scale, int mono, int leftPosition); - int getWidth(); - int getLeftPosition(); - void render(); - void MenuColumn::renderMouseOver(); - int addRow(char * rowName, PFNRowCallback callback); -private: - char columnName[MAX_COLUMN_NAME]; - int columnWidth; - int leftPosition; - std::vector rows; - int xLeftMouseOver; - int xRightMouseOver; - int yTopMouseOver; - int yBottomMouseOver; -}; class Menu { public: diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp new file mode 100644 index 0000000000..bd60021a21 --- /dev/null +++ b/interface/src/MenuColumn.cpp @@ -0,0 +1,150 @@ + +#include +#include "InterfaceConfig.h" +#include "MenuRow.h" +#include "MenuColumn.h" +#include "Menu.h" +#include "Util.h" + + + +MenuColumn::MenuColumn() +{ +} +MenuColumn::MenuColumn(char * columnName) +{ + int length = std::min(MAX_COLUMN_NAME - 1,(int) strlen(columnName)); + strncpy(this->columnName, columnName, length); + this->columnName[length] = '\0'; + columnWidth = 0; + leftPosition = 0; + xLeftMouseOver = 0; + xRightMouseOver = 0; + yTopMouseOver = 0; + yBottomMouseOver = 0; +} + +MenuColumn::~MenuColumn() +{ +} + +void MenuColumn::mouseClickRow(int iRowIndex) { + rows[iRowIndex].call(); +} + +bool MenuColumn::mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight) { + int xRight = xLeft + 200; + int yTop = menuHeight; + int yBottom = menuHeight; + int columnWidth; + bool bRet = false; + for (unsigned int i = 0; i < rows.size(); ++i) { + columnWidth = rows[i].getWidth(); + yTop = yBottom + lineHeight; + if (x > xLeft && x < xRight && y > yBottom && y < yTop) { + mouseClickRow(i); + bRet = true; + break; + } + yBottom = yTop; + } + return bRet; +} + +void MenuColumn::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) { + xLeftMouseOver = xLeft; + xRightMouseOver = xRight; + yTopMouseOver = yTop; + yBottomMouseOver = yBottom; +} + +bool MenuColumn::mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight) { + int xRight = xLeft + 100; + int yTop = menuHeight; + int yBottom = menuHeight; + int columnWidth; + bool bRet = false; + for (unsigned int i = 0; i < rows.size(); ++i) { + columnWidth = rows[i].getWidth(); + yTop = yBottom + lineHeight ; + if (x > xLeft && x < xRight && y > yBottom && y < yTop) { + setMouseOver(xLeft, xRight, yBottom, yTop); + bRet = true; + break; + } + yBottom = yTop; + } + if (!bRet) { + setMouseOver(0, 0, 0, 0); + } + return bRet; +} + +char * MenuColumn::getName() { + return this->columnName; +} + +int MenuColumn::getWidth(float scale, int mono, int leftPosition){ + if (columnWidth == 0) { + columnWidth = widthText( scale, mono, this->columnName); + this->leftPosition = leftPosition; + } + return columnWidth; +} + +int MenuColumn::getWidth(){ + return columnWidth; +} + +int MenuColumn::getLeftPosition(){ + return leftPosition; +} + +int MenuColumn::addRow(char * rowName, PFNRowCallback callback){ + MenuRow * pRow; + pRow = new MenuRow(rowName, callback); + rows.push_back(*pRow); + delete pRow; + return 0; + +} + +void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { + int iRow = rows.size(); + if (iRow > 0) { + glColor3f(0.9,0.9,0.9); + glBegin(GL_QUADS); { + glVertex2f(leftPosition, yOffset + menuHeight); + glVertex2f(leftPosition+100, yOffset + menuHeight); + glVertex2f(leftPosition+100, yOffset + menuHeight + iRow*lineHeight); + glVertex2f(leftPosition , yOffset + menuHeight + iRow* lineHeight); + } + glEnd(); + } + float scale = 0.10; + int mono = 0; + int y = menuHeight + lineHeight / 2 ; + char * rowName; + int columnWidth; + for (unsigned int i = 0; i < rows.size(); ++i) + { + 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); + y += lineHeight; + } + renderMouseOver(yOffset); +} + +void MenuColumn::renderMouseOver(int yOffset) { + if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 0){ + glColor4f(0,0,0,0.1); + glBegin(GL_QUADS); { + glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver); + glVertex2f(xRightMouseOver, yOffset + yTopMouseOver); + glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver); + glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver); + } + glEnd(); + } +} diff --git a/interface/src/MenuColumn.h b/interface/src/MenuColumn.h new file mode 100644 index 0000000000..be4033326b --- /dev/null +++ b/interface/src/MenuColumn.h @@ -0,0 +1,28 @@ + +class MenuColumn { + public: + MenuColumn(); + MenuColumn(char * columnName); + ~MenuColumn(); + void mouseClickRow(int iColumnIndex); + bool mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight); + void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); + bool mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight); + char * getName(); + int getWidth(float scale, int mono, int leftPosition); + int getWidth(); + int getLeftPosition(); + void render(int yOffset, int menuHeight, int lineHeight); + void MenuColumn::renderMouseOver(int yOffset); + int addRow(char * rowName, PFNRowCallback callback); +private: + char columnName[MAX_COLUMN_NAME]; + int columnWidth; + int leftPosition; + std::vector rows; + int xLeftMouseOver; + int xRightMouseOver; + int yTopMouseOver; + int yBottomMouseOver; +}; + diff --git a/interface/src/MenuRow.cpp b/interface/src/MenuRow.cpp new file mode 100644 index 0000000000..e8efd29008 --- /dev/null +++ b/interface/src/MenuRow.cpp @@ -0,0 +1,53 @@ + +#include +#include "InterfaceConfig.h" +#include "MenuRow.h" +#include "MenuColumn.h" +#include "Menu.h" +#include "Util.h" + + +MenuRow::MenuRow() +{ +} +MenuRow::MenuRow(char * columnName, PFNRowCallback callback) +{ + int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); + strncpy(this->rowName, columnName, length); + memcpy(this->rowName + length, " \0", 5); + this->callback = callback; + rowWidth = 0; +} + +MenuRow::~MenuRow() +{ +} + +void MenuRow::call() { + callback(-2); +} + +char * MenuRow::getName() { + int length = (int) strlen(this->rowName) - 4; + int currentValue = callback(-1); + if (currentValue == 0) { + memcpy(this->rowName + length, " OFF\0", 5); + } else if (currentValue == 1) { + memcpy(this->rowName + length, " ON \0", 5); + } else { + memcpy(this->rowName + length, " \0", 5); + } + return this->rowName; +} + +int MenuRow::getWidth(float scale, int mono, int leftPosition){ + if (rowWidth == 0) { + rowWidth = widthText( scale, mono, this->rowName); + } + return rowWidth; +} + +int MenuRow::getWidth(){ + return rowWidth; +} + diff --git a/interface/src/MenuRow.h b/interface/src/MenuRow.h new file mode 100644 index 0000000000..57deeb300d --- /dev/null +++ b/interface/src/MenuRow.h @@ -0,0 +1,23 @@ + +#include + +#define MAX_COLUMN_NAME 50 +#define SPACE_BETWEEN_COLUMNS 20 +#define SPACE_BEFORE_ROW_NAME 10 +typedef int(CALLBACK * PFNRowCallback)(int); + +class MenuRow { + public: + MenuRow(); + MenuRow(char * rowName, PFNRowCallback); + ~MenuRow(); + void call(); + char * getName(); + int getWidth(float scale, int mono, int leftPosition); + int getWidth(); +private: + char rowName[MAX_COLUMN_NAME]; + int rowWidth; + PFNRowCallback callback; +}; + diff --git a/interface/src/main.cpp b/interface/src/main.cpp index b1e69d749c..d3697ce930 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -57,6 +57,8 @@ #include "FieldOfView.h" #include "Stars.h" +#include "MenuRow.h" +#include "MenuColumn.h" #include "Menu.h" #include "Head.h" #include "Hand.h" From 4dbff4623485590c0967d60c34fcae5036db880e Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 11 Apr 2013 00:13:40 +0200 Subject: [PATCH 4/6] #19171 Code Review changes --- interface/src/Menu.cpp | 148 +++++++++++++++++------------------ interface/src/Menu.h | 39 ++++----- interface/src/MenuColumn.cpp | 111 +++++++++++++------------- interface/src/MenuColumn.h | 43 +++++----- interface/src/MenuRow.cpp | 19 +++-- interface/src/MenuRow.h | 30 ++++--- interface/src/Util.cpp | 7 +- interface/src/main.cpp | 46 +++++------ shared/src/SharedUtil.cpp | 5 -- 9 files changed, 221 insertions(+), 227 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 730b2e27c1..4c770fabf0 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1,137 +1,133 @@ #include + #include "InterfaceConfig.h" +#include "Util.h" + #include "MenuRow.h" #include "MenuColumn.h" #include "Menu.h" -#include "Util.h" -int lineHeight = 30; -int menuHeight = 30; -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 - // change the value in the other platforms (if required). +const int lineHeight = 30; +const int menuHeight = 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 + // change the value in the other platforms (if required). -Menu::Menu(){ - iCurrentColumn = -1; - xLeftMouseOver = 0; - xRightMouseOver = 0; - yTopMouseOver = 0; - yBottomMouseOver = 0; +Menu::Menu() { + currentColumn = -1; + leftMouseOver = 0; + rightMouseOver = 0; + topMouseOver = 0; + bottomMouseOver = 0; } -Menu::~Menu(){ +Menu::~Menu() { columns.clear(); } void Menu::mouseClickColumn(int iColumnIndex) { - if (iCurrentColumn == iColumnIndex) { - iCurrentColumn = -1; + if (currentColumn == iColumnIndex) { + currentColumn = -1; } else { - iCurrentColumn = iColumnIndex; + currentColumn = iColumnIndex; } } -void Menu::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) { - xLeftMouseOver = xLeft; - xRightMouseOver = xRight; - yTopMouseOver = yTop; - yBottomMouseOver = yBottom; +void Menu::setMouseOver(int leftPosition, int rightPosition, int yTop, int yBottom) { + leftMouseOver = leftPosition; + rightMouseOver = rightPosition; + topMouseOver = yTop; + bottomMouseOver = yBottom; } void Menu::renderMouseOver() { - if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 0){ - glColor4f(0,0,0,0.1); + if (leftMouseOver != 0 || topMouseOver != 0 || rightMouseOver != 0 ||& bottomMouseOver != 0) { + glColor4f(0, 0, 0, 0.1); glBegin(GL_QUADS); { - glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver); - glVertex2f(xRightMouseOver, yOffset + yTopMouseOver); - glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver); - glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver); + glVertex2f(leftMouseOver, yOffset + topMouseOver); + glVertex2f(rightMouseOver, yOffset + topMouseOver); + glVertex2f(rightMouseOver, yOffset + bottomMouseOver); + glVertex2f(leftMouseOver, yOffset + bottomMouseOver); } glEnd(); } } bool Menu::mouseClick(int x, int y) { - int xLeft = 0.5 * SPACE_BETWEEN_COLUMNS; - int xRight; - int columnWidth; - bool bRet = false; - for (unsigned int i = 0; i < columns.size(); ++i) - { + int leftPosition = 0.5 * SPACE_BETWEEN_COLUMNS; + int rightPosition = 0; + int columnWidth = 0; + bool menuFound = false; + for (unsigned int i = 0; i < columns.size(); ++i) { columnWidth = columns[i].getWidth(); - xRight = xLeft + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS; - if (x > xLeft && x < xRight && y > 0 && y < menuHeight){ + rightPosition = leftPosition + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS; + if (x > leftPosition && x < rightPosition && y > 0 && y < menuHeight) { mouseClickColumn(i); - bRet = true; + menuFound = true; break; - } - if (iCurrentColumn == i) { - bRet = columns[i].mouseClick(x, y, xLeft, menuHeight, lineHeight); - if (bRet) { - iCurrentColumn = -1; + } else if (currentColumn == i) { + menuFound = columns[i].mouseClick(x, y, leftPosition, menuHeight, lineHeight); + if (menuFound) { + currentColumn = -1; } } - xLeft = xRight; + leftPosition = rightPosition; } - return bRet; + return menuFound; } bool Menu::mouseOver(int x, int y) { - int xLeft = 0.5 * SPACE_BETWEEN_COLUMNS; - int xRight; + int leftPosition = 0.5 * SPACE_BETWEEN_COLUMNS; + int rightPosition; int columnWidth; - bool bRet = false; - for (unsigned int i = 0; i < columns.size(); ++i) - { + bool overMenu = false; + for (unsigned int i = 0; i < columns.size(); ++i) { columnWidth = columns[i].getWidth(); - xRight = xLeft + columnWidth + SPACE_BETWEEN_COLUMNS; - if (x > xLeft && x < xRight && y > 0 && y < menuHeight){ - printf("Mouse Over: %d %d", x, y); - - setMouseOver(xLeft, xRight, 0, menuHeight); - bRet = true; - if (iCurrentColumn >= 0) { - columns[iCurrentColumn].setMouseOver(0, 0, 0, 0); - iCurrentColumn = i; + rightPosition = leftPosition + columnWidth + SPACE_BETWEEN_COLUMNS; + if (x > leftPosition && x < rightPosition && y > 0 && y < menuHeight) { + setMouseOver(leftPosition, rightPosition, 0, menuHeight); + overMenu = true; + if (currentColumn >= 0) { + columns[currentColumn].setMouseOver(0, 0, 0, 0); + currentColumn = i; } break; - } else if (iCurrentColumn == i) { - columns[i].mouseOver(x, y, xLeft, menuHeight, lineHeight); + } else if (currentColumn == i) { + columns[i].mouseOver(x, y, leftPosition, menuHeight, lineHeight); } - xLeft = xRight; + leftPosition = rightPosition; } - if (!bRet) { + if (!overMenu) { setMouseOver(0, 0, 0, 0); } - return bRet; + return overMenu; } -void Menu::render(int screenwidth, int screenheight) { +void Menu::render(int screenWidth, int screenHeight) { float scale = 0.10; int mono = 0; - glColor3f(0.9,0.9,0.9); - int width = screenwidth; - int height = screenheight; + glColor3f(0.9, 0.9, 0.9); + int width = screenWidth; + int height = screenHeight; glBegin(GL_QUADS); { glVertex2f(0, yOffset); glVertex2f(width, yOffset); - glVertex2f( width, menuHeight + yOffset); + glVertex2f(width, menuHeight + yOffset); glVertex2f(0 , menuHeight + yOffset); } glEnd(); - int x = SPACE_BETWEEN_COLUMNS; - char * columnName; + int xPosition = SPACE_BETWEEN_COLUMNS; + char* columnName; int columnWidth; - for (unsigned int i = 0; i < columns.size(); ++i) - { + for (unsigned int i = 0; i < columns.size(); ++i) { columnName = columns[i].getName(); - columnWidth = columns[i].getWidth(scale, mono, x- 0.5 * SPACE_BETWEEN_COLUMNS); - drawtext(x,18 + yOffset, scale, 0, 1.0, mono, columnName, 0, 0, 0); - x += columnWidth + SPACE_BETWEEN_COLUMNS; - if (iCurrentColumn == i) { + 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); + xPosition += columnWidth + SPACE_BETWEEN_COLUMNS; + if (currentColumn == i) { columns[i].render(yOffset, menuHeight, lineHeight); } } @@ -140,9 +136,9 @@ void Menu::render(int screenwidth, int screenheight) { MenuColumn* Menu::addColumn(char *columnName) { - MenuColumn * pColumn; + MenuColumn* pColumn; pColumn = new MenuColumn(columnName); columns.push_back(*pColumn); delete pColumn; - return &columns[columns.size()-1]; + return &columns[columns.size() - 1]; } \ No newline at end of file diff --git a/interface/src/Menu.h b/interface/src/Menu.h index c5b6b995f3..d448235c1d 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -1,30 +1,31 @@ +#ifndef __hifi__Menu__ +#define __hifi__Menu__ #include #define MAX_COLUMN_NAME 50 #define SPACE_BETWEEN_COLUMNS 20 #define SPACE_BEFORE_ROW_NAME 10 -typedef int(CALLBACK * PFNRowCallback)(int); - class Menu { - public: - Menu(); - ~Menu(); - void mouseClickColumn(int iColumnIndex); - void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); - void renderMouseOver(); - bool mouseClick(int x, int y); - bool mouseOver(int x, int y); - void render(int screenwidth, int screenheight); - void renderColumn(int i); - MenuColumn* addColumn(char *columnName); +public: + Menu(); + ~Menu(); + void mouseClickColumn(int iColumnIndex); + void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); + void renderMouseOver(); + bool mouseClick(int x, int y); + bool mouseOver(int x, int y); + void render(int screenwidth, int screenheight); + void renderColumn(int i); + MenuColumn* addColumn(char *columnName); private: std::vector columns; - int iCurrentColumn; - int xLeftMouseOver; - int xRightMouseOver; - int yTopMouseOver; - int yBottomMouseOver; -}; \ No newline at end of file + int currentColumn; + int leftMouseOver; + int rightMouseOver; + int topMouseOver; + int bottomMouseOver; +}; +#endif /* defined(__hifi__Menu__) */ diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp index bd60021a21..87ebc897c6 100644 --- a/interface/src/MenuColumn.cpp +++ b/interface/src/MenuColumn.cpp @@ -1,78 +1,79 @@ #include + #include "InterfaceConfig.h" +#include "Util.h" + #include "MenuRow.h" #include "MenuColumn.h" #include "Menu.h" -#include "Util.h" -MenuColumn::MenuColumn() -{ +MenuColumn::MenuColumn() { } -MenuColumn::MenuColumn(char * columnName) -{ + +MenuColumn::MenuColumn(char * columnName) { int length = std::min(MAX_COLUMN_NAME - 1,(int) strlen(columnName)); strncpy(this->columnName, columnName, length); this->columnName[length] = '\0'; columnWidth = 0; leftPosition = 0; - xLeftMouseOver = 0; - xRightMouseOver = 0; - yTopMouseOver = 0; - yBottomMouseOver = 0; + leftMouseOver = 0; + rightMouseOver = 0; + topMouseOver = 0; + bottomMouseOver = 0; } -MenuColumn::~MenuColumn() -{ +MenuColumn::~MenuColumn() { + rows.clear(); } -void MenuColumn::mouseClickRow(int iRowIndex) { - rows[iRowIndex].call(); +void MenuColumn::mouseClickRow(int numberOfRowsIndex) { + rows[numberOfRowsIndex].call(); } -bool MenuColumn::mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight) { - int xRight = xLeft + 200; - int yTop = menuHeight; - int yBottom = menuHeight; - int columnWidth; +bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) { + int rightPosition = leftPosition + 200; + int topPosition = menuHeight; + int bottomPosition = menuHeight; + int columnWidth = 0; bool bRet = false; for (unsigned int i = 0; i < rows.size(); ++i) { columnWidth = rows[i].getWidth(); - yTop = yBottom + lineHeight; - if (x > xLeft && x < xRight && y > yBottom && y < yTop) { + topPosition = bottomPosition + lineHeight; + if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) { mouseClickRow(i); bRet = true; break; } - yBottom = yTop; + bottomPosition = topPosition; } return bRet; } -void MenuColumn::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) { - xLeftMouseOver = xLeft; - xRightMouseOver = xRight; - yTopMouseOver = yTop; - yBottomMouseOver = yBottom; +void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPosition, int bottomPosition) { + leftMouseOver = leftPosition; + rightMouseOver = rightPosition; + topMouseOver = topPosition; + bottomMouseOver = bottomPosition; } -bool MenuColumn::mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight) { - int xRight = xLeft + 100; - int yTop = menuHeight; - int yBottom = menuHeight; - int columnWidth; +bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int lineHeight) { + int rightPosition = leftPosition + 100; + int topPosition = menuHeight; + int bottomPosition = menuHeight; + int columnWidth = 0; bool bRet = false; for (unsigned int i = 0; i < rows.size(); ++i) { columnWidth = rows[i].getWidth(); - yTop = yBottom + lineHeight ; - if (x > xLeft && x < xRight && y > yBottom && y < yTop) { - setMouseOver(xLeft, xRight, yBottom, yTop); + topPosition = bottomPosition + lineHeight ; + if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) { + setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition); bRet = true; break; } - yBottom = yTop; + bottomPosition = topPosition; } if (!bRet) { setMouseOver(0, 0, 0, 0); @@ -80,54 +81,52 @@ bool MenuColumn::mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeig return bRet; } -char * MenuColumn::getName() { +char* MenuColumn::getName() { return this->columnName; } -int MenuColumn::getWidth(float scale, int mono, int leftPosition){ +int MenuColumn::getWidth(float scale, int mono, int leftPosition) { if (columnWidth == 0) { - columnWidth = widthText( scale, mono, this->columnName); + columnWidth = widthText(scale, mono, this->columnName); this->leftPosition = leftPosition; } return columnWidth; } -int MenuColumn::getWidth(){ +int MenuColumn::getWidth() { return columnWidth; } -int MenuColumn::getLeftPosition(){ +int MenuColumn::getLeftPosition() { return leftPosition; } -int MenuColumn::addRow(char * rowName, PFNRowCallback callback){ - MenuRow * pRow; +int MenuColumn::addRow(char * rowName, PFNRowCallback callback) { + MenuRow* pRow; pRow = new MenuRow(rowName, callback); rows.push_back(*pRow); delete pRow; return 0; - } void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { - int iRow = rows.size(); - if (iRow > 0) { + int numberOfRows = rows.size(); + if (numberOfRows > 0) { glColor3f(0.9,0.9,0.9); glBegin(GL_QUADS); { glVertex2f(leftPosition, yOffset + menuHeight); glVertex2f(leftPosition+100, yOffset + menuHeight); - glVertex2f(leftPosition+100, yOffset + menuHeight + iRow*lineHeight); - glVertex2f(leftPosition , yOffset + menuHeight + iRow* lineHeight); + glVertex2f(leftPosition+100, yOffset + menuHeight + numberOfRows*lineHeight); + glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight); } glEnd(); } float scale = 0.10; int mono = 0; int y = menuHeight + lineHeight / 2 ; - char * rowName; - int columnWidth; - for (unsigned int i = 0; i < rows.size(); ++i) - { + char* rowName; + int columnWidth = 0; + for (unsigned int i = 0; i < rows.size(); ++i) { 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); @@ -137,13 +136,13 @@ void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) { } void MenuColumn::renderMouseOver(int yOffset) { - if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 0){ + if (leftMouseOver != 0 || topMouseOver != 0 || rightMouseOver != 0 ||& bottomMouseOver != 0) { glColor4f(0,0,0,0.1); glBegin(GL_QUADS); { - glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver); - glVertex2f(xRightMouseOver, yOffset + yTopMouseOver); - glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver); - glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver); + glVertex2f(leftMouseOver, yOffset + topMouseOver); + glVertex2f(rightMouseOver, yOffset + topMouseOver); + glVertex2f(rightMouseOver, yOffset + bottomMouseOver); + glVertex2f(leftMouseOver , yOffset + bottomMouseOver); } glEnd(); } diff --git a/interface/src/MenuColumn.h b/interface/src/MenuColumn.h index be4033326b..ae5edd098b 100644 --- a/interface/src/MenuColumn.h +++ b/interface/src/MenuColumn.h @@ -1,28 +1,33 @@ +#ifndef __hifi__MenuColumn__ +#define __hifi__MenuColumn__ +#include class MenuColumn { - public: - MenuColumn(); - MenuColumn(char * columnName); - ~MenuColumn(); - void mouseClickRow(int iColumnIndex); - bool mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight); - void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); - bool mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight); - char * getName(); - int getWidth(float scale, int mono, int leftPosition); - int getWidth(); - int getLeftPosition(); - void render(int yOffset, int menuHeight, int lineHeight); - void MenuColumn::renderMouseOver(int yOffset); - int addRow(char * rowName, PFNRowCallback callback); +public: + MenuColumn(); + MenuColumn(char * columnName); + ~MenuColumn(); + void mouseClickRow(int iColumnIndex); + bool mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight); + void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); + bool mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight); + char * getName(); + int getWidth(float scale, int mono, int leftPosition); + int getWidth(); + int getLeftPosition(); + void render(int yOffset, int menuHeight, int lineHeight); + void MenuColumn::renderMouseOver(int yOffset); + int addRow(char * rowName, PFNRowCallback callback); private: char columnName[MAX_COLUMN_NAME]; int columnWidth; int leftPosition; std::vector rows; - int xLeftMouseOver; - int xRightMouseOver; - int yTopMouseOver; - int yBottomMouseOver; + int leftMouseOver; + int rightMouseOver; + int topMouseOver; + int bottomMouseOver; }; +#endif /* defined(__hifi__MenuColumn__) */ + diff --git a/interface/src/MenuRow.cpp b/interface/src/MenuRow.cpp index e8efd29008..0aa04a10cb 100644 --- a/interface/src/MenuRow.cpp +++ b/interface/src/MenuRow.cpp @@ -1,17 +1,17 @@ #include + #include "InterfaceConfig.h" +#include "Util.h" + #include "MenuRow.h" #include "MenuColumn.h" #include "Menu.h" -#include "Util.h" -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)); strncpy(this->rowName, columnName, length); memcpy(this->rowName + length, " \0", 5); @@ -19,15 +19,14 @@ MenuRow::MenuRow(char * columnName, PFNRowCallback callback) rowWidth = 0; } -MenuRow::~MenuRow() -{ +MenuRow::~MenuRow() { } void MenuRow::call() { callback(-2); } -char * MenuRow::getName() { +char* MenuRow::getName() { int length = (int) strlen(this->rowName) - 4; int currentValue = callback(-1); if (currentValue == 0) { @@ -40,14 +39,14 @@ char * MenuRow::getName() { return this->rowName; } -int MenuRow::getWidth(float scale, int mono, int leftPosition){ +int MenuRow::getWidth(float scale, int mono, int leftPosition) { if (rowWidth == 0) { rowWidth = widthText( scale, mono, this->rowName); } return rowWidth; } -int MenuRow::getWidth(){ +int MenuRow::getWidth() { return rowWidth; } diff --git a/interface/src/MenuRow.h b/interface/src/MenuRow.h index 57deeb300d..c477c856de 100644 --- a/interface/src/MenuRow.h +++ b/interface/src/MenuRow.h @@ -1,23 +1,27 @@ +#ifndef __hifi__MenuRow__ +#define __hifi__MenuRow__ -#include +const int MAX_COLUMN_NAME = 50; +const int SPACE_BETWEEN_COLUMNS = 20; +const int SPACE_BEFORE_ROW_NAME = 10; -#define MAX_COLUMN_NAME 50 -#define SPACE_BETWEEN_COLUMNS 20 -#define SPACE_BEFORE_ROW_NAME 10 -typedef int(CALLBACK * PFNRowCallback)(int); +#define MenuCallBack CALLBACK + +typedef int(MenuCallBack * PFNRowCallback)(int); class MenuRow { - public: - MenuRow(); - MenuRow(char * rowName, PFNRowCallback); - ~MenuRow(); - void call(); - char * getName(); - int getWidth(float scale, int mono, int leftPosition); - int getWidth(); +public: + MenuRow(); + MenuRow(char * rowName, PFNRowCallback); + ~MenuRow(); + void call(); + char * getName(); + int getWidth(float scale, int mono, int leftPosition); + int getWidth(); private: char rowName[MAX_COLUMN_NAME]; int rowWidth; PFNRowCallback callback; }; +#endif /* defined(__hifi__MenuRow__) */ diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 46f0398a36..7489fb6302 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -93,10 +93,9 @@ double diffclock(timeval *clock1,timeval *clock2) int widthText(float scale, int mono, char *string) { int width = 0; if (!mono) { - width =scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string); - } - else { - width =scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string); + width = scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string); + } else { + width = scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string); } return width; } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index d3697ce930..95db701619 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -240,7 +240,7 @@ void Timer(int extra) void displayStats(void) { int statsVerticalOffset = 50; - if (menuOn == 0) { + if (::menuOn == 0) { statsVerticalOffset = 8; } // bitmap chars are about 10 pels high @@ -840,7 +840,7 @@ void display(void) } // Show menu - if (menuOn) { + if (::menuOn) { glLineWidth(1.0f); glPointSize(1.0f); menu.render(WIDTH,HEIGHT); @@ -868,7 +868,7 @@ void display(void) frameCount++; } -int CALLBACK setValue(int state, int *value) { +int MenuCallBack setValue(int state, int *value) { if (state == -2) { *value = !(*value); } else if (state == -1) { @@ -879,36 +879,33 @@ int CALLBACK setValue(int state, int *value) { return *value; } -int CALLBACK setHead(int state) { +int MenuCallBack setHead(int state) { return setValue(state, &displayHead); } -int CALLBACK setField(int state) { +int MenuCallBack setField(int state) { return setValue(state, &displayField); } -int CALLBACK setNoise(int state) { +int MenuCallBack setNoise(int state) { int iRet = setValue(state, &noiseOn); - if (noiseOn) - { + if (noiseOn) { myHead.setNoise(noise); - } - else - { + } else { myHead.setNoise(0); } return iRet; } -int CALLBACK setStats(int state) { +int MenuCallBack setStats(int state) { return setValue(state, &statsOn); } -int CALLBACK setMenu(int state) { - return setValue(state, &menuOn); +int MenuCallBack setMenu(int state) { + return setValue(state, &::menuOn); } -int CALLBACK setMirror(int state) { +int MenuCallBack setMirror(int state) { return setValue(state, &headMirror); } @@ -1240,20 +1237,19 @@ void mouseFunc( int button, int state, int x, int y ) { if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { - if (menu.mouseClick(x, y) == false) { - mouseX = x; - mouseY = y; - mousePressed = 1; - lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT); + if (!menu.mouseClick(x, y)) { + mouseX = x; + mouseY = y; + mousePressed = 1; + lattice.mouseClick((float)x/(float)WIDTH, (float)y/(float)HEIGHT); mouseStartX = x; mouseStartY = y; } } - if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) - { - mouseX = x; - mouseY = y; - mousePressed = 0; + if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) { + mouseX = x; + mouseY = y; + mousePressed = 0; } } diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index 7a8ae3772f..fddcca6cd7 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -19,11 +19,6 @@ #include #endif - -#ifdef _WIN32 -#endif - - double usecTimestamp(timeval *time) { return (time->tv_sec * 1000000.0 + time->tv_usec); } From b43475a34eaf247acff0b05a82c331413d50c965 Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 11 Apr 2013 00:23:41 +0200 Subject: [PATCH 5/6] #19171 Missing Code Review changes --- interface/src/Menu.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface/src/Menu.h b/interface/src/Menu.h index d448235c1d..4c12913c07 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -3,10 +3,6 @@ #include -#define MAX_COLUMN_NAME 50 -#define SPACE_BETWEEN_COLUMNS 20 -#define SPACE_BEFORE_ROW_NAME 10 - class Menu { public: From ebc5874441797fc737f9018a9626f0d095f936f0 Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 11 Apr 2013 00:47:53 +0200 Subject: [PATCH 6/6] #19171 Missing Code Review changes - part 2 --- interface/src/Menu.cpp | 48 ++++++++++++++++++------------------ interface/src/MenuColumn.cpp | 22 ++++++++--------- interface/src/MenuColumn.h | 2 +- interface/src/MenuRow.cpp | 1 + 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 4c770fabf0..efbea9beab 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -9,9 +9,9 @@ #include "Menu.h" -const int lineHeight = 30; -const int menuHeight = 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 LINE_HEIGHT = 30; +const int MENU_HEIGHT = 30; +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). @@ -28,29 +28,29 @@ Menu::~Menu() { columns.clear(); } -void Menu::mouseClickColumn(int iColumnIndex) { - if (currentColumn == iColumnIndex) { +void Menu::mouseClickColumn(int columnIndex) { + if (currentColumn == columnIndex) { currentColumn = -1; } 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; rightMouseOver = rightPosition; - topMouseOver = yTop; - bottomMouseOver = yBottom; + topMouseOver = top; + bottomMouseOver = bottom; } void Menu::renderMouseOver() { if (leftMouseOver != 0 || topMouseOver != 0 || rightMouseOver != 0 ||& bottomMouseOver != 0) { glColor4f(0, 0, 0, 0.1); glBegin(GL_QUADS); { - glVertex2f(leftMouseOver, yOffset + topMouseOver); - glVertex2f(rightMouseOver, yOffset + topMouseOver); - glVertex2f(rightMouseOver, yOffset + bottomMouseOver); - glVertex2f(leftMouseOver, yOffset + bottomMouseOver); + glVertex2f(leftMouseOver, MENU_Y_OFFSET + topMouseOver); + glVertex2f(rightMouseOver, MENU_Y_OFFSET + topMouseOver); + glVertex2f(rightMouseOver, MENU_Y_OFFSET + bottomMouseOver); + glVertex2f(leftMouseOver, MENU_Y_OFFSET + bottomMouseOver); } glEnd(); } @@ -64,12 +64,12 @@ bool Menu::mouseClick(int x, int y) { for (unsigned int i = 0; i < columns.size(); ++i) { columnWidth = columns[i].getWidth(); 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); menuFound = true; break; } 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) { currentColumn = -1; } @@ -87,8 +87,8 @@ bool Menu::mouseOver(int x, int y) { for (unsigned int i = 0; i < columns.size(); ++i) { columnWidth = columns[i].getWidth(); rightPosition = leftPosition + columnWidth + SPACE_BETWEEN_COLUMNS; - if (x > leftPosition && x < rightPosition && y > 0 && y < menuHeight) { - setMouseOver(leftPosition, rightPosition, 0, menuHeight); + if (x > leftPosition && x < rightPosition && y > 0 && y < MENU_HEIGHT) { + setMouseOver(leftPosition, rightPosition, 0, MENU_HEIGHT); overMenu = true; if (currentColumn >= 0) { columns[currentColumn].setMouseOver(0, 0, 0, 0); @@ -96,7 +96,7 @@ bool Menu::mouseOver(int x, int y) { } break; } else if (currentColumn == i) { - columns[i].mouseOver(x, y, leftPosition, menuHeight, lineHeight); + columns[i].mouseOver(x, y, leftPosition, MENU_HEIGHT, LINE_HEIGHT); } leftPosition = rightPosition; } @@ -113,10 +113,10 @@ void Menu::render(int screenWidth, int screenHeight) { int width = screenWidth; int height = screenHeight; glBegin(GL_QUADS); { - glVertex2f(0, yOffset); - glVertex2f(width, yOffset); - glVertex2f(width, menuHeight + yOffset); - glVertex2f(0 , menuHeight + yOffset); + glVertex2f(0, MENU_Y_OFFSET); + glVertex2f(width, MENU_Y_OFFSET); + glVertex2f(width, MENU_HEIGHT + MENU_Y_OFFSET); + glVertex2f(0 , MENU_HEIGHT + MENU_Y_OFFSET); } glEnd(); 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) { columnName = columns[i].getName(); 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; if (currentColumn == i) { - columns[i].render(yOffset, menuHeight, lineHeight); + columns[i].render(MENU_Y_OFFSET, MENU_HEIGHT, LINE_HEIGHT); } } renderMouseOver(); diff --git a/interface/src/MenuColumn.cpp b/interface/src/MenuColumn.cpp index 87ebc897c6..afc9e99570 100644 --- a/interface/src/MenuColumn.cpp +++ b/interface/src/MenuColumn.cpp @@ -38,18 +38,18 @@ bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int int topPosition = menuHeight; int bottomPosition = menuHeight; int columnWidth = 0; - bool bRet = false; + bool menuFound = false; for (unsigned int i = 0; i < rows.size(); ++i) { columnWidth = rows[i].getWidth(); topPosition = bottomPosition + lineHeight; if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) { mouseClickRow(i); - bRet = true; + menuFound = true; break; } bottomPosition = topPosition; } - return bRet; + return menuFound; } 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 bottomPosition = menuHeight; int columnWidth = 0; - bool bRet = false; + bool overMenu = false; for (unsigned int i = 0; i < rows.size(); ++i) { columnWidth = rows[i].getWidth(); topPosition = bottomPosition + lineHeight ; if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) { setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition); - bRet = true; + overMenu = true; break; } bottomPosition = topPosition; } - if (!bRet) { + if (!overMenu) { setMouseOver(0, 0, 0, 0); } - return bRet; + return overMenu; } char* MenuColumn::getName() { @@ -102,10 +102,10 @@ int MenuColumn::getLeftPosition() { } int MenuColumn::addRow(char * rowName, PFNRowCallback callback) { - MenuRow* pRow; - pRow = new MenuRow(rowName, callback); - rows.push_back(*pRow); - delete pRow; + MenuRow* row; + row = new MenuRow(rowName, callback); + rows.push_back(*row); + delete row; return 0; } diff --git a/interface/src/MenuColumn.h b/interface/src/MenuColumn.h index ae5edd098b..4f55bbd14e 100644 --- a/interface/src/MenuColumn.h +++ b/interface/src/MenuColumn.h @@ -11,7 +11,7 @@ public: bool mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight); void setMouseOver(int xLeft, int xRight, int yTop, int yBottom); 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(); int getLeftPosition(); diff --git a/interface/src/MenuRow.cpp b/interface/src/MenuRow.cpp index 0aa04a10cb..7c1f75b847 100644 --- a/interface/src/MenuRow.cpp +++ b/interface/src/MenuRow.cpp @@ -11,6 +11,7 @@ MenuRow::MenuRow() { } + MenuRow::MenuRow(char * columnName, PFNRowCallback callback) { int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName)); strncpy(this->rowName, columnName, length);