| 1 | /*************************************************************************** |
| 2 | layer.cpp - description |
| 3 | ------------------- |
| 4 | begin : september 20th, 2003 |
| 5 | copyright : (C) 2003-2007 by Duong Khang NGUYEN |
| 6 | email : neoneurone @ gmail com |
| 7 | |
| 8 | $Id: layer.cpp 375 2008-10-28 14:47:15Z neoneurone $ |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | /*************************************************************************** |
| 12 | * * |
| 13 | * This program is free software; you can redistribute it and/or modify * |
| 14 | * it under the terms of the GNU General Public License as published by * |
| 15 | * the Free Software Foundation; either version 2 of the License, or * |
| 16 | * any later version. * |
| 17 | * * |
| 18 | ***************************************************************************/ |
| 19 | |
| 20 | // Useful enumerations |
| 21 | #include "opencity_structure_type.h" |
| 22 | |
| 23 | // OpenCity headers |
| 24 | #include "layer.h" |
| 25 | #include "structure.h" |
| 26 | #include "guicontainer.h" // for the "Query" function |
| 27 | #include "guibutton.h" |
| 28 | |
| 29 | // Static variables |
| 30 | uint Layer::_uiNumberLayer = 0; |
| 31 | GUIContainer* Layer::pctrQ; ///< The query container |
| 32 | GUIButton* Layer::pbtnQRo, * Layer::pbtnQRf; ///< Residential query button |
| 33 | GUIButton* Layer::pbtnQCo, * Layer::pbtnQCf; ///< Commercial query button |
| 34 | GUIButton* Layer::pbtnQIo, * Layer::pbtnQIf; ///< Industrial query button |
| 35 | GUIButton* Layer::pbtnQWo, * Layer::pbtnQWf; ///< Water query button |
| 36 | GUIButton* Layer::pbtnQEo, * Layer::pbtnQEf; ///< Electricity query button |
| 37 | GUIButton* Layer::pbtnQGo, * Layer::pbtnQGf; ///< Gas query button |
| 38 | |
| 39 | |
| 40 | Layer::Layer(){ |
| 41 | OPENCITY_DEBUG( "ctor" ); |
| 42 | |
| 43 | // IF called first time THEN create all the static variables |
| 44 | // we do it here, because we need an initialized OpenGL context |
| 45 | // if we do it on the declaration line, there will be runtime errors ! |
| 46 | if ( Layer::_uiNumberLayer++ > 0) |
| 47 | return; |
| 48 | |
| 49 | _CreateQueryContainer(); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /*=====================================================================*/ |
| 54 | Layer::~Layer(){ |
| 55 | OPENCITY_DEBUG( "dtor" ); |
| 56 | |
| 57 | // IF not called for the last derived class THEN return |
| 58 | if ( Layer::_uiNumberLayer-- > 1) |
| 59 | return; |
| 60 | |
| 61 | _DeleteQueryContainer(); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /*=====================================================================*/ |
| 66 | const uint |
| 67 | Layer::GetMaxLinear() const |
| 68 | { |
| 69 | return _uiLayerWidth * _uiLayerLength - 1; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /*=====================================================================*/ |
| 74 | void |
| 75 | Layer::GetLayerSize( |
| 76 | uint & w, |
| 77 | uint & l) const |
| 78 | { |
| 79 | w = _uiLayerWidth; |
| 80 | l = _uiLayerLength; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | /*=====================================================================*/ |
| 85 | void |
| 86 | Layer::_CreateQueryContainer() |
| 87 | { |
| 88 | // On buttons |
| 89 | Layer::pbtnQRo = |
| 90 | new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix("graphism/gui/query_residential_on"), 1); |
| 91 | Layer::pbtnQWo = |
| 92 | new GUIButton( GUIBUTTON_POSITION_2, ocDataDirPrefix("graphism/gui/query_water_on"), 1); |
| 93 | Layer::pbtnQEo = |
| 94 | new GUIButton( GUIBUTTON_POSITION_3, ocDataDirPrefix("graphism/gui/query_electricity_on"), 1); |
| 95 | Layer::pbtnQGo = |
| 96 | new GUIButton( GUIBUTTON_POSITION_4, ocDataDirPrefix("graphism/gui/query_gas_on"), 1); |
| 97 | Layer::pbtnQIo = |
| 98 | new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix("graphism/gui/query_industrial_on"), 1); |
| 99 | Layer::pbtnQCo = |
| 100 | new GUIButton( GUIBUTTON_POSITION_6, ocDataDirPrefix("graphism/gui/query_commercial_on"), 1); |
| 101 | |
| 102 | // Off buttons |
| 103 | Layer::pbtnQRf = |
| 104 | new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix("graphism/gui/query_residential_off"), 1); |
| 105 | Layer::pbtnQWf = |
| 106 | new GUIButton( GUIBUTTON_POSITION_2, ocDataDirPrefix("graphism/gui/query_water_off"), 1); |
| 107 | Layer::pbtnQEf = |
| 108 | new GUIButton( GUIBUTTON_POSITION_3, ocDataDirPrefix("graphism/gui/query_electricity_off"), 1); |
| 109 | Layer::pbtnQGf = |
| 110 | new GUIButton( GUIBUTTON_POSITION_4, ocDataDirPrefix("graphism/gui/query_gas_off"), 1); |
| 111 | Layer::pbtnQIf = |
| 112 | new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix("graphism/gui/query_industrial_off"), 1); |
| 113 | Layer::pbtnQCf = |
| 114 | new GUIButton( GUIBUTTON_POSITION_6, ocDataDirPrefix("graphism/gui/query_commercial_off"), 1); |
| 115 | |
| 116 | // Query container |
| 117 | Layer::pctrQ = |
| 118 | new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/querycircle_bg.png" ) ); |
| 119 | |
| 120 | // Add all the controls with their ON state |
| 121 | Layer::pctrQ->Add( Layer::pbtnQRo ); |
| 122 | Layer::pctrQ->Add( Layer::pbtnQWo ); |
| 123 | Layer::pctrQ->Add( Layer::pbtnQEo ); |
| 124 | Layer::pctrQ->Add( Layer::pbtnQGo ); |
| 125 | Layer::pctrQ->Add( Layer::pbtnQIo ); |
| 126 | Layer::pctrQ->Add( Layer::pbtnQCo ); |
| 127 | |
| 128 | // Add all the controls with their OFF state |
| 129 | Layer::pctrQ->Add( Layer::pbtnQRf ); |
| 130 | Layer::pctrQ->Add( Layer::pbtnQWf ); |
| 131 | Layer::pctrQ->Add( Layer::pbtnQEf ); |
| 132 | Layer::pctrQ->Add( Layer::pbtnQGf ); |
| 133 | Layer::pctrQ->Add( Layer::pbtnQIf ); |
| 134 | Layer::pctrQ->Add( Layer::pbtnQCf ); |
| 135 | |
| 136 | // Disable unused query icons |
| 137 | Layer::pbtnQWo->Unset( OC_GUIMAIN_VISIBLE ); |
| 138 | Layer::pbtnQGo->Unset( OC_GUIMAIN_VISIBLE ); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | /*=====================================================================*/ |
| 143 | void |
| 144 | Layer::_DeleteQueryContainer() |
| 145 | { |
| 146 | // Destroy all the static stuff when called by the last derived class |
| 147 | delete Layer::pctrQ; |
| 148 | |
| 149 | delete Layer::pbtnQCf; |
| 150 | delete Layer::pbtnQIf; |
| 151 | delete Layer::pbtnQGf; |
| 152 | delete Layer::pbtnQEf; |
| 153 | delete Layer::pbtnQWf; |
| 154 | delete Layer::pbtnQRf; |
| 155 | |
| 156 | delete Layer::pbtnQCo; |
| 157 | delete Layer::pbtnQIo; |
| 158 | delete Layer::pbtnQGo; |
| 159 | delete Layer::pbtnQEo; |
| 160 | delete Layer::pbtnQWo; |
| 161 | delete Layer::pbtnQRo; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 |