UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_components.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "ui_internal.h"
26#include "ui_components.h"
27
35{
36 unsigned char min = 0;
37 unsigned char max = ui_global.numComponents;
38
39 while (min != max) {
40 const int mid = (min + max) >> 1;
41 const int diff = strcmp(ui_global.components[mid]->name, name);
42 assert(mid < max);
43 assert(mid >= min);
44
45 if (diff == 0)
46 return ui_global.components[mid];
47
48 if (diff > 0)
49 max = mid;
50 else
51 min = mid + 1;
52 }
53
54 return nullptr;
55}
56
62{
63 if (ui_global.numComponents >= UI_MAX_COMPONENTS)
64 Com_Error(ERR_FATAL, "UI_InsertComponent: hit MAX_COMPONENTS");
65
66 /* search the insertion position */
67 int pos = 0;
68 for (; pos < ui_global.numComponents; pos++) {
69 const uiNode_t* node = ui_global.components[pos];
70 if (strcmp(component->name, node->name) < 0)
71 break;
72 }
73
74 /* create the space */
75 for (int i = ui_global.numComponents - 1; i >= pos; i--)
76 ui_global.components[i + 1] = ui_global.components[i];
77
78 /* insert */
79 ui_global.components[pos] = component;
80 ui_global.numComponents++;
81}
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
#define ERR_FATAL
Definition common.h:210
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
char name[MAX_VAR]
Definition ui_nodes.h:82
uiNode_t * UI_GetComponent(const char *name)
Searches all components for the specified one.
void UI_InsertComponent(uiNode_t *component)
Add a new component to the list of all components.
Internal data use by the UI package.
#define UI_MAX_COMPONENTS
Definition ui_internal.h:30
uiGlobal_t ui_global
Definition ui_main.cpp:38