Re #333 (D26 : New / enhanced menu controls) Added GfuiComboboxGetNumberOfChoices + cleaned up the combobox code

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3334 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: d43e042a3a934bc74cede329b65e526e100b65a2
Former-commit-id: d2897d7a96131ce406370c6d13550cd2b0ec991e
This commit is contained in:
pouillot 2011-02-07 09:35:37 +00:00
parent 7daa125973
commit 7616446533
2 changed files with 77 additions and 149 deletions

View file

@ -202,30 +202,39 @@ gfuiDrawCombobox(tGfuiObject *obj)
//Do nothing because children already draw themselves //Do nothing because children already draw themselves
} }
static tGfuiCombobox*
gfuiGetCombobox(void *scr, int id)
{
tGfuiScreen *screen = (tGfuiScreen*)scr;
tGfuiObject* curObject = screen->objects;
if (curObject)
{
do
{
curObject = curObject->next;
if (curObject->id == id && curObject->widget == GFUI_COMBOBOX)
return &(curObject->u.combobox);
}
while (curObject != screen->objects);
}
return 0;
}
unsigned int unsigned int
GfuiComboboxAddText(void *scr, int id, const char *text) GfuiComboboxAddText(void *scr, int id, const char *text)
{ {
tGfuiObject *curObject;
tGfuiScreen *screen = (tGfuiScreen*)scr;
unsigned int index = 0; unsigned int index = 0;
tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
curObject = screen->objects; if (combo)
if (curObject != NULL) {
do {
curObject = curObject->next;
if (curObject->id == id) {
if (curObject->widget == GFUI_COMBOBOX)
{ {
tGfuiCombobox *combo = &(curObject->u.combobox);
combo->pInfo->vecChoices.push_back(text); combo->pInfo->vecChoices.push_back(text);
index = combo->pInfo->vecChoices.size(); index = combo->pInfo->vecChoices.size();
GfuiLabelSetText(combo->scr, combo->labelId, GfuiLabelSetText(combo->scr, combo->labelId,
combo->pInfo->vecChoices[combo->pInfo->nPos].c_str()); combo->pInfo->vecChoices[combo->pInfo->nPos].c_str());
} }
return index;
}
} while (curObject != screen->objects);
}
return index; return index;
} }
@ -233,53 +242,23 @@ GfuiComboboxAddText(void *scr, int id, const char *text)
void void
GfuiComboboxSetSelectedIndex(void *scr, int id, unsigned int index) GfuiComboboxSetSelectedIndex(void *scr, int id, unsigned int index)
{ {
tGfuiObject *curObject; tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
tGfuiScreen *screen = (tGfuiScreen*)scr;
curObject = screen->objects; if (combo && index < combo->pInfo->vecChoices.size())
if (curObject != NULL) {
do {
curObject = curObject->next;
if (curObject->id == id) {
if (curObject->widget == GFUI_COMBOBOX)
{ {
tGfuiCombobox *combo = &(curObject->u.combobox);
if (combo->pInfo->vecChoices.size()<= index)
return;
combo->pInfo->nPos = index; combo->pInfo->nPos = index;
GfuiLabelSetText(combo->scr, combo->labelId, GfuiLabelSetText(combo->scr, combo->labelId,
combo->pInfo->vecChoices[combo->pInfo->nPos].c_str()); combo->pInfo->vecChoices[combo->pInfo->nPos].c_str());
} }
return;
}
} while (curObject != screen->objects);
}
} }
void void
GfuiComboboxSetTextColor(void *scr, int id, const Color& color) GfuiComboboxSetTextColor(void *scr, int id, const Color& color)
{ {
tGfuiObject *curObject; tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
tGfuiScreen *screen = (tGfuiScreen*)scr;
curObject = screen->objects; if (combo)
if (curObject != NULL) {
do {
curObject = curObject->next;
if (curObject->id == id) {
if (curObject->widget == GFUI_COMBOBOX)
{
tGfuiCombobox *combo = &(curObject->u.combobox);
GfuiLabelSetColor(combo->scr, combo->labelId, color.GetPtr()); GfuiLabelSetColor(combo->scr, combo->labelId, color.GetPtr());
}
return;
}
} while (curObject != screen->objects);
}
return;
} }
@ -287,120 +266,68 @@ GfuiComboboxSetTextColor(void *scr, int id, const Color& color)
void void
GfuiComboboxSetPosition(void *scr, int id, unsigned int pos) GfuiComboboxSetPosition(void *scr, int id, unsigned int pos)
{ {
tGfuiObject *curObject; tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
tGfuiScreen *screen = (tGfuiScreen*)scr;
unsigned int index = 0;
curObject = screen->objects; if (combo)
if (curObject != NULL)
{
do {
curObject = curObject->next;
if (curObject->id == id)
{
if (curObject->widget == GFUI_COMBOBOX)
{
tGfuiCombobox *combo = &(curObject->u.combobox);
combo->pInfo->nPos = pos; combo->pInfo->nPos = pos;
}
return;
}
} while (curObject != screen->objects);
}
} }
unsigned int unsigned int
GfuiComboboxGetPosition(void *scr, int id) GfuiComboboxGetPosition(void *scr, int id)
{ {
tGfuiObject *curObject;
tGfuiScreen *screen = (tGfuiScreen*)scr;
unsigned int index = 0; unsigned int index = 0;
curObject = screen->objects; tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
if (curObject != NULL)
{
do
{
curObject = curObject->next;
if (curObject->id == id)
{
if (curObject->widget == GFUI_COMBOBOX)
{
tGfuiCombobox *combo = &(curObject->u.combobox);
return combo->pInfo->nPos;
}
return 0;
}
} while (curObject != screen->objects);
}
return 0; if (combo)
index = combo->pInfo->nPos;
return index;
} }
const char* const char*
GfuiComboboxGetText(void *scr, int id) GfuiComboboxGetText(void *scr, int id)
{ {
tGfuiObject *curObject; const char* pszText = 0;
tGfuiScreen *screen = (tGfuiScreen*)scr;
char* pszText = 0;
curObject = screen->objects; tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
if (curObject != NULL)
{ if (combo && combo->pInfo->nPos >= 0 && combo->pInfo->nPos < combo->pInfo->vecChoices.size())
do pszText = combo->pInfo->vecChoices[combo->pInfo->nPos].c_str();
{
curObject = curObject->next;
if (curObject->id == id)
{
if (curObject->widget == GFUI_COMBOBOX)
{
tGfuiCombobox *combo = &(curObject->u.combobox);
if (combo->pInfo->nPos >= 0
&& combo->pInfo->nPos < combo->pInfo->vecChoices.size())
return combo->pInfo->vecChoices[combo->pInfo->nPos].c_str();
}
return 0;
}
} while (curObject != screen->objects);
}
return pszText; return pszText;
} }
unsigned
GfuiComboboxGetNumberOfChoices(void *scr, int id)
{
unsigned nChoices = 0;
tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
if (combo)
nChoices = combo->pInfo->vecChoices.size();
return nChoices;
}
void void
GfuiComboboxClear(void *scr, int id) GfuiComboboxClear(void *scr, int id)
{ {
tGfuiObject *curObject; tGfuiCombobox* combo = gfuiGetCombobox(scr, id);
tGfuiScreen *screen = (tGfuiScreen*)scr;
curObject = screen->objects; if (combo)
if (curObject != NULL)
{ {
do
{
curObject = curObject->next;
if (curObject->id == id)
{
if (curObject->widget == GFUI_COMBOBOX)
{
tGfuiCombobox *combo = &(curObject->u.combobox);
combo->pInfo->nPos = 0; combo->pInfo->nPos = 0;
combo->pInfo->vecChoices.clear(); combo->pInfo->vecChoices.clear();
GfuiLabelSetText(combo->scr, combo->labelId, ""); GfuiLabelSetText(combo->scr, combo->labelId, "");
} }
break;
}
} while (curObject != screen->objects);
}
} }
void void
gfuiReleaseCombobox(tGfuiObject *obj) gfuiReleaseCombobox(tGfuiObject *obj)
{ {
tGfuiCombobox *combobox; delete obj->u.combobox.pInfo;
combobox = &(obj->u.combobox);
delete combobox->pInfo;
free(obj); free(obj);
} }

View file

@ -397,6 +397,7 @@ TGFCLIENT_API void GfuiComboboxSetPosition(void *scr, int id, unsigned int pos);
TGFCLIENT_API unsigned int GfuiComboboxGetPosition(void *scr, int id); TGFCLIENT_API unsigned int GfuiComboboxGetPosition(void *scr, int id);
TGFCLIENT_API const char* GfuiComboboxGetText(void *scr, int id); TGFCLIENT_API const char* GfuiComboboxGetText(void *scr, int id);
TGFCLIENT_API void GfuiComboboxClear(void *scr, int id); TGFCLIENT_API void GfuiComboboxClear(void *scr, int id);
TGFCLIENT_API unsigned GfuiComboboxGetNumberOfChoices(void *scr, int id);
TGFCLIENT_API int GfuiProgressbarCreate(void *scr, int x, int y, int w, int h, TGFCLIENT_API int GfuiProgressbarCreate(void *scr, int x, int y, int w, int h,
const char *pszProgressbackImg, const char *progressbarimg, const char *pszProgressbackImg, const char *progressbarimg,