| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/lib/uires.h $ |
| 21 | * $Revision: 19 $ |
| 22 | * $Date: 10/21/99 1:53p $ |
| 23 | * $Author: Kevin $ |
| 24 | * |
| 25 | * Resources |
| 26 | * |
| 27 | * $Log: /DescentIII/main/lib/uires.h $ |
| 28 | * |
| 29 | * 19 10/21/99 1:53p Kevin |
| 30 | * Mac Merge |
| 31 | * |
| 32 | * 18 7/06/99 5:52p Kevin |
| 33 | * PXO & multiplayer fixes for the patch |
| 34 | * |
| 35 | * 17 5/20/99 10:50p Samir |
| 36 | * changed way memory was allocated for strings in text items, empty |
| 37 | * strings all point to same empty buffer for efficiency. |
| 38 | * |
| 39 | * 16 5/10/99 10:53p Ardussi |
| 40 | * changes to compile on Mac |
| 41 | * |
| 42 | * 15 9/30/98 4:32p Samir |
| 43 | * added snazzy text. |
| 44 | * |
| 45 | * 14 9/23/98 11:46a Samir |
| 46 | * added static text saturation. |
| 47 | * |
| 48 | * 13 8/20/98 6:45p Samir |
| 49 | * use const char for UITextItem create. |
| 50 | * |
| 51 | * 12 5/25/98 8:18p Samir |
| 52 | * added function to get text pointer to text item. |
| 53 | * |
| 54 | * 11 5/01/98 6:24p Samir |
| 55 | * added draw class field to draw for each resource. |
| 56 | * |
| 57 | * 10 3/13/98 11:51a Samir |
| 58 | * default text color is black. |
| 59 | * |
| 60 | * 9 3/10/98 7:26p Samir |
| 61 | * Fixed UIBitmapItem::get_chunked_bitmap. |
| 62 | * |
| 63 | * 8 3/05/98 6:40p Samir |
| 64 | * Virtualized a lot of functions. |
| 65 | * |
| 66 | * 7 2/13/98 6:34p Samir |
| 67 | * Added UIStatic class. |
| 68 | * |
| 69 | * 6 2/10/98 4:55p Samir |
| 70 | * Added radio buttons. |
| 71 | * |
| 72 | * 5 1/30/98 7:04p Samir |
| 73 | * Moved from ui.h and uilib.h. |
| 74 | * |
| 75 | * 4 1/18/98 4:22p Samir |
| 76 | * Implemented new UIItem system. |
| 77 | * |
| 78 | * 3 1/02/98 12:50p Samir |
| 79 | * Added font caps to UITextItem. |
| 80 | * |
| 81 | * 2 12/30/97 5:13p Samir |
| 82 | * INitial revision |
| 83 | * |
| 84 | * $NoKeywords: $ |
| 85 | */ |
| 86 | |
| 87 | #ifndef UIRES_H |
| 88 | #define UIRES_H |
| 89 | |
| 90 | #include "bitmap.h" |
| 91 | #include "grdefs.h" |
| 92 | |
| 93 | enum tUIResClass { uiItem, uiTextItem, uiBitmapItem }; |
| 94 | |
| 95 | enum tUIDrawClass { uiDrawNormal, uiDrawAlphaSaturate, uiDrawFaded }; |
| 96 | |
| 97 | // UIItem |
| 98 | // the root class for all resource items |
| 99 | |
| 100 | class UIItem { |
| 101 | public: |
| 102 | UIItem(){}; |
| 103 | virtual ~UIItem(){}; |
| 104 | |
| 105 | // if returns false, then it didn't draw. |
| 106 | virtual bool draw(int x, int y, tUIDrawClass draw_class = uiDrawNormal) { return false; }; |
| 107 | virtual bool draw(int x, int y, int w, int h) { return false; }; |
| 108 | virtual int width() { return 0; }; |
| 109 | virtual int height() { return 0; }; |
| 110 | virtual tUIResClass class_type() { return uiItem; }; |
| 111 | virtual void set_alpha(uint8_t alpha){}; |
| 112 | virtual uint8_t get_alpha() const { return 0; }; |
| 113 | virtual void set_color(ddgr_color col){}; |
| 114 | virtual ddgr_color get_color() const { return GR_BLACK; }; |
| 115 | virtual UIItem *CopyUIItem() { return NULL; }; |
| 116 | }; |
| 117 | |
| 118 | // UITextItem |
| 119 | // used by user interface system, contains information about how to render |
| 120 | // text. allows for alpha, color and different fonts. |
| 121 | |
| 122 | class UITextItem : public UIItem { |
| 123 | friend void SetUITextItemText(UITextItem *uit, char *newtext, uint32_t color); |
| 124 | |
| 125 | uint8_t m_Alpha; // alpha value of text. |
| 126 | ddgr_color m_Color; // color of text. |
| 127 | int m_Font; |
| 128 | |
| 129 | static int m_DefaultFont; |
| 130 | static int m_Sat; |
| 131 | |
| 132 | protected: |
| 133 | char *m_Text; |
| 134 | |
| 135 | public: |
| 136 | static void SetDefaultFont(int font) { UITextItem::m_DefaultFont = font; } |
| 137 | static void SetSaturationFactor(int sat) { UITextItem::m_Sat = sat; } |
| 138 | static char dummy_str[4]; |
| 139 | |
| 140 | public: |
| 141 | UITextItem() { |
| 142 | m_Text = NULL; |
| 143 | m_Alpha = 255; |
| 144 | m_Color = GR_WHITE; |
| 145 | m_Font = m_DefaultFont; |
| 146 | }; |
| 147 | UITextItem(const char *text, ddgr_color color = GR_WHITE, uint8_t alpha = 255); |
| 148 | UITextItem(int font, const char *text, ddgr_color color = GR_WHITE, uint8_t alpha = 255); |
| 149 | virtual ~UITextItem(); |
| 150 | |
| 151 | // if returns false, then it didn't draw. |
| 152 | virtual bool draw(int x, int y, tUIDrawClass draw_class = uiDrawNormal); |
| 153 | virtual bool draw(int x, int y, int w, int h) { return draw(x, y); }; |
| 154 | virtual int width(); |
| 155 | virtual int height(); |
| 156 | virtual tUIResClass class_type() const { return uiTextItem; }; |
| 157 | virtual UIItem *CopyUIItem(); |
| 158 | |
| 159 | // set visual characteristics of text item |
| 160 | virtual void set_alpha(uint8_t alpha) { m_Alpha = alpha; }; |
| 161 | virtual void set_color(ddgr_color col) { m_Color = col; }; |
| 162 | |
| 163 | void set_font(int font) { m_Font = font; }; |
| 164 | |
| 165 | // get visual characteristics of text item |
| 166 | virtual uint8_t get_alpha() const { return m_Alpha; }; |
| 167 | virtual ddgr_color get_color() const { return m_Color; }; |
| 168 | int get_font() const { return m_Font; }; |
| 169 | |
| 170 | // operators |
| 171 | operator const char *() const { // access m_Text |
| 172 | return m_Text; |
| 173 | }; |
| 174 | |
| 175 | const char *GetBuffer() const { return m_Text; }; |
| 176 | |
| 177 | const UITextItem &operator=(const UITextItem &item); |
| 178 | }; |
| 179 | |
| 180 | #define UISNAZZYTEXTF_BLINKING 0x1 |
| 181 | #define UISNAZZYTEXTF_RESERVED 0xffff0000 |
| 182 | |
| 183 | class UISnazzyTextItem : public UITextItem { |
| 184 | unsigned m_flags; |
| 185 | |
| 186 | union { |
| 187 | int i; |
| 188 | float f; |
| 189 | } m_internaldata; |
| 190 | |
| 191 | union { |
| 192 | int i; |
| 193 | float f; |
| 194 | } m_data; |
| 195 | |
| 196 | public: |
| 197 | UISnazzyTextItem() { m_flags = m_data.i = m_internaldata.i = 0; }; |
| 198 | UISnazzyTextItem(unsigned flags, const char *text, ddgr_color color = GR_WHITE, uint8_t alpha = 255); |
| 199 | UISnazzyTextItem(unsigned flags, int font, const char *text, ddgr_color color = GR_WHITE, uint8_t alpha = 255); |
| 200 | |
| 201 | void set_data(int data) { m_data.i = data; }; |
| 202 | void set_data(float data) { m_data.f = data; }; |
| 203 | |
| 204 | void set_flags(unsigned flags); |
| 205 | |
| 206 | virtual bool draw(int x, int y, tUIDrawClass draw_class = uiDrawNormal); |
| 207 | virtual UIItem *CopyUIItem(); |
| 208 | |
| 209 | const UISnazzyTextItem &operator=(const UISnazzyTextItem &item); |
| 210 | }; |
| 211 | |
| 212 | // UIBitmapItem |
| 213 | // used by user interface system, contains information about how to render |
| 214 | // text. allows for alpha, color and different fonts. |
| 215 | |
| 216 | class UIBitmapItem : public UIItem { |
| 217 | bool m_IsValid; |
| 218 | bool m_IsChunked; // is this a chunked bitmap? |
| 219 | |
| 220 | union { |
| 221 | chunked_bitmap *chunk; // a chunked bitmap. |
| 222 | int handle; // a simple bitmap |
| 223 | } m_Bitmap; // a bitmap. |
| 224 | |
| 225 | uint8_t m_Alpha; // alpha value of text. |
| 226 | |
| 227 | public: |
| 228 | UIBitmapItem() { |
| 229 | m_IsValid = false; |
| 230 | m_Alpha = 255; |
| 231 | }; |
| 232 | UIBitmapItem(chunked_bitmap *chunk, uint8_t alpha = 255) { |
| 233 | m_IsValid = true; |
| 234 | m_Bitmap.chunk = chunk; |
| 235 | m_Alpha = alpha; |
| 236 | m_IsChunked = true; |
| 237 | }; |
| 238 | UIBitmapItem(int bm_handle, uint8_t alpha = 255) { |
| 239 | m_IsValid = true; |
| 240 | m_Alpha = alpha; |
| 241 | m_IsChunked = false; |
| 242 | m_Bitmap.handle = bm_handle; |
| 243 | }; |
| 244 | virtual ~UIBitmapItem(){}; |
| 245 | |
| 246 | // if returns false, then it didn't draw. |
| 247 | virtual bool draw(int x, int y, tUIDrawClass draw_class = uiDrawNormal); |
| 248 | virtual bool draw(int x, int y, int w, int h) { return draw(x, y); }; |
| 249 | virtual int width(); |
| 250 | virtual int height(); |
| 251 | virtual tUIResClass class_type() const { return uiBitmapItem; }; |
| 252 | virtual UIItem *CopyUIItem(); |
| 253 | |
| 254 | // flag checking |
| 255 | bool is_chunked() const { return m_IsChunked; }; |
| 256 | bool is_valid() const { return m_IsValid; }; |
| 257 | |
| 258 | // set visual characteristics of bitmap |
| 259 | void set_chunked_bitmap(chunked_bitmap *chunk) { |
| 260 | m_IsValid = true; |
| 261 | m_IsChunked = true; |
| 262 | m_Bitmap.chunk = chunk; |
| 263 | }; |
| 264 | void set_bitmap(int bm_handle) { |
| 265 | m_IsValid = true; |
| 266 | m_IsChunked = false; |
| 267 | m_Bitmap.handle = bm_handle; |
| 268 | }; |
| 269 | virtual void set_alpha(uint8_t alpha) { // sets the alpha |
| 270 | m_Alpha = alpha; |
| 271 | }; |
| 272 | |
| 273 | // get visual characteristics |
| 274 | chunked_bitmap *get_chunked_bitmap() const { return (chunked_bitmap *)m_Bitmap.chunk; }; |
| 275 | int get_bitmap() const { return m_Bitmap.handle; }; |
| 276 | virtual uint8_t get_alpha() const { // gets alpha. |
| 277 | return m_Alpha; |
| 278 | }; |
| 279 | |
| 280 | // const UIBitmapItem& UIBitmapItem::operator =(const UIBitmapItem& item); // JCA made Mac compatible |
| 281 | const UIBitmapItem &operator=(const UIBitmapItem &item); |
| 282 | }; |
| 283 | |
| 284 | // UIPrimativeItem |
| 285 | // used to render simple 2d backgrounds. |
| 286 | |
| 287 | class UIPrimativeItem : public UIItem { |
| 288 | ddgr_color color; |
| 289 | uint8_t alpha; |
| 290 | |
| 291 | public: |
| 292 | UIPrimativeItem(ddgr_color col, uint8_t alph = 255) { |
| 293 | color = col; |
| 294 | alpha = alph; |
| 295 | }; |
| 296 | |
| 297 | virtual UIItem *CopyUIItem(); |
| 298 | |
| 299 | virtual void set_color(ddgr_color col) { color = col; }; |
| 300 | virtual ddgr_color get_color() const { return color; }; |
| 301 | virtual void set_alpha(uint8_t alph) { alpha = alph; }; |
| 302 | virtual uint8_t get_alpha() const { return alpha; }; |
| 303 | |
| 304 | // const UIPrimativeItem& UIPrimativeItem::operator =(const UIPrimativeItem& item) // JCA made Mac compatible |
| 305 | const UIPrimativeItem &operator=(const UIPrimativeItem &item) { |
| 306 | color = item.color; |
| 307 | alpha = item.alpha; |
| 308 | return *this; |
| 309 | }; |
| 310 | |
| 311 | // if returns false, then it didn't draw. |
| 312 | virtual bool draw(int x, int y, tUIDrawClass draw_class = uiDrawNormal) { return false; }; |
| 313 | virtual bool draw(int x, int y, int w, int h); |
| 314 | }; |
| 315 | |
| 316 | #endif |