UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_components.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, 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 
61 void UI_InsertComponent(uiNode_t* component)
62 {
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--)
77 
78  /* insert */
79  ui_global.components[pos] = component;
81 }
#define UI_MAX_COMPONENTS
Definition: ui_internal.h:30
uiGlobal_t ui_global
Definition: ui_main.cpp:38
uiNode_t * components[UI_MAX_COMPONENTS]
Definition: ui_internal.h:71
uiNode_t * UI_GetComponent(const char *name)
Searches all components for the specified one.
char name[MAX_VAR]
Definition: ui_nodes.h:82
#define ERR_FATAL
Definition: common.h:210
Internal data use by the UI package.
void Com_Error(int code, const char *fmt,...)
Definition: common.cpp:417
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
int numComponents
Definition: ui_internal.h:72
QGL_EXTERN GLint i
Definition: r_gl.h:113
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
void UI_InsertComponent(uiNode_t *component)
Add a new component to the list of all components.