guiSeparatorCtrl.cpp
Engine/source/gui/editor/guiSeparatorCtrl.cpp
Public Functions
ConsoleDocClass(GuiSeparatorCtrl , "@brief A <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> that renders <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> horizontal or vertical separator with " "an optional text label (horizontal only)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiseparatorctrl/">GuiSeparatorCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " profile = \"GuiDefaultProfile\";\n" " position = \"505 0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " extent = \"10 17\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " minExtent = \"10 17\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " canSave = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " visible = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " horizSizing = \"left\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControls\n</a>" )
ImplementEnumType(GuiSeparatorType , "GuiSeparatorCtrl <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">orientations\n\n</a>" "@ingroup GuiControls" )
Detailed Description
Public Functions
ConsoleDocClass(GuiSeparatorCtrl , "@brief A <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> that renders <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> horizontal or vertical separator with " "an optional text label (horizontal only)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiseparatorctrl/">GuiSeparatorCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " profile = \"GuiDefaultProfile\";\n" " position = \"505 0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " extent = \"10 17\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " minExtent = \"10 17\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " canSave = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " visible = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " horizSizing = \"left\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiControls\n</a>" )
IMPLEMENT_CONOBJECT(GuiSeparatorCtrl )
ImplementEnumType(GuiSeparatorType , "GuiSeparatorCtrl <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">orientations\n\n</a>" "@ingroup GuiControls" )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "gui/editor/guiSeparatorCtrl.h" 26 27#include "gfx/gfxDevice.h" 28#include "gfx/gfxDrawUtil.h" 29#include "console/console.h" 30#include "console/consoleTypes.h" 31#include "gui/core/guiCanvas.h" 32#include "gui/core/guiDefaultControlRender.h" 33 34IMPLEMENT_CONOBJECT(GuiSeparatorCtrl); 35 36ConsoleDocClass( GuiSeparatorCtrl, 37 "@brief A control that renders a horizontal or vertical separator with " 38 "an optional text label (horizontal only)\n\n" 39 40 "@tsexample\n" 41 "new GuiSeparatorCtrl()\n" 42 "{\n" 43 " profile = \"GuiDefaultProfile\";\n" 44 " position = \"505 0\";\n" 45 " extent = \"10 17\";\n" 46 " minExtent = \"10 17\";\n" 47 " canSave = \"1\";\n" 48 " visible = \"1\";\n" 49 " horizSizing = \"left\";\n" 50 "};\n" 51 "@endtsexample\n\n" 52 53 "@ingroup GuiControls\n"); 54 55ImplementEnumType( GuiSeparatorType, 56 "GuiSeparatorCtrl orientations\n\n" 57 "@ingroup GuiControls" ) 58 { GuiSeparatorCtrl::separatorTypeVertical, "Vertical" }, 59 { GuiSeparatorCtrl::separatorTypeHorizontal,"Horizontal" } 60EndImplementEnumType; 61 62 63//-------------------------------------------------------------------------- 64GuiSeparatorCtrl::GuiSeparatorCtrl() : GuiControl() 65{ 66 mInvisible = false; 67 mTextLeftMargin = 0; 68 mMargin = 2; 69 setExtent( 12, 35 ); 70 mSeparatorType = GuiSeparatorCtrl::separatorTypeVertical; 71} 72 73//-------------------------------------------------------------------------- 74void GuiSeparatorCtrl::initPersistFields() 75{ 76 addField("caption", TypeRealString, Offset(mText, GuiSeparatorCtrl), 77 "Optional text label to display." ); 78 addField("type", TYPEID< separatorTypeOptions >(), Offset(mSeparatorType, GuiSeparatorCtrl), 79 "Orientation of separator." ); 80 addField("borderMargin", TypeS32, Offset(mMargin, GuiSeparatorCtrl)); 81 addField("invisible", TypeBool, Offset(mInvisible, GuiSeparatorCtrl));// Nonsense. Should use GuiControl's visibility. 82 addField("leftMargin", TypeS32, Offset(mTextLeftMargin, GuiSeparatorCtrl), 83 "Left margin of text label." ); 84 85 Parent::initPersistFields(); 86} 87 88//-------------------------------------------------------------------------- 89void GuiSeparatorCtrl::onRender(Point2I offset, const RectI &updateRect) 90{ 91 Parent::onRender( offset, updateRect ); 92 93 if( mInvisible ) 94 return; 95 96 if( mText.isNotEmpty() && mSeparatorType != separatorTypeVertical ) 97 { 98 // If text is present and we have a left margin, then draw some separator, then the 99 // text, and then the rest of the separator. 100 101 S32 posx = offset.x + mMargin; 102 S32 fontheight = mProfile->mFont->getHeight(); 103 S32 seppos = (fontheight - 2) / 2 + offset.y; 104 if( mTextLeftMargin > 0 ) 105 { 106 RectI rect( Point2I( posx, seppos ), Point2I( mTextLeftMargin, 2 ) ); 107 renderSlightlyLoweredBox(rect, mProfile); 108 posx += mTextLeftMargin; 109 } 110 111 GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor ); 112 posx = GFX->getDrawUtil()->drawText(mProfile->mFont, Point2I(posx,offset.y), mText, mProfile->mFontColors); 113 114 RectI rect( Point2I( posx, seppos ), Point2I( getWidth() - posx + offset.x, 2 ) ); 115 116 // Space text and separator a bit apart at right end. 117 118 rect.point.x += 2; 119 rect.extent.x -= 2; 120 121 if( rect.extent.x > 0 ) 122 renderSlightlyLoweredBox( rect, mProfile ); 123 } 124 else 125 { 126 if( mSeparatorType == separatorTypeHorizontal ) 127 { 128 S32 seppos = getHeight() / 2 + offset.y; 129 RectI rect(Point2I(offset.x + mMargin ,seppos),Point2I(getWidth() - (mMargin * 2),2)); 130 renderSlightlyLoweredBox(rect, mProfile); 131 } 132 else 133 { 134 S32 seppos = getWidth() / 2 + offset.x; 135 RectI rect(Point2I(seppos, offset.y + mMargin),Point2I(2, getHeight() - (mMargin * 2))); 136 renderSlightlyLoweredBox(rect, mProfile); 137 } 138 } 139 140 renderChildControls(offset, updateRect); 141} 142 143 144