(Mostly) updated verve implementation.

This commit is contained in:
Areloch 2019-03-07 16:23:41 -06:00
parent 775ca57047
commit 87ee749801
538 changed files with 68727 additions and 49 deletions

View file

@ -0,0 +1,216 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "Verve/GUI/VEditorButton.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDrawUtil.h"
#include "gui/core/guiCanvas.h"
#include "gui/core/guiDefaultControlRender.h"
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT( VEditorButton );
//-----------------------------------------------------------------------------
VEditorButton::VEditorButton( void ) :
mIsDraggable( false )
{
// Void.
}
void VEditorButton::initPersistFields( void )
{
Parent::initPersistFields();
addField( "IsDraggable", TypeBool, Offset( mIsDraggable, VEditorButton ) );
}
//-----------------------------------------------------------------------------
void VEditorButton::onMouseDown( const GuiEvent &pEvent )
{
if ( !mActive )
{
return;
}
Parent::onMouseDown( pEvent );
onMouseEvent( "onMouseDown", pEvent );
}
void VEditorButton::onMouseUp( const GuiEvent &pEvent )
{
if ( !mActive )
{
return;
}
Parent::onMouseUp( pEvent );
if ( mIsDraggable && isMouseLocked() )
{
// Unlock.
mouseUnlock();
}
onMouseEvent( "onMouseUp", pEvent );
}
void VEditorButton::onMouseDragged( const GuiEvent &pEvent )
{
if ( !mActive || !mIsDraggable )
{
return;
}
Parent::onMouseDragged( pEvent );
if ( !isMouseLocked() )
{
GuiCanvas *canvas = getRoot();
if ( canvas->getMouseLockedControl() )
{
GuiEvent event;
canvas->getMouseLockedControl()->onMouseLeave( event );
canvas->mouseUnlock( canvas->getMouseLockedControl() );
}
// Lock.
mouseLock();
}
onMouseEvent( "onMouseDragged", pEvent );
}
void VEditorButton::onRightMouseDown( const GuiEvent &pEvent )
{
if ( !mActive )
{
return;
}
Parent::onRightMouseDown( pEvent );
onMouseEvent( "onRightMouseDown", pEvent );
}
void VEditorButton::onRightMouseUp( const GuiEvent &pEvent )
{
if ( !mActive )
{
return;
}
Parent::onRightMouseUp( pEvent );
onMouseEvent( "onRightMouseUp", pEvent );
}
void VEditorButton::onMouseEnter( const GuiEvent &pEvent )
{
if ( !mActive )
{
return;
}
Parent::onMouseEnter( pEvent );
onMouseEvent( "onMouseEnter", pEvent );
}
void VEditorButton::onMouseLeave( const GuiEvent &pEvent )
{
if ( !mActive )
{
return;
}
Parent::onMouseLeave( pEvent );
onMouseEvent( "onMouseLeave", pEvent );
}
void VEditorButton::onMouseEvent( const char *pEventName, const GuiEvent &pEvent )
{
// Argument Buffers.
char argBuffer[3][32];
// Format Event-Position Buffer.
dSprintf( argBuffer[0], 32, "%d %d", pEvent.mousePoint.x, pEvent.mousePoint.y );
// Format Event-Modifier Buffer.
dSprintf( argBuffer[1], 32, "%d", pEvent.modifier );
// Format Mouse-Click Count Buffer.
dSprintf( argBuffer[2], 32, "%d", pEvent.mouseClickCount );
// Call Scripts.
Con::executef( this, pEventName, argBuffer[0], argBuffer[1], argBuffer[2] );
}
//-----------------------------------------------------------------------------
void VEditorButton::onRender( Point2I offset, const RectI& updateRect )
{
// Fetch Texture.
GFXTexHandle texture = getTextureForCurrentState();
// Valid?
if ( texture )
{
GFX->getDrawUtil()->clearBitmapModulation();
GFX->getDrawUtil()->drawBitmapStretch( texture, RectI( offset, getExtent() ) );
}
else
{
if ( mProfile->mBorder != 0 )
{
RectI boundsRect( offset, getExtent() );
if ( mDepressed || mStateOn || mMouseOver )
{
renderFilledBorder( boundsRect, mProfile->mBorderColorHL, mProfile->mFillColorHL );
}
else
{
renderFilledBorder( boundsRect, mProfile->mBorderColor, mProfile->mFillColor );
}
}
}
// Render Text.
GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor );
renderJustifiedText( offset + mProfile->mTextOffset, getExtent(), mButtonText );
renderChildControls( offset, updateRect);
}
//-----------------------------------------------------------------------------
//
// Console Methods.
//
//-----------------------------------------------------------------------------
DefineEngineMethod( VEditorButton, getState, bool, (), , "()" )
{
return object->getStateOn();
}

