mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:42:58 +02:00
#19171 split of menu.cpp in menuColumn.cpp and menuRow.cpp
This commit is contained in:
parent
d6189694c8
commit
eb646ade84
7 changed files with 263 additions and 231 deletions
|
@ -1,199 +1,17 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
#include "MenuRow.h"
|
||||||
|
#include "MenuColumn.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
int menuHeight = 30;
|
|
||||||
int lineHeight = 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
|
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).
|
||||||
|
|
||||||
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(){
|
Menu::Menu(){
|
||||||
iCurrentColumn = -1;
|
iCurrentColumn = -1;
|
||||||
|
@ -251,7 +69,7 @@ bool Menu::mouseClick(int x, int y) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (iCurrentColumn == i) {
|
if (iCurrentColumn == i) {
|
||||||
bRet = columns[i].mouseClick(x, y, xLeft);
|
bRet = columns[i].mouseClick(x, y, xLeft, menuHeight, lineHeight);
|
||||||
if (bRet) {
|
if (bRet) {
|
||||||
iCurrentColumn = -1;
|
iCurrentColumn = -1;
|
||||||
}
|
}
|
||||||
|
@ -281,7 +99,7 @@ bool Menu::mouseOver(int x, int y) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (iCurrentColumn == i) {
|
} else if (iCurrentColumn == i) {
|
||||||
columns[i].mouseOver(x, y, xLeft);
|
columns[i].mouseOver(x, y, xLeft, menuHeight, lineHeight);
|
||||||
}
|
}
|
||||||
xLeft = xRight;
|
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);
|
drawtext(x,18 + yOffset, scale, 0, 1.0, mono, columnName, 0, 0, 0);
|
||||||
x += columnWidth + SPACE_BETWEEN_COLUMNS;
|
x += columnWidth + SPACE_BETWEEN_COLUMNS;
|
||||||
if (iCurrentColumn == i) {
|
if (iCurrentColumn == i) {
|
||||||
columns[i].render();
|
columns[i].render(yOffset, menuHeight, lineHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
renderMouseOver();
|
renderMouseOver();
|
||||||
|
|
|
@ -7,48 +7,6 @@
|
||||||
typedef int(CALLBACK * PFNRowCallback)(int);
|
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<MenuRow> rows;
|
|
||||||
int xLeftMouseOver;
|
|
||||||
int xRightMouseOver;
|
|
||||||
int yTopMouseOver;
|
|
||||||
int yBottomMouseOver;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Menu {
|
class Menu {
|
||||||
public:
|
public:
|
||||||
|
|
150
interface/src/MenuColumn.cpp
Normal file
150
interface/src/MenuColumn.cpp
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#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();
|
||||||
|
}
|
||||||
|
}
|
28
interface/src/MenuColumn.h
Normal file
28
interface/src/MenuColumn.h
Normal file
|
@ -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<MenuRow> rows;
|
||||||
|
int xLeftMouseOver;
|
||||||
|
int xRightMouseOver;
|
||||||
|
int yTopMouseOver;
|
||||||
|
int yBottomMouseOver;
|
||||||
|
};
|
||||||
|
|
53
interface/src/MenuRow.cpp
Normal file
53
interface/src/MenuRow.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
23
interface/src/MenuRow.h
Normal file
23
interface/src/MenuRow.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
};
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
#include "FieldOfView.h"
|
#include "FieldOfView.h"
|
||||||
#include "Stars.h"
|
#include "Stars.h"
|
||||||
|
|
||||||
|
#include "MenuRow.h"
|
||||||
|
#include "MenuColumn.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "Head.h"
|
#include "Head.h"
|
||||||
#include "Hand.h"
|
#include "Hand.h"
|
||||||
|
|
Loading…
Reference in a new issue