diff --git a/src/libs/tgfclient/guibutton.cpp b/src/libs/tgfclient/guibutton.cpp index 8a94dd82..a5e9fb79 100644 --- a/src/libs/tgfclient/guibutton.cpp +++ b/src/libs/tgfclient/guibutton.cpp @@ -41,6 +41,106 @@ gfuiButtonInit(void) } +int +GfuiGrButtonCreateEx(void *scr, const char *disabled, const char *enabled, const char *focused, const char *pushed, + int x, int y, int imageWidth,int imageHeight,int align, int mouse, + void *userDataOnPush, tfuiCallback onPush, + void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost) +{ + tGfuiGrButton *button; + tGfuiObject *object; + tGfuiScreen *screen = (tGfuiScreen*)scr; + int w, h; + + object = (tGfuiObject*)calloc(1, sizeof(tGfuiObject)); + object->widget = GFUI_GRBUTTON; + object->focusMode = GFUI_FOCUS_MOUSE_MOVE; + object->id = screen->curId++; + object->visible = 1; + + button = &(object->u.grbutton); + button->state = GFUI_BTN_RELEASED; + button->userDataOnPush = userDataOnPush; + button->onPush = onPush; + button->userDataOnFocus = userDataOnFocus; + button->onFocus = onFocus; + button->onFocusLost = onFocusLost; + button->mouseBehaviour = mouse; + + + + + button->disabled = GfImgReadTex(disabled, w, h); + button->enabled = GfImgReadTex(enabled, w, h); + button->focused = GfImgReadTex(focused, w, h); + button->pushed = GfImgReadTex(pushed, w, h); + + switch (align) { + case GFUI_ALIGN_HR_VB: + object->xmin = x - imageWidth; + object->xmax = x; + object->ymin = y; + object->ymax = y + imageHeight; + break; + case GFUI_ALIGN_HR_VC: + object->xmin = x - imageWidth; + object->xmax = x; + object->ymin = y - imageHeight / 2; + object->ymax = y + imageHeight / 2; + break; + case GFUI_ALIGN_HR_VT: + object->xmin = x - imageWidth; + object->xmax = x; + object->ymin = y - imageHeight; + object->ymax = y; + break; + case GFUI_ALIGN_HC_VB: + object->xmin = x - imageWidth / 2; + object->xmax = x + imageWidth / 2; + object->ymin = y; + object->ymax = y + imageHeight; + break; + case GFUI_ALIGN_HC_VC: + object->xmin = x - imageWidth / 2; + object->xmax = x + imageWidth / 2; + object->ymin = y - imageHeight / 2; + object->ymax = y + imageHeight / 2; + break; + case GFUI_ALIGN_HC_VT: + object->xmin = x - imageWidth / 2; + object->xmax = x + imageWidth / 2; + object->ymin = y - imageHeight; + object->ymax = y; + break; + case GFUI_ALIGN_HL_VB: + object->xmin = x; + object->xmax = x + imageWidth; + object->ymin = y; + object->ymax = y + imageHeight; + break; + case GFUI_ALIGN_HL_VC: + object->xmin = x; + object->xmax = x + imageWidth; + object->ymin = y - imageHeight / 2; + object->ymax = y + imageHeight / 2; + break; + case GFUI_ALIGN_HL_VT: + object->xmin = x; + object->xmax = x + imageWidth; + object->ymin = y - imageHeight; + object->ymax = y; + break; + default: + break; + } + + button->width = imageWidth; + button->height = imageHeight; + + gfuiAddObject(screen, object); + return object->id; +} + /** Add a graphical button to a screen. @ingroup gui @param scr Screen diff --git a/src/libs/tgfclient/guimenu.cpp b/src/libs/tgfclient/guimenu.cpp index 41473083..f6e1c88d 100644 --- a/src/libs/tgfclient/guimenu.cpp +++ b/src/libs/tgfclient/guimenu.cpp @@ -547,29 +547,47 @@ CreateImageButtonControl(void *menuHandle,void *param,const char *pControlName,v onFocusLost = remInfo; } - const char* pszDisabledImage = GfParmGetStr(param, pControlName, "disabledimage", ""); - const char* pszEnabledImage = GfParmGetStr(param, pControlName, "enabledimage", ""); - const char* pszFocusedImage = GfParmGetStr(param, pControlName, "focusedimage", ""); - const char* pszPushedImage = GfParmGetStr(param, pControlName, "pushedimage", ""); + std::string strEnabledImage,strDisabledImage,strFocusedImage,strPushedImage; + + strDisabledImage = GfParmGetStr(param, pControlName, "disabledimage", ""); + strEnabledImage = GfParmGetStr(param, pControlName, "enabledimage", ""); + strFocusedImage = GfParmGetStr(param, pControlName, "focusedimage", ""); + strPushedImage = GfParmGetStr(param, pControlName, "pushedimage", ""); const int x = (int)GfParmGetNum(param,pControlName,"x",NULL,0.0); const int y = (int)GfParmGetNum(param,pControlName,"y",NULL,0.0); - //const int w = (int)GfParmGetNum(param,pControlName,"width",NULL,0.0); - //const int h = (int)GfParmGetNum(param,pControlName,"height",NULL,0.0); + const int w = (int)GfParmGetNum(param,pControlName,"width",NULL,0.0); + const int h = (int)GfParmGetNum(param,pControlName,"height",NULL,0.0); const char* pszAlignH = GfParmGetStr(param, pControlName, "alignH", ""); const char* pszAlignV = GfParmGetStr(param, pControlName, "alignV", ""); const int alignment = GetAlignment(pszAlignH,pszAlignV); + int id = -1; - return GfuiGrButtonCreate(menuHandle, - pszDisabledImage,pszEnabledImage, - pszFocusedImage,pszPushedImage, - x,y,alignment,GFUI_MOUSE_UP, - userdata, - onpush, - userDataOnFocus, - onFocus, - onFocusLost); + if ((w ==0)&&(h==0)) + { + id = GfuiGrButtonCreate(menuHandle, + strDisabledImage.c_str(),strEnabledImage.c_str(),strFocusedImage.c_str(),strPushedImage.c_str(), + x,y,alignment,GFUI_MOUSE_UP + ,userdata, + onpush, + userDataOnFocus, + onFocus, + onFocusLost); + } + else + { + id = GfuiGrButtonCreateEx(menuHandle, + strDisabledImage.c_str(),strEnabledImage.c_str(),strFocusedImage.c_str(),strPushedImage.c_str(), + x,y,w,h,alignment,GFUI_MOUSE_UP + ,userdata, + onpush, + userDataOnFocus, + onFocus, + onFocusLost); + } + + return id; } int diff --git a/src/libs/tgfclient/tgfclient.h b/src/libs/tgfclient/tgfclient.h index da2611de..107d21e1 100644 --- a/src/libs/tgfclient/tgfclient.h +++ b/src/libs/tgfclient/tgfclient.h @@ -207,6 +207,10 @@ extern int GfuiGrButtonCreate(void *scr, const char *disabled, const char *enabl int x, int y, int align, int mouse, void *userDataOnPush, tfuiCallback onPush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost); +extern int GfuiGrButtonCreateEx(void *scr, const char *disabled, const char *enabled, const char *focused, const char *pushed, + int x, int y, int imageWidth,int imageHeight,int align, int mouse, + void *userDataOnPush, tfuiCallback onPush, + void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost); extern void GfuiButtonSetText(void *scr, int id, const char *text); extern int GfuiButtonGetFocused(void);