mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 07:37:31 +02:00
fixed bug in rendering menu rows where state was longer than 5 characters
This commit is contained in:
parent
37322fcb73
commit
e429dfe61f
2 changed files with 20 additions and 25 deletions
|
@ -24,20 +24,18 @@ MenuRow::MenuRow() :
|
||||||
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) :
|
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback) :
|
||||||
callback(callback),
|
callback(callback),
|
||||||
stateNameCallback(NULL) {
|
stateNameCallback(NULL) {
|
||||||
int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName));
|
this->nameLength = strlen(columnName);
|
||||||
strncpy(this->rowName, columnName, length);
|
strncpy(this->rowName, columnName, MAX_COLUMN_NAME); // copy the base name
|
||||||
memcpy(this->rowName + length, " \0", 5);
|
strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state
|
||||||
rowWidth = 0;
|
rowWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) :
|
MenuRow::MenuRow(const char * columnName, MenuRowCallback callback, MenuStateNameCallback stateNameCallback) :
|
||||||
callback(callback),
|
callback(callback),
|
||||||
stateNameCallback(stateNameCallback) {
|
stateNameCallback(stateNameCallback) {
|
||||||
int length = std::min(MAX_COLUMN_NAME - 5,(int) strlen(columnName));
|
this->nameLength = strlen(columnName);
|
||||||
strncpy(this->rowName, columnName, length);
|
strncpy(this->rowName, columnName, MAX_COLUMN_NAME);
|
||||||
|
strncpy(this->rowName, this->getName(), MAX_COLUMN_NAME); // now add in state
|
||||||
// note: it would be good to also include the initial state
|
|
||||||
memcpy(this->rowName + length, " \0", 5);
|
|
||||||
rowWidth = 0;
|
rowWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,32 +46,27 @@ void MenuRow::call() {
|
||||||
callback(MENU_ROW_PICKED);
|
callback(MENU_ROW_PICKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* MenuRow::getName() {
|
const char* MenuRow::getStateName() {
|
||||||
int length = (int) strlen(this->rowName) - 4;
|
|
||||||
int currentValue = callback(MENU_ROW_GET_VALUE);
|
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
|
// 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.
|
// to display in the menu. Otherwise, use the default implementation.
|
||||||
if (stateNameCallback != NULL) {
|
if (stateNameCallback != NULL) {
|
||||||
const char* stateName = stateNameCallback(currentValue);
|
stateName = stateNameCallback(currentValue);
|
||||||
int stateNameLength = strlen(stateName);
|
|
||||||
printf("MenuRow::getName() stateName=%s stateNameLength=%d\n",stateName,stateNameLength);
|
|
||||||
|
|
||||||
// XXXBHG - BUG!!! - only 5 characters?? someplace else hard coded? for some reason, we end up
|
|
||||||
// with memory corruption down the line, if we allow these states to be longer than 5 characters
|
|
||||||
// including the NULL termination.
|
|
||||||
strncpy(this->rowName + length, stateName,4); // only 4 chars
|
|
||||||
memcpy(this->rowName + length + 5, "\0", 0); // null terminate!!
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (currentValue == 0) {
|
if (currentValue == 0) {
|
||||||
memcpy(this->rowName + length, " OFF\0", 5);
|
stateName = " OFF ";
|
||||||
} else if (currentValue == 1) {
|
} else if (currentValue == 1) {
|
||||||
memcpy(this->rowName + length, " ON \0", 5);
|
stateName = " ON ";
|
||||||
} else {
|
} else {
|
||||||
memcpy(this->rowName + length, " \0", 5);
|
stateName = " ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return stateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* MenuRow::getName() {
|
||||||
|
strcpy(this->rowName + nameLength, getStateName());
|
||||||
return this->rowName;
|
return this->rowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,11 @@ public:
|
||||||
~MenuRow();
|
~MenuRow();
|
||||||
void call();
|
void call();
|
||||||
char * getName();
|
char * getName();
|
||||||
|
const char* getStateName();
|
||||||
int getWidth(float scale, int mono, int leftPosition);
|
int getWidth(float scale, int mono, int leftPosition);
|
||||||
int getWidth();
|
int getWidth();
|
||||||
private:
|
private:
|
||||||
|
int nameLength;
|
||||||
char rowName[MAX_COLUMN_NAME];
|
char rowName[MAX_COLUMN_NAME];
|
||||||
int rowWidth;
|
int rowWidth;
|
||||||
MenuRowCallback callback;
|
MenuRowCallback callback;
|
||||||
|
|
Loading…
Reference in a new issue