ui_node_string.c

Go to the documentation of this file.
00001 
00021 /*
00022 Copyright (C) 2002-2010 UFO: Alien Invasion.
00023 
00024 This program is free software; you can redistribute it and/or
00025 modify it under the terms of the GNU General Public License
00026 as published by the Free Software Foundation; either version 2
00027 of the License, or (at your option) any later version.
00028 
00029 This program is distributed in the hope that it will be useful,
00030 but WITHOUT ANY WARRANTY; without even the implied warranty of
00031 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00032 
00033 See the GNU General Public License for more details.
00034 
00035 You should have received a copy of the GNU General Public License
00036 along with this program; if not, write to the Free Software
00037 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00038 
00039 */
00040 
00041 #include "../ui_nodes.h"
00042 #include "../ui_font.h"
00043 #include "../ui_parse.h"
00044 #include "../ui_tooltip.h"
00045 #include "../ui_render.h"
00046 #include "ui_node_string.h"
00047 #include "ui_node_abstractnode.h"
00048 
00049 #define EXTRADATA_TYPE stringExtraData_t
00050 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00051 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00052 
00053 static void UI_StringNodeDraw (uiNode_t *node)
00054 {
00055     vec2_t nodepos;
00056     const char *font = UI_GetFontFromNode(node);
00057     const char* ref = UI_GetReferenceString(node, node->text);
00058     static vec4_t disabledColor = {0.5, 0.5, 0.5, 1.0};
00059     vec_t *color;
00060 
00061     if (!ref)
00062         return;
00063     UI_GetNodeAbsPos(node, nodepos);
00064 
00065     if (node->disabled)
00066         color = disabledColor;
00067     else
00068         color = node->color;
00069 
00070     R_Color(color);
00071     if (node->size[0] == 0)
00072         UI_DrawString(font, node->textalign, nodepos[0], nodepos[1], nodepos[0], node->size[0], 0, ref, 0, 0, NULL, qfalse, 0);
00073     else
00074         UI_DrawStringInBox(font, node->textalign, nodepos[0] + node->padding, nodepos[1] + node->padding, node->size[0] - node->padding - node->padding, node->size[1] - node->padding - node->padding, ref, EXTRADATA(node).longlines);
00075     R_Color(NULL);
00076 }
00077 
00084 static void UI_StringNodeDrawTooltip (uiNode_t *node, int x, int y)
00085 {
00086     if (node->tooltip) {
00087         UI_Tooltip(node, x, y);
00088     } else {
00089         const char *font = UI_GetFontFromNode(node);
00090         const char* text = UI_GetReferenceString(node, node->text);
00091         qboolean isTruncated;
00092         if (!text)
00093             return;
00094 
00095         R_FontTextSize(font, text, node->size[0] - node->padding - node->padding, EXTRADATA(node).longlines, NULL, NULL, NULL, &isTruncated);
00096         if (isTruncated) {
00097             const int tooltipWidth = 250;
00098             static char tooltiptext[MAX_VAR * 4];
00099             tooltiptext[0] = '\0';
00100             Q_strcat(tooltiptext, text, sizeof(tooltiptext));
00101             UI_DrawTooltip(tooltiptext, x, y, tooltipWidth);
00102         }
00103     }
00104 }
00105 
00106 static void UI_StringNodeLoading (uiNode_t *node)
00107 {
00108     node->padding = 3;
00109     Vector4Set(node->color, 1.0, 1.0, 1.0, 1.0);
00110     EXTRADATA(node).longlines = LONGLINES_PRETTYCHOP;
00111 }
00112 
00113 static const value_t properties[] = {
00114     /* What to do with text lines longer than node width. Default is to wordwrap them to make multiple lines.
00115      * It can be LONGLINES_WRAP, LONGLINES_CHOP, LONGLINES_PRETTYCHOP
00116      */
00117     {"longlines", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, longlines), MEMBER_SIZEOF(EXTRADATA_TYPE, longlines)},
00118 
00119     {NULL, V_NULL, 0, 0}
00120 };
00121 
00122 void UI_RegisterStringNode (uiBehaviour_t *behaviour)
00123 {
00124     behaviour->name = "string";
00125     behaviour->properties = properties;
00126     behaviour->draw = UI_StringNodeDraw;
00127     behaviour->drawTooltip = UI_StringNodeDrawTooltip;
00128     behaviour->loading = UI_StringNodeLoading;
00129     behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00130 }

Generated by  doxygen 1.6.2