View file

@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _VT_VEDITORBUTTON_H_
#define _VT_VEDITORBUTTON_H_
#ifndef _GUIBITMAPBUTTON_H_
#include "gui/buttons/guiBitmapButtonCtrl.h"
#endif
class VEditorButton : public GuiBitmapButtonTextCtrl
{
typedef GuiBitmapButtonTextCtrl Parent;
public:
bool mIsDraggable;
public:
VEditorButton();
static void initPersistFields( void );
void onMouseDown( const GuiEvent &pEvent );
void onMouseUp( const GuiEvent &pEvent );
void onMouseDragged( const GuiEvent &pEvent );
void onRightMouseDown( const GuiEvent &pEvent );
void onRightMouseUp( const GuiEvent &pEvent );
void onMouseEnter( const GuiEvent &pEvent );
void onMouseLeave( const GuiEvent &pEvent );
void onMouseEvent( const char *pEventName, const GuiEvent &pEvent );
void onRender( Point2I offset, const RectI &updateRect );
public:
DECLARE_CONOBJECT( VEditorButton );
};
#endif //_VT_VEDITORBUTTON_H_

View file

@ -0,0 +1,97 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "Verve/GUI/VEditorScrollControl.h"
#include "gfx/gfxDrawUtil.h"
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT( VEditorScrollControl );
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// Mouse Methods.
//
//-----------------------------------------------------------------------------
void VEditorScrollControl::onMouseUp( const GuiEvent &pEvent )
{
Parent::onMouseUp( pEvent );
// Event.
onMouseEvent( "onMouseUp", pEvent );
}
void VEditorScrollControl::onRightMouseUp( const GuiEvent &pEvent )
{
Parent::onMouseUp( pEvent );
// Event.
onMouseEvent( "onRightMouseUp", pEvent );
}
void VEditorScrollControl::onMouseEvent( const char *pEventName, const GuiEvent &pEvent )
{
const S32 offsetX = ( mHasVScrollBar ) ? mScrollBarThickness : 0;
const S32 offsetY = ( mHasHScrollBar ) ? mScrollBarThickness : 0;
const RectI contentRect( 2, 2, getWidth() - offsetX - 4 - 1, getHeight() - offsetY - 4 - ( mHasHScrollBar ) );
if ( !contentRect.pointInRect( pEvent.mousePoint ) )
{
// Return!
return;
}
// Argument Buffers.
char argBuffer[3][32];
// Format Event-Position Buffer.
dSprintf( argBuffer[0], 32, "%d %d", pEvent.mousePoint.x, pEvent.mousePoint.y );
// Format Event-Modifier Buffer.
dSprintf( argBuffer[1], 32, "%d", pEvent.modifier );
// Format Mouse-Click Count Buffer.
dSprintf( argBuffer[2], 32, "%d", pEvent.mouseClickCount );
// Call Scripts.
Con::executef( this, pEventName, argBuffer[0], argBuffer[1], argBuffer[2] );
}
//-----------------------------------------------------------------------------
//
// Render Methods.
//
//-----------------------------------------------------------------------------
void VEditorScrollControl::onRender( Point2I pOffset, const RectI &pUpdateRect )
{
Parent::onRender( pOffset, pUpdateRect );
const S32 offsetX = ( mHasVScrollBar ) ? mScrollBarThickness : 1;
const S32 offsetY = ( mHasHScrollBar ) ? mScrollBarThickness : 1;
RectI contentRect( pOffset.x + 1, pOffset.y + 1, getWidth() - offsetX - 1, getHeight() - offsetY - 1 );
contentRect.intersect( pUpdateRect );
GFX->getDrawUtil()->drawRect( contentRect, mProfile->mBorderColor );
}

