| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 13 | version. |
|---|
| 14 | |
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 23 | |
|---|
| 24 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | #include "OgreStableHeaders.h" |
|---|
| 30 | #include "OgreOverlayElementCommands.h" |
|---|
| 31 | #include "OgreOverlayElement.h" |
|---|
| 32 | #include "OgreStringConverter.h" |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | namespace Ogre { |
|---|
| 36 | |
|---|
| 37 | namespace OverlayElementCommands { |
|---|
| 38 | |
|---|
| 39 | //----------------------------------------------------------------------- |
|---|
| 40 | String CmdLeft::doGet(const void* target) const |
|---|
| 41 | { |
|---|
| 42 | return StringConverter::toString( |
|---|
| 43 | static_cast<const OverlayElement*>(target)->getLeft() ); |
|---|
| 44 | } |
|---|
| 45 | void CmdLeft::doSet(void* target, const String& val) |
|---|
| 46 | { |
|---|
| 47 | static_cast<OverlayElement*>(target)->setLeft(StringConverter::parseReal(val)); |
|---|
| 48 | } |
|---|
| 49 | //----------------------------------------------------------------------- |
|---|
| 50 | String CmdTop::doGet(const void* target) const |
|---|
| 51 | { |
|---|
| 52 | return StringConverter::toString( |
|---|
| 53 | static_cast<const OverlayElement*>(target)->getTop() ); |
|---|
| 54 | } |
|---|
| 55 | void CmdTop::doSet(void* target, const String& val) |
|---|
| 56 | { |
|---|
| 57 | static_cast<OverlayElement*>(target)->setTop(StringConverter::parseReal(val)); |
|---|
| 58 | } |
|---|
| 59 | //----------------------------------------------------------------------- |
|---|
| 60 | String CmdWidth::doGet(const void* target) const |
|---|
| 61 | { |
|---|
| 62 | return StringConverter::toString( |
|---|
| 63 | static_cast<const OverlayElement*>(target)->getWidth() ); |
|---|
| 64 | } |
|---|
| 65 | void CmdWidth::doSet(void* target, const String& val) |
|---|
| 66 | { |
|---|
| 67 | static_cast<OverlayElement*>(target)->setWidth(StringConverter::parseReal(val)); |
|---|
| 68 | } |
|---|
| 69 | //----------------------------------------------------------------------- |
|---|
| 70 | String CmdHeight::doGet(const void* target) const |
|---|
| 71 | { |
|---|
| 72 | return StringConverter::toString( |
|---|
| 73 | static_cast<const OverlayElement*>(target)->getHeight() ); |
|---|
| 74 | } |
|---|
| 75 | void CmdHeight::doSet(void* target, const String& val) |
|---|
| 76 | { |
|---|
| 77 | static_cast<OverlayElement*>(target)->setHeight(StringConverter::parseReal(val)); |
|---|
| 78 | } |
|---|
| 79 | //----------------------------------------------------------------------- |
|---|
| 80 | String CmdMaterial::doGet(const void* target) const |
|---|
| 81 | { |
|---|
| 82 | return static_cast<const OverlayElement*>(target)->getMaterialName(); |
|---|
| 83 | } |
|---|
| 84 | void CmdMaterial::doSet(void* target, const String& val) |
|---|
| 85 | { |
|---|
| 86 | if (val != "") |
|---|
| 87 | { |
|---|
| 88 | static_cast<OverlayElement*>(target)->setMaterialName(val); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | //----------------------------------------------------------------------- |
|---|
| 92 | //----------------------------------------------------------------------- |
|---|
| 93 | String CmdCaption::doGet(const void* target) const |
|---|
| 94 | { |
|---|
| 95 | return static_cast<const OverlayElement*>(target)->getCaption(); |
|---|
| 96 | } |
|---|
| 97 | void CmdCaption::doSet(void* target, const String& val) |
|---|
| 98 | { |
|---|
| 99 | static_cast<OverlayElement*>(target)->setCaption(val); |
|---|
| 100 | } |
|---|
| 101 | //----------------------------------------------------------------------- |
|---|
| 102 | //----------------------------------------------------------------------- |
|---|
| 103 | //----------------------------------------------------------------------- |
|---|
| 104 | String CmdMetricsMode::doGet(const void* target) const |
|---|
| 105 | { |
|---|
| 106 | GuiMetricsMode gmm = |
|---|
| 107 | static_cast<const OverlayElement*>(target)->getMetricsMode(); |
|---|
| 108 | |
|---|
| 109 | switch (gmm) |
|---|
| 110 | { |
|---|
| 111 | case GMM_PIXELS : |
|---|
| 112 | return "pixels"; |
|---|
| 113 | |
|---|
| 114 | case GMM_RELATIVE_ASPECT_ADJUSTED : |
|---|
| 115 | return "relative_aspect_adjusted"; |
|---|
| 116 | |
|---|
| 117 | default : |
|---|
| 118 | return "relative"; |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | void CmdMetricsMode::doSet(void* target, const String& val) |
|---|
| 122 | { |
|---|
| 123 | if (val == "pixels") |
|---|
| 124 | { |
|---|
| 125 | static_cast<OverlayElement*>(target)->setMetricsMode(GMM_PIXELS); |
|---|
| 126 | } |
|---|
| 127 | else if (val == "relative_aspect_adjusted") |
|---|
| 128 | { |
|---|
| 129 | static_cast<OverlayElement*>(target)->setMetricsMode(GMM_RELATIVE_ASPECT_ADJUSTED); |
|---|
| 130 | } |
|---|
| 131 | else |
|---|
| 132 | { |
|---|
| 133 | static_cast<OverlayElement*>(target)->setMetricsMode(GMM_RELATIVE); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | //----------------------------------------------------------------------- |
|---|
| 137 | //----------------------------------------------------------------------- |
|---|
| 138 | //----------------------------------------------------------------------- |
|---|
| 139 | String CmdHorizontalAlign::doGet(const void* target) const |
|---|
| 140 | { |
|---|
| 141 | GuiHorizontalAlignment gha = |
|---|
| 142 | static_cast<const OverlayElement*>(target)->getHorizontalAlignment(); |
|---|
| 143 | switch(gha) |
|---|
| 144 | { |
|---|
| 145 | case GHA_LEFT: |
|---|
| 146 | return "left"; |
|---|
| 147 | case GHA_RIGHT: |
|---|
| 148 | return "right"; |
|---|
| 149 | case GHA_CENTER: |
|---|
| 150 | return "center"; |
|---|
| 151 | } |
|---|
| 152 | // To keep compiler happy |
|---|
| 153 | return "center"; |
|---|
| 154 | } |
|---|
| 155 | void CmdHorizontalAlign::doSet(void* target, const String& val) |
|---|
| 156 | { |
|---|
| 157 | if (val == "left") |
|---|
| 158 | { |
|---|
| 159 | static_cast<OverlayElement*>(target)->setHorizontalAlignment(GHA_LEFT); |
|---|
| 160 | } |
|---|
| 161 | else if (val == "right") |
|---|
| 162 | { |
|---|
| 163 | static_cast<OverlayElement*>(target)->setHorizontalAlignment(GHA_RIGHT); |
|---|
| 164 | } |
|---|
| 165 | else |
|---|
| 166 | { |
|---|
| 167 | static_cast<OverlayElement*>(target)->setHorizontalAlignment(GHA_CENTER); |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | //----------------------------------------------------------------------- |
|---|
| 171 | //----------------------------------------------------------------------- |
|---|
| 172 | //----------------------------------------------------------------------- |
|---|
| 173 | String CmdVerticalAlign::doGet(const void* target) const |
|---|
| 174 | { |
|---|
| 175 | GuiVerticalAlignment gva = |
|---|
| 176 | static_cast<const OverlayElement*>(target)->getVerticalAlignment(); |
|---|
| 177 | switch(gva) |
|---|
| 178 | { |
|---|
| 179 | case GVA_TOP: |
|---|
| 180 | return "top"; |
|---|
| 181 | case GVA_BOTTOM: |
|---|
| 182 | return "bottom"; |
|---|
| 183 | case GVA_CENTER: |
|---|
| 184 | return "center"; |
|---|
| 185 | } |
|---|
| 186 | // To keep compiler happy |
|---|
| 187 | return "center"; |
|---|
| 188 | } |
|---|
| 189 | void CmdVerticalAlign::doSet(void* target, const String& val) |
|---|
| 190 | { |
|---|
| 191 | if (val == "top") |
|---|
| 192 | { |
|---|
| 193 | static_cast<OverlayElement*>(target)->setVerticalAlignment(GVA_TOP); |
|---|
| 194 | } |
|---|
| 195 | else if (val == "bottom") |
|---|
| 196 | { |
|---|
| 197 | static_cast<OverlayElement*>(target)->setVerticalAlignment(GVA_BOTTOM); |
|---|
| 198 | } |
|---|
| 199 | else |
|---|
| 200 | { |
|---|
| 201 | static_cast<OverlayElement*>(target)->setVerticalAlignment(GVA_CENTER); |
|---|
| 202 | } |
|---|
| 203 | } |
|---|
| 204 | //----------------------------------------------------------------------- |
|---|
| 205 | //----------------------------------------------------------------------- |
|---|
| 206 | //----------------------------------------------------------------------- |
|---|
| 207 | //----------------------------------------------------------------------- |
|---|
| 208 | String CmdVisible::doGet(const void* target) const |
|---|
| 209 | { |
|---|
| 210 | bool visible = |
|---|
| 211 | static_cast<const OverlayElement*>(target)->isVisible(); |
|---|
| 212 | switch(visible) |
|---|
| 213 | { |
|---|
| 214 | case true: |
|---|
| 215 | return "true"; |
|---|
| 216 | case false: |
|---|
| 217 | return "false"; |
|---|
| 218 | } |
|---|
| 219 | // To keep compiler happy |
|---|
| 220 | return "true"; |
|---|
| 221 | } |
|---|
| 222 | void CmdVisible::doSet(void* target, const String& val) |
|---|
| 223 | { |
|---|
| 224 | if (val == "true") |
|---|
| 225 | { |
|---|
| 226 | static_cast<OverlayElement*>(target)->show(); |
|---|
| 227 | } |
|---|
| 228 | else if (val == "false") |
|---|
| 229 | { |
|---|
| 230 | static_cast<OverlayElement*>(target)->hide(); |
|---|
| 231 | } |
|---|
| 232 | } |
|---|
| 233 | //----------------------------------------------------------------------- |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | |
|---|