ui_node_ekg.c
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "../ui_nodes.h"
00027 #include "../ui_parse.h"
00028 #include "../ui_render.h"
00029 #include "ui_node_ekg.h"
00030 #include "ui_node_abstractnode.h"
00031
00032 #include "../../client.h"
00033
00034 #define EXTRADATA_TYPE ekgExtraData_t
00035 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00036
00037 static void UI_EKGNodeDraw (uiNode_t *node)
00038 {
00039 vec2_t size;
00040 vec2_t nodepos;
00041 const image_t *image;
00042
00043 const char* imageName = UI_GetReferenceString(node, node->image);
00044 if (!imageName || imageName[0] == '\0')
00045 return;
00046
00047 UI_GetNodeAbsPos(node, nodepos);
00048
00049 image = UI_LoadImage(imageName);
00050 if (image) {
00051 const int ekgHeight = node->size[1];
00052 const int ekgWidth = image->width;
00053
00054 const int ekgImageParts = image->height / node->size[1];
00055 const int ekgMaxIndex = ekgImageParts - 1;
00056
00058 const int ekgDivide = 20;
00059
00060 const int ekgMaxValue = ekgDivide * ekgMaxIndex;
00061 int ekgValue;
00062 float current;
00063
00065
00066 if (node->name[0] == 'm')
00067 current = Cvar_GetValue("mn_morale") / EXTRADATA(node).scaleCvarValue;
00068 else
00069 current = Cvar_GetValue("mn_hp") / EXTRADATA(node).scaleCvarValue;
00070
00071 ekgValue = min(current, ekgMaxValue);
00072
00073 EXTRADATA(node).super.texl[1] = (ekgMaxIndex - (int)(ekgValue / ekgDivide)) * ekgHeight;
00074 EXTRADATA(node).super.texh[1] = EXTRADATA(node).super.texl[1] + ekgHeight;
00075 EXTRADATA(node).super.texl[0] = -(int) (EXTRADATA(node).scrollSpeed * CL_Milliseconds()) % ekgWidth;
00076 EXTRADATA(node).super.texh[0] = EXTRADATA(node).super.texl[0] + node->size[0];
00078 if (node->size[0] && !node->size[1]) {
00079 const float scale = image->width / node->size[0];
00080 Vector2Set(size, node->size[0], image->height / scale);
00081 } else if (node->size[1] && !node->size[0]) {
00082 const float scale = image->height / node->size[1];
00083 Vector2Set(size, image->width / scale, node->size[1]);
00084 } else {
00085 if (EXTRADATA(node).super.preventRatio) {
00086
00087 const float ratio = (float) image->width / (float) image->height;
00088 if (node->size[1] * ratio > node->size[0]) {
00089 Vector2Set(size, node->size[0], node->size[0] / ratio);
00090 } else {
00091 Vector2Set(size, node->size[1] * ratio, node->size[1]);
00092 }
00093 } else {
00094 Vector2Copy(node->size, size);
00095 }
00096 }
00097 UI_DrawNormImage(nodepos[0], nodepos[1], size[0], size[1],
00098 EXTRADATA(node).super.texh[0], EXTRADATA(node).super.texh[1], EXTRADATA(node).super.texl[0], EXTRADATA(node).super.texl[1], image);
00099 }
00100 }
00101
00105 static void UI_EKGNodeLoading (uiNode_t *node)
00106 {
00107 EXTRADATA(node).scaleCvarValue = 1.0f;
00108 EXTRADATA(node).scrollSpeed= 0.07f;
00109 }
00110
00111 static const value_t properties[] = {
00112
00113 {"scrollspeed", V_FLOAT, UI_EXTRADATA_OFFSETOF(ekgExtraData_t, scrollSpeed), MEMBER_SIZEOF(ekgExtraData_t, scrollSpeed)},
00114
00115 {"scale", V_FLOAT, UI_EXTRADATA_OFFSETOF(ekgExtraData_t, scaleCvarValue), MEMBER_SIZEOF(ekgExtraData_t, scaleCvarValue)},
00116
00117 {NULL, V_NULL, 0, 0}
00118 };
00119
00120 void UI_RegisterEKGNode (uiBehaviour_t* behaviour)
00121 {
00122 behaviour->name = "ekg";
00123 behaviour->loading = UI_EKGNodeLoading;
00124 behaviour->extends = "image";
00125 behaviour->draw = UI_EKGNodeDraw;
00126 behaviour->properties = properties;
00127 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00128 }