| 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/ui/UIHotspot.cpp $ |
| 21 | * $Revision: 16 $ |
| 22 | * $Date: 4/26/99 9:11p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Hotspot code. |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/ui/UIHotspot.cpp $ |
| 28 | * |
| 29 | * 16 4/26/99 9:11p Matt |
| 30 | * Took out saturation used by old newui. |
| 31 | * |
| 32 | * 15 4/24/99 8:23p Samir |
| 33 | * set hotspot hotkey after gadget is created. |
| 34 | * |
| 35 | * 14 4/14/99 1:53a Jeff |
| 36 | * fixed case mismatched #includes |
| 37 | * |
| 38 | * 13 10/13/98 3:47p Samir |
| 39 | * hotspots now handle spacebats |
| 40 | * |
| 41 | * 12 10/01/98 12:57p Samir |
| 42 | * fixed hotspots so their width and height touch text, no outer border. |
| 43 | * |
| 44 | * 11 9/30/98 4:33p Samir |
| 45 | * disabled gadgets display dim text. |
| 46 | * |
| 47 | * 10 6/05/98 5:58p Jeff |
| 48 | * Added a way to change the items for the states of a HotSpot |
| 49 | * |
| 50 | * 9 5/01/98 6:23p Samir |
| 51 | * saturate hotspots when active. |
| 52 | * |
| 53 | * 8 3/09/98 3:43p Samir |
| 54 | * Hotspot selected when mouse button goes up. |
| 55 | * |
| 56 | * 7 1/30/98 7:05p Samir |
| 57 | * Each gadget now has their own coordinate system. |
| 58 | * |
| 59 | * 6 1/23/98 5:34p Samir |
| 60 | * Allow for nonpersistant UIItems. |
| 61 | * |
| 62 | * 5 1/18/98 4:22p Samir |
| 63 | * Implemented new UIItem system. |
| 64 | * |
| 65 | * 4 1/05/98 4:36p Samir |
| 66 | * Moved centering and fittext control flags to UIGadget class. |
| 67 | * |
| 68 | * 3 1/02/98 2:13p Samir |
| 69 | * Set alpha to full for item with focus. |
| 70 | * |
| 71 | * 2 1/02/98 12:47p Samir |
| 72 | * Added selection and bettering centering? |
| 73 | * |
| 74 | * 1 12/30/97 4:36p Samir |
| 75 | * Initial revision |
| 76 | * |
| 77 | * $NoKeywords: $ |
| 78 | */ |
| 79 | |
| 80 | #include "UIlib.h"cxx . . $ `<file>/ui/UIlib.h`/ |
| 81 | |
| 82 | // ---------------------------------------------------------------------------- |
| 83 | // UIHotspot |
| 84 | // This is simply a region within the parent window that when clicked on |
| 85 | // or key pressed, does something. |
| 86 | |
| 87 | UIHotspotcxx . . $ UIHotspot#::UIHotspotcxx . . $ UIHotspot#UIHotspot(49f6e7a06ebc5aa8).() { |
| 88 | m_ItemOffcxx . . $ UIHotspot#m_ItemOff. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 89 | m_ItemOncxx . . $ UIHotspot#m_ItemOn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 90 | } |
| 91 | |
| 92 | UIHotspotcxx . . $ UIHotspot#::~cxx . . $ UIHotspot#`~UIHotspot`(ced63f7c635d850d).UIHotspotcxx . . $ UIHotspot#() {} |
| 93 | |
| 94 | // optional key, when pressed, triggers hotspot. |
| 95 | void UIHotspotcxx . . $ UIHotspot#::Createcxx . . $ UIHotspot#Create(ee4237d76742fc72).(UIWindowcxx . . $ UIWindow# *wnd, int id, int key, UIItemcxx . . $ UIItem# *itemoff, UIItemcxx . . $ UIItem# *itemon, int x, int y, int w, int h, |
| 96 | int flags) { |
| 97 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(itemoff); |
| 98 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(itemon); |
| 99 | |
| 100 | if (itemoff) |
| 101 | m_ItemOffcxx . . $ UIHotspot#m_ItemOff. = itemoff->CopyUIItemcxx . . $ UIItem#CopyUIItem(ff7db2a2e5605676).(); |
| 102 | if (itemon) |
| 103 | m_ItemOncxx . . $ UIHotspot#m_ItemOn. = itemon->CopyUIItemcxx . . $ UIItem#CopyUIItem(ff7db2a2e5605676).(); |
| 104 | |
| 105 | m_ItemCurcxx . . $ UIHotspot#m_ItemCur. = m_ItemOffcxx . . $ UIHotspot#m_ItemOff.; |
| 106 | |
| 107 | UIGadgetcxx . . $ UIGadget#::Createcxx . . $ UIGadget#Create(43707b8add2f137d).(wnd, id, x, y, w, h, flags); |
| 108 | |
| 109 | if (key) { |
| 110 | UIGadgetcxx . . $ UIGadget#::SetHotkeycxx . . $ UIGadget#SetHotkey(d4f767463ce0a6b3).(key); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void UIHotspotcxx . . $ UIHotspot#::SetStatescxx . . $ UIHotspot#SetStates(ca92f25ca46ed94).(UIItemcxx . . $ UIItem# *itemoff, UIItemcxx . . $ UIItem# *itemon) { |
| 115 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(itemoff); |
| 116 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(itemon); |
| 117 | |
| 118 | // determine which state it currently set, so we can set it on the new state |
| 119 | bool currstate = false; |
| 120 | |
| 121 | if (m_ItemOncxx . . $ UIHotspot#m_ItemOn. == m_ItemCurcxx . . $ UIHotspot#m_ItemCur.) |
| 122 | currstate = true; |
| 123 | |
| 124 | if (m_ItemOffcxx . . $ UIHotspot#m_ItemOff.) |
| 125 | delete m_ItemOffcxx . . $ UIHotspot#m_ItemOff.; |
| 126 | if (m_ItemOncxx . . $ UIHotspot#m_ItemOn.) |
| 127 | delete m_ItemOncxx . . $ UIHotspot#m_ItemOn.; |
| 128 | |
| 129 | m_ItemOffcxx . . $ UIHotspot#m_ItemOff. = itemoff->CopyUIItemcxx . . $ UIItem#CopyUIItem(ff7db2a2e5605676).(); |
| 130 | m_ItemOncxx . . $ UIHotspot#m_ItemOn. = itemon->CopyUIItemcxx . . $ UIItem#CopyUIItem(ff7db2a2e5605676).(); |
| 131 | |
| 132 | if (currstate) |
| 133 | m_ItemCurcxx . . $ UIHotspot#m_ItemCur. = m_ItemOncxx . . $ UIHotspot#m_ItemOn.; |
| 134 | else |
| 135 | m_ItemCurcxx . . $ UIHotspot#m_ItemCur. = m_ItemOffcxx . . $ UIHotspot#m_ItemOff.; |
| 136 | } |
| 137 | |
| 138 | // override: behavior when gadget is destroyed. |
| 139 | void UIHotspotcxx . . $ UIHotspot#::OnDestroycxx . . $ UIHotspot#OnDestroy(49f6e7a06ebc5aa8).() { |
| 140 | UIGadgetcxx . . $ UIGadget#::OnDestroycxx . . $ UIGadget#OnDestroy(49f6e7a06ebc5aa8).(); |
| 141 | |
| 142 | if (m_ItemOffcxx . . $ UIHotspot#m_ItemOff.) |
| 143 | delete m_ItemOffcxx . . $ UIHotspot#m_ItemOff.; |
| 144 | if (m_ItemOncxx . . $ UIHotspot#m_ItemOn.) |
| 145 | delete m_ItemOncxx . . $ UIHotspot#m_ItemOn.; |
| 146 | |
| 147 | m_ItemOffcxx . . $ UIHotspot#m_ItemOff. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 148 | m_ItemOncxx . . $ UIHotspot#m_ItemOn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 149 | } |
| 150 | |
| 151 | // behavior when key is pressed. |
| 152 | void UIHotspotcxx . . $ UIHotspot#::OnKeyDowncxx . . $ UIHotspot#OnKeyDown(d4f767463ce0a6b3).(int key) { |
| 153 | if (key == KEY_SPACEBARcxx . . $ `ddio/ddio_common.h:271:9`!) { |
| 154 | OnSelectcxx . . $ UIGadget#OnSelect(49f6e7a06ebc5aa8).(); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // behavior when mouse button is pressed. |
| 159 | void UIHotspotcxx . . $ UIHotspot#::OnMouseBtnDowncxx . . $ UIHotspot#OnMouseBtnDown(d4f767463ce0a6b3).(int btn) { |
| 160 | if (btn == UILMSEBTNcxx . . $ `ui/uisys.h:36:9`!) { |
| 161 | LOCK_FOCUScxx . . $ `ui/uisys.h:107:9`!(this); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // override: behavior when mouse button is released. |
| 166 | void UIHotspotcxx . . $ UIHotspot#::OnMouseBtnUpcxx . . $ UIHotspot#OnMouseBtnUp(d4f767463ce0a6b3).(int btn) { |
| 167 | if (btn == UILMSEBTNcxx . . $ `ui/uisys.h:36:9`!) { |
| 168 | if (HasFocuscxx . . $ UIGadget#HasFocus(50ce9a9e25b4a850).()) { |
| 169 | if (PT_IN_GADGETcxx . . $ PT_IN_GADGET(55d2799d541f12b5).(UIGadgetcxx . . $ UIGadget#::m_Wndcxx . . $ UIGadget#m_Wnd., this, UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx., UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my.)) { |
| 170 | OnSelectcxx . . $ UIGadget#OnSelect(49f6e7a06ebc5aa8).(); |
| 171 | } |
| 172 | } |
| 173 | UNLOCK_FOCUScxx . . $ `ui/uisys.h:109:9`!(this); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // override: behavior when gadget loses input focus. |
| 178 | void UIHotspotcxx . . $ UIHotspot#::OnLostFocuscxx . . $ UIHotspot#OnLostFocus(49f6e7a06ebc5aa8).() { m_ItemCurcxx . . $ UIHotspot#m_ItemCur. = m_ItemOffcxx . . $ UIHotspot#m_ItemOff.; } |
| 179 | |
| 180 | // override: behavior when gadget gains input focus. |
| 181 | void UIHotspotcxx . . $ UIHotspot#::OnGainFocuscxx . . $ UIHotspot#OnGainFocus(49f6e7a06ebc5aa8).() { m_ItemCurcxx . . $ UIHotspot#m_ItemCur. = m_ItemOncxx . . $ UIHotspot#m_ItemOn.; } |
| 182 | |
| 183 | // override: called when resized or before drawing. |
| 184 | void UIHotspotcxx . . $ UIHotspot#::OnFormatcxx . . $ UIHotspot#OnFormat(49f6e7a06ebc5aa8).() { |
| 185 | if (m_Flagscxx . . $ UIGadget#m_Flags. & UIF_FITcxx . . $ `ui/ui.h:343:9`!) { |
| 186 | m_Wcxx . . $ UIObject#m_W. = m_ItemCurcxx . . $ UIHotspot#m_ItemCur.->widthcxx . . $ UIItem#width(b126dc7c1de90089).(); |
| 187 | m_Hcxx . . $ UIObject#m_H. = m_ItemCurcxx . . $ UIHotspot#m_ItemCur.->heightcxx . . $ UIItem#height(b126dc7c1de90089).(); |
| 188 | } |
| 189 | |
| 190 | UIGadgetcxx . . $ UIGadget#::OnFormatcxx . . $ UIGadget#OnFormat(49f6e7a06ebc5aa8).(); |
| 191 | } |
| 192 | |
| 193 | // behavior when gadget is being drawn. |
| 194 | void UIHotspotcxx . . $ UIHotspot#::OnDrawcxx . . $ UIHotspot#OnDraw(49f6e7a06ebc5aa8).() { |
| 195 | // draw simple background. |
| 196 | if (m_ItemCurcxx . . $ UIHotspot#m_ItemCur.) { |
| 197 | int x = (m_Wcxx . . $ UIObject#m_W. / 2 - m_ItemCurcxx . . $ UIHotspot#m_ItemCur.->widthcxx . . $ UIItem#width(b126dc7c1de90089).() / 2); |
| 198 | int y = (m_Hcxx . . $ UIObject#m_H. / 2 - m_ItemCurcxx . . $ UIHotspot#m_ItemCur.->heightcxx . . $ UIItem#height(b126dc7c1de90089).() / 2); |
| 199 | if (IsDisabledcxx . . $ UIGadget#IsDisabled(c9857a73d68e59ba).()) |
| 200 | m_ItemCurcxx . . $ UIHotspot#m_ItemCur.->drawcxx . . $ UIItem#draw(84329bcd07240ccf).(x, y, uiDrawFadedcxx . . $ uiDrawFaded.); |
| 201 | else { |
| 202 | m_ItemCurcxx . . $ UIHotspot#m_ItemCur.->drawcxx . . $ UIItem#draw(84329bcd07240ccf).(x, y); |
| 203 | } |
| 204 | } |
| 205 | } |