ui_node_custombutton.c

Go to the documentation of this file.
00001 
00023 /*
00024 Copyright (C) 2002-2010 UFO: Alien Invasion.
00025 
00026 This program is free software; you can redistribute it and/or
00027 modify it under the terms of the GNU General Public License
00028 as published by the Free Software Foundation; either version 2
00029 of the License, or (at your option) any later version.
00030 
00031 This program is distributed in the hope that it will be useful,
00032 but WITHOUT ANY WARRANTY; without even the implied warranty of
00033 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00034 
00035 See the GNU General Public License for more details.
00036 
00037 You should have received a copy of the GNU General Public License
00038 along with this program; if not, write to the Free Software
00039 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00040 
00041 */
00042 
00043 #include "../ui_main.h"
00044 #include "../ui_icon.h"
00045 #include "../ui_parse.h"
00046 #include "../ui_font.h"
00047 #include "../ui_input.h"
00048 #include "../ui_render.h"
00049 #include "ui_node_custombutton.h"
00050 #include "ui_node_button.h"
00051 #include "ui_node_abstractnode.h"
00052 
00053 #define UI_CUSTOMBUTTON_TEX_HEIGHT 64
00054 #define UI_CUSTOMBUTTON_TEX_WIDTH 256
00055 
00056 #define EXTRADATA_TYPE customButtonExtraData_t
00057 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00058 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00059 
00063 static void UI_CustomButtonNodeDraw (uiNode_t *node)
00064 {
00065     const char *text;
00066     int texY;
00067     const float *textColor;
00068     const char *image;
00069     vec2_t pos;
00070     static vec4_t disabledColor = {0.5, 0.5, 0.5, 1.0};
00071     uiIconStatus_t iconStatus = ICON_STATUS_NORMAL;
00072     const char *font = UI_GetFontFromNode(node);
00073 
00074     if (!node->onClick || node->disabled) {
00076         textColor = disabledColor;
00077         texY = UI_CUSTOMBUTTON_TEX_HEIGHT * 2;
00078         iconStatus = ICON_STATUS_DISABLED;
00079     } else if (node->state) {
00080         textColor = node->selectedColor;
00081         texY = UI_CUSTOMBUTTON_TEX_HEIGHT;
00082         iconStatus = ICON_STATUS_HOVER;
00083     } else {
00084         textColor = node->color;
00085         texY = 0;
00086     }
00087 
00088     UI_GetNodeAbsPos(node, pos);
00089 
00090     image = UI_GetReferenceString(node, node->image);
00091     if (image) {
00092         const int texX = rint(EXTRADATA(node).texl[0]);
00093         texY += EXTRADATA(node).texl[1];
00094         UI_DrawNormImageByName(pos[0], pos[1], node->size[0], node->size[1],
00095             texX + node->size[0], texY + node->size[1], texX, texY, image);
00096     }
00097 
00098     if (EXTRADATA(node).super.icon) {
00099         UI_DrawIconInBox(EXTRADATA(node).super.icon, iconStatus, pos[0], pos[1], node->size[0], node->size[1]);
00100     }
00101 
00102     text = UI_GetReferenceString(node, node->text);
00103     if (text != NULL && *text != '\0') {
00104         R_Color(textColor);
00105         UI_DrawStringInBox(font, node->textalign,
00106             pos[0] + node->padding, pos[1] + node->padding,
00107             node->size[0] - node->padding - node->padding, node->size[1] - node->padding - node->padding,
00108             text, LONGLINES_PRETTYCHOP);
00109         R_Color(NULL);
00110     }
00111 }
00112 
00113 static const value_t properties[] = {
00114     /* Skin position. Define the top-left position of the skin we will used from the image. Y should not be bigger than 64. To compute the high corner we use the node size. */
00115     {"texl", V_POS, UI_EXTRADATA_OFFSETOF(customButtonExtraData_t, texl), MEMBER_SIZEOF(customButtonExtraData_t, texl)},
00116     {NULL, V_NULL, 0, 0}
00117 };
00118 
00119 void UI_RegisterCustomButtonNode (uiBehaviour_t *behaviour)
00120 {
00121     behaviour->name = "custombutton";
00122     behaviour->extends = "button";
00123     behaviour->draw = UI_CustomButtonNodeDraw;
00124     behaviour->properties = properties;
00125     behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00126 }

Generated by  doxygen 1.6.2