View file

@ -0,0 +1,56 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _VT_VEDITORSCROLLCONTROL_H_
#define _VT_VEDITORSCROLLCONTROL_H_
#ifndef _GUISCROLLCTRL_H_
#include "gui/containers/guiScrollCtrl.h"
#endif
//-----------------------------------------------------------------------------
class VEditorScrollControl : public GuiScrollCtrl
{
typedef GuiScrollCtrl Parent;
public:
// Mouse.
virtual void onMouseUp( const GuiEvent &pEvent );
virtual void onRightMouseUp( const GuiEvent &pEvent );
void onMouseEvent( const char *pEventName, const GuiEvent &pEvent );
// Rendering.
void onRender( Point2I pOffset, const RectI &pUpdateRect );
// Console Declaration.
DECLARE_CONOBJECT( VEditorScrollControl );
};
//-----------------------------------------------------------------------------
#endif // _VT_VEDITORSCROLLCONTROL_H_

View file

@ -0,0 +1,145 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "Verve/GUI/VEditorWindow.h"
#include "gfx/gfxInit.h"
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT( VEditorWindow );
//-----------------------------------------------------------------------------
bool VEditorWindow::onAdd( void )
{
if ( !Parent::onAdd() )
{
return false;
}
GFXAdapter *adapter = GFXInit::getBestAdapterChoice();
if ( adapter && adapter->mType != NullDevice )
{
mPlatformWindow->setMinimumWindowSize( Point2I( 904, 287 ) );
}
return true;
}
//-----------------------------------------------------------------------------
DefineEngineMethod( VEditorWindow, resetCursor, void, (),, "( )" )
{
S32 currCursor = PlatformCursorController::curArrow;
if ( object->mCursorChanged == currCursor )
{
return;
}
PlatformWindow *window = object->getPlatformWindow();
PlatformCursorController *controller = window->getCursorController();
if( object->mCursorChanged != -1)
{
controller->popCursor();
}
controller->pushCursor(currCursor);
object->mCursorChanged = currCursor;
Platform::setWindowLocked( false );
}
DefineEngineMethod( VEditorWindow, setVideoMode, void, (S32 width, S32 height, bool fullscreen, S32 bitDepth, S32 refreshRate, S32 antiAliasLevel),
(800,600,false,32,60, 0),
"(int width, int height, bool fullscreen, [int bitDepth], [int refreshRate])\n"
"Change the video mode of this canvas. This method has the side effect of setting the $pref::Video::mode to the new values.\n\n"
"\\param width The screen width to set.\n"
"\\param height The screen height to set.\n"
"\\param fullscreen Specify true to run fullscreen or false to run in a window\n"
"\\param bitDepth [optional] The desired bit-depth. Defaults to the current setting. This parameter is ignored if you are running in a window.\n"
"\\param refreshRate [optional] The desired refresh rate. Defaults to the current setting. This parameter is ignored if you are running in a window"
"\\param antialiasLevel [optional] The level of anti-aliasing to apply 0 = none" )
{
if (!object->getPlatformWindow())
return;
// Update the video mode and tell the window to reset.
GFXVideoMode vm = object->getPlatformWindow()->getVideoMode();
bool changed = false;
if (width == 0 && height > 0)
{
// Our width is 0 but our height isn't...
// Try to find a matching width
for(S32 i=0; i<object->getPlatformWindow()->getGFXDevice()->getVideoModeList()->size(); i++)
{
const GFXVideoMode &newVm = (*(object->getPlatformWindow()->getGFXDevice()->getVideoModeList()))[i];
if(newVm.resolution.y == height)
{
width = newVm.resolution.x;
changed = true;
break;
}
}
}
else if (height == 0 && width > 0)
{
// Our height is 0 but our width isn't...
// Try to find a matching height
for(S32 i=0; i<object->getPlatformWindow()->getGFXDevice()->getVideoModeList()->size(); i++)
{
const GFXVideoMode &newVm = (*(object->getPlatformWindow()->getGFXDevice()->getVideoModeList()))[i];
if(newVm.resolution.x == width)
{
height = newVm.resolution.y;
changed = true;
break;
}
}
}
if (width == 0 || height == 0)
{
// Got a bad size for both of our dimensions or one of our dimensions and
// didn't get a match for the other default back to our current resolution
width = vm.resolution.x;
height = vm.resolution.y;
changed = true;
}
if (changed)
Con::errorf("GuiCanvas::setVideoMode(): Error - Invalid resolution of (%d, %d) - attempting (%d, %d)", width, height, width, height);
vm.resolution = Point2I(width, height);
vm.fullScreen = fullscreen;
vm.bitDepth = bitDepth;
vm.refreshRate = refreshRate;
vm.antialiasLevel = antiAliasLevel;
#ifndef TORQUE_OS_XENON
object->getPlatformWindow()->setVideoMode(vm);
#endif
}

View file

@ -0,0 +1,49 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _VT_VEDITORWINDOW_H_
#define _VT_VEDITORWINDOW_H_
#ifndef _GUICANVAS_H_
#include "gui/core/guiCanvas.h"
#endif
//-----------------------------------------------------------------------------
class VEditorWindow : public GuiCanvas
{
typedef GuiCanvas Parent;
public:
// Properties.
virtual bool onAdd( void );
// Console Declaration.
DECLARE_CONOBJECT( VEditorWindow );
};
//-----------------------------------------------------------------------------
#endif // _VT_VEDITORWINDOW_H_

View file

@ -0,0 +1,114 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "Verve/GUI/VFadeControl.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDrawUtil.h"
#include "math/mMathFn.h"
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT( VFadeControl );
//-----------------------------------------------------------------------------
VFadeControl::VFadeControl( void ) :
mActive( false ),
mFadeType( k_TypeInvalid ),
mElapsedTime( 0 ),
mDuration( 1000 ),
mLastTime( 0 )
{
// Void.
}
//-----------------------------------------------------------------------------
//
// Render Methods.
//
//-----------------------------------------------------------------------------
void VFadeControl::onRender( Point2I pOffset, const RectI &pUpdateRect )
{
Parent::onRender( pOffset, pUpdateRect );
if ( mFadeType == k_TypeInvalid )
{
// Invalid Fade State.
return;
}
// Fetch Time.
const U32 time = Platform::getRealMilliseconds();
// Fetch Delta.
const U32 delta = ( time - mLastTime );
// Store Time.
mLastTime = time;
if ( mActive )
{
// Update Elapsed Time.
mElapsedTime += delta;
}
F32 alpha = 1.f - mClampF( F32( mElapsedTime ) / F32( mDuration ), 0.f, 1.f );
if ( mFadeType == k_TypeOut )
{
// Flip.
alpha = 1.f - alpha;
}
if ( alpha > 0.f )
{
// Render.
GFX->getDrawUtil()->drawRectFill( pOffset, pOffset + getExtent(), ColorI( 0, 0, 0, alpha * 255 ) );
}
if ( mElapsedTime >= mDuration )
{
// Stop.
mActive = false;
}
}
//-----------------------------------------------------------------------------
//
// Control Methods.
//
//-----------------------------------------------------------------------------
void VFadeControl::start( eFadeType pType, S32 pDuration )
{
mActive = true;
mFadeType = pType;
mElapsedTime = 0;
mDuration = pDuration;
mLastTime = Platform::getRealMilliseconds();
}
void VFadeControl::pause( void )
{
mActive = false;
}

View file

@ -0,0 +1,73 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _VT_VFADECONTROL_H_
#define _VT_VFADECONTROL_H_
#ifndef _GUICONTROL_H_
#include "gui/core/guiControl.h"
#endif
//-----------------------------------------------------------------------------
class VFadeControl : public GuiControl
{
typedef GuiControl Parent;
public:
enum eFadeType
{
k_TypeIn,
k_TypeOut,
k_TypeInvalid,
};
bool mActive;
eFadeType mFadeType;
S32 mElapsedTime;
S32 mDuration;
S32 mLastTime;
public:
VFadeControl( void );
// Render Methods.
virtual void onRender( Point2I pOffset, const RectI &pUpdateRect );
// Console Declaration.
DECLARE_CONOBJECT( VFadeControl );
public:
void start( eFadeType pType, S32 pDuration );
void pause( void );
};
//-----------------------------------------------------------------------------
#endif // _VT_VFADECONTROL_H_

View file

@ -0,0 +1,476 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "Verve/GUI/VTimeLineControl.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDrawUtil.h"
#include "gui/core/guiCanvas.h"
//-----------------------------------------------------------------------------
const S32 gUnitsPerSec = 200;
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT( VTimeLineControl );
//-----------------------------------------------------------------------------
VTimeLineControl::VTimeLineControl( void ) :
mIsController( true ),
mController( NULL ),
mDurationOffset( 50 )
{
mSelection.Active = false;
mSelection.StartTime = 0;
mSelection.EndTime = 0;
}
void VTimeLineControl::initPersistFields( void )
{
Parent::initPersistFields();
addField( "IsController", TypeBool, Offset( mIsController, VTimeLineControl ) );
addField( "Controller", TYPEID<VController>(), Offset( mController, VTimeLineControl ) );
addField( "DurationOffset", TypeS32, Offset( mDurationOffset, VTimeLineControl ) );
}
//-----------------------------------------------------------------------------
//
// Mouse Methods.
//
//-----------------------------------------------------------------------------
void VTimeLineControl::onMouseDown( const GuiEvent &pEvent )
{
Parent::onMouseDown( pEvent );
if ( !mIsController || !mController || mController->isPlaying() )
{
return;
}
if ( !isMouseLocked() )
{
GuiCanvas *canvas = getRoot();
if ( canvas->getMouseLockedControl() )
{
GuiEvent event;
canvas->getMouseLockedControl()->onMouseLeave( event );
canvas->mouseUnlock( canvas->getMouseLockedControl() );
}
// Lock.
mouseLock();
}
// Calculate Time.
const Point2I hitPoint = globalToLocalCoord( pEvent.mousePoint );
const S32 time = mClamp( toTime( hitPoint.x ), 0, mController->getDuration() );
// Selection?
if ( pEvent.modifier & SI_SHIFT )
{
if ( !mSelection.Active )
{
// Selection Active.
mSelection.Active = true;
mSelection.StartTime = mController->getTime();
mSelection.EndTime = time;
}
else
{
// Update Selection.
mSelection.EndTime = time;
}
// Callback.
Con::executef( this, "onSelectionUpdate" );
}
else
{
if ( mSelection.Active )
{
// Selection Invalid.
mSelection.Active = false;
// Callback.
Con::executef( this, "onSelectionUpdate" );
}
}
// Set First Responder.
setFirstResponder();
if ( pEvent.modifier & SI_CTRL )
{
// Set Time, No Reset.
mController->setTime( time );
}
else
{
// Reset.
mController->reset( time );
}
}
void VTimeLineControl::onMouseUp( const GuiEvent &pEvent )
{
if ( isMouseLocked() )
{
// Unlock.
mouseUnlock();
}
if ( mIsController && mController && !mController->isPlaying() )
{
// Stop without Reset.
mController->stop( false );
}
}
void VTimeLineControl::onMouseDragged( const GuiEvent &pEvent )
{
Parent::onMouseDragged( pEvent );
if ( !mIsController || !mController || mController->isPlaying() )
{
return;
}
// Calculate Time.
const Point2I hitPoint = globalToLocalCoord( pEvent.mousePoint );
const S32 time = mClamp( toTime( hitPoint.x ), 0, mController->getDuration() );
if ( pEvent.modifier & SI_SHIFT )
{
if ( mSelection.Active )
{
// Update Selection.
mSelection.EndTime = time;
// Callback.
Con::executef( this, "onSelectionUpdate" );
}
}
else
{
if ( mSelection.Active )
{
// Selection Invalid.
mSelection.Active = false;
// Callback.
Con::executef( this, "onSelectionUpdate" );
}
}
if ( pEvent.modifier & SI_CTRL )
{
// Set Time, No Reset.
mController->setTime( time );
}
else if ( !mSelection.Active )
{
// Reset.
mController->reset( time );
}
}
void VTimeLineControl::onRightMouseDown( const GuiEvent &pEvent )
{
Parent::onRightMouseDown( pEvent );
if ( !mIsController || !mController || mController->isPlaying() )
{
return;
}
// Calculate Time.
const Point2I hitPoint = globalToLocalCoord( pEvent.mousePoint );
const S32 time = mClamp( toTime( hitPoint.x ), 0, mController->getDuration() );
// Set First Responder.
setFirstResponder();
if ( mSelection.Active )
{
const S32 minTime = getMin( mSelection.StartTime, mSelection.EndTime );
const S32 maxTime = getMax( mSelection.StartTime, mSelection.EndTime );
if ( time >= minTime && time <= maxTime )
{
// Callback.
onMouseEvent( "onSelectionRightClick", pEvent );
// Don't Update Time.
return;
}
else
{
if ( mSelection.Active )
{
// Selection Invalid.
mSelection.Active = false;
// Callback.
Con::executef( this, "onSelectionUpdate" );
}
}
}
// Reset.
mController->reset( time );
}
void VTimeLineControl::onMouseEvent( const char *pEventName, const GuiEvent &pEvent )
{
// Argument Buffers.
char argBuffer[3][32];
// Format Event-Position Buffer.
dSprintf( argBuffer[0], 32, "%d %d", pEvent.mousePoint.x, pEvent.mousePoint.y );
// Format Event-Modifier Buffer.
dSprintf( argBuffer[1], 32, "%d", pEvent.modifier );
// Format Mouse-Click Count Buffer.
dSprintf( argBuffer[2], 32, "%d", pEvent.mouseClickCount );
// Call Scripts.
Con::executef( this, pEventName, argBuffer[0], argBuffer[1], argBuffer[2] );
}
//-----------------------------------------------------------------------------
//
// Render Methods.
//
//-----------------------------------------------------------------------------
void VTimeLineControl::onPreRender( void )
{
setUpdate();
}
void VTimeLineControl::onRender( Point2I offset, const RectI &updateRect )
{
if ( !mController )
{
// Default Render.
Parent::onRender( offset, updateRect );
// Quit.
return;
}
// Render Properties.
const S32 tickOffset = toPoint( 0 );
const S32 timeLineWidth = toPoint( mController->getDuration() ) - tickOffset;
const F32 tickStep = 0.5f;
const S32 tickInterval = ( mIsController ) ? getWidth() : timeLineWidth;
const S32 tickIntervalCount = ( S32 )mFloor( tickInterval / ( gUnitsPerSec * tickStep ) ) + 1;
// Tick Render Proeprties.
const Point2I tickExtent( 0, getHeight() - 1 );
// Text Render Properties.
const Point2I textExtent( gUnitsPerSec, mProfile->mFontSize );
const Point2I textOffset( 4, -mProfile->mFontSize );
// Render Border.
GFX->getDrawUtil()->drawRectFill( RectI( offset + Point2I( tickOffset + 1, 1 ), Point2I( timeLineWidth - 1, getHeight() - 1 ) ), mProfile->mFillColorHL );
// Font Color.
GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor );
for ( S32 i = 0; i < tickIntervalCount; i++ )
{
// Tick Position.
const Point2I tickPosition = offset + Point2I( tickOffset + i * ( gUnitsPerSec * tickStep ), 0 );
// Line Color.
const ColorI lineColor = ( ( i % 2 ) ) ? mProfile->mBorderColorHL : mProfile->mBorderColor;
// Draw Line.
GFX->getDrawUtil()->drawLine( tickPosition, tickPosition + tickExtent, lineColor );
if ( mIsController )
{
// Render Times.
renderJustifiedText( tickPosition + tickExtent + textOffset, textExtent, avar( "%.2f", ( F32 )( i * tickStep ) ) );
}
}
// Render Children
renderChildControls( offset, updateRect );
if ( mSelection.Active )
{
// Selection Width.
const S32 selectionWidth = mCeil( mAbs( toPoint( mSelection.EndTime ) - toPoint( mSelection.StartTime ) ) );
// Selection Position.
const S32 selectionPositionX = toPoint( getMin( mSelection.StartTime, mSelection.EndTime ) );
// Selection Properties.
const Point2I selectionExtent( selectionWidth, getHeight() );
const Point2I selectionPosition = offset + Point2I( selectionPositionX, 0 );
// Render Time Cue.
GFX->getDrawUtil()->drawRectFill( RectI( selectionPosition, selectionExtent ), ColorI( 0, 0, 0, 128 ) );
if ( mIsController )
{
// Buffer.
char buffer[2][128];
dSprintf( buffer[0], 128, "%.2f", ( F32 )( mSelection.StartTime / 1000.f ) );
dSprintf( buffer[1], 128, "%.2f", ( F32 )( mSelection.EndTime / 1000.f ) );
if ( mSelection.StartTime < mSelection.EndTime )
{
// Fetch Width.
const S32 textWidth = mProfile->mFont->getStrWidth( buffer[0] );
// Text Position.
const Point2I startText = Point2I( getMax( ( S32 )( selectionPosition.x - ( textWidth + 2 ) ), updateRect.point.x + 4 ), selectionPosition.y + 2 );
const Point2I endText = Point2I( getMin( ( S32 )( selectionPosition.x + selectionWidth + 4 ), updateRect.point.x + updateRect.extent.x - ( textWidth + 2 ) ), selectionPosition.y + 2 );
// Render Time Text.
renderJustifiedText( startText, textExtent, buffer[0] );
renderJustifiedText( endText, textExtent, buffer[1] );
}
else
{
// Fetch Width.
const S32 textWidth = mProfile->mFont->getStrWidth( buffer[1] );
// Text Position.
const Point2I startText = Point2I( getMax( ( S32 )( selectionPosition.x - ( textWidth + 2 ) ), updateRect.point.x + 4 ), selectionPosition.y + 2 );
const Point2I endText = Point2I( getMin( ( S32 )( selectionPosition.x + selectionWidth + 4 ), updateRect.point.x + updateRect.extent.x - ( textWidth + 2 ) ), selectionPosition.y + 2 );
// Render Time Text.
renderJustifiedText( startText, textExtent, buffer[1] );
renderJustifiedText( endText, textExtent, buffer[0] );
}
}
}
if ( mController && !mSelection.Active )
{
// Time Cue Properties.
const Point2I timeCueExtent( ( mIsController ) ? 4 : 2, getHeight() );
const Point2I timeCuePosition = offset + Point2I( toPoint( mController->getTime() ) - ( timeCueExtent.x / 2 ), 0 );
// Render Time Cue.
GFX->getDrawUtil()->drawRectFill( RectI( timeCuePosition, timeCueExtent ), ColorI( 0,0,0,128 ) );
if ( mIsController )
{
// Buffer.
char buffer[128];
dSprintf( buffer, 128, "%.2f", ( F32 )( mController->getTime() / 1000.f ) );
// Fetch Width.
const S32 textWidth = mProfile->mFont->getStrWidth( buffer );
// Text Position.
const Point2I textPosition( getMin( getMax( timeCuePosition.x + 6, updateRect.point.x + 4 ), updateRect.point.x + updateRect.extent.x - ( textWidth + 2 ) ), timeCuePosition.y + 2 );
// Render Time Text.
renderJustifiedText( textPosition, textExtent, buffer );
}
}
}
//-----------------------------------------------------------------------------
//
// Console Methods.
//
//-----------------------------------------------------------------------------
DefineEngineMethod( VTimeLineControl, toPoint, S32, (S32 time), (0), "( pTime )" )
{
return object->toPoint(time);
}
S32 VTimeLineControl::toTime( const S32 &pPoint )
{
return ( ( S32 )( 1000.f * ( F32 )pPoint / gUnitsPerSec ) - mDurationOffset );
}
DefineEngineMethod( VTimeLineControl, toTime, S32, (S32 point), (0), "( pPoint )" )
{
return object->toTime(point);
}
S32 VTimeLineControl::toPoint( const S32 &pTime )
{
return ( S32 )( gUnitsPerSec * ( ( F32 )( pTime + mDurationOffset ) / 1000.f ) );
}
DefineEngineMethod( VTimeLineControl, getSelection, const char *, (),, "( )" )
{
const S32 minTime = getMin( object->mSelection.StartTime, object->mSelection.EndTime );
const S32 maxTime = getMax( object->mSelection.StartTime, object->mSelection.EndTime );
// Fetch Return Buffer.
char *retBuffer = Con::getReturnBuffer( 256 );
// Write.
dSprintf( retBuffer, 256, "%d %d %d", object->mSelection.Active, minTime, maxTime - minTime );
// Return.
return retBuffer;
}
DefineEngineMethod( VTimeLineControl, setSelection, void, (bool active, S32 time, S32 duration), (true, -1, 1), "( pActive, [pTime, pDuration] )" )
{
object->mSelection.Active = active;
if (time != -1)
{
object->mSelection.StartTime = time;
object->mSelection.EndTime = object->mSelection.StartTime + duration;
}
}
DefineEngineMethod( VTimeLineControl, updateDuration, void, (),, "( )" )
{
object->updateDuration();
}
void VTimeLineControl::updateDuration( void )
{
if ( !mController )
{
// No Controller.
return;
}
// Add 500ms.
const S32 length = toPoint( mController->getDuration() + 500 );
// Set Min Extent.
setMinExtent( Point2I( length, getHeight() ) );
if ( getWidth() < length )
{
// Conform to Min Extent.
setExtent( length, getHeight() );
}
}

