Debian Codegraph @

ui/UIGroup.cpp

raw symbols SCIP
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/UIGroup.cpp $
21 * $Revision: 6 $
22 * $Date: 4/14/99 1:53a $
23 * $Author: Jeff $
24 *
25 * Group box
26 *
27 * $Log: /DescentIII/Main/ui/UIGroup.cpp $
28 *
29 * 6 4/14/99 1:53a Jeff
30 * fixed case mismatched #includes
31 *
32 * 5 10/20/98 12:14p Jeff
33 * added color to the UIGroup
34 *
35 * 4 10/16/98 1:42p Jeff
36 * updated UIGroup
37 *
38 * 3 10/12/98 11:30a Kevin
39 * More memory stuff
40 *
41 * 2 10/07/98 11:25a Jeff
42 * created UIGroup
43 *
44 * $NoKeywords: $
45 */
46
47 #include <cstdlib>
48 #include <cstring>
49
50 #include "UIlib.h"
51 #include "mem.h"
52
53 // ----------------------------------------------------------------------------
54 // UIGroup
55 // Draws a group box on to the window
56
57 UIGroup::UIGroup() {
58 m_Label = NULL;
59 m_bTextCreated = false;
60 }
61
62 UIGroup::~UIGroup() {}
63
64 void UIGroup::Create(UIWindow *parent, char *label, int x, int y, int w, int h, ddgr_color label_color,
65 ddgr_color box_color, int flags) {
66 ASSERT(parent);
67 ASSERT(label);
68
69 m_LabelColor = label_color;
70 m_BoxColor = box_color;
71
72 UIStatic::Create(parent, NULL, x, y, w, h, flags);
73
74 int length = strlen(label);
75 if (length) {
76 m_Label = (char *)mem_malloc(length + 1);
77 strcpy(m_Label, label);
78 }
79 }
80
81 void UIGroup::OnDraw() {
82 ui_DrawSetAlpha(255);
83
84 int text_height = 0;
85 int text_width = 0;
86
87 if (m_Label) {
88 text_height = ui_GetTextHeight("X") / 2;
89 text_width = ui_GetTextWidth(m_Label);
90 }
91
92 ui_DrawLine(m_BoxColor, 0, text_height, 0, m_H - 1); // left side
93 ui_DrawLine(m_BoxColor, 0, m_H - 1, m_W - 1, m_H - 1); // bottom
94 ui_DrawLine(m_BoxColor, m_W - 1, m_H - 1, m_W - 1, text_height); // right side
95
96 int top_edge_length = 0;
97
98 top_edge_length = (m_W - text_width) / 2;
99 if (m_Label)
100 top_edge_length -= 3;
101
102 if (top_edge_length < 0)
103 top_edge_length = 0;
104
105 ui_DrawLine(m_BoxColor, 0, text_height, top_edge_length, text_height);
106 ui_DrawLine(m_BoxColor, m_W, text_height, m_W - top_edge_length, text_height);
107
108 if (!m_bTextCreated) {
109 m_bTextCreated = true;
110 UITextItem item{(m_Label) ? m_Label : "", m_LabelColor};
111 m_tLabel.Create(m_Wnd, &item, m_X + top_edge_length + 3, m_Y);
112 }
113 }
114
115 void UIGroup::OnDestroy() {
116 if (m_Label)
117 mem_free(m_Label);
118 }