VEditorButton.cpp
Engine/source/Verve/GUI/VEditorButton.cpp
Public Functions
DefineEngineMethod(VEditorButton , getState , bool , () , "()" )
Detailed Description
Public Functions
DefineEngineMethod(VEditorButton , getState , bool , () , "()" )
IMPLEMENT_CONOBJECT(VEditorButton )
1 2//----------------------------------------------------------------------------- 3// Verve 4// Copyright (C) 2014 - Violent Tulip 5// 6// Permission is hereby granted, free of charge, to any person obtaining a copy 7// of this software and associated documentation files (the "Software"), to 8// deal in the Software without restriction, including without limitation the 9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10// sell copies of the Software, and to permit persons to whom the Software is 11// furnished to do so, subject to the following conditions: 12// 13// The above copyright notice and this permission notice shall be included in 14// all copies or substantial portions of the Software. 15// 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22// IN THE SOFTWARE. 23//----------------------------------------------------------------------------- 24#include "Verve/GUI/VEditorButton.h" 25#include "console/consoleTypes.h" 26#include "gfx/gfxDrawUtil.h" 27#include "gui/core/guiCanvas.h" 28#include "gui/core/guiDefaultControlRender.h" 29 30//----------------------------------------------------------------------------- 31IMPLEMENT_CONOBJECT( VEditorButton ); 32//----------------------------------------------------------------------------- 33 34VEditorButton::VEditorButton( void ) : 35 mIsDraggable( false ) 36{ 37 // Void. 38} 39 40void VEditorButton::initPersistFields( void ) 41{ 42 Parent::initPersistFields(); 43 44 addField( "IsDraggable", TypeBool, Offset( mIsDraggable, VEditorButton ) ); 45} 46 47//----------------------------------------------------------------------------- 48 49void VEditorButton::onMouseDown( const GuiEvent &pEvent ) 50{ 51 if ( !mActive ) 52 { 53 return; 54 } 55 56 Parent::onMouseDown( pEvent ); 57 58 onMouseEvent( "onMouseDown", pEvent ); 59} 60 61void VEditorButton::onMouseUp( const GuiEvent &pEvent ) 62{ 63 if ( !mActive ) 64 { 65 return; 66 } 67 68 Parent::onMouseUp( pEvent ); 69 70 if ( mIsDraggable && isMouseLocked() ) 71 { 72 // Unlock. 73 mouseUnlock(); 74 } 75 76 onMouseEvent( "onMouseUp", pEvent ); 77} 78 79void VEditorButton::onMouseDragged( const GuiEvent &pEvent ) 80{ 81 if ( !mActive || !mIsDraggable ) 82 { 83 return; 84 } 85 86 Parent::onMouseDragged( pEvent ); 87 88 if ( !isMouseLocked() ) 89 { 90 GuiCanvas *canvas = getRoot(); 91 if ( canvas->getMouseLockedControl() ) 92 { 93 GuiEvent event; 94 canvas->getMouseLockedControl()->onMouseLeave( event ); 95 canvas->mouseUnlock( canvas->getMouseLockedControl() ); 96 } 97 98 // Lock. 99 mouseLock(); 100 } 101 102 onMouseEvent( "onMouseDragged", pEvent ); 103} 104 105void VEditorButton::onRightMouseDown( const GuiEvent &pEvent ) 106{ 107 if ( !mActive ) 108 { 109 return; 110 } 111 112 Parent::onRightMouseDown( pEvent ); 113 114 onMouseEvent( "onRightMouseDown", pEvent ); 115} 116 117void VEditorButton::onRightMouseUp( const GuiEvent &pEvent ) 118{ 119 if ( !mActive ) 120 { 121 return; 122 } 123 124 Parent::onRightMouseUp( pEvent ); 125 126 onMouseEvent( "onRightMouseUp", pEvent ); 127} 128 129void VEditorButton::onMouseEnter( const GuiEvent &pEvent ) 130{ 131 if ( !mActive ) 132 { 133 return; 134 } 135 136 Parent::onMouseEnter( pEvent ); 137 138 onMouseEvent( "onMouseEnter", pEvent ); 139} 140 141void VEditorButton::onMouseLeave( const GuiEvent &pEvent ) 142{ 143 if ( !mActive ) 144 { 145 return; 146 } 147 148 Parent::onMouseLeave( pEvent ); 149 150 onMouseEvent( "onMouseLeave", pEvent ); 151} 152 153void VEditorButton::onMouseEvent( const char *pEventName, const GuiEvent &pEvent ) 154{ 155 // Argument Buffers. 156 char argBuffer[3][32]; 157 158 // Format Event-Position Buffer. 159 dSprintf( argBuffer[0], 32, "%d %d", pEvent.mousePoint.x, pEvent.mousePoint.y ); 160 161 // Format Event-Modifier Buffer. 162 dSprintf( argBuffer[1], 32, "%d", pEvent.modifier ); 163 164 // Format Mouse-Click Count Buffer. 165 dSprintf( argBuffer[2], 32, "%d", pEvent.mouseClickCount ); 166 167 // Call Scripts. 168 Con::executef( this, pEventName, argBuffer[0], argBuffer[1], argBuffer[2] ); 169} 170 171//----------------------------------------------------------------------------- 172 173void VEditorButton::onRender( Point2I offset, const RectI& updateRect ) 174{ 175 // Fetch Texture. 176 GFXTexHandle texture = getTextureForCurrentState(); 177 178 // Valid? 179 if ( texture ) 180 { 181 GFX->getDrawUtil()->clearBitmapModulation(); 182 GFX->getDrawUtil()->drawBitmapStretch( texture, RectI( offset, getExtent() ) ); 183 } 184 else 185 { 186 if ( mProfile->mBorder != 0 ) 187 { 188 RectI boundsRect( offset, getExtent() ); 189 190 if ( mDepressed || mStateOn || mMouseOver ) 191 { 192 renderFilledBorder( boundsRect, mProfile->mBorderColorHL, mProfile->mFillColorHL ); 193 } 194 else 195 { 196 renderFilledBorder( boundsRect, mProfile->mBorderColor, mProfile->mFillColor ); 197 } 198 } 199 } 200 201 // Render Text. 202 GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor ); 203 renderJustifiedText( offset + mProfile->mTextOffset, getExtent(), mButtonText ); 204 205 renderChildControls( offset, updateRect); 206} 207 208//----------------------------------------------------------------------------- 209// 210// Console Methods. 211// 212//----------------------------------------------------------------------------- 213 214DefineEngineMethod( VEditorButton, getState, bool, (), , "()" ) 215{ 216 return object->getStateOn(); 217} 218