mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 20:58:28 +02:00
#19171 Code Review changes
This commit is contained in:
parent
eb646ade84
commit
4dbff46234
9 changed files with 221 additions and 227 deletions
|
@ -1,137 +1,133 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
#include "MenuRow.h"
|
#include "MenuRow.h"
|
||||||
#include "MenuColumn.h"
|
#include "MenuColumn.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "Util.h"
|
|
||||||
|
|
||||||
|
|
||||||
int lineHeight = 30;
|
const int lineHeight = 30;
|
||||||
int menuHeight = 30;
|
const 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
|
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).
|
// change the value in the other platforms (if required).
|
||||||
|
|
||||||
|
|
||||||
Menu::Menu(){
|
Menu::Menu() {
|
||||||
iCurrentColumn = -1;
|
currentColumn = -1;
|
||||||
xLeftMouseOver = 0;
|
leftMouseOver = 0;
|
||||||
xRightMouseOver = 0;
|
rightMouseOver = 0;
|
||||||
yTopMouseOver = 0;
|
topMouseOver = 0;
|
||||||
yBottomMouseOver = 0;
|
bottomMouseOver = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Menu::~Menu(){
|
Menu::~Menu() {
|
||||||
columns.clear();
|
columns.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::mouseClickColumn(int iColumnIndex) {
|
void Menu::mouseClickColumn(int iColumnIndex) {
|
||||||
if (iCurrentColumn == iColumnIndex) {
|
if (currentColumn == iColumnIndex) {
|
||||||
iCurrentColumn = -1;
|
currentColumn = -1;
|
||||||
} else {
|
} else {
|
||||||
iCurrentColumn = iColumnIndex;
|
currentColumn = iColumnIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) {
|
void Menu::setMouseOver(int leftPosition, int rightPosition, int yTop, int yBottom) {
|
||||||
xLeftMouseOver = xLeft;
|
leftMouseOver = leftPosition;
|
||||||
xRightMouseOver = xRight;
|
rightMouseOver = rightPosition;
|
||||||
yTopMouseOver = yTop;
|
topMouseOver = yTop;
|
||||||
yBottomMouseOver = yBottom;
|
bottomMouseOver = yBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::renderMouseOver() {
|
void Menu::renderMouseOver() {
|
||||||
if (xLeftMouseOver != 0 || yTopMouseOver != 0 || xRightMouseOver != 0 ||& yBottomMouseOver != 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(xLeftMouseOver, yOffset + yTopMouseOver);
|
glVertex2f(leftMouseOver, yOffset + topMouseOver);
|
||||||
glVertex2f(xRightMouseOver, yOffset + yTopMouseOver);
|
glVertex2f(rightMouseOver, yOffset + topMouseOver);
|
||||||
glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver);
|
glVertex2f(rightMouseOver, yOffset + bottomMouseOver);
|
||||||
glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver);
|
glVertex2f(leftMouseOver, yOffset + bottomMouseOver);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Menu::mouseClick(int x, int y) {
|
bool Menu::mouseClick(int x, int y) {
|
||||||
int xLeft = 0.5 * SPACE_BETWEEN_COLUMNS;
|
int leftPosition = 0.5 * SPACE_BETWEEN_COLUMNS;
|
||||||
int xRight;
|
int rightPosition = 0;
|
||||||
int columnWidth;
|
int columnWidth = 0;
|
||||||
bool bRet = false;
|
bool menuFound = false;
|
||||||
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();
|
||||||
xRight = xLeft + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS;
|
rightPosition = leftPosition + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS;
|
||||||
if (x > xLeft && x < xRight && y > 0 && y < menuHeight){
|
if (x > leftPosition && x < rightPosition && y > 0 && y < menuHeight) {
|
||||||
mouseClickColumn(i);
|
mouseClickColumn(i);
|
||||||
bRet = true;
|
menuFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
} else if (currentColumn == i) {
|
||||||
if (iCurrentColumn == i) {
|
menuFound = columns[i].mouseClick(x, y, leftPosition, menuHeight, lineHeight);
|
||||||
bRet = columns[i].mouseClick(x, y, xLeft, menuHeight, lineHeight);
|
if (menuFound) {
|
||||||
if (bRet) {
|
currentColumn = -1;
|
||||||
iCurrentColumn = -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xLeft = xRight;
|
leftPosition = rightPosition;
|
||||||
}
|
}
|
||||||
return bRet;
|
return menuFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Menu::mouseOver(int x, int y) {
|
bool Menu::mouseOver(int x, int y) {
|
||||||
int xLeft = 0.5 * SPACE_BETWEEN_COLUMNS;
|
int leftPosition = 0.5 * SPACE_BETWEEN_COLUMNS;
|
||||||
int xRight;
|
int rightPosition;
|
||||||
int columnWidth;
|
int columnWidth;
|
||||||
bool bRet = false;
|
bool overMenu = false;
|
||||||
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();
|
||||||
xRight = xLeft + columnWidth + SPACE_BETWEEN_COLUMNS;
|
rightPosition = leftPosition + columnWidth + SPACE_BETWEEN_COLUMNS;
|
||||||
if (x > xLeft && x < xRight && y > 0 && y < menuHeight){
|
if (x > leftPosition && x < rightPosition && y > 0 && y < menuHeight) {
|
||||||
printf("Mouse Over: %d %d", x, y);
|
setMouseOver(leftPosition, rightPosition, 0, menuHeight);
|
||||||
|
overMenu = true;
|
||||||
setMouseOver(xLeft, xRight, 0, menuHeight);
|
if (currentColumn >= 0) {
|
||||||
bRet = true;
|
columns[currentColumn].setMouseOver(0, 0, 0, 0);
|
||||||
if (iCurrentColumn >= 0) {
|
currentColumn = i;
|
||||||
columns[iCurrentColumn].setMouseOver(0, 0, 0, 0);
|
|
||||||
iCurrentColumn = i;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (iCurrentColumn == i) {
|
} else if (currentColumn == i) {
|
||||||
columns[i].mouseOver(x, y, xLeft, menuHeight, lineHeight);
|
columns[i].mouseOver(x, y, leftPosition, menuHeight, lineHeight);
|
||||||
}
|
}
|
||||||
xLeft = xRight;
|
leftPosition = rightPosition;
|
||||||
}
|
}
|
||||||
if (!bRet) {
|
if (!overMenu) {
|
||||||
setMouseOver(0, 0, 0, 0);
|
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;
|
float scale = 0.10;
|
||||||
int mono = 0;
|
int mono = 0;
|
||||||
glColor3f(0.9,0.9,0.9);
|
glColor3f(0.9, 0.9, 0.9);
|
||||||
int width = screenwidth;
|
int width = screenWidth;
|
||||||
int height = screenheight;
|
int height = screenHeight;
|
||||||
glBegin(GL_QUADS); {
|
glBegin(GL_QUADS); {
|
||||||
glVertex2f(0, yOffset);
|
glVertex2f(0, yOffset);
|
||||||
glVertex2f(width, yOffset);
|
glVertex2f(width, yOffset);
|
||||||
glVertex2f( width, menuHeight + yOffset);
|
glVertex2f(width, menuHeight + yOffset);
|
||||||
glVertex2f(0 , menuHeight + yOffset);
|
glVertex2f(0 , menuHeight + yOffset);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
int x = SPACE_BETWEEN_COLUMNS;
|
int xPosition = SPACE_BETWEEN_COLUMNS;
|
||||||
char * columnName;
|
char* columnName;
|
||||||
int columnWidth;
|
int columnWidth;
|
||||||
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, x- 0.5 * SPACE_BETWEEN_COLUMNS);
|
columnWidth = columns[i].getWidth(scale, mono, xPosition - 0.5 * SPACE_BETWEEN_COLUMNS);
|
||||||
drawtext(x,18 + yOffset, scale, 0, 1.0, mono, columnName, 0, 0, 0);
|
drawtext(xPosition, 18 + yOffset, scale, 0, 1.0, mono, columnName, 0, 0, 0);
|
||||||
x += columnWidth + SPACE_BETWEEN_COLUMNS;
|
xPosition += columnWidth + SPACE_BETWEEN_COLUMNS;
|
||||||
if (iCurrentColumn == i) {
|
if (currentColumn == i) {
|
||||||
columns[i].render(yOffset, menuHeight, lineHeight);
|
columns[i].render(yOffset, menuHeight, lineHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,9 +136,9 @@ void Menu::render(int screenwidth, int screenheight) {
|
||||||
|
|
||||||
|
|
||||||
MenuColumn* Menu::addColumn(char *columnName) {
|
MenuColumn* Menu::addColumn(char *columnName) {
|
||||||
MenuColumn * pColumn;
|
MenuColumn* pColumn;
|
||||||
pColumn = new MenuColumn(columnName);
|
pColumn = new MenuColumn(columnName);
|
||||||
columns.push_back(*pColumn);
|
columns.push_back(*pColumn);
|
||||||
delete pColumn;
|
delete pColumn;
|
||||||
return &columns[columns.size()-1];
|
return &columns[columns.size() - 1];
|
||||||
}
|
}
|
|
@ -1,30 +1,31 @@
|
||||||
|
#ifndef __hifi__Menu__
|
||||||
|
#define __hifi__Menu__
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define MAX_COLUMN_NAME 50
|
#define MAX_COLUMN_NAME 50
|
||||||
#define SPACE_BETWEEN_COLUMNS 20
|
#define SPACE_BETWEEN_COLUMNS 20
|
||||||
#define SPACE_BEFORE_ROW_NAME 10
|
#define SPACE_BEFORE_ROW_NAME 10
|
||||||
typedef int(CALLBACK * PFNRowCallback)(int);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Menu {
|
class Menu {
|
||||||
public:
|
public:
|
||||||
Menu();
|
Menu();
|
||||||
~Menu();
|
~Menu();
|
||||||
void mouseClickColumn(int iColumnIndex);
|
void mouseClickColumn(int iColumnIndex);
|
||||||
void setMouseOver(int xLeft, int xRight, int yTop, int yBottom);
|
void setMouseOver(int xLeft, int xRight, int yTop, int yBottom);
|
||||||
void renderMouseOver();
|
void renderMouseOver();
|
||||||
bool mouseClick(int x, int y);
|
bool mouseClick(int x, int y);
|
||||||
bool mouseOver(int x, int y);
|
bool mouseOver(int x, int y);
|
||||||
void render(int screenwidth, int screenheight);
|
void render(int screenwidth, int screenheight);
|
||||||
void renderColumn(int i);
|
void renderColumn(int i);
|
||||||
MenuColumn* addColumn(char *columnName);
|
MenuColumn* addColumn(char *columnName);
|
||||||
private:
|
private:
|
||||||
std::vector<MenuColumn> columns;
|
std::vector<MenuColumn> columns;
|
||||||
int iCurrentColumn;
|
int currentColumn;
|
||||||
int xLeftMouseOver;
|
int leftMouseOver;
|
||||||
int xRightMouseOver;
|
int rightMouseOver;
|
||||||
int yTopMouseOver;
|
int topMouseOver;
|
||||||
int yBottomMouseOver;
|
int bottomMouseOver;
|
||||||
};
|
};
|
||||||
|
#endif /* defined(__hifi__Menu__) */
|
||||||
|
|
|
@ -1,78 +1,79 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
#include "MenuRow.h"
|
#include "MenuRow.h"
|
||||||
#include "MenuColumn.h"
|
#include "MenuColumn.h"
|
||||||
#include "Menu.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));
|
int length = std::min(MAX_COLUMN_NAME - 1,(int) strlen(columnName));
|
||||||
strncpy(this->columnName, columnName, length);
|
strncpy(this->columnName, columnName, length);
|
||||||
this->columnName[length] = '\0';
|
this->columnName[length] = '\0';
|
||||||
columnWidth = 0;
|
columnWidth = 0;
|
||||||
leftPosition = 0;
|
leftPosition = 0;
|
||||||
xLeftMouseOver = 0;
|
leftMouseOver = 0;
|
||||||
xRightMouseOver = 0;
|
rightMouseOver = 0;
|
||||||
yTopMouseOver = 0;
|
topMouseOver = 0;
|
||||||
yBottomMouseOver = 0;
|
bottomMouseOver = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuColumn::~MenuColumn()
|
MenuColumn::~MenuColumn() {
|
||||||
{
|
rows.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuColumn::mouseClickRow(int iRowIndex) {
|
void MenuColumn::mouseClickRow(int numberOfRowsIndex) {
|
||||||
rows[iRowIndex].call();
|
rows[numberOfRowsIndex].call();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuColumn::mouseClick(int x, int y, int xLeft, int menuHeight, int lineHeight) {
|
bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) {
|
||||||
int xRight = xLeft + 200;
|
int rightPosition = leftPosition + 200;
|
||||||
int yTop = menuHeight;
|
int topPosition = menuHeight;
|
||||||
int yBottom = menuHeight;
|
int bottomPosition = menuHeight;
|
||||||
int columnWidth;
|
int columnWidth = 0;
|
||||||
bool bRet = false;
|
bool bRet = 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();
|
||||||
yTop = yBottom + lineHeight;
|
topPosition = bottomPosition + lineHeight;
|
||||||
if (x > xLeft && x < xRight && y > yBottom && y < yTop) {
|
if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) {
|
||||||
mouseClickRow(i);
|
mouseClickRow(i);
|
||||||
bRet = true;
|
bRet = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yBottom = yTop;
|
bottomPosition = topPosition;
|
||||||
}
|
}
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuColumn::setMouseOver(int xLeft, int xRight, int yTop, int yBottom) {
|
void MenuColumn::setMouseOver(int leftPosition, int rightPosition, int topPosition, int bottomPosition) {
|
||||||
xLeftMouseOver = xLeft;
|
leftMouseOver = leftPosition;
|
||||||
xRightMouseOver = xRight;
|
rightMouseOver = rightPosition;
|
||||||
yTopMouseOver = yTop;
|
topMouseOver = topPosition;
|
||||||
yBottomMouseOver = yBottom;
|
bottomMouseOver = bottomPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuColumn::mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeight) {
|
bool MenuColumn::mouseOver(int x, int y, int leftPosition, int menuHeight, int lineHeight) {
|
||||||
int xRight = xLeft + 100;
|
int rightPosition = leftPosition + 100;
|
||||||
int yTop = menuHeight;
|
int topPosition = menuHeight;
|
||||||
int yBottom = menuHeight;
|
int bottomPosition = menuHeight;
|
||||||
int columnWidth;
|
int columnWidth = 0;
|
||||||
bool bRet = false;
|
bool bRet = 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();
|
||||||
yTop = yBottom + lineHeight ;
|
topPosition = bottomPosition + lineHeight ;
|
||||||
if (x > xLeft && x < xRight && y > yBottom && y < yTop) {
|
if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) {
|
||||||
setMouseOver(xLeft, xRight, yBottom, yTop);
|
setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition);
|
||||||
bRet = true;
|
bRet = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yBottom = yTop;
|
bottomPosition = topPosition;
|
||||||
}
|
}
|
||||||
if (!bRet) {
|
if (!bRet) {
|
||||||
setMouseOver(0, 0, 0, 0);
|
setMouseOver(0, 0, 0, 0);
|
||||||
|
@ -80,54 +81,52 @@ bool MenuColumn::mouseOver(int x, int y, int xLeft, int menuHeight, int lineHeig
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * MenuColumn::getName() {
|
char* MenuColumn::getName() {
|
||||||
return this->columnName;
|
return this->columnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MenuColumn::getWidth(float scale, int mono, int leftPosition){
|
int MenuColumn::getWidth(float scale, int mono, int leftPosition) {
|
||||||
if (columnWidth == 0) {
|
if (columnWidth == 0) {
|
||||||
columnWidth = widthText( scale, mono, this->columnName);
|
columnWidth = widthText(scale, mono, this->columnName);
|
||||||
this->leftPosition = leftPosition;
|
this->leftPosition = leftPosition;
|
||||||
}
|
}
|
||||||
return columnWidth;
|
return columnWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MenuColumn::getWidth(){
|
int MenuColumn::getWidth() {
|
||||||
return columnWidth;
|
return columnWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MenuColumn::getLeftPosition(){
|
int MenuColumn::getLeftPosition() {
|
||||||
return leftPosition;
|
return leftPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MenuColumn::addRow(char * rowName, PFNRowCallback callback){
|
int MenuColumn::addRow(char * rowName, PFNRowCallback callback) {
|
||||||
MenuRow * pRow;
|
MenuRow* pRow;
|
||||||
pRow = new MenuRow(rowName, callback);
|
pRow = new MenuRow(rowName, callback);
|
||||||
rows.push_back(*pRow);
|
rows.push_back(*pRow);
|
||||||
delete pRow;
|
delete pRow;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) {
|
void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) {
|
||||||
int iRow = rows.size();
|
int numberOfRows = rows.size();
|
||||||
if (iRow > 0) {
|
if (numberOfRows > 0) {
|
||||||
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+100, yOffset + menuHeight);
|
||||||
glVertex2f(leftPosition+100, yOffset + menuHeight + iRow*lineHeight);
|
glVertex2f(leftPosition+100, yOffset + menuHeight + numberOfRows*lineHeight);
|
||||||
glVertex2f(leftPosition , yOffset + menuHeight + iRow* lineHeight);
|
glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
float scale = 0.10;
|
float scale = 0.10;
|
||||||
int mono = 0;
|
int mono = 0;
|
||||||
int y = menuHeight + lineHeight / 2 ;
|
int y = menuHeight + lineHeight / 2 ;
|
||||||
char * rowName;
|
char* rowName;
|
||||||
int columnWidth;
|
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);
|
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);
|
||||||
|
@ -137,13 +136,13 @@ void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuColumn::renderMouseOver(int yOffset) {
|
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);
|
glColor4f(0,0,0,0.1);
|
||||||
glBegin(GL_QUADS); {
|
glBegin(GL_QUADS); {
|
||||||
glVertex2f(xLeftMouseOver, yOffset + yTopMouseOver);
|
glVertex2f(leftMouseOver, yOffset + topMouseOver);
|
||||||
glVertex2f(xRightMouseOver, yOffset + yTopMouseOver);
|
glVertex2f(rightMouseOver, yOffset + topMouseOver);
|
||||||
glVertex2f(xRightMouseOver, yOffset + yBottomMouseOver);
|
glVertex2f(rightMouseOver, yOffset + bottomMouseOver);
|
||||||
glVertex2f(xLeftMouseOver , yOffset + yBottomMouseOver);
|
glVertex2f(leftMouseOver , yOffset + bottomMouseOver);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,33 @@
|
||||||
|
#ifndef __hifi__MenuColumn__
|
||||||
|
#define __hifi__MenuColumn__
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class MenuColumn {
|
class MenuColumn {
|
||||||
public:
|
public:
|
||||||
MenuColumn();
|
MenuColumn();
|
||||||
MenuColumn(char * columnName);
|
MenuColumn(char * columnName);
|
||||||
~MenuColumn();
|
~MenuColumn();
|
||||||
void mouseClickRow(int iColumnIndex);
|
void mouseClickRow(int iColumnIndex);
|
||||||
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();
|
||||||
void render(int yOffset, int menuHeight, int lineHeight);
|
void render(int yOffset, int menuHeight, int lineHeight);
|
||||||
void MenuColumn::renderMouseOver(int yOffset);
|
void MenuColumn::renderMouseOver(int yOffset);
|
||||||
int addRow(char * rowName, PFNRowCallback callback);
|
int addRow(char * rowName, PFNRowCallback callback);
|
||||||
private:
|
private:
|
||||||
char columnName[MAX_COLUMN_NAME];
|
char columnName[MAX_COLUMN_NAME];
|
||||||
int columnWidth;
|
int columnWidth;
|
||||||
int leftPosition;
|
int leftPosition;
|
||||||
std::vector<MenuRow> rows;
|
std::vector<MenuRow> rows;
|
||||||
int xLeftMouseOver;
|
int leftMouseOver;
|
||||||
int xRightMouseOver;
|
int rightMouseOver;
|
||||||
int yTopMouseOver;
|
int topMouseOver;
|
||||||
int yBottomMouseOver;
|
int bottomMouseOver;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /* defined(__hifi__MenuColumn__) */
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
#include "MenuRow.h"
|
#include "MenuRow.h"
|
||||||
#include "MenuColumn.h"
|
#include "MenuColumn.h"
|
||||||
#include "Menu.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));
|
int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName));
|
||||||
strncpy(this->rowName, columnName, length);
|
strncpy(this->rowName, columnName, length);
|
||||||
memcpy(this->rowName + length, " \0", 5);
|
memcpy(this->rowName + length, " \0", 5);
|
||||||
|
@ -19,15 +19,14 @@ MenuRow::MenuRow(char * columnName, PFNRowCallback callback)
|
||||||
rowWidth = 0;
|
rowWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuRow::~MenuRow()
|
MenuRow::~MenuRow() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuRow::call() {
|
void MenuRow::call() {
|
||||||
callback(-2);
|
callback(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
char * MenuRow::getName() {
|
char* MenuRow::getName() {
|
||||||
int length = (int) strlen(this->rowName) - 4;
|
int length = (int) strlen(this->rowName) - 4;
|
||||||
int currentValue = callback(-1);
|
int currentValue = callback(-1);
|
||||||
if (currentValue == 0) {
|
if (currentValue == 0) {
|
||||||
|
@ -40,14 +39,14 @@ char * MenuRow::getName() {
|
||||||
return this->rowName;
|
return this->rowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MenuRow::getWidth(float scale, int mono, int leftPosition){
|
int MenuRow::getWidth(float scale, int mono, int leftPosition) {
|
||||||
if (rowWidth == 0) {
|
if (rowWidth == 0) {
|
||||||
rowWidth = widthText( scale, mono, this->rowName);
|
rowWidth = widthText( scale, mono, this->rowName);
|
||||||
}
|
}
|
||||||
return rowWidth;
|
return rowWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MenuRow::getWidth(){
|
int MenuRow::getWidth() {
|
||||||
return rowWidth;
|
return rowWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
|
#ifndef __hifi__MenuRow__
|
||||||
|
#define __hifi__MenuRow__
|
||||||
|
|
||||||
#include <vector>
|
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 MenuCallBack CALLBACK
|
||||||
#define SPACE_BETWEEN_COLUMNS 20
|
|
||||||
#define SPACE_BEFORE_ROW_NAME 10
|
typedef int(MenuCallBack * PFNRowCallback)(int);
|
||||||
typedef int(CALLBACK * PFNRowCallback)(int);
|
|
||||||
|
|
||||||
class MenuRow {
|
class MenuRow {
|
||||||
public:
|
public:
|
||||||
MenuRow();
|
MenuRow();
|
||||||
MenuRow(char * rowName, PFNRowCallback);
|
MenuRow(char * rowName, PFNRowCallback);
|
||||||
~MenuRow();
|
~MenuRow();
|
||||||
void call();
|
void call();
|
||||||
char * getName();
|
char * getName();
|
||||||
int getWidth(float scale, int mono, int leftPosition);
|
int getWidth(float scale, int mono, int leftPosition);
|
||||||
int getWidth();
|
int getWidth();
|
||||||
private:
|
private:
|
||||||
char rowName[MAX_COLUMN_NAME];
|
char rowName[MAX_COLUMN_NAME];
|
||||||
int rowWidth;
|
int rowWidth;
|
||||||
PFNRowCallback callback;
|
PFNRowCallback callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /* defined(__hifi__MenuRow__) */
|
||||||
|
|
|
@ -93,10 +93,9 @@ double diffclock(timeval *clock1,timeval *clock2)
|
||||||
int widthText(float scale, int mono, char *string) {
|
int widthText(float scale, int mono, char *string) {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
if (!mono) {
|
if (!mono) {
|
||||||
width =scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string);
|
width = scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string);
|
||||||
}
|
} else {
|
||||||
else {
|
width = scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string);
|
||||||
width =scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string);
|
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@ void Timer(int extra)
|
||||||
void displayStats(void)
|
void displayStats(void)
|
||||||
{
|
{
|
||||||
int statsVerticalOffset = 50;
|
int statsVerticalOffset = 50;
|
||||||
if (menuOn == 0) {
|
if (::menuOn == 0) {
|
||||||
statsVerticalOffset = 8;
|
statsVerticalOffset = 8;
|
||||||
}
|
}
|
||||||
// bitmap chars are about 10 pels high
|
// bitmap chars are about 10 pels high
|
||||||
|
@ -840,7 +840,7 @@ void display(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show menu
|
// Show menu
|
||||||
if (menuOn) {
|
if (::menuOn) {
|
||||||
glLineWidth(1.0f);
|
glLineWidth(1.0f);
|
||||||
glPointSize(1.0f);
|
glPointSize(1.0f);
|
||||||
menu.render(WIDTH,HEIGHT);
|
menu.render(WIDTH,HEIGHT);
|
||||||
|
@ -868,7 +868,7 @@ void display(void)
|
||||||
frameCount++;
|
frameCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK setValue(int state, int *value) {
|
int MenuCallBack setValue(int state, int *value) {
|
||||||
if (state == -2) {
|
if (state == -2) {
|
||||||
*value = !(*value);
|
*value = !(*value);
|
||||||
} else if (state == -1) {
|
} else if (state == -1) {
|
||||||
|
@ -879,36 +879,33 @@ int CALLBACK setValue(int state, int *value) {
|
||||||
return *value;
|
return *value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK setHead(int state) {
|
int MenuCallBack setHead(int state) {
|
||||||
return setValue(state, &displayHead);
|
return setValue(state, &displayHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK setField(int state) {
|
int MenuCallBack setField(int state) {
|
||||||
return setValue(state, &displayField);
|
return setValue(state, &displayField);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK setNoise(int state) {
|
int MenuCallBack setNoise(int state) {
|
||||||
int iRet = setValue(state, &noiseOn);
|
int iRet = setValue(state, &noiseOn);
|
||||||
if (noiseOn)
|
if (noiseOn) {
|
||||||
{
|
|
||||||
myHead.setNoise(noise);
|
myHead.setNoise(noise);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
myHead.setNoise(0);
|
myHead.setNoise(0);
|
||||||
}
|
}
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK setStats(int state) {
|
int MenuCallBack setStats(int state) {
|
||||||
return setValue(state, &statsOn);
|
return setValue(state, &statsOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK setMenu(int state) {
|
int MenuCallBack setMenu(int state) {
|
||||||
return setValue(state, &menuOn);
|
return setValue(state, &::menuOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALLBACK setMirror(int state) {
|
int MenuCallBack setMirror(int state) {
|
||||||
return setValue(state, &headMirror);
|
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( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
|
||||||
{
|
{
|
||||||
if (menu.mouseClick(x, y) == false) {
|
if (!menu.mouseClick(x, y)) {
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
mouseY = y;
|
mouseY = y;
|
||||||
mousePressed = 1;
|
mousePressed = 1;
|
||||||
lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT);
|
lattice.mouseClick((float)x/(float)WIDTH, (float)y/(float)HEIGHT);
|
||||||
mouseStartX = x;
|
mouseStartX = x;
|
||||||
mouseStartY = y;
|
mouseStartY = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP )
|
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
|
||||||
{
|
mouseX = x;
|
||||||
mouseX = x;
|
mouseY = y;
|
||||||
mouseY = y;
|
mousePressed = 0;
|
||||||
mousePressed = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,6 @@
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
double usecTimestamp(timeval *time) {
|
double usecTimestamp(timeval *time) {
|
||||||
return (time->tv_sec * 1000000.0 + time->tv_usec);
|
return (time->tv_sec * 1000000.0 + time->tv_usec);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue