Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jeffrey Ventrella 2013-05-21 17:38:36 -07:00
commit 25dfc7bc4b
8 changed files with 0 additions and 16504 deletions

View file

@ -233,11 +233,6 @@ void Application::initializeGL() {
glutInit(&argc, 0);
#endif
#ifdef _WIN32
glewInit();
printLog( "Glew Init complete.\n" );
#endif
// Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large
// field of view and near and far clip to make it interesting.
//viewFrustumOffsetCamera.setFieldOfView(90.0);

File diff suppressed because it is too large Load diff

View file

@ -1,158 +0,0 @@
//
// Menu.cpp
// hifi
//
// Created by Dominque Vincent on 4/10/13.
//
//
#include <algorithm>
#include "InterfaceConfig.h"
#include "Util.h"
#include "MenuRow.h"
#include "MenuColumn.h"
#include "Menu.h"
const int LINE_HEIGHT = 30;
const int MENU_HEIGHT = 30;
#ifdef _WIN32
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).
#else
const int MENU_Y_OFFSET = 0;
#endif
Menu::Menu() {
currentColumn = -1;
leftMouseOver = 0;
rightMouseOver = 0;
topMouseOver = 0;
bottomMouseOver = 0;
}
Menu::~Menu() {
columns.clear();
}
void Menu::mouseClickColumn(int columnIndex) {
if (currentColumn == columnIndex) {
currentColumn = -1;
} else {
currentColumn = columnIndex;
}
}
void Menu::setMouseOver(int leftPosition, int rightPosition, int top, int bottom) {
leftMouseOver = leftPosition;
rightMouseOver = rightPosition;
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, MENU_Y_OFFSET + topMouseOver);
glVertex2f(rightMouseOver, MENU_Y_OFFSET + topMouseOver);
glVertex2f(rightMouseOver, MENU_Y_OFFSET + bottomMouseOver);
glVertex2f(leftMouseOver, MENU_Y_OFFSET + bottomMouseOver);
}
glEnd();
}
}
bool Menu::mouseClick(int x, int y) {
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();
rightPosition = leftPosition + columnWidth + 1.5 * SPACE_BETWEEN_COLUMNS;
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, MENU_HEIGHT, LINE_HEIGHT);
if (menuFound) {
currentColumn = -1;
}
}
leftPosition = rightPosition;
}
return menuFound;
}
bool Menu::mouseOver(int x, int y) {
int leftPosition = 0.5 * SPACE_BETWEEN_COLUMNS;
int rightPosition;
int columnWidth;
bool overMenu = false;
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 < MENU_HEIGHT) {
setMouseOver(leftPosition, rightPosition, 0, MENU_HEIGHT);
overMenu = true;
if (currentColumn >= 0) {
columns[currentColumn].setMouseOver(0, 0, 0, 0);
currentColumn = i;
}
break;
} else if (currentColumn == i) {
columns[i].mouseOver(x, y, leftPosition, MENU_HEIGHT, LINE_HEIGHT);
}
leftPosition = rightPosition;
}
if (!overMenu) {
setMouseOver(0, 0, 0, 0);
}
return overMenu;
}
const float MENU_COLOR[3] = {0.75, 0.75, 0.75};
void Menu::render(int screenWidth, int screenHeight) {
float scale = 0.10;
int mono = 0;
glColor3fv(MENU_COLOR);
int width = screenWidth;
glEnable(GL_LINE_SMOOTH);
glBegin(GL_QUADS); {
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;
char* columnName;
int columnWidth;
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 + MENU_Y_OFFSET, scale, 0, 1.0, mono, columnName, 0, 0, 0);
xPosition += columnWidth + SPACE_BETWEEN_COLUMNS;
if (currentColumn == i) {
columns[i].render(MENU_Y_OFFSET, MENU_HEIGHT, LINE_HEIGHT);
}
}
renderMouseOver();
}
MenuColumn* Menu::addColumn(const char *columnName) {
MenuColumn* pColumn;
pColumn = new MenuColumn(columnName);
columns.push_back(*pColumn);
delete pColumn;
return &columns[columns.size() - 1];
}

View file

@ -1,36 +0,0 @@
//
// Menu.h
// hifi
//
// Created by Dominque Vincent on 4/10/13.
//
//
#ifndef __hifi__Menu__
#define __hifi__Menu__
#include <vector>
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(const char *columnName);
void hidePopupMenu() { currentColumn = -1; };
private:
std::vector<MenuColumn> columns;
int currentColumn;
int leftMouseOver;
int rightMouseOver;
int topMouseOver;
int bottomMouseOver;
};
#endif /* defined(__hifi__Menu__) */

View file

@ -1,183 +0,0 @@
//
// MenuColumn.cpp
// hifi
//
// Created by Dominque Vincent on 4/10/13.
//
//
#include <algorithm>
#include <cstring>
#include "InterfaceConfig.h"
#include "Util.h"
#include "MenuRow.h"
#include "MenuColumn.h"
#include "Menu.h"
#include "ui/TextRenderer.h"
MenuColumn::MenuColumn() {
}
MenuColumn::MenuColumn(const 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;
leftMouseOver = 0;
rightMouseOver = 0;
topMouseOver = 0;
bottomMouseOver = 0;
}
MenuColumn::~MenuColumn() {
rows.clear();
}
void MenuColumn::mouseClickRow(int numberOfRowsIndex) {
rows[numberOfRowsIndex].call();
}
bool MenuColumn::mouseClick(int x, int y, int leftPosition, int menuHeight, int lineHeight) {
int rightPosition = leftPosition + 200; // XXXBHG - this looks like a hack?
int topPosition = menuHeight;
int bottomPosition = menuHeight;
int columnWidth = 0;
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);
menuFound = true;
break;
}
bottomPosition = topPosition;
}
return menuFound;
}
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 leftPosition, int menuHeight, int lineHeight) {
int maxColumnWidth = this->getMaxRowWidth();
int rightPosition = leftPosition + maxColumnWidth;
int topPosition = menuHeight;
int bottomPosition = menuHeight;
bool overMenu = false;
for (unsigned int i = 0; i < rows.size(); ++i) {
topPosition = bottomPosition + lineHeight ;
if (x > leftPosition && x < rightPosition && y > bottomPosition && y < topPosition) {
setMouseOver(leftPosition, rightPosition, bottomPosition, topPosition);
overMenu = true;
break;
}
bottomPosition = topPosition;
}
if (!overMenu) {
setMouseOver(0, 0, 0, 0);
}
return overMenu;
}
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(const char* rowName, MenuRowCallback callback) {
MenuRow* row;
row = new MenuRow(rowName, callback);
rows.push_back(*row);
delete row;
return 0;
}
int MenuColumn::addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) {
MenuRow* row;
row = new MenuRow(rowName, callback, stateNameCallback);
rows.push_back(*row);
delete row;
return 0;
}
int MenuColumn::getMaxRowWidth() {
float scale = 0.09;
int mono = 0;
int maxColumnWidth = 100 - (SPACE_BEFORE_ROW_NAME*2); // the minimum size we want
for (unsigned int i = 0; i < rows.size(); ++i) {
maxColumnWidth = std::max(maxColumnWidth,rows[i].getWidth(scale, mono, 0));
}
maxColumnWidth += SPACE_BEFORE_ROW_NAME*2; // space before and after!!
return maxColumnWidth;
}
static TextRenderer* textRenderer() {
static TextRenderer* renderer = new TextRenderer(SANS_FONT_FAMILY, 11);
return renderer;
}
void MenuColumn::render(int yOffset, int menuHeight, int lineHeight) {
int numberOfRows = rows.size();
if (numberOfRows > 0) {
int maxColumnWidth = this->getMaxRowWidth();
glColor3f(0.9,0.9,0.9);
glBegin(GL_QUADS); {
glVertex2f(leftPosition, yOffset + menuHeight);
glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight);
glVertex2f(leftPosition+maxColumnWidth, yOffset + menuHeight + numberOfRows*lineHeight);
glVertex2f(leftPosition , yOffset + menuHeight + numberOfRows* lineHeight);
}
glEnd();
}
int y = menuHeight + lineHeight / 2 ;
char* rowName;
for (unsigned int i = 0; i < rows.size(); ++i) {
rowName = rows[i].getName();
glColor3f(0, 0, 0);
textRenderer()->draw(leftPosition + SPACE_BEFORE_ROW_NAME, y + 5 + yOffset, rowName);
y += lineHeight;
}
renderMouseOver(yOffset);
}
void MenuColumn::renderMouseOver(int yOffset) {
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);
}
glEnd();
}
}

View file

@ -1,44 +0,0 @@
//
// MenuColumn.h
// hifi
//
// Created by Dominque Vincent on 4/10/13.
//
//
#ifndef __hifi__MenuColumn__
#define __hifi__MenuColumn__
#include <vector>
class MenuColumn {
public:
MenuColumn();
MenuColumn(const 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 renderMouseOver(int yOffset);
int addRow(const char* rowName, MenuRowCallback callback);
int addRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback);
int getMaxRowWidth();
private:
char columnName[MAX_COLUMN_NAME];
int columnWidth;
int leftPosition;
std::vector<MenuRow> rows;
int leftMouseOver;
int rightMouseOver;
int topMouseOver;
int bottomMouseOver;
};
#endif /* defined(__hifi__MenuColumn__) */

View file

@ -1,83 +0,0 @@
//
// MenuRow.cpp
// hifi
//
// Created by Dominque Vincent on 4/10/13.
//
//
#include <algorithm>
#include <cstring>
#include "InterfaceConfig.h"
#include "Util.h"
#include "MenuRow.h"
#include "MenuColumn.h"
#include "Menu.h"
MenuRow::MenuRow() :
callback(NULL),
stateNameCallback(NULL) {
}
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) :
callback(callback),
stateNameCallback(NULL) {
this->nameLength = strlen(columnName);
strncpy(this->rowName, columnName, MAX_COLUMN_NAME); // copy the base name
strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state
rowWidth = 0;
}
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) :
callback(callback),
stateNameCallback(stateNameCallback) {
this->nameLength = strlen(columnName);
strncpy(this->rowName, columnName, MAX_COLUMN_NAME);
strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state
rowWidth = 0;
}
MenuRow::~MenuRow() {
}
void MenuRow::call() {
callback(MENU_ROW_PICKED);
}
const char* MenuRow::getStateName() {
int currentValue = callback(MENU_ROW_GET_VALUE);
const char* stateName;
// If the MenuRow has a custom stateNameCallback function, then call it to get a string
// to display in the menu. Otherwise, use the default implementation.
if (stateNameCallback != NULL) {
stateName = stateNameCallback(currentValue);
} else {
if (currentValue == 0) {
stateName = " OFF ";
} else if (currentValue == 1) {
stateName = " ON ";
} else {
stateName = " ";
}
}
return stateName;
}
char* MenuRow::getName() {
strcpy(this->rowName + nameLength, getStateName());
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;
}

View file

@ -1,40 +0,0 @@
//
// MenuRow.h
// hifi
//
// Created by Dominque Vincent on 4/10/13.
//
//
#ifndef __hifi__MenuRow__
#define __hifi__MenuRow__
const int MAX_COLUMN_NAME = 50;
const int SPACE_BETWEEN_COLUMNS = 20;
const int SPACE_BEFORE_ROW_NAME = 10;
const int MENU_ROW_PICKED = -2;
const int MENU_ROW_GET_VALUE = -1;
typedef int(*MenuRowCallback)(int);
typedef const char*(*MenuStateNameCallback)(int);
class MenuRow {
public:
MenuRow();
MenuRow(const char* rowName, MenuRowCallback callback);
MenuRow(const char* rowName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback);
~MenuRow();
void call();
char * getName();
const char* getStateName();
int getWidth(float scale, int mono, int leftPosition);
int getWidth();
private:
int nameLength;
char rowName[MAX_COLUMN_NAME];
int rowWidth;
MenuRowCallback callback;
MenuStateNameCallback stateNameCallback;
};
#endif /* defined(__hifi__MenuRow__) */