1 //----------------------------------------------------------------------------
2 // EDGE Heads-up-display Style code
3 //----------------------------------------------------------------------------
4 //
5 // Copyright (c) 2004-2009 The EDGE Team.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 //----------------------------------------------------------------------------
18
19 #include "i_defs.h"
20 #include "hu_style.h"
21 #include "hu_draw.h"
22
23 #include "dm_defs.h"
24 #include "dm_state.h"
25 #include "r_local.h"
26 #include "r_colormap.h"
27 #include "r_draw.h"
28 #include "r_modes.h"
29 #include "r_image.h"
30
31
32 // Edge has lots of style
33 style_container_c hu_styles;
34
35
style_c(styledef_c * _def)36 style_c::style_c(styledef_c *_def) : def(_def), bg_image(NULL)
37 {
38 for (int T = 0; T < styledef_c::NUM_TXST; T++)
39 fonts[T] = NULL;
40 }
41
~style_c()42 style_c::~style_c()
43 {
44 /* nothing to do */
45 }
46
47
Load()48 void style_c::Load()
49 {
50 if (def->bg.image_name.c_str())
51 {
52 const char *name = def->bg.image_name.c_str();
53
54 bg_image = W_ImageLookup(name, INS_Flat, ILF_Null);
55
56 if (! bg_image)
57 bg_image = W_ImageLookup(name, INS_Graphic);
58 }
59
60 for (int T = 0; T < styledef_c::NUM_TXST; T++)
61 {
62 if (def->text[T].font)
63 fonts[T] = hu_fonts.Lookup(def->text[T].font);
64 }
65 }
66
67
DrawBackground()68 void style_c::DrawBackground()
69 {
70 float alpha = PERCENT_2_FLOAT(def->bg.translucency);
71
72 if (alpha < 0.02)
73 return;
74
75 HUD_SetAlpha(alpha);
76
77 if (! bg_image)
78 {
79 if (def->bg.colour != RGB_NO_VALUE)
80 HUD_SolidBox(0, 0, 320, 200, def->bg.colour);
81
82 HUD_SetAlpha();
83 return;
84 }
85
86 if (def->special & (SYLSP_Tiled | SYLSP_TiledNoScale))
87 {
88 HUD_SetScale(def->bg.scale);
89
90 HUD_TileImage(0, 0, 320, 200, bg_image);
91
92 HUD_SetScale();
93 }
94 else
95 {
96 HUD_StretchImage(0, 0, 320, 200, bg_image);
97 }
98
99 HUD_SetAlpha();
100 }
101
102 // ---> style_container_c class
103
104 //
105 // style_container_c::CleanupObject()
106 //
CleanupObject(void * obj)107 void style_container_c::CleanupObject(void *obj)
108 {
109 style_c *a = *(style_c**)obj;
110
111 if (a) delete a;
112 }
113
114 //
115 // style_container_c::Lookup()
116 //
117 // Never returns NULL.
118 //
Lookup(styledef_c * def)119 style_c* style_container_c::Lookup(styledef_c *def)
120 {
121 SYS_ASSERT(def);
122
123 for (epi::array_iterator_c it = GetIterator(0); it.IsValid(); it++)
124 {
125 style_c *st = ITERATOR_TO_TYPE(it, style_c*);
126
127 if (def == st->def)
128 return st;
129 }
130
131 style_c *new_st = new style_c(def);
132
133 new_st->Load();
134 Insert(new_st);
135
136 return new_st;
137 }
138
139
140 //
141 // HL_WriteText
142 //
143 // Compatibility crud...
144 //
HL_WriteText(style_c * style,int text_type,int x,int y,const char * str,float scale)145 void HL_WriteText(style_c *style, int text_type, int x, int y, const char *str, float scale)
146 {
147 HUD_SetFont(style->fonts[text_type]);
148 HUD_SetScale(scale * style->def->text[text_type].scale);
149
150 const colourmap_c *colmap = style->def->text[text_type].colmap;
151
152 if (colmap)
153 HUD_SetTextColor(V_GetFontColor(colmap));
154
155 HUD_DrawText(x, y, str);
156
157 HUD_SetFont();
158 HUD_SetScale();
159 HUD_SetTextColor();
160 }
161
162
163 //--- editor settings ---
164 // vi:ts=4:sw=4:noexpandtab
165