00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "../ui_main.h"
00031 #include "../ui_actions.h"
00032 #include "../ui_parse.h"
00033 #include "../ui_font.h"
00034 #include "../ui_render.h"
00035 #include "../ui_icon.h"
00036 #include "ui_node_button.h"
00037 #include "ui_node_custombutton.h"
00038 #include "ui_node_abstractnode.h"
00039 #include "ui_node_panel.h"
00040
00041 #define EXTRADATA_TYPE buttonExtraData_t
00042 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00043 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00044
00045 #include "../../client.h"
00046
00047 #define TILE_SIZE 64
00048 #define CORNER_SIZE 17
00049 #define MID_SIZE 1
00050 #define MARGE 3
00051
00055 static void UI_ButtonNodeClick (uiNode_t * node, int x, int y)
00056 {
00057 if (node->onClick) {
00058 UI_ExecuteEventActions(node, node->onClick);
00059 }
00060 }
00061
00065 static void UI_ButtonNodeDraw (uiNode_t *node)
00066 {
00067 static const int panelTemplate[] = {
00068 CORNER_SIZE, MID_SIZE, CORNER_SIZE,
00069 CORNER_SIZE, MID_SIZE, CORNER_SIZE,
00070 MARGE
00071 };
00072 const char *text;
00073 int texX, texY;
00074 const float *textColor;
00075 const char *image;
00076 vec2_t pos;
00077 static vec4_t disabledColor = {0.5, 0.5, 0.5, 1.0};
00078 int iconPadding = 0;
00079 uiIconStatus_t iconStatus = ICON_STATUS_NORMAL;
00080 const char *font = UI_GetFontFromNode(node);
00081
00082 if (!node->onClick || node->disabled) {
00084 textColor = disabledColor;
00085 texX = TILE_SIZE;
00086 texY = TILE_SIZE;
00087 iconStatus = ICON_STATUS_DISABLED;
00088 } else if (node->state) {
00089 textColor = node->selectedColor;
00090 texX = TILE_SIZE;
00091 texY = 0;
00092 iconStatus = ICON_STATUS_HOVER;
00093 } else {
00094 textColor = node->color;
00095 texX = 0;
00096 texY = 0;
00097 }
00098
00099 UI_GetNodeAbsPos(node, pos);
00100
00101 image = UI_GetReferenceString(node, node->image);
00102 if (image)
00103 UI_DrawPanel(pos, node->size, image, texX, texY, panelTemplate);
00104
00105
00107 if (EXTRADATA(node).icon) {
00108
00109 int size = node->size[1] - node->padding - node->padding;
00110 if (size < EXTRADATA(node).icon->size[0])
00111 size = EXTRADATA(node).icon->size[0];
00112 UI_DrawIconInBox(EXTRADATA(node).icon, iconStatus, pos[0] + node->padding, pos[1] + node->padding, size, node->size[1] - node->padding - node->padding);
00113 iconPadding = size + node->padding;
00114 }
00115
00116 text = UI_GetReferenceString(node, node->text);
00117 if (text != NULL && *text != '\0') {
00118 R_Color(textColor);
00119 text = _(text);
00120 UI_DrawStringInBox(font, node->textalign,
00121 pos[0] + node->padding + iconPadding, pos[1] + node->padding,
00122 node->size[0] - node->padding - node->padding - iconPadding, node->size[1] - node->padding - node->padding,
00123 text, LONGLINES_PRETTYCHOP);
00124 R_Color(NULL);
00125 }
00126 }
00127
00131 static void UI_ButtonNodeLoading (uiNode_t *node)
00132 {
00133 node->padding = 8;
00134 node->textalign = ALIGN_CC;
00135 Vector4Set(node->selectedColor, 1, 1, 1, 1);
00136 Vector4Set(node->color, 1, 1, 1, 1);
00137 }
00138
00142 static void UI_ButtonNodeLoaded (uiNode_t *node)
00143 {
00144
00145 if (node->size[1] == 0) {
00146 const char *font = UI_GetFontFromNode(node);
00147 node->size[1] = (UI_FontGetHeight(font) / 2) + (node->padding * 2);
00148 }
00149 #ifdef DEBUG
00150 if (node->size[0] < CORNER_SIZE + MID_SIZE + CORNER_SIZE || node->size[1] < CORNER_SIZE + MID_SIZE + CORNER_SIZE)
00151 Com_DPrintf(DEBUG_CLIENT, "Node '%s' too small. It can create graphical glitches\n", UI_GetPath(node));
00152 #endif
00153 }
00154
00155 static const value_t properties[] = {
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 {"icon", V_UI_ICONREF, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, icon), MEMBER_SIZEOF(EXTRADATA_TYPE, icon)},
00167
00168 {NULL, V_NULL, 0, 0}
00169 };
00170
00171
00172 void UI_RegisterButtonNode (uiBehaviour_t *behaviour)
00173 {
00174 behaviour->name = "button";
00175 behaviour->draw = UI_ButtonNodeDraw;
00176 behaviour->loaded = UI_ButtonNodeLoaded;
00177 behaviour->leftClick = UI_ButtonNodeClick;
00178 behaviour->loading = UI_ButtonNodeLoading;
00179 behaviour->properties = properties;
00180 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00181 }