View file

@ -0,0 +1,91 @@
//-----------------------------------------------------------------------------
// Verve
// Copyright (C) 2014 - Violent Tulip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _VT_VTIMELINECONTROL_H_
#define _VT_VTIMELINECONTROL_H_
#ifndef _GUICONTROL_H_
#include "gui/core/guiControl.h"
#endif
#ifndef _VT_VCONTROLLER_H_
#include "Verve/Core/VController.h"
#endif
//-----------------------------------------------------------------------------
class VTimeLineControl : public GuiControl
{
typedef GuiControl Parent;
public:
struct sSelection
{
bool Active;
S32 StartTime;
S32 EndTime;
};
bool mIsController;
VController *mController;
S32 mDurationOffset;
sSelection mSelection;
public:
VTimeLineControl( void );
static void initPersistFields( void );
// Mouse.
virtual void onMouseDown( const GuiEvent &pEvent );
virtual void onMouseUp( const GuiEvent &pEvent );
virtual void onMouseDragged( const GuiEvent &pEvent );
virtual void onRightMouseDown( const GuiEvent &pEvent );
void onMouseEvent( const char *pEventName, const GuiEvent &pEvent );
// Rendering.
void onPreRender( void );
void onRender( Point2I offset, const RectI &updateRect );
// Console Declaration.
DECLARE_CONOBJECT( VTimeLineControl );
public:
S32 toTime( const S32 &pPoint );
S32 toPoint( const S32 &pTime );
void updateDuration( void );
};
//-----------------------------------------------------------------------------
#endif // _VT_VTIMELINECONTROL_H_