00001 00005 /* 00006 Copyright (C) 2002-2010 UFO: Alien Invasion. 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License 00010 as published by the Free Software Foundation; either version 2 00011 of the License, or (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 00017 See the GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00023 */ 00024 00025 #include "ui_internal.h" 00026 #include "ui_components.h" 00027 00034 uiNode_t *UI_GetComponent (const char *name) 00035 { 00036 unsigned char min = 0; 00037 unsigned char max = ui_global.numComponents; 00038 00039 while (min != max) { 00040 const int mid = (min + max) >> 1; 00041 const char diff = strcmp(ui_global.components[mid]->name, name); 00042 assert(mid < max); 00043 assert(mid >= min); 00044 00045 if (diff == 0) 00046 return ui_global.components[mid]; 00047 00048 if (diff > 0) 00049 max = mid; 00050 else 00051 min = mid + 1; 00052 } 00053 00054 return NULL; 00055 } 00056 00061 void UI_InsertComponent(uiNode_t* component) 00062 { 00063 int pos = 0; 00064 int i; 00065 00066 if (ui_global.numComponents >= UI_MAX_COMPONENTS) 00067 Com_Error(ERR_FATAL, "UI_InsertComponent: hit MAX_COMPONENTS"); 00068 00069 /* search the insertion position */ 00070 for (pos = 0; pos < ui_global.numComponents; pos++) { 00071 const uiNode_t* node = ui_global.components[pos]; 00072 if (strcmp(component->name, node->name) < 0) 00073 break; 00074 } 00075 00076 /* create the space */ 00077 for (i = ui_global.numComponents - 1; i >= pos; i--) 00078 ui_global.components[i + 1] = ui_global.components[i]; 00079 00080 /* insert */ 00081 ui_global.components[pos] = component; 00082 ui_global.numComponents++; 00083 }