Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/Button.h"
@@ -13,54 +12,53 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( Button )
GWEN_CONTROL_CONSTRUCTOR(Button)
{
m_Image = NULL;
m_bDepressed = false;
m_bCenterImage = false;
SetSize( 100, 20 );
SetMouseInputEnabled( true );
SetIsToggle( false );
SetAlignment( Gwen::Pos::Center );
SetTextPadding( Padding( 3, 0, 3, 0 ) );
SetSize(100, 20);
SetMouseInputEnabled(true);
SetIsToggle(false);
SetAlignment(Gwen::Pos::Center);
SetTextPadding(Padding(3, 0, 3, 0));
m_bToggleStatus = false;
SetKeyboardInputEnabled( false );
SetTabable( false );
SetKeyboardInputEnabled(false);
SetTabable(false);
}
void Button::Render( Skin::Base* skin )
void Button::Render(Skin::Base* skin)
{
if ( ShouldDrawBackground() )
if (ShouldDrawBackground())
{
bool bDrawDepressed = IsDepressed() && IsHovered();
if ( IsToggle() ) bDrawDepressed = bDrawDepressed || GetToggleState();
if (IsToggle()) bDrawDepressed = bDrawDepressed || GetToggleState();
bool bDrawHovered = IsHovered() && ShouldDrawHover();
skin->DrawButton( this, bDrawDepressed, bDrawHovered );
skin->DrawButton(this, bDrawDepressed, bDrawHovered);
}
}
void Button::OnMouseClickLeft( int /*x*/, int /*y*/, bool bDown )
void Button::OnMouseClickLeft(int /*x*/, int /*y*/, bool bDown)
{
if ( bDown )
if (bDown)
{
m_bDepressed = true;
Gwen::MouseFocus = this;
onDown.Call( this );
onDown.Call(this);
}
else
{
if ( IsHovered() && m_bDepressed )
if (IsHovered() && m_bDepressed)
{
OnPress();
}
m_bDepressed = false;
Gwen::MouseFocus = NULL;
onUp.Call( this );
onUp.Call(this);
}
Redraw();
@@ -68,60 +66,59 @@ void Button::OnMouseClickLeft( int /*x*/, int /*y*/, bool bDown )
void Button::OnPress()
{
if ( IsToggle() )
if (IsToggle())
{
SetToggleState( !GetToggleState() );
SetToggleState(!GetToggleState());
}
onPress.Call( this );
onPress.Call(this);
}
void Button::SetImage( const TextObject& strName, bool bCenter )
void Button::SetImage(const TextObject& strName, bool bCenter)
{
if ( strName.GetUnicode() == L"" )
if (strName.GetUnicode() == L"")
{
if ( m_Image )
if (m_Image)
{
delete m_Image;
m_Image= NULL;
m_Image = NULL;
}
return;
}
if ( !m_Image )
if (!m_Image)
{
m_Image = new ImagePanel( this );
m_Image = new ImagePanel(this);
}
m_Image->SetImage( strName );
m_Image->SetImage(strName);
m_Image->SizeToContents();
m_Image->SetPos( m_Padding.left, 2 );
m_Image->SetPos(m_Padding.left, 2);
m_bCenterImage = bCenter;
int IdealTextPadding = m_Image->Right() + m_Padding.left + 4;
if ( m_rTextPadding.left < IdealTextPadding )
if (m_rTextPadding.left < IdealTextPadding)
{
m_rTextPadding.left = IdealTextPadding;
}
}
void Button::SetToggleState( bool b )
{
if ( m_bToggleStatus == b ) return;
void Button::SetToggleState(bool b)
{
if (m_bToggleStatus == b) return;
m_bToggleStatus = b;
onToggle.Call( this );
onToggle.Call(this);
if ( m_bToggleStatus )
if (m_bToggleStatus)
{
onToggleOn.Call( this );
onToggleOn.Call(this);
}
else
{
onToggleOff.Call( this );
onToggleOff.Call(this);
}
}
@@ -129,19 +126,19 @@ void Button::SizeToContents()
{
BaseClass::SizeToContents();
if ( m_Image )
if (m_Image)
{
int height = m_Image->Height() + 4;
if ( Height() < height )
if (Height() < height)
{
SetHeight( height );
SetHeight(height);
}
}
}
bool Button::OnKeySpace( bool bDown )
bool Button::OnKeySpace(bool bDown)
{
OnMouseClickLeft( 0, 0, bDown );
OnMouseClickLeft(0, 0, bDown);
return true;
}
@@ -150,20 +147,20 @@ void Button::AcceleratePressed()
OnPress();
}
void Button::Layout( Skin::Base* pSkin )
{
BaseClass::Layout( pSkin );
if ( m_Image )
{
Gwen::Align::CenterVertically( m_Image );
void Button::Layout(Skin::Base* pSkin)
{
BaseClass::Layout(pSkin);
if (m_Image)
{
Gwen::Align::CenterVertically(m_Image);
if ( m_bCenterImage )
Gwen::Align::CenterHorizontally( m_Image );
if (m_bCenterImage)
Gwen::Align::CenterHorizontally(m_Image);
}
}
void Button::OnMouseDoubleClickLeft( int x, int y )
{
OnMouseClickLeft( x, y, true );
onDoubleClick.Call( this );
void Button::OnMouseDoubleClickLeft(int x, int y)
{
OnMouseClickLeft(x, y, true);
onDoubleClick.Call(this);
};

View File

@@ -12,79 +12,75 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/Label.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class ImagePanel;
class GWEN_EXPORT Button : public Label
{
public:
GWEN_CONTROL(Button, Label);
virtual void Render(Skin::Base* skin);
virtual void OnMouseClickLeft(int x, int y, bool bDown);
virtual void OnMouseDoubleClickLeft(int x, int y);
virtual bool OnKeySpace(bool bDown);
virtual void OnPress();
virtual void AcceleratePressed();
virtual bool IsDepressed() const { return m_bDepressed; }
//
// Buttons can be toggle type, which means that it is
// toggled on and off. Its toggle status is in IsDepressed.
//
virtual void SetIsToggle(bool b) { m_bToggle = b; }
virtual bool IsToggle() const { return m_bToggle; }
virtual bool GetToggleState() const { return m_bToggleStatus; }
virtual void SetToggleState(bool b);
virtual void Toggle() { SetToggleState(!GetToggleState()); }
virtual void SetImage(const TextObject& strName, bool bCenter = false);
// You can use this to trigger OnPress directly from other controls using GWEN_CALL_EX
virtual void ReceiveEventPress(Base* /*pControl*/)
{
class ImagePanel;
class GWEN_EXPORT Button : public Label
{
public:
GWEN_CONTROL( Button, Label );
virtual void Render( Skin::Base* skin );
virtual void OnMouseClickLeft( int x, int y, bool bDown );
virtual void OnMouseDoubleClickLeft( int x, int y );
virtual bool OnKeySpace( bool bDown );
virtual void OnPress();
virtual void AcceleratePressed();
virtual bool IsDepressed() const { return m_bDepressed; }
//
// Buttons can be toggle type, which means that it is
// toggled on and off. Its toggle status is in IsDepressed.
//
virtual void SetIsToggle( bool b ){ m_bToggle = b; }
virtual bool IsToggle() const { return m_bToggle; }
virtual bool GetToggleState() const { return m_bToggleStatus; }
virtual void SetToggleState( bool b );
virtual void Toggle(){ SetToggleState( !GetToggleState() ); }
virtual void SetImage( const TextObject& strName, bool bCenter = false );
// You can use this to trigger OnPress directly from other controls using GWEN_CALL_EX
virtual void ReceiveEventPress( Base* /*pControl*/ )
{
OnPress();
}
virtual void SizeToContents();
virtual void Layout( Skin::Base* pSkin );
virtual bool OnKeyReturn(bool bDown)
{
onKeyboardReturn.Call(this);
return true;
}
public:
Gwen::Event::Caller onPress;
Gwen::Event::Caller onDown;
Gwen::Event::Caller onUp;
Gwen::Event::Caller onDoubleClick;
Gwen::Event::Caller onKeyboardReturn;
Gwen::Event::Caller onToggle;
Gwen::Event::Caller onToggleOn;
Gwen::Event::Caller onToggleOff;
protected:
ImagePanel* m_Image;
bool m_bDepressed;
bool m_bToggle;
bool m_bToggleStatus;
bool m_bCenterImage;
};
OnPress();
}
}
virtual void SizeToContents();
virtual void Layout(Skin::Base* pSkin);
virtual bool OnKeyReturn(bool bDown)
{
onKeyboardReturn.Call(this);
return true;
}
public:
Gwen::Event::Caller onPress;
Gwen::Event::Caller onDown;
Gwen::Event::Caller onUp;
Gwen::Event::Caller onDoubleClick;
Gwen::Event::Caller onKeyboardReturn;
Gwen::Event::Caller onToggle;
Gwen::Event::Caller onToggleOn;
Gwen::Event::Caller onToggleOff;
protected:
ImagePanel* m_Image;
bool m_bDepressed;
bool m_bToggle;
bool m_bToggleStatus;
bool m_bCenterImage;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Canvas.h"
#include "Gwen/Skin.h"
@@ -18,14 +17,13 @@
using namespace Gwen::Controls;
Canvas::Canvas( Gwen::Skin::Base* pSkin ) : BaseClass( NULL ), m_bAnyDelete( false ),m_fScale(-1)
Canvas::Canvas(Gwen::Skin::Base* pSkin) : BaseClass(NULL), m_bAnyDelete(false), m_fScale(-1)
{
SetBounds( 0, 0, 10000, 10000 );
SetSkin( pSkin );
SetScale( 1.0f );
SetBackgroundColor( Color( 255, 255, 255, 255 ) );
SetDrawBackground( false );
SetBounds(0, 0, 10000, 10000);
SetSkin(pSkin);
SetScale(1.0f);
SetBackgroundColor(Color(255, 255, 255, 255));
SetDrawBackground(false);
}
void Canvas::RenderCanvas()
@@ -35,51 +33,48 @@ void Canvas::RenderCanvas()
Gwen::Renderer::Base* render = m_Skin->GetRender();
render->Begin();
RecurseLayout( m_Skin );
RecurseLayout(m_Skin);
render->SetClipRegion( GetBounds() );
render->SetRenderOffset( Gwen::Point( 0, 0 ) );
render->SetScale( Scale() );
render->SetClipRegion(GetBounds());
render->SetRenderOffset(Gwen::Point(0, 0));
render->SetScale(Scale());
if ( m_bDrawBackground )
{
render->SetDrawColor( m_BackgroundColor );
render->DrawFilledRect( GetRenderBounds() );
}
if (m_bDrawBackground)
{
render->SetDrawColor(m_BackgroundColor);
render->DrawFilledRect(GetRenderBounds());
}
DoRender( m_Skin );
DoRender(m_Skin);
DragAndDrop::RenderOverlay( this, m_Skin );
DragAndDrop::RenderOverlay(this, m_Skin);
ToolTip::RenderToolTip( m_Skin );
ToolTip::RenderToolTip(m_Skin);
render->EndClip();
render->EndClip();
render->End();
ProcessDelayedDeletes();
}
void Canvas::Render( Gwen::Skin::Base* /*pRender*/ )
void Canvas::Render(Gwen::Skin::Base* /*pRender*/)
{
m_bNeedsRedraw = false;
}
void Canvas::OnBoundsChanged( Gwen::Rect oldBounds )
void Canvas::OnBoundsChanged(Gwen::Rect oldBounds)
{
BaseClass::OnBoundsChanged( oldBounds );
InvalidateChildren( true );
BaseClass::OnBoundsChanged(oldBounds);
InvalidateChildren(true);
}
void Canvas::DoThink()
{
if ( Hidden() ) return;
if (Hidden()) return;
#ifndef GWEN_NO_ANIMATION
#ifndef GWEN_NO_ANIMATION
Gwen::Anim::Think();
#endif
#endif
// Reset tabbing
{
@@ -89,48 +84,47 @@ void Canvas::DoThink()
ProcessDelayedDeletes();
// Check has focus etc..
RecurseLayout( m_Skin );
RecurseLayout(m_Skin);
// If we didn't have a next tab, cycle to the start.
if ( NextTab == NULL )
if (NextTab == NULL)
NextTab = FirstTab;
Gwen::Input::OnCanvasThink( this );
Gwen::Input::OnCanvasThink(this);
}
void Canvas::SetScale( float f )
{
if ( m_fScale == f ) return;
void Canvas::SetScale(float f)
{
if (m_fScale == f) return;
m_fScale = f;
if ( m_Skin && m_Skin->GetRender() )
m_Skin->GetRender()->SetScale( m_fScale );
if (m_Skin && m_Skin->GetRender())
m_Skin->GetRender()->SetScale(m_fScale);
OnScaleChanged();
Redraw();
}
void Canvas::AddDelayedDelete( Gwen::Controls::Base* pControl )
void Canvas::AddDelayedDelete(Gwen::Controls::Base* pControl)
{
if ( !m_bAnyDelete || m_DeleteSet.find( pControl ) == m_DeleteSet.end() )
if (!m_bAnyDelete || m_DeleteSet.find(pControl) == m_DeleteSet.end())
{
m_bAnyDelete = true;
m_DeleteSet.insert( pControl );
m_DeleteList.push_back( pControl );
m_DeleteSet.insert(pControl);
m_DeleteList.push_back(pControl);
}
}
void Canvas::PreDelete( Controls::Base * pControl )
void Canvas::PreDelete(Controls::Base* pControl)
{
if ( m_bAnyDelete )
if (m_bAnyDelete)
{
std::set< Controls::Base * >::iterator itFind;
if ( ( itFind = m_DeleteSet.find( pControl ) ) != m_DeleteSet.end() )
std::set<Controls::Base*>::iterator itFind;
if ((itFind = m_DeleteSet.find(pControl)) != m_DeleteSet.end())
{
m_DeleteList.remove( pControl );
m_DeleteSet.erase( pControl );
m_DeleteList.remove(pControl);
m_DeleteSet.erase(pControl);
m_bAnyDelete = !m_DeleteSet.empty();
}
}
@@ -138,7 +132,7 @@ void Canvas::PreDelete( Controls::Base * pControl )
void Canvas::ProcessDelayedDeletes()
{
while( m_bAnyDelete )
while (m_bAnyDelete)
{
m_bAnyDelete = false;
@@ -147,7 +141,7 @@ void Canvas::ProcessDelayedDeletes()
m_DeleteList.clear();
m_DeleteSet.clear();
for ( Gwen::Controls::Base::List::iterator it = deleteList.begin(); it != deleteList.end(); ++it )
for (Gwen::Controls::Base::List::iterator it = deleteList.begin(); it != deleteList.end(); ++it)
{
Gwen::Controls::Base* pControl = *it;
delete pControl;
@@ -158,76 +152,76 @@ void Canvas::ProcessDelayedDeletes()
void Canvas::Release()
{
Base::List::iterator iter = Children.begin();
while ( iter != Children.end() )
while (iter != Children.end())
{
Base* pChild = *iter;
iter = Children.erase( iter );
iter = Children.erase(iter);
delete pChild;
}
delete this;
}
bool Canvas::InputMouseMoved( int x, int y, int deltaX, int deltaY )
bool Canvas::InputMouseMoved(int x, int y, int deltaX, int deltaY)
{
if ( Hidden() ) return false;
if (Hidden()) return false;
// Todo: Handle scaling here..
//float fScale = 1.0f / Scale();
Gwen::Input::OnMouseMoved( this, x, y, deltaX, deltaY );
Gwen::Input::OnMouseMoved(this, x, y, deltaX, deltaY);
if ( !Gwen::HoveredControl ) return false;
if ( Gwen::HoveredControl == this ) return false;
if ( Gwen::HoveredControl->GetCanvas() != this ) return false;
if (!Gwen::HoveredControl) return false;
if (Gwen::HoveredControl == this) return false;
if (Gwen::HoveredControl->GetCanvas() != this) return false;
Gwen::HoveredControl->OnMouseMoved( x, y, deltaX, deltaY );
Gwen::HoveredControl->OnMouseMoved(x, y, deltaX, deltaY);
Gwen::HoveredControl->UpdateCursor();
DragAndDrop::OnMouseMoved( Gwen::HoveredControl, x, y );
DragAndDrop::OnMouseMoved(Gwen::HoveredControl, x, y);
return true;
}
bool Canvas::InputMouseButton( int iButton, bool bDown )
bool Canvas::InputMouseButton(int iButton, bool bDown)
{
if ( Hidden() ) return false;
if (Hidden()) return false;
return Gwen::Input::OnMouseClicked( this, iButton, bDown );
return Gwen::Input::OnMouseClicked(this, iButton, bDown);
}
bool Canvas::InputKey( int iKey, bool bDown )
bool Canvas::InputKey(int iKey, bool bDown)
{
if ( Hidden() ) return false;
if ( iKey <= Gwen::Key::Invalid ) return false;
if ( iKey >= Gwen::Key::Count ) return false;
if (Hidden()) return false;
if (iKey <= Gwen::Key::Invalid) return false;
if (iKey >= Gwen::Key::Count) return false;
return Gwen::Input::OnKeyEvent( this, iKey, bDown );
return Gwen::Input::OnKeyEvent(this, iKey, bDown);
}
bool Canvas::InputCharacter( Gwen::UnicodeChar chr )
bool Canvas::InputCharacter(Gwen::UnicodeChar chr)
{
if ( Hidden() ) return false;
if ( !iswprint( chr ) ) return false;
if (Hidden()) return false;
if (!iswprint(chr)) return false;
//Handle Accelerators
if ( Gwen::Input::HandleAccelerator( this, chr ) )
if (Gwen::Input::HandleAccelerator(this, chr))
return true;
//Handle characters
if ( !Gwen::KeyboardFocus ) return false;
if ( Gwen::KeyboardFocus->GetCanvas() != this ) return false;
if ( !Gwen::KeyboardFocus->Visible() ) return false;
if ( Gwen::Input::IsControlDown() ) return false;
if (!Gwen::KeyboardFocus) return false;
if (Gwen::KeyboardFocus->GetCanvas() != this) return false;
if (!Gwen::KeyboardFocus->Visible()) return false;
if (Gwen::Input::IsControlDown()) return false;
return KeyboardFocus->OnChar( chr );
return KeyboardFocus->OnChar(chr);
}
bool Canvas::InputMouseWheel( int val )
bool Canvas::InputMouseWheel(int val)
{
if ( Hidden() ) return false;
if ( !Gwen::HoveredControl ) return false;
if ( Gwen::HoveredControl == this ) return false;
if ( Gwen::HoveredControl->GetCanvas() != this ) return false;
if (Hidden()) return false;
if (!Gwen::HoveredControl) return false;
if (Gwen::HoveredControl == this) return false;
if (Gwen::HoveredControl->GetCanvas() != this) return false;
return Gwen::HoveredControl->OnMouseWheeled( val );
return Gwen::HoveredControl->OnMouseWheeled(val);
}

View File

@@ -12,96 +12,92 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/InputHandler.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT Canvas : public Base
{
public:
namespace Controls
{
class GWEN_EXPORT Canvas : public Base
{
public:
typedef Controls::Base BaseClass;
typedef Controls::Base BaseClass;
Canvas(Skin::Base* pSkin);
Canvas( Skin::Base* pSkin );
//
// For additional initialization
// (which is sometimes not appropriate in the constructor)
//
virtual void Initialize(){};
//
// For additional initialization
// (which is sometimes not appropriate in the constructor)
//
virtual void Initialize(){};
//
// You should call this to render your canvas.
//
virtual void RenderCanvas();
//
// You should call this to render your canvas.
//
virtual void RenderCanvas();
//
// Call this whenever you want to process input. This
// is usually once a frame..
//
virtual void DoThink();
//
// Call this whenever you want to process input. This
// is usually once a frame..
//
virtual void DoThink();
//
// In most situations you will be rendering the canvas
// every frame. But in some situations you will only want
// to render when there have been changes. You can do this
// by checking NeedsRedraw().
//
virtual bool NeedsRedraw() { return m_bNeedsRedraw; }
virtual void Redraw() { m_bNeedsRedraw = true; }
//
// In most situations you will be rendering the canvas
// every frame. But in some situations you will only want
// to render when there have been changes. You can do this
// by checking NeedsRedraw().
//
virtual bool NeedsRedraw(){ return m_bNeedsRedraw; }
virtual void Redraw(){ m_bNeedsRedraw = true; }
// Internal. Do not call directly.
virtual void Render(Skin::Base* pRender);
// Internal. Do not call directly.
virtual void Render( Skin::Base* pRender );
// Childpanels call parent->GetCanvas() until they get to
// this top level function.
virtual Controls::Canvas* GetCanvas() { return this; }
// Childpanels call parent->GetCanvas() until they get to
// this top level function.
virtual Controls::Canvas* GetCanvas(){ return this; }
virtual void SetScale(float f);
virtual float Scale() const { return m_fScale; }
virtual void SetScale( float f );
virtual float Scale() const { return m_fScale; }
virtual void OnBoundsChanged(Gwen::Rect oldBounds);
virtual void OnBoundsChanged( Gwen::Rect oldBounds );
//
// Call this to delete the canvas, and its children
// in the right order.
//
virtual void Release();
//
// Call this to delete the canvas, and its children
// in the right order.
//
virtual void Release();
// Delayed deletes
virtual void AddDelayedDelete(Controls::Base* pControl);
virtual void ProcessDelayedDeletes();
// Delayed deletes
virtual void AddDelayedDelete( Controls::Base* pControl );
virtual void ProcessDelayedDeletes();
Controls::Base* FirstTab;
Controls::Base* NextTab;
Controls::Base* FirstTab;
Controls::Base* NextTab;
// Input
virtual bool InputMouseMoved(int x, int y, int deltaX, int deltaY);
virtual bool InputMouseButton(int iButton, bool bDown);
virtual bool InputKey(int iKey, bool bDown);
virtual bool InputCharacter(Gwen::UnicodeChar chr);
virtual bool InputMouseWheel(int val);
// Input
virtual bool InputMouseMoved( int x, int y, int deltaX, int deltaY );
virtual bool InputMouseButton( int iButton, bool bDown );
virtual bool InputKey( int iKey, bool bDown );
virtual bool InputCharacter( Gwen::UnicodeChar chr );
virtual bool InputMouseWheel( int val );
// Background
virtual void SetBackgroundColor(const Gwen::Color& color) { m_BackgroundColor = color; }
virtual void SetDrawBackground(bool bShouldDraw) { m_bDrawBackground = bShouldDraw; }
// Background
virtual void SetBackgroundColor( const Gwen::Color& color ){ m_BackgroundColor = color; }
virtual void SetDrawBackground( bool bShouldDraw ){ m_bDrawBackground = bShouldDraw; }
private:
bool m_bNeedsRedraw;
bool m_bAnyDelete;
float m_fScale;
private:
Controls::Base::List m_DeleteList;
std::set<Controls::Base*> m_DeleteSet;
friend class Controls::Base;
void PreDelete(Controls::Base*);
bool m_bNeedsRedraw;
bool m_bAnyDelete;
float m_fScale;
Controls::Base::List m_DeleteList;
std::set< Controls::Base* > m_DeleteSet;
friend class Controls::Base;
void PreDelete( Controls::Base * );
bool m_bDrawBackground;
Gwen::Color m_BackgroundColor;
};
}
}
bool m_bDrawBackground;
Gwen::Color m_BackgroundColor;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,31 +4,27 @@
See license in Gwen.h
*/
#include "Gwen/Controls/CheckBox.h"
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( CheckBox )
GWEN_CONTROL_CONSTRUCTOR(CheckBox)
{
SetSize( 13, 13 );
SetSize(13, 13);
m_bChecked = true;
Toggle();
}
void CheckBox::Render( Skin::Base* skin )
void CheckBox::Render(Skin::Base* skin)
{
skin->DrawCheckBox( this, m_bChecked, IsDepressed() );
skin->DrawCheckBox(this, m_bChecked, IsDepressed());
}
void CheckBox::OnPress()
{
if ( IsChecked() && !AllowUncheck() )
if (IsChecked() && !AllowUncheck())
return;
Toggle();
@@ -36,22 +32,22 @@ void CheckBox::OnPress()
void CheckBox::OnCheckStatusChanged()
{
if ( IsChecked() )
if (IsChecked())
{
onChecked.Call( this );
onChecked.Call(this);
}
else
{
onUnChecked.Call( this );
onUnChecked.Call(this);
}
onCheckChanged.Call( this );
onCheckChanged.Call(this);
}
void CheckBox::SetChecked( bool bChecked )
{
if ( m_bChecked == bChecked ) return;
void CheckBox::SetChecked(bool bChecked)
{
if (m_bChecked == bChecked) return;
m_bChecked = bChecked;
OnCheckStatusChanged();
m_bChecked = bChecked;
OnCheckStatusChanged();
}

View File

@@ -15,68 +15,67 @@
#include "Gwen/Controls/Symbol.h"
#include "Gwen/Controls/LabelClickable.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT CheckBox : public Button
{
public:
GWEN_CONTROL(CheckBox, Button);
virtual void Render(Skin::Base* skin);
virtual void OnPress();
virtual void SetChecked(bool Checked);
virtual void Toggle() { SetChecked(!IsChecked()); }
virtual bool IsChecked() { return m_bChecked; }
Gwen::Event::Caller onChecked;
Gwen::Event::Caller onUnChecked;
Gwen::Event::Caller onCheckChanged;
private:
// For derived controls
virtual bool AllowUncheck() { return true; }
void OnCheckStatusChanged();
bool m_bChecked;
};
class GWEN_EXPORT CheckBoxWithLabel : public Base
{
public:
GWEN_CONTROL_INLINE(CheckBoxWithLabel, Base)
{
SetSize(200, 19);
class GWEN_EXPORT CheckBox : public Button
{
public:
m_Checkbox = new CheckBox(this);
m_Checkbox->Dock(Pos::Left);
m_Checkbox->SetMargin(Margin(0, 3, 3, 3));
m_Checkbox->SetTabable(false);
GWEN_CONTROL( CheckBox, Button );
m_Label = new LabelClickable(this);
m_Label->Dock(Pos::Fill);
m_Label->onPress.Add(m_Checkbox, &CheckBox::ReceiveEventPress);
m_Label->SetTabable(false);
virtual void Render( Skin::Base* skin );
virtual void OnPress();
virtual void SetChecked( bool Checked );
virtual void Toggle() { SetChecked( !IsChecked() ); }
virtual bool IsChecked() { return m_bChecked; }
Gwen::Event::Caller onChecked;
Gwen::Event::Caller onUnChecked;
Gwen::Event::Caller onCheckChanged;
private:
// For derived controls
virtual bool AllowUncheck(){ return true; }
void OnCheckStatusChanged();
bool m_bChecked;
};
class GWEN_EXPORT CheckBoxWithLabel : public Base
{
public:
GWEN_CONTROL_INLINE( CheckBoxWithLabel, Base )
{
SetSize( 200, 19 );
m_Checkbox = new CheckBox( this );
m_Checkbox->Dock( Pos::Left );
m_Checkbox->SetMargin( Margin( 0, 3, 3, 3 ) );
m_Checkbox->SetTabable( false );
m_Label = new LabelClickable( this );
m_Label->Dock( Pos::Fill );
m_Label->onPress.Add( m_Checkbox, &CheckBox::ReceiveEventPress );
m_Label->SetTabable( false );
SetTabable( false );
}
virtual CheckBox* Checkbox() { return m_Checkbox; }
virtual LabelClickable* Label() { return m_Label; }
virtual bool OnKeySpace( bool bDown ) { if ( bDown ) m_Checkbox->SetChecked( !m_Checkbox->IsChecked() ); return true; }
private:
CheckBox* m_Checkbox;
LabelClickable* m_Label;
};
SetTabable(false);
}
}
virtual CheckBox* Checkbox() { return m_Checkbox; }
virtual LabelClickable* Label() { return m_Label; }
virtual bool OnKeySpace(bool bDown)
{
if (bDown) m_Checkbox->SetChecked(!m_Checkbox->IsChecked());
return true;
}
private:
CheckBox* m_Checkbox;
LabelClickable* m_Label;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Utility.h"
#include "Gwen/Controls/ColorControls.h"
@@ -12,7 +11,7 @@ using namespace Gwen;
using namespace Gwen::Controls;
//Find a place to put these...
Color HSVToColor( float h, float s, float v )
Color HSVToColor(float h, float s, float v)
{
if (h < 0.0f) h += 360.0f;
if (h > 360.0f) h -= 360.0f;
@@ -26,10 +25,10 @@ Color HSVToColor( float h, float s, float v )
{
r = g = b = v;
}
double min,max,delta,hue;
double min, max, delta, hue;
max = v;
delta = (max * s)/255.0;
delta = (max * s) / 255.0;
min = max - delta;
hue = h;
@@ -39,7 +38,7 @@ Color HSVToColor( float h, float s, float v )
if (h > 300)
{
g = (int)min;
hue = (hue - 360.0)/60.0;
hue = (hue - 360.0) / 60.0;
b = (int)((hue * delta - min) * -1);
}
else
@@ -55,13 +54,13 @@ Color HSVToColor( float h, float s, float v )
if (h < 120)
{
b = (int)min;
hue = (hue/60.0 - 2.0 ) * delta;
hue = (hue / 60.0 - 2.0) * delta;
r = (int)(min - hue);
}
else
{
r = (int)min;
hue = (hue/60 - 2.0) * delta;
hue = (hue / 60 - 2.0) * delta;
b = (int)(min + hue);
}
}
@@ -71,25 +70,25 @@ Color HSVToColor( float h, float s, float v )
if (h < 240)
{
r = (int)min;
hue = (hue/60.0 - 4.0 ) * delta;
hue = (hue / 60.0 - 4.0) * delta;
g = (int)(min - hue);
}
else
{
g = (int)min;
hue = (hue/60 - 4.0) * delta;
hue = (hue / 60 - 4.0) * delta;
r = (int)(min + hue);
}
}
return Color( r, g, b, 255);
return Color(r, g, b, 255);
}
HSV RGBtoHSV( int r, int g, int b )
HSV RGBtoHSV(int r, int g, int b)
{
double min,max,delta,temp;
min = GwenUtil_Min(r,GwenUtil_Min(g,b));
max = GwenUtil_Max(r,GwenUtil_Max(g,b));
double min, max, delta, temp;
min = GwenUtil_Min(r, GwenUtil_Min(g, b));
max = GwenUtil_Max(r, GwenUtil_Max(g, b));
delta = max - min;
HSV hsv;
@@ -100,52 +99,49 @@ HSV RGBtoHSV( int r, int g, int b )
}
else
{
temp = delta/max;
hsv.s = (int)(temp*255);
temp = delta / max;
hsv.s = (int)(temp * 255);
if (r == (int)max)
{
temp = (double)(g-b)/delta;
temp = (double)(g - b) / delta;
}
else if (g == (int)max)
{
temp = 2.0 + ((double)(b - r) / delta);
}
else
if (g == (int)max)
{
temp = 2.0 + ((double)(b-r)/delta);
}
else
{
temp = 4.0 + ((double)(r-g)/delta);
}
temp *= 60;
if (temp < 0)
{
temp+=360;
}
if (temp == 360)
{
temp = 0;
}
hsv.h = (int)temp;
{
temp = 4.0 + ((double)(r - g) / delta);
}
temp *= 60;
if (temp < 0)
{
temp += 360;
}
if (temp == 360)
{
temp = 0;
}
hsv.h = (int)temp;
}
hsv.s /= 255.0f;
hsv.v /= 255.0f;
return hsv;
}
GWEN_CONTROL_CONSTRUCTOR( ColorLerpBox )
GWEN_CONTROL_CONSTRUCTOR(ColorLerpBox)
{
SetColor( Gwen::Color(255, 128, 0, 255) );
SetSize( 128, 128 );
SetMouseInputEnabled( true );
SetColor(Gwen::Color(255, 128, 0, 255));
SetSize(128, 128);
SetMouseInputEnabled(true);
m_bDepressed = false;
}
}
//Find a place to put this? color member?
Gwen::Color LerpColor( Gwen::Color &toColor, Gwen::Color &fromColor, float amount )
Gwen::Color LerpColor(Gwen::Color& toColor, Gwen::Color& fromColor, float amount)
{
Gwen::Color colorDelta = toColor - fromColor;
@@ -159,29 +155,29 @@ Gwen::Color LerpColor( Gwen::Color &toColor, Gwen::Color &fromColor, float amoun
Gwen::Color ColorLerpBox::GetSelectedColor()
{
return GetColorAtPos( cursorPos.x, cursorPos.y );
return GetColorAtPos(cursorPos.x, cursorPos.y);
}
void ColorLerpBox::SetColor( Gwen::Color color, bool onlyHue )
void ColorLerpBox::SetColor(Gwen::Color color, bool onlyHue)
{
HSV hsv = RGBtoHSV(color.r, color.g, color.b);
m_Hue = hsv.h;
if ( !onlyHue )
if (!onlyHue)
{
cursorPos.x = hsv.s * Width();
cursorPos.y = (1 - hsv.v) * Height();
}
onSelectionChanged.Call( this );
onSelectionChanged.Call(this);
}
void ColorLerpBox::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
void ColorLerpBox::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
{
if ( m_bDepressed )
if (m_bDepressed)
{
cursorPos = CanvasPosToLocal( Gwen::Point( x, y ) );
cursorPos = CanvasPosToLocal(Gwen::Point(x, y));
//Do we have clamp?
if ( cursorPos.x < 0)
if (cursorPos.x < 0)
cursorPos.x = 0;
if (cursorPos.x > Width())
cursorPos.x = Width();
@@ -191,97 +187,14 @@ void ColorLerpBox::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
if (cursorPos.y > Height())
cursorPos.y = Height();
onSelectionChanged.Call( this );
onSelectionChanged.Call(this);
}
}
void ColorLerpBox::OnMouseClickLeft( int x, int y, bool bDown )
void ColorLerpBox::OnMouseClickLeft(int x, int y, bool bDown)
{
m_bDepressed = bDown;
if ( bDown )
Gwen::MouseFocus = this;
else
Gwen::MouseFocus = NULL;
OnMouseMoved( x, y, 0, 0);
}
Gwen::Color ColorLerpBox::GetColorAtPos( int x, int y )
{
float xPercent = ( (float)x / (float)Width() );
float yPercent = 1 - ( (float)y / (float)Height() );
Gwen::Color result = HSVToColor( m_Hue, xPercent, yPercent );
result.a = 255;
return result;
}
void ColorLerpBox::Render( Gwen::Skin::Base* skin )
{
//Is there any way to move this into skin? Not for now, no idea how we'll "actually" render these
BaseClass::Render( skin );
for ( int x = 0; x<Width(); x++)
{
for ( int y = 0; y<Height(); y++)
{
skin->GetRender()->SetDrawColor( GetColorAtPos( x, y ) );
skin->GetRender()->DrawPixel( x, y );
}
}
skin->GetRender()->SetDrawColor( Gwen::Color( 0, 0, 0, 255 ) );
skin->GetRender()->DrawLinedRect( GetRenderBounds() );
Gwen::Color selected = GetSelectedColor();
if ( (selected.r + selected.g + selected.b) / 3 < 170 )
skin->GetRender()->SetDrawColor( Gwen::Color( 255, 255, 255, 255 ) );
else
skin->GetRender()->SetDrawColor( Gwen::Color( 0, 0, 0, 255 ) );
Gwen::Rect testRect = Gwen::Rect( cursorPos.x -3, cursorPos.y -3, 6, 6);
skin->GetRender()->DrawShavedCornerRect( testRect );
}
GWEN_CONTROL_CONSTRUCTOR( ColorSlider )
{
SetSize( 32, 128 );
SetMouseInputEnabled( true );
m_bDepressed = false;
}
void ColorSlider::Render( Gwen::Skin::Base* skin )
{
//Is there any way to move this into skin? Not for now, no idea how we'll "actually" render these
int y = 0;
for ( y = 0; y < Height(); y++)
{
float yPercent = (float)y / (float)Height();
skin->GetRender()->SetDrawColor( HSVToColor( yPercent * 360, 1, 1 ) );
skin->GetRender()->DrawFilledRect( Gwen::Rect( 5, y, Width() - 10, 1 ) );
}
int drawHeight = m_iSelectedDist - 3;
//Draw our selectors
skin->GetRender()->SetDrawColor( Gwen::Color( 0, 0, 0, 255 ));
skin->GetRender()->DrawFilledRect( Gwen::Rect( 0, drawHeight + 2, Width(), 1));
skin->GetRender()->DrawFilledRect( Gwen::Rect( 0, drawHeight, 5, 5) );
skin->GetRender()->DrawFilledRect( Gwen::Rect( Width() - 5, drawHeight, 5, 5) );
skin->GetRender()->SetDrawColor( Gwen::Color( 255, 255, 255, 255 ) );
skin->GetRender()->DrawFilledRect( Gwen::Rect( 1, drawHeight + 1, 3, 3 ) );
skin->GetRender()->DrawFilledRect( Gwen::Rect( Width() - 4, drawHeight + 1, 3, 3 ) );
}
void ColorSlider::OnMouseClickLeft( int x, int y, bool bDown )
{
m_bDepressed = bDown;
if ( bDown)
if (bDown)
Gwen::MouseFocus = this;
else
Gwen::MouseFocus = NULL;
@@ -289,17 +202,95 @@ void ColorSlider::OnMouseClickLeft( int x, int y, bool bDown )
OnMouseMoved(x, y, 0, 0);
}
Gwen::Color ColorSlider::GetColorAtHeight( int y )
Gwen::Color ColorLerpBox::GetColorAtPos(int x, int y)
{
float xPercent = ((float)x / (float)Width());
float yPercent = 1 - ((float)y / (float)Height());
Gwen::Color result = HSVToColor(m_Hue, xPercent, yPercent);
result.a = 255;
return result;
}
void ColorLerpBox::Render(Gwen::Skin::Base* skin)
{
//Is there any way to move this into skin? Not for now, no idea how we'll "actually" render these
BaseClass::Render(skin);
for (int x = 0; x < Width(); x++)
{
for (int y = 0; y < Height(); y++)
{
skin->GetRender()->SetDrawColor(GetColorAtPos(x, y));
skin->GetRender()->DrawPixel(x, y);
}
}
skin->GetRender()->SetDrawColor(Gwen::Color(0, 0, 0, 255));
skin->GetRender()->DrawLinedRect(GetRenderBounds());
Gwen::Color selected = GetSelectedColor();
if ((selected.r + selected.g + selected.b) / 3 < 170)
skin->GetRender()->SetDrawColor(Gwen::Color(255, 255, 255, 255));
else
skin->GetRender()->SetDrawColor(Gwen::Color(0, 0, 0, 255));
Gwen::Rect testRect = Gwen::Rect(cursorPos.x - 3, cursorPos.y - 3, 6, 6);
skin->GetRender()->DrawShavedCornerRect(testRect);
}
GWEN_CONTROL_CONSTRUCTOR(ColorSlider)
{
SetSize(32, 128);
SetMouseInputEnabled(true);
m_bDepressed = false;
}
void ColorSlider::Render(Gwen::Skin::Base* skin)
{
//Is there any way to move this into skin? Not for now, no idea how we'll "actually" render these
int y = 0;
for (y = 0; y < Height(); y++)
{
float yPercent = (float)y / (float)Height();
skin->GetRender()->SetDrawColor(HSVToColor(yPercent * 360, 1, 1));
skin->GetRender()->DrawFilledRect(Gwen::Rect(5, y, Width() - 10, 1));
}
int drawHeight = m_iSelectedDist - 3;
//Draw our selectors
skin->GetRender()->SetDrawColor(Gwen::Color(0, 0, 0, 255));
skin->GetRender()->DrawFilledRect(Gwen::Rect(0, drawHeight + 2, Width(), 1));
skin->GetRender()->DrawFilledRect(Gwen::Rect(0, drawHeight, 5, 5));
skin->GetRender()->DrawFilledRect(Gwen::Rect(Width() - 5, drawHeight, 5, 5));
skin->GetRender()->SetDrawColor(Gwen::Color(255, 255, 255, 255));
skin->GetRender()->DrawFilledRect(Gwen::Rect(1, drawHeight + 1, 3, 3));
skin->GetRender()->DrawFilledRect(Gwen::Rect(Width() - 4, drawHeight + 1, 3, 3));
}
void ColorSlider::OnMouseClickLeft(int x, int y, bool bDown)
{
m_bDepressed = bDown;
if (bDown)
Gwen::MouseFocus = this;
else
Gwen::MouseFocus = NULL;
OnMouseMoved(x, y, 0, 0);
}
Gwen::Color ColorSlider::GetColorAtHeight(int y)
{
float yPercent = (float)y / (float)Height();
return HSVToColor( yPercent * 360, 1, 1);
return HSVToColor(yPercent * 360, 1, 1);
}
void ColorSlider::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
void ColorSlider::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
{
if ( m_bDepressed )
if (m_bDepressed)
{
Gwen::Point cursorPos = CanvasPosToLocal( Gwen::Point( x, y ) );
Gwen::Point cursorPos = CanvasPosToLocal(Gwen::Point(x, y));
if (cursorPos.y < 0)
cursorPos.y = 0;
@@ -307,20 +298,20 @@ void ColorSlider::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
cursorPos.y = Height();
m_iSelectedDist = cursorPos.y;
onSelectionChanged.Call( this );
onSelectionChanged.Call(this);
}
}
void ColorSlider::SetColor( Gwen::Color color)
void ColorSlider::SetColor(Gwen::Color color)
{
HSV hsv = RGBtoHSV( color.r, color.g, color.b );
HSV hsv = RGBtoHSV(color.r, color.g, color.b);
m_iSelectedDist = hsv.h / 360 * Height();
onSelectionChanged.Call( this );
onSelectionChanged.Call(this);
}
Gwen::Color ColorSlider::GetSelectedColor()
{
return GetColorAtHeight( m_iSelectedDist );
return GetColorAtHeight(m_iSelectedDist);
}

View File

@@ -3,7 +3,7 @@
Copyright (c) 2010 Facepunch Studios
See license in Gwen.h
*/
#pragma once
#ifndef GWEN_CONTROLS_COLORCONTROLS_H
#define GWEN_CONTROLS_COLORCONTROLS_H
@@ -12,50 +12,47 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
namespace Controls
{
class GWEN_EXPORT ColorLerpBox : public Controls::Base
{
public:
GWEN_CONTROL(ColorLerpBox, Controls::Base);
virtual void Render(Gwen::Skin::Base* skin);
Gwen::Color GetColorAtPos(int x, int y);
void SetColor(Gwen::Color color, bool onlyHue = true);
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
virtual void OnMouseClickLeft(int x, int y, bool bDown);
Gwen::Color GetSelectedColor();
class GWEN_EXPORT ColorLerpBox : public Controls::Base
{
public:
GWEN_CONTROL( ColorLerpBox, Controls::Base );
virtual void Render( Gwen::Skin::Base* skin );
Gwen::Color GetColorAtPos(int x, int y );
void SetColor( Gwen::Color color, bool onlyHue = true );
virtual void OnMouseMoved( int x, int y, int deltaX, int deltaY );
virtual void OnMouseClickLeft( int x, int y, bool bDown );
Gwen::Color GetSelectedColor();
Event::Caller onSelectionChanged;
Event::Caller onSelectionChanged;
protected:
Gwen::Point cursorPos;
bool m_bDepressed;
int m_Hue;
};
protected:
Gwen::Point cursorPos;
bool m_bDepressed;
int m_Hue;
};
class GWEN_EXPORT ColorSlider : public Controls::Base
{
public:
GWEN_CONTROL( ColorSlider, Controls::Base );
virtual void Render( Gwen::Skin::Base* skin );
virtual void OnMouseMoved( int x, int y, int deltaX, int deltaY );
virtual void OnMouseClickLeft( int x, int y, bool bDown );
Gwen::Color GetSelectedColor();
Gwen::Color GetColorAtHeight(int y );
void SetColor( Gwen::Color color );
class GWEN_EXPORT ColorSlider : public Controls::Base
{
public:
GWEN_CONTROL(ColorSlider, Controls::Base);
virtual void Render(Gwen::Skin::Base* skin);
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
virtual void OnMouseClickLeft(int x, int y, bool bDown);
Gwen::Color GetSelectedColor();
Gwen::Color GetColorAtHeight(int y);
void SetColor(Gwen::Color color);
Event::Caller onSelectionChanged;
Event::Caller onSelectionChanged;
protected:
int m_iSelectedDist;
bool m_bDepressed;
protected:
int m_iSelectedDist;
bool m_bDepressed;
};
} // namespace Controls
};
}
}
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ColorPicker.h"
#include "Gwen/Controls/HorizontalSlider.h"
#include "Gwen/Controls/GroupBox.h"
@@ -15,45 +14,45 @@ using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( ColorPicker )
GWEN_CONTROL_CONSTRUCTOR(ColorPicker)
{
SetMouseInputEnabled( true );
SetMouseInputEnabled(true);
SetKeyboardInputEnabled(true);
SetSize( 256, 150 );
SetSize(256, 150);
CreateControls();
SetColor( Gwen::Color( 50, 60, 70, 255 ) );
SetColor(Gwen::Color(50, 60, 70, 255));
}
void ColorPicker::CreateColorControl( Gwen::String name, int y )
void ColorPicker::CreateColorControl(Gwen::String name, int y)
{
int colorSize = 12;
GroupBox* colorGroup = new GroupBox( this );
colorGroup->SetPos( 10, y );
colorGroup->SetText( name );
colorGroup->SetSize( 160, 35 );
colorGroup->SetName( name + "groupbox" );
GroupBox* colorGroup = new GroupBox(this);
colorGroup->SetPos(10, y);
colorGroup->SetText(name);
colorGroup->SetSize(160, 35);
colorGroup->SetName(name + "groupbox");
ColorDisplay* disp = new ColorDisplay( colorGroup );
ColorDisplay* disp = new ColorDisplay(colorGroup);
disp->SetName(name);
disp->SetBounds( 0 , 10, colorSize, colorSize );
disp->SetBounds(0, 10, colorSize, colorSize);
TextBoxNumeric* numeric = new TextBoxNumeric( colorGroup );
numeric->SetName( name + "Box" );
numeric->SetPos( 105, 7 );
numeric->SetSize( 26, 16 );
numeric->SetSelectAllOnFocus( true );
numeric->onTextChanged.Add( this, &ColorPicker::NumericTyped );
TextBoxNumeric* numeric = new TextBoxNumeric(colorGroup);
numeric->SetName(name + "Box");
numeric->SetPos(105, 7);
numeric->SetSize(26, 16);
numeric->SetSelectAllOnFocus(true);
numeric->onTextChanged.Add(this, &ColorPicker::NumericTyped);
HorizontalSlider* slider = new HorizontalSlider( colorGroup );
slider->SetPos( colorSize + 5 , 10 );
slider->SetRange( 0, 255 );
slider->SetSize( 80, colorSize );
slider->SetName( name + "Slider");
slider->onValueChanged.Add( this, &ColorPicker::SlidersMoved );
HorizontalSlider* slider = new HorizontalSlider(colorGroup);
slider->SetPos(colorSize + 5, 10);
slider->SetRange(0, 255);
slider->SetSize(80, colorSize);
slider->SetName(name + "Slider");
slider->onValueChanged.Add(this, &ColorPicker::SlidersMoved);
}
void ColorPicker::NumericTyped( Gwen::Controls::Base* control )
void ColorPicker::NumericTyped(Gwen::Controls::Base* control)
{
if (!control)
return;
@@ -62,32 +61,32 @@ void ColorPicker::NumericTyped( Gwen::Controls::Base* control )
if (!box)
return;
if ( box->GetText() == L"")
if (box->GetText() == L"")
return;
int textValue = atoi( Utility::UnicodeToString( box->GetText()).c_str() );
if ( textValue < 0) textValue = 0;
if ( textValue > 255) textValue = 255;
int textValue = atoi(Utility::UnicodeToString(box->GetText()).c_str());
if (textValue < 0) textValue = 0;
if (textValue > 255) textValue = 255;
if ( box->GetName().find("Red") != Gwen::String::npos )
SetRed( textValue );
if (box->GetName().find("Red") != Gwen::String::npos)
SetRed(textValue);
if ( box->GetName().find("Green") != Gwen::String::npos )
SetGreen( textValue );
if (box->GetName().find("Green") != Gwen::String::npos)
SetGreen(textValue);
if ( box->GetName().find("Blue") != Gwen::String::npos )
SetBlue( textValue );
if (box->GetName().find("Blue") != Gwen::String::npos)
SetBlue(textValue);
if ( box->GetName().find("Alpha") != Gwen::String::npos )
SetAlpha( textValue );
if (box->GetName().find("Alpha") != Gwen::String::npos)
SetAlpha(textValue);
UpdateControls();
}
void ColorPicker::SetColor( Gwen::Color color )
void ColorPicker::SetColor(Gwen::Color color)
{
m_Color = color;
UpdateControls();
m_Color = color;
UpdateControls();
}
void ColorPicker::CreateControls()
@@ -95,128 +94,124 @@ void ColorPicker::CreateControls()
int startY = 5;
int height = 35;
CreateColorControl( "Red", startY );
CreateColorControl( "Green", startY + height );
CreateColorControl( "Blue", startY + height * 2 );
CreateColorControl( "Alpha", startY + height * 3 );
CreateColorControl("Red", startY);
CreateColorControl("Green", startY + height);
CreateColorControl("Blue", startY + height * 2);
CreateColorControl("Alpha", startY + height * 3);
GroupBox* finalGroup = new GroupBox( this );
finalGroup->SetPos( 180, 40 );
finalGroup->SetSize( 60, 60 );
finalGroup->SetText( "Result" );
finalGroup->SetName( "ResultGroupBox" );
GroupBox* finalGroup = new GroupBox(this);
finalGroup->SetPos(180, 40);
finalGroup->SetSize(60, 60);
finalGroup->SetText("Result");
finalGroup->SetName("ResultGroupBox");
ColorDisplay* disp = new ColorDisplay( finalGroup );
disp->SetName( "Result" );
disp->SetBounds( 0 , 10, 32, 32 );
disp->SetDrawCheckers( true );
ColorDisplay* disp = new ColorDisplay(finalGroup);
disp->SetName("Result");
disp->SetBounds(0, 10, 32, 32);
disp->SetDrawCheckers(true);
//UpdateControls();
}
void ColorPicker::UpdateColorControls( Gwen::String name, Gwen::Color col, int sliderVal )
void ColorPicker::UpdateColorControls(Gwen::String name, Gwen::Color col, int sliderVal)
{
Base* el = FindChildByName( name, true );
Base* el = FindChildByName(name, true);
ColorDisplay* disp = el ? el->DynamicCastColorDisplay() : 0;
disp->SetColor( col );
disp->SetColor(col);
HorizontalSlider* slider = FindChildByName( name + "Slider", true )->DynamicCastHorizontalSlider();
slider->SetValue( sliderVal );
HorizontalSlider* slider = FindChildByName(name + "Slider", true)->DynamicCastHorizontalSlider();
slider->SetValue(sliderVal);
TextBoxNumeric* box = FindChildByName( name + "Box", true )->DynamicCastTextBoxNumeric();
box->SetText( Gwen::Utility::ToString( sliderVal ) );
TextBoxNumeric* box = FindChildByName(name + "Box", true)->DynamicCastTextBoxNumeric();
box->SetText(Gwen::Utility::ToString(sliderVal));
}
void ColorPicker::UpdateControls()
{
//This is a little weird, but whatever for now
UpdateColorControls( "Red", Color( GetColor().r, 0, 0, 255 ), GetColor().r );
UpdateColorControls( "Green", Color( 0, GetColor().g, 0, 255 ), GetColor().g );
UpdateColorControls( "Blue", Color( 0, 0, GetColor().b, 255 ), GetColor().b );
UpdateColorControls( "Alpha", Color( 255, 255, 255, GetColor().a ), GetColor().a );
UpdateColorControls("Red", Color(GetColor().r, 0, 0, 255), GetColor().r);
UpdateColorControls("Green", Color(0, GetColor().g, 0, 255), GetColor().g);
UpdateColorControls("Blue", Color(0, 0, GetColor().b, 255), GetColor().b);
UpdateColorControls("Alpha", Color(255, 255, 255, GetColor().a), GetColor().a);
ColorDisplay* disp = FindChildByName( "Result", true )->DynamicCastColorDisplay();
disp->SetColor( Color( GetColor().r, GetColor().g, GetColor().b, GetColor().a ) );
ColorDisplay* disp = FindChildByName("Result", true)->DynamicCastColorDisplay();
disp->SetColor(Color(GetColor().r, GetColor().g, GetColor().b, GetColor().a));
onColorChanged.Call( this );
onColorChanged.Call(this);
}
void ColorPicker::SlidersMoved( Gwen::Controls::Base* control )
void ColorPicker::SlidersMoved(Gwen::Controls::Base* control)
{
HorizontalSlider* slider = control->DynamicCastHorizontalSlider();
if (slider)
SetColorByName( GetColorFromName( slider->GetName() ), slider->GetValue() );
SetColorByName(GetColorFromName(slider->GetName()), slider->GetValue());
UpdateControls();
//SetColor( Gwen::Color( redSlider->GetValue(), greenSlider->GetValue(), blueSlider->GetValue(), alphaSlider->GetValue() ) );
}
void ColorPicker::Layout( Skin::Base* skin )
void ColorPicker::Layout(Skin::Base* skin)
{
BaseClass::Layout( skin );
BaseClass::Layout(skin);
SizeToChildren( false, true );
SetSize( Width(), Height() + 5 );
SizeToChildren(false, true);
SetSize(Width(), Height() + 5);
GroupBox* groupBox = FindChildByName( "ResultGroupBox", true )->DynamicCastGroupBox();
if ( groupBox )
groupBox->SetPos( groupBox->X(), Height() * 0.5f - groupBox->Height() * 0.5f );
GroupBox* groupBox = FindChildByName("ResultGroupBox", true)->DynamicCastGroupBox();
if (groupBox)
groupBox->SetPos(groupBox->X(), Height() * 0.5f - groupBox->Height() * 0.5f);
UpdateControls();
}
void ColorPicker::Render( Skin::Base* skin )
void ColorPicker::Render(Skin::Base* skin)
{
skin->DrawBackground( this );
skin->DrawBackground(this);
}
int ColorPicker::GetColorByName( Gwen::String colorName )
int ColorPicker::GetColorByName(Gwen::String colorName)
{
if ( colorName == "Red")
if (colorName == "Red")
return GetColor().r;
else if ( colorName == "Green")
else if (colorName == "Green")
return GetColor().g;
else if ( colorName == "Blue")
else if (colorName == "Blue")
return GetColor().b;
else if ( colorName == "Alpha")
else if (colorName == "Alpha")
return GetColor().a;
else
return 0;
}
Gwen::String ColorPicker::GetColorFromName( Gwen::String name )
Gwen::String ColorPicker::GetColorFromName(Gwen::String name)
{
if ( name.find("Red") != Gwen::String::npos )
if (name.find("Red") != Gwen::String::npos)
return "Red";
if ( name.find("Green") != Gwen::String::npos )
if (name.find("Green") != Gwen::String::npos)
return "Green";
if ( name.find("Blue") != Gwen::String::npos )
if (name.find("Blue") != Gwen::String::npos)
return "Blue";
if ( name.find("Alpha") != Gwen::String::npos )
if (name.find("Alpha") != Gwen::String::npos)
return "Alpha";
else
return "";
}
void ColorPicker::SetColorByName( Gwen::String colorName, int colorValue )
void ColorPicker::SetColorByName(Gwen::String colorName, int colorValue)
{
if ( colorName == "Red")
SetRed( colorValue );
else if ( colorName == "Green")
SetGreen( colorValue );
else if ( colorName == "Blue")
SetBlue( colorValue );
else if ( colorName == "Alpha")
SetAlpha( colorValue );
if (colorName == "Red")
SetRed(colorValue);
else if (colorName == "Green")
SetGreen(colorValue);
else if (colorName == "Blue")
SetBlue(colorValue);
else if (colorName == "Alpha")
SetAlpha(colorValue);
}
void ColorPicker::SetAlphaVisible( bool visible )
void ColorPicker::SetAlphaVisible(bool visible)
{
GroupBox* groupBox = FindChildByName( "Alphagroupbox", true )->DynamicCastGroupBox();
groupBox->SetHidden( !visible );
GroupBox* groupBox = FindChildByName("Alphagroupbox", true)->DynamicCastGroupBox();
groupBox->SetHidden(!visible);
Invalidate();
}

View File

@@ -12,78 +12,74 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
namespace ControlsInternal
{
class GWEN_EXPORT ColorDisplay : public Controls::Base
{
public:
GWEN_CONTROL_INLINE(ColorDisplay, Controls::Base)
{
class GWEN_EXPORT ColorDisplay : public Controls::Base
{
public:
GWEN_CONTROL_INLINE( ColorDisplay, Controls::Base )
{
SetSize( 32, 32 );
m_Color = Color( 255, 0, 0, 255 );
m_DrawCheckers = true;
}
virtual void Render( Gwen::Skin::Base* skin )
{
skin->DrawColorDisplay( this, m_Color );
}
virtual void SetColor( Gwen::Color color ) { m_Color = color; }
virtual Gwen::Color GetColor() { return m_Color; }
virtual void SetRed( int red ) { m_Color.r = red; }
virtual void SetGreen( int green ) { m_Color.g = green;}
virtual void SetBlue( int blue ) { m_Color.b = blue; }
virtual void SetAlpha( int alpha ) { m_Color.a = alpha;}
virtual void SetDrawCheckers( bool should ) { m_DrawCheckers = should; }
protected:
Gwen::Color m_Color;
bool m_DrawCheckers;
};
SetSize(32, 32);
m_Color = Color(255, 0, 0, 255);
m_DrawCheckers = true;
}
namespace Controls
virtual void Render(Gwen::Skin::Base* skin)
{
class GWEN_EXPORT ColorPicker : public Base
{
public:
GWEN_CONTROL( ColorPicker, Base );
virtual void Render( Skin::Base* skin );
virtual void Layout( Skin::Base* skin );
virtual void CreateControls();
virtual void SlidersMoved( Gwen::Controls::Base* control );
virtual void NumericTyped( Gwen::Controls::Base* control );
virtual void UpdateControls();
virtual void UpdateColorControls( Gwen::String name, Gwen::Color col, int sliderVal );
virtual void CreateColorControl( Gwen::String name, int y );
virtual void SetColor( Gwen::Color color );
virtual Gwen::Color GetColor() { return m_Color; }
int GetColorByName( Gwen::String colorName );
void SetColorByName( Gwen::String colorName, int colorValue );
Gwen::String GetColorFromName( Gwen::String name );
virtual void SetAlphaVisible( bool visible );
virtual void SetRed( int red ) { m_Color.r = red; }
virtual void SetGreen( int green ) { m_Color.g = green;}
virtual void SetBlue( int blue ) { m_Color.b = blue; }
virtual void SetAlpha( int alpha ) { m_Color.a = alpha;}
Event::Caller onColorChanged;
protected:
Gwen::Color m_Color;
};
skin->DrawColorDisplay(this, m_Color);
}
}
virtual void SetColor(Gwen::Color color) { m_Color = color; }
virtual Gwen::Color GetColor() { return m_Color; }
virtual void SetRed(int red) { m_Color.r = red; }
virtual void SetGreen(int green) { m_Color.g = green; }
virtual void SetBlue(int blue) { m_Color.b = blue; }
virtual void SetAlpha(int alpha) { m_Color.a = alpha; }
virtual void SetDrawCheckers(bool should) { m_DrawCheckers = should; }
protected:
Gwen::Color m_Color;
bool m_DrawCheckers;
};
} // namespace ControlsInternal
namespace Controls
{
class GWEN_EXPORT ColorPicker : public Base
{
public:
GWEN_CONTROL(ColorPicker, Base);
virtual void Render(Skin::Base* skin);
virtual void Layout(Skin::Base* skin);
virtual void CreateControls();
virtual void SlidersMoved(Gwen::Controls::Base* control);
virtual void NumericTyped(Gwen::Controls::Base* control);
virtual void UpdateControls();
virtual void UpdateColorControls(Gwen::String name, Gwen::Color col, int sliderVal);
virtual void CreateColorControl(Gwen::String name, int y);
virtual void SetColor(Gwen::Color color);
virtual Gwen::Color GetColor() { return m_Color; }
int GetColorByName(Gwen::String colorName);
void SetColorByName(Gwen::String colorName, int colorValue);
Gwen::String GetColorFromName(Gwen::String name);
virtual void SetAlphaVisible(bool visible);
virtual void SetRed(int red) { m_Color.r = red; }
virtual void SetGreen(int green) { m_Color.g = green; }
virtual void SetBlue(int blue) { m_Color.b = blue; }
virtual void SetAlpha(int alpha) { m_Color.a = alpha; }
Event::Caller onColorChanged;
protected:
Gwen::Color m_Color;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,89 +4,81 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ComboBox.h"
#include "Gwen/Controls/Menu.h"
using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
class GWEN_EXPORT DownArrow : public Controls::Base
{
public:
public:
GWEN_CONTROL_INLINE(DownArrow, Controls::Base)
{
SetMouseInputEnabled(true);
SetSize(15, 15);
}
GWEN_CONTROL_INLINE( DownArrow, Controls::Base )
{
SetMouseInputEnabled( true );
SetSize( 15, 15 );
void Render(Skin::Base* skin)
{
skin->DrawArrowDown(this->m_Bounds);
}
}
void SetComboBox(ComboBox* p) { m_ComboBox = p; }
void Render( Skin::Base* skin )
{
skin->DrawArrowDown(this->m_Bounds);
}
void SetComboBox( ComboBox* p ){ m_ComboBox = p; }
protected:
ComboBox* m_ComboBox;
protected:
ComboBox* m_ComboBox;
};
GWEN_CONTROL_CONSTRUCTOR( ComboBox )
GWEN_CONTROL_CONSTRUCTOR(ComboBox)
{
SetSize( 100, 20 );
SetMouseInputEnabled( true );
SetSize(100, 20);
SetMouseInputEnabled(true);
m_Menu = new Menu( this );
m_Menu->SetHidden( true );
m_Menu->SetDisableIconMargin( true );
m_Menu->SetTabable( false );
m_Menu = new Menu(this);
m_Menu->SetHidden(true);
m_Menu->SetDisableIconMargin(true);
m_Menu->SetTabable(false);
ComboBoxButton* m_OpenButton = new ComboBoxButton( this );
ComboBoxButton* m_OpenButton = new ComboBoxButton(this);
m_OpenButton->onDown.Add( this, &ComboBox::OpenButtonPressed );
m_OpenButton->Dock( Pos::Right );
m_OpenButton->SetMargin( Margin( 2, 2, 2, 2 ) );
m_OpenButton->SetWidth( 16 );
m_OpenButton->SetTabable( false );
m_OpenButton->onDown.Add(this, &ComboBox::OpenButtonPressed);
m_OpenButton->Dock(Pos::Right);
m_OpenButton->SetMargin(Margin(2, 2, 2, 2));
m_OpenButton->SetWidth(16);
m_OpenButton->SetTabable(false);
m_SelectedItem = NULL;
SetAlignment( Gwen::Pos::Left | Gwen::Pos::CenterV );
SetText( L"" );
SetMargin( Margin( 3, 0, 0, 0 ) );
SetTabable( true );
SetAlignment(Gwen::Pos::Left | Gwen::Pos::CenterV);
SetText(L"");
SetMargin(Margin(3, 0, 0, 0));
SetTabable(true);
}
MenuItem* ComboBox::AddItem( const UnicodeString& strLabel, const String& strName, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::Function fn )
MenuItem* ComboBox::AddItem(const UnicodeString& strLabel, const String& strName, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::Function fn)
{
MenuItem* pItem = m_Menu->AddItem( strLabel, L"", pHandler, fn );
pItem->SetName( strName );
MenuItem* pItem = m_Menu->AddItem(strLabel, L"", pHandler, fn);
pItem->SetName(strName);
pItem->onMenuItemSelected.Add( this, &ComboBox::OnItemSelected );
pItem->onMenuItemSelected.Add(this, &ComboBox::OnItemSelected);
//Default
if ( m_SelectedItem == NULL )
OnItemSelected( pItem );
if (m_SelectedItem == NULL)
OnItemSelected(pItem);
return pItem;
}
void ComboBox::Render( Skin::Base* skin )
void ComboBox::Render(Skin::Base* skin)
{
skin->DrawComboBox( this );
skin->DrawComboBox(this);
}
void ComboBox::OpenButtonPressed( Controls::Base* /*pControl*/ )
void ComboBox::OpenButtonPressed(Controls::Base* /*pControl*/)
{
OnPress();
}
@@ -97,34 +89,34 @@ void ComboBox::OnPress()
GetCanvas()->CloseMenus();
if ( bWasMenuHidden )
if (bWasMenuHidden)
{
OpenList();
}
else
else
{
m_Menu->SetHidden( true );
m_Menu->SetHidden(true);
}
}
void ComboBox::ClearItems()
{
if ( m_Menu )
if (m_Menu)
{
m_Menu->ClearItems();
}
}
void ComboBox::OnItemSelected( Controls::Base* pControl )
void ComboBox::OnItemSelected(Controls::Base* pControl)
{
//Convert selected to a menu item
MenuItem* pItem = pControl->DynamicCastMenuItem();
if ( !pItem ) return;
MenuItem* pItem = pControl->DynamicCastMenuItem();
if (!pItem) return;
m_SelectedItem = pItem;
SetText( m_SelectedItem->GetText() );
m_Menu->SetHidden( true );
SetText(m_SelectedItem->GetText());
m_Menu->SetHidden(true);
onSelection.Call( this );
onSelection.Call(this);
Focus();
Invalidate();
@@ -132,19 +124,18 @@ void ComboBox::OnItemSelected( Controls::Base* pControl )
void ComboBox::OnLostKeyboardFocus()
{
SetTextColor( Color( 0, 0, 0, 255 ) );
SetTextColor(Color(0, 0, 0, 255));
}
void ComboBox::OnKeyboardFocus()
{
//Until we add the blue highlighting again
SetTextColor( Color( 0, 0, 0, 255 ) );
SetTextColor(Color(0, 0, 0, 255));
//m_SelectedText->SetTextColor( Color( 255, 255, 255, 255 ) );
}
Gwen::Controls::Label* ComboBox::GetSelectedItem()
{
{
return m_SelectedItem;
}
@@ -155,54 +146,52 @@ bool ComboBox::IsMenuOpen()
void ComboBox::OpenList()
{
if ( !m_Menu ) return;
if (!m_Menu) return;
m_Menu->SetParent( GetCanvas() );
m_Menu->SetHidden( false );
m_Menu->SetParent(GetCanvas());
m_Menu->SetHidden(false);
m_Menu->BringToFront();
Gwen::Point p = LocalPosToCanvas( Gwen::Point( 0, 0 ) );
Gwen::Point p = LocalPosToCanvas(Gwen::Point(0, 0));
m_Menu->SetBounds( Gwen::Rect ( p.x, p.y + Height(), Width(), m_Menu->Height()) );
m_Menu->SetBounds(Gwen::Rect(p.x, p.y + Height(), Width(), m_Menu->Height()));
}
void ComboBox::CloseList()
{
}
bool ComboBox::OnKeyUp( bool bDown )
bool ComboBox::OnKeyUp(bool bDown)
{
if ( bDown )
if (bDown)
{
Base::List & children = m_Menu->GetChildren();
Base::List::reverse_iterator it = std::find( children.rbegin(), children.rend(), m_SelectedItem );
Base::List& children = m_Menu->GetChildren();
Base::List::reverse_iterator it = std::find(children.rbegin(), children.rend(), m_SelectedItem);
if ( it != children.rend() && ( ++it != children.rend() ) )
if (it != children.rend() && (++it != children.rend()))
{
Base* pUpElement = *it;
OnItemSelected( pUpElement );
OnItemSelected(pUpElement);
}
}
return true;
}
bool ComboBox::OnKeyDown( bool bDown )
bool ComboBox::OnKeyDown(bool bDown)
{
if ( bDown )
if (bDown)
{
Base::List & children = m_Menu->GetChildren();
Base::List::iterator it = std::find( children.begin(), children.end(), m_SelectedItem );
Base::List& children = m_Menu->GetChildren();
Base::List::iterator it = std::find(children.begin(), children.end(), m_SelectedItem);
if ( it != children.end() && ( ++it != children.end() ) )
if (it != children.end() && (++it != children.end()))
{
Base* pDownElement = *it;
OnItemSelected( pDownElement );
OnItemSelected(pDownElement);
}
}
return true;
}
void ComboBox::RenderFocus( Gwen::Skin::Base* /*skin*/ )
void ComboBox::RenderFocus(Gwen::Skin::Base* /*skin*/)
{
}

View File

@@ -15,73 +15,69 @@
#include "Gwen/Controls/TextBox.h"
#include "Gwen/Controls/Menu.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT ComboBoxButton : public Button
{
GWEN_CONTROL_INLINE(ComboBoxButton, Button) {}
virtual void Render(Skin::Base* skin)
{
class GWEN_EXPORT ComboBoxButton : public Button
{
GWEN_CONTROL_INLINE( ComboBoxButton, Button ){}
virtual void Render( Skin::Base* skin )
{
skin->DrawComboBoxButton( this, m_bDepressed );
}
};
class GWEN_EXPORT ComboBox : public Button
{
public:
GWEN_CONTROL( ComboBox, Button );
virtual void Render( Skin::Base* skin );
virtual Gwen::Controls::Label* GetSelectedItem();
virtual void OnPress();
void OpenButtonPressed( Controls::Base* /*pControl*/ );
virtual void OnItemSelected( Controls::Base* pControl );
virtual void OpenList();
virtual void CloseList();
virtual Controls::Base* GetControlAt( int x, int y )
{
if ( x < 0 || y < 0 || x >= Width() || y >= Height() )
return NULL;
return this;
}
virtual bool IsMenuComponent()
{
return true;
}
virtual void ClearItems();
virtual MenuItem* AddItem( const UnicodeString& strLabel, const String& strName = "", Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL );
virtual bool OnKeyUp( bool bDown );
virtual bool OnKeyDown( bool bDown );
virtual void RenderFocus( Gwen::Skin::Base* skin );
virtual void OnLostKeyboardFocus();
virtual void OnKeyboardFocus();
virtual bool IsMenuOpen();
Gwen::Event::Caller onSelection;
protected:
Menu* m_Menu;
MenuItem* m_SelectedItem;
Controls::Base* m_Button;
};
skin->DrawComboBoxButton(this, m_bDepressed);
}
}
};
class GWEN_EXPORT ComboBox : public Button
{
public:
GWEN_CONTROL(ComboBox, Button);
virtual void Render(Skin::Base* skin);
virtual Gwen::Controls::Label* GetSelectedItem();
virtual void OnPress();
void OpenButtonPressed(Controls::Base* /*pControl*/);
virtual void OnItemSelected(Controls::Base* pControl);
virtual void OpenList();
virtual void CloseList();
virtual Controls::Base* GetControlAt(int x, int y)
{
if (x < 0 || y < 0 || x >= Width() || y >= Height())
return NULL;
return this;
}
virtual bool IsMenuComponent()
{
return true;
}
virtual void ClearItems();
virtual MenuItem* AddItem(const UnicodeString& strLabel, const String& strName = "", Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL);
virtual bool OnKeyUp(bool bDown);
virtual bool OnKeyDown(bool bDown);
virtual void RenderFocus(Gwen::Skin::Base* skin);
virtual void OnLostKeyboardFocus();
virtual void OnKeyboardFocus();
virtual bool IsMenuOpen();
Gwen::Event::Caller onSelection;
protected:
Menu* m_Menu;
MenuItem* m_SelectedItem;
Controls::Base* m_Button;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -5,48 +5,48 @@
using namespace Gwen;
using namespace Controls;
GWEN_CONTROL_CONSTRUCTOR( CrossSplitter )
GWEN_CONTROL_CONSTRUCTOR(CrossSplitter)
{
m_VSplitter = new SplitterBar( this );
m_VSplitter->SetPos( 0, 128 );
m_VSplitter->onDragged.Add( this, &CrossSplitter::OnVerticalMoved );
m_VSplitter->SetCursor( Gwen::CursorType::SizeNS );
m_VSplitter = new SplitterBar(this);
m_VSplitter->SetPos(0, 128);
m_VSplitter->onDragged.Add(this, &CrossSplitter::OnVerticalMoved);
m_VSplitter->SetCursor(Gwen::CursorType::SizeNS);
m_HSplitter = new SplitterBar( this );
m_HSplitter->SetPos( 128, 0 );
m_HSplitter->onDragged.Add( this, &CrossSplitter::OnHorizontalMoved );
m_HSplitter->SetCursor( Gwen::CursorType::SizeWE );
m_HSplitter = new SplitterBar(this);
m_HSplitter->SetPos(128, 0);
m_HSplitter->onDragged.Add(this, &CrossSplitter::OnHorizontalMoved);
m_HSplitter->SetCursor(Gwen::CursorType::SizeWE);
m_CSplitter = new SplitterBar( this );
m_CSplitter->SetPos( 128, 128 );
m_CSplitter->onDragged.Add( this, &CrossSplitter::OnCenterMoved );
m_CSplitter->SetCursor( Gwen::CursorType::SizeAll );
m_CSplitter = new SplitterBar(this);
m_CSplitter->SetPos(128, 128);
m_CSplitter->onDragged.Add(this, &CrossSplitter::OnCenterMoved);
m_CSplitter->SetCursor(Gwen::CursorType::SizeAll);
m_fHVal = 0.5f;
m_fVVal = 0.5f;
SetPanel( 0, NULL );
SetPanel( 1, NULL );
SetPanel( 2, NULL );
SetPanel( 3, NULL );
SetPanel(0, NULL);
SetPanel(1, NULL);
SetPanel(2, NULL);
SetPanel(3, NULL);
SetSplitterSize( 5 );
SetSplittersVisible( false );
SetSplitterSize(5);
SetSplittersVisible(false);
m_iZoomedSection = -1;
}
void CrossSplitter::UpdateVSplitter()
{
m_VSplitter->MoveTo( m_VSplitter->X(), ( Height() - m_VSplitter->Height() ) * ( m_fVVal ));
m_VSplitter->MoveTo(m_VSplitter->X(), (Height() - m_VSplitter->Height()) * (m_fVVal));
}
void CrossSplitter::UpdateHSplitter()
{
m_HSplitter->MoveTo( ( Width() - m_HSplitter->Width() ) * ( m_fHVal ), m_HSplitter->Y() );
m_HSplitter->MoveTo((Width() - m_HSplitter->Width()) * (m_fHVal), m_HSplitter->Y());
}
void CrossSplitter::OnCenterMoved( Controls::Base * /*control*/ )
{
void CrossSplitter::OnCenterMoved(Controls::Base* /*control*/)
{
//Move the other two bars into position
CalculateValueCenter();
Invalidate();
@@ -54,111 +54,110 @@ void CrossSplitter::OnCenterMoved( Controls::Base * /*control*/ )
void CrossSplitter::UpdateCSplitter()
{
m_CSplitter->MoveTo( ( Width() - m_CSplitter->Width() ) * ( m_fHVal ), ( Height() - m_CSplitter->Height() ) * ( m_fVVal ));
m_CSplitter->MoveTo((Width() - m_CSplitter->Width()) * (m_fHVal), (Height() - m_CSplitter->Height()) * (m_fVVal));
}
void CrossSplitter::OnHorizontalMoved( Controls::Base * /*control*/ )
{
void CrossSplitter::OnHorizontalMoved(Controls::Base* /*control*/)
{
m_fHVal = CalculateValueHorizontal();
Invalidate();
}
void CrossSplitter::OnVerticalMoved( Controls::Base * /*control*/ )
void CrossSplitter::OnVerticalMoved(Controls::Base* /*control*/)
{
m_fVVal = CalculateValueVertical();
m_fVVal = CalculateValueVertical();
Invalidate();
}
void CrossSplitter::CalculateValueCenter()
{
m_fHVal = (float)m_CSplitter->X() / (float)( Width() - m_CSplitter->Width() );
m_fVVal = (float)m_CSplitter->Y() / (float)( Height() - m_CSplitter->Height() );
m_fHVal = (float)m_CSplitter->X() / (float)(Width() - m_CSplitter->Width());
m_fVVal = (float)m_CSplitter->Y() / (float)(Height() - m_CSplitter->Height());
}
float CrossSplitter::CalculateValueHorizontal()
{
return (float)m_HSplitter->X() / (float)( Width() - m_HSplitter->Width() );
return (float)m_HSplitter->X() / (float)(Width() - m_HSplitter->Width());
}
float CrossSplitter::CalculateValueVertical()
{
return (float)m_VSplitter->Y() / (float)( Height() - m_VSplitter->Height() );
return (float)m_VSplitter->Y() / (float)(Height() - m_VSplitter->Height());
}
void CrossSplitter::Layout( Skin::Base* /*skin*/ )
void CrossSplitter::Layout(Skin::Base* /*skin*/)
{
m_VSplitter->SetSize( Width(), m_fBarSize );
m_HSplitter->SetSize( m_fBarSize, Height() );
m_CSplitter->SetSize( m_fBarSize, m_fBarSize );
m_VSplitter->SetSize(Width(), m_fBarSize);
m_HSplitter->SetSize(m_fBarSize, Height());
m_CSplitter->SetSize(m_fBarSize, m_fBarSize);
UpdateVSplitter();
UpdateHSplitter();
UpdateCSplitter();
if ( m_iZoomedSection == -1 )
if (m_iZoomedSection == -1)
{
if ( m_Sections[0] )
m_Sections[0]->SetBounds( 0, 0, m_HSplitter->X(), m_VSplitter->Y() );
if (m_Sections[0])
m_Sections[0]->SetBounds(0, 0, m_HSplitter->X(), m_VSplitter->Y());
if ( m_Sections[1] )
m_Sections[1]->SetBounds( m_HSplitter->X() + m_fBarSize, 0, Width() - ( m_HSplitter->X() + m_fBarSize ), m_VSplitter->Y() );
if (m_Sections[1])
m_Sections[1]->SetBounds(m_HSplitter->X() + m_fBarSize, 0, Width() - (m_HSplitter->X() + m_fBarSize), m_VSplitter->Y());
if ( m_Sections[2] )
m_Sections[2]->SetBounds( 0, m_VSplitter->Y() + m_fBarSize, m_HSplitter->X(), Height() - ( m_VSplitter->Y() + m_fBarSize ) );
if (m_Sections[2])
m_Sections[2]->SetBounds(0, m_VSplitter->Y() + m_fBarSize, m_HSplitter->X(), Height() - (m_VSplitter->Y() + m_fBarSize));
if ( m_Sections[3] )
m_Sections[3]->SetBounds( m_HSplitter->X() + m_fBarSize, m_VSplitter->Y() + m_fBarSize, Width() - ( m_HSplitter->X() + m_fBarSize ), Height() - ( m_VSplitter->Y() + m_fBarSize ) );
if (m_Sections[3])
m_Sections[3]->SetBounds(m_HSplitter->X() + m_fBarSize, m_VSplitter->Y() + m_fBarSize, Width() - (m_HSplitter->X() + m_fBarSize), Height() - (m_VSplitter->Y() + m_fBarSize));
}
else
{
//This should probably use Fill docking instead
m_Sections[(int)m_iZoomedSection]->SetBounds( 0, 0, Width(), Height() );
m_Sections[(int)m_iZoomedSection]->SetBounds(0, 0, Width(), Height());
}
}
void CrossSplitter::SetPanel( int index, Controls::Base* pPanel)
void CrossSplitter::SetPanel(int index, Controls::Base* pPanel)
{
Debug::AssertCheck( index >= 0 && index <= 3, "CrossSplitter::SetPanel out of range" );
Debug::AssertCheck(index >= 0 && index <= 3, "CrossSplitter::SetPanel out of range");
m_Sections[index] = pPanel;
if ( pPanel )
if (pPanel)
{
pPanel->Dock( Pos::None );
pPanel->SetParent( this );
pPanel->Dock(Pos::None);
pPanel->SetParent(this);
}
Invalidate();
}
Controls::Base* CrossSplitter::GetPanel( int i )
Controls::Base* CrossSplitter::GetPanel(int i)
{
return m_Sections[i];
}
void CrossSplitter::ZoomChanged()
{
onZoomChange.Call( this );
if ( m_iZoomedSection == -1 )
onZoomChange.Call(this);
if (m_iZoomedSection == -1)
{
onUnZoomed.Call( this );
onUnZoomed.Call(this);
}
else
{
onZoomed.Call( this );
onZoomed.Call(this);
}
}
void CrossSplitter::Zoom( int section )
void CrossSplitter::Zoom(int section)
{
UnZoom();
if ( m_Sections[section] )
if (m_Sections[section])
{
for (int i = 0; i < 4; i++)
{
if ( i != section && m_Sections[i] )
m_Sections[i]->SetHidden( true );
if (i != section && m_Sections[i])
m_Sections[i]->SetHidden(true);
}
m_iZoomedSection = section;
@@ -171,10 +170,10 @@ void CrossSplitter::UnZoom()
{
m_iZoomedSection = -1;
for ( int i = 0; i < 4; i++ )
for (int i = 0; i < 4; i++)
{
if ( m_Sections[i] )
m_Sections[i]->SetHidden( false );
if (m_Sections[i])
m_Sections[i]->SetHidden(false);
}
Invalidate();

View File

@@ -6,58 +6,66 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/SplitterBar.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT CrossSplitter : public Controls::Base
{
public:
GWEN_CONTROL(CrossSplitter, Controls::Base);
void Layout(Skin::Base* skin);
virtual float CalculateValueVertical();
virtual float CalculateValueHorizontal();
virtual void CalculateValueCenter();
virtual void UpdateHSplitter();
virtual void UpdateVSplitter();
virtual void UpdateCSplitter();
virtual void OnVerticalMoved(Controls::Base* control);
virtual void OnHorizontalMoved(Controls::Base* control);
virtual void OnCenterMoved(Controls::Base* control);
virtual void SetPanel(int i, Controls::Base* pPanel);
virtual Controls::Base* GetPanel(int i);
virtual bool IsZoomed() { return m_iZoomedSection != -1; }
virtual void Zoom(int section);
virtual void UnZoom();
virtual void ZoomChanged();
virtual void CenterPanels()
{
class GWEN_EXPORT CrossSplitter : public Controls::Base
{
public:
GWEN_CONTROL( CrossSplitter, Controls::Base );
void Layout( Skin::Base* skin );
virtual float CalculateValueVertical();
virtual float CalculateValueHorizontal();
virtual void CalculateValueCenter();
virtual void UpdateHSplitter();
virtual void UpdateVSplitter();
virtual void UpdateCSplitter();
virtual void OnVerticalMoved( Controls::Base * control );
virtual void OnHorizontalMoved( Controls::Base * control );
virtual void OnCenterMoved( Controls::Base * control );
virtual void SetPanel( int i, Controls::Base* pPanel );
virtual Controls::Base* GetPanel( int i );
virtual bool IsZoomed(){ return m_iZoomedSection != -1; }
virtual void Zoom( int section );
virtual void UnZoom();
virtual void ZoomChanged();
virtual void CenterPanels() { m_fHVal = 0.5f; m_fVVal = 0.5f; Invalidate(); }
virtual void SetSplittersVisible( bool b ){ m_VSplitter->SetShouldDrawBackground( b ); m_HSplitter->SetShouldDrawBackground( b ); m_CSplitter->SetShouldDrawBackground( b ); }
virtual void SetSplitterSize( int size ) { m_fBarSize = size; }
private:
SplitterBar* m_VSplitter;
SplitterBar* m_HSplitter;
SplitterBar* m_CSplitter;
Controls::Base* m_Sections[4];
float m_fHVal;
float m_fVVal;
int m_fBarSize;
int m_iZoomedSection;
Gwen::Event::Caller onZoomed;
Gwen::Event::Caller onUnZoomed;
Gwen::Event::Caller onZoomChange;
};
m_fHVal = 0.5f;
m_fVVal = 0.5f;
Invalidate();
}
}
virtual void SetSplittersVisible(bool b)
{
m_VSplitter->SetShouldDrawBackground(b);
m_HSplitter->SetShouldDrawBackground(b);
m_CSplitter->SetShouldDrawBackground(b);
}
virtual void SetSplitterSize(int size) { m_fBarSize = size; }
private:
SplitterBar* m_VSplitter;
SplitterBar* m_HSplitter;
SplitterBar* m_CSplitter;
Controls::Base* m_Sections[4];
float m_fHVal;
float m_fVVal;
int m_fBarSize;
int m_iZoomedSection;
Gwen::Event::Caller onZoomed;
Gwen::Event::Caller onUnZoomed;
Gwen::Event::Caller onZoomChange;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -11,9 +11,9 @@
using namespace Gwen;
using namespace Gwen::Dialogs;
void Gwen::Dialogs::FileOpenEx( bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::FunctionStr fnCallback )
void Gwen::Dialogs::FileOpenEx(bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::FunctionStr fnCallback)
{
if ( bUseSystem && Gwen::Platform::FileOpen( Name, StartPath, Extension, pHandler, fnCallback ) )
if (bUseSystem && Gwen::Platform::FileOpen(Name, StartPath, Extension, pHandler, fnCallback))
{
return;
}

View File

@@ -11,9 +11,9 @@
using namespace Gwen;
using namespace Gwen::Dialogs;
void Gwen::Dialogs::FileSaveEx( bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::FunctionStr fnCallback )
void Gwen::Dialogs::FileSaveEx(bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::FunctionStr fnCallback)
{
if ( bUseSystem && Gwen::Platform::FileSave( Name, StartPath, Extension, pHandler, fnCallback ) )
if (bUseSystem && Gwen::Platform::FileSave(Name, StartPath, Extension, pHandler, fnCallback))
{
return;
}

View File

@@ -9,4 +9,3 @@
using namespace Gwen;
using namespace Gwen::Controls;

View File

@@ -4,32 +4,31 @@
#include "Gwen/Gwen.h"
namespace Gwen
namespace Gwen
{
namespace Dialogs
{
// Usage:
//
// Gwen::Dialogs::FileOpen( true, "Open Map", "C:\my\folder\", "My Map Format|*.bmf", this, &MyClass::OpenFilename );
//
namespace Dialogs
{
// Usage:
//
// Gwen::Dialogs::FileOpen( true, "Open Map", "C:\my\folder\", "My Map Format|*.bmf", this, &MyClass::OpenFilename );
//
//
// The REAL function.
// If bUseSystem is used, it may use the system's modal dialog - which
// will steal focus and pause the rest of GWEN until it's continued.
//
void GWEN_EXPORT FileOpenEx( bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::FunctionStr fnCallback = NULL );
//
// The REAL function.
// If bUseSystem is used, it may use the system's modal dialog - which
// will steal focus and pause the rest of GWEN until it's continued.
//
void GWEN_EXPORT FileOpenEx(bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::FunctionStr fnCallback = NULL);
//
// Templated function simply to avoid having to manually cast the callback function.
//
template< typename A>
void FileOpen( bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, A fnCallback = NULL )
{
FileOpenEx( bUseSystem, Name, StartPath, Extension, pHandler, (Gwen::Event::Handler::FunctionStr)fnCallback );
}
}
//
// Templated function simply to avoid having to manually cast the callback function.
//
template <typename A>
void FileOpen(bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, A fnCallback = NULL)
{
FileOpenEx(bUseSystem, Name, StartPath, Extension, pHandler, (Gwen::Event::Handler::FunctionStr)fnCallback);
}
} // namespace Dialogs
} // namespace Gwen
#endif

View File

@@ -4,37 +4,36 @@
#include "Gwen/Gwen.h"
namespace Gwen
namespace Gwen
{
namespace Dialogs
{
// Usage:
//
// Gwen::Dialogs::FileOpen( true, "Open Map", "C:\my\folder\", "My Map Format|*.bmf", this, &MyClass::OpenFilename );
//
namespace Dialogs
{
// Usage:
//
// Gwen::Dialogs::FileOpen( true, "Open Map", "C:\my\folder\", "My Map Format|*.bmf", this, &MyClass::OpenFilename );
//
//
// Callback function, for success
//
typedef void (Event::Handler::*FileSaveSuccessCallback)( const String& filename );
//
// Callback function, for success
//
typedef void (Event::Handler::*FileSaveSuccessCallback)(const String& filename);
//
// The REAL function.
// If bUseSystem is used, it may use the system's modal dialog - which
// will steal focus and pause the rest of GWEN until it's continued.
//
void GWEN_EXPORT FileSaveEx( bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::FunctionStr fnCallback = NULL );
//
// The REAL function.
// If bUseSystem is used, it may use the system's modal dialog - which
// will steal focus and pause the rest of GWEN until it's continued.
//
void GWEN_EXPORT FileSaveEx(bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::FunctionStr fnCallback = NULL);
//
// Templated function simply to avoid having to manually cast the callback function.
//
template< typename A>
void FileSave( bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, A fnCallback = NULL )
{
FileSaveEx( bUseSystem, Name, StartPath, Extension, pHandler, (Gwen::Event::Handler::FunctionStr)fnCallback );
}
}
//
// Templated function simply to avoid having to manually cast the callback function.
//
template <typename A>
void FileSave(bool bUseSystem, const String& Name, const String& StartPath, const String& Extension, Gwen::Event::Handler* pHandler = NULL, A fnCallback = NULL)
{
FileSaveEx(bUseSystem, Name, StartPath, Extension, pHandler, (Gwen::Event::Handler::FunctionStr)fnCallback);
}
} // namespace Dialogs
} // namespace Gwen
#endif

View File

@@ -4,11 +4,11 @@
#include "Gwen/Gwen.h"
namespace Gwen
namespace Gwen
{
namespace Dialogs
{
//TODO. YesNo, Ok etc
}
namespace Dialogs
{
//TODO. YesNo, Ok etc
}
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/DockBase.h"
@@ -16,11 +15,10 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( DockBase )
GWEN_CONTROL_CONSTRUCTOR(DockBase)
{
SetPadding( Padding( 1, 1, 1, 1 ) );
SetSize( 200, 200 );
SetPadding(Padding(1, 1, 1, 1));
SetSize(200, 200);
m_DockedTabControl = NULL;
m_Left = NULL;
@@ -32,139 +30,141 @@ GWEN_CONTROL_CONSTRUCTOR( DockBase )
}
TabControl* DockBase::GetTabControl()
{
return m_DockedTabControl;
{
return m_DockedTabControl;
}
void DockBase::SetupChildDock( int iPos )
void DockBase::SetupChildDock(int iPos)
{
if ( !m_DockedTabControl )
if (!m_DockedTabControl)
{
m_DockedTabControl = new DockedTabControl( this );
m_DockedTabControl->onLoseTab.Add( this, &DockBase::OnTabRemoved );
m_DockedTabControl->SetTabStripPosition( Pos::Bottom );
m_DockedTabControl->SetShowTitlebar( true );
m_DockedTabControl = new DockedTabControl(this);
m_DockedTabControl->onLoseTab.Add(this, &DockBase::OnTabRemoved);
m_DockedTabControl->SetTabStripPosition(Pos::Bottom);
m_DockedTabControl->SetShowTitlebar(true);
}
Dock( iPos );
Dock(iPos);
int iSizeDirection = Pos::Left;
if ( iPos == Pos::Left ) iSizeDirection = Pos::Right;
if ( iPos == Pos::Top ) iSizeDirection = Pos::Bottom;
if ( iPos == Pos::Bottom ) iSizeDirection = Pos::Top;
if (iPos == Pos::Left) iSizeDirection = Pos::Right;
if (iPos == Pos::Top) iSizeDirection = Pos::Bottom;
if (iPos == Pos::Bottom) iSizeDirection = Pos::Top;
ControlsInternal::Resizer* sizer = new ControlsInternal::Resizer( this );
sizer->Dock( iSizeDirection );
sizer->SetResizeDir( iSizeDirection );
sizer->SetSize( 2, 2 );
sizer->SetTarget( this );
ControlsInternal::Resizer* sizer = new ControlsInternal::Resizer(this);
sizer->Dock(iSizeDirection);
sizer->SetResizeDir(iSizeDirection);
sizer->SetSize(2, 2);
sizer->SetTarget(this);
}
void DockBase::Render( Skin::Base* /*skin*/ )
void DockBase::Render(Skin::Base* /*skin*/)
{
//Gwen::Render->SetDrawColor( Colors::Black );
//Gwen::Render->DrawLinedRect( GetRenderBounds() );
}
DockBase** DockBase::GetChildDockPtr( int iPos )
DockBase** DockBase::GetChildDockPtr(int iPos)
{
if ( iPos == Pos::Left ) return &m_Left;
if ( iPos == Pos::Right ) return &m_Right;
if ( iPos == Pos::Top ) return &m_Top;
if ( iPos == Pos::Bottom ) return &m_Bottom;
if (iPos == Pos::Left) return &m_Left;
if (iPos == Pos::Right) return &m_Right;
if (iPos == Pos::Top) return &m_Top;
if (iPos == Pos::Bottom) return &m_Bottom;
return NULL;
}
DockBase* DockBase::GetChildDock( int iPos )
DockBase* DockBase::GetChildDock(int iPos)
{
DockBase** pDock = GetChildDockPtr( iPos );
if ( !(*pDock) )
DockBase** pDock = GetChildDockPtr(iPos);
if (!(*pDock))
{
(*pDock) = new DockBase( this );
(*pDock)->SetupChildDock( iPos );
(*pDock) = new DockBase(this);
(*pDock)->SetupChildDock(iPos);
}
else
{
(*pDock)->SetHidden( false );
(*pDock)->SetHidden(false);
}
return *pDock;
}
int DockBase::GetDroppedTabDirection( int x, int y )
int DockBase::GetDroppedTabDirection(int x, int y)
{
int w = Width();
int h = Height();
float top = (float)y / (float) h;
float left = (float)x / (float) w;
float right = (float)(w - x) /(float) w;
float bottom = (float)(h - y) / (float) h;
float top = (float)y / (float)h;
float left = (float)x / (float)w;
float right = (float)(w - x) / (float)w;
float bottom = (float)(h - y) / (float)h;
float minimum = GwenUtil_Min( GwenUtil_Min( GwenUtil_Min( top, left ), right ), bottom );
m_bDropFar = ( minimum < 0.2f );
if ( minimum > 0.3 ) return Pos::Fill;
float minimum = GwenUtil_Min(GwenUtil_Min(GwenUtil_Min(top, left), right), bottom);
m_bDropFar = (minimum < 0.2f);
if (minimum > 0.3) return Pos::Fill;
if ( top == minimum && (!m_Top || m_Top->Hidden()) ) return Pos::Top;
if ( left == minimum && (!m_Left || m_Left->Hidden()) ) return Pos::Left;
if ( right == minimum && (!m_Right || m_Right->Hidden()) ) return Pos::Right;
if ( bottom == minimum && (!m_Bottom || m_Bottom->Hidden()) ) return Pos::Bottom;
if (top == minimum && (!m_Top || m_Top->Hidden())) return Pos::Top;
if (left == minimum && (!m_Left || m_Left->Hidden())) return Pos::Left;
if (right == minimum && (!m_Right || m_Right->Hidden())) return Pos::Right;
if (bottom == minimum && (!m_Bottom || m_Bottom->Hidden())) return Pos::Bottom;
return Pos::Fill;
}
bool DockBase::DragAndDrop_CanAcceptPackage( Gwen::DragAndDrop::Package* pPackage )
bool DockBase::DragAndDrop_CanAcceptPackage(Gwen::DragAndDrop::Package* pPackage)
{
// A TAB button dropped
if ( pPackage->name == "TabButtonMove" )
// A TAB button dropped
if (pPackage->name == "TabButtonMove")
return true;
// a TAB window dropped
if ( pPackage->name == "TabWindowMove" )
if (pPackage->name == "TabWindowMove")
return true;
return false;
}
void AddTabToDock( TabButton* pTabButton, DockedTabControl* pControl )
void AddTabToDock(TabButton* pTabButton, DockedTabControl* pControl)
{
pControl->AddPage( pTabButton );
pControl->AddPage(pTabButton);
}
bool DockBase::DragAndDrop_HandleDrop( Gwen::DragAndDrop::Package* pPackage, int x, int y )
bool DockBase::DragAndDrop_HandleDrop(Gwen::DragAndDrop::Package* pPackage, int x, int y)
{
Gwen::Point pPos = CanvasPosToLocal( Gwen::Point( x, y ) );
int dir = GetDroppedTabDirection( pPos.x, pPos.y );
Gwen::Point pPos = CanvasPosToLocal(Gwen::Point(x, y));
int dir = GetDroppedTabDirection(pPos.x, pPos.y);
DockedTabControl* pAddTo = m_DockedTabControl;
if ( dir == Pos::Fill && pAddTo == NULL ) return false;
if (dir == Pos::Fill && pAddTo == NULL) return false;
if ( dir != Pos::Fill )
if (dir != Pos::Fill)
{
DockBase* pDock = GetChildDock( dir );
DockBase* pDock = GetChildDock(dir);
pAddTo = pDock->m_DockedTabControl;
if ( !m_bDropFar ) pDock->BringToFront();
else pDock->SendToBack();
if (!m_bDropFar)
pDock->BringToFront();
else
pDock->SendToBack();
}
if ( pPackage->name == "TabButtonMove" )
if (pPackage->name == "TabButtonMove")
{
TabButton* pTabButton = DragAndDrop::SourceControl->DynamicCastTabButton();
if ( !pTabButton ) return false;
if (!pTabButton) return false;
AddTabToDock( pTabButton, pAddTo );
AddTabToDock(pTabButton, pAddTo);
}
if ( pPackage->name == "TabWindowMove" )
if (pPackage->name == "TabWindowMove")
{
DockedTabControl* pTabControl = DragAndDrop::SourceControl->DynamicCastDockedTabControl();
if ( !pTabControl ) return false;
if ( pTabControl == pAddTo ) return false;
if (!pTabControl) return false;
if (pTabControl == pAddTo) return false;
pTabControl->MoveTabsTo( pAddTo );
pTabControl->MoveTabsTo(pAddTo);
}
Invalidate();
@@ -174,17 +174,17 @@ bool DockBase::DragAndDrop_HandleDrop( Gwen::DragAndDrop::Package* pPackage, int
bool DockBase::IsEmpty()
{
if ( m_DockedTabControl && m_DockedTabControl->TabCount() > 0 ) return false;
if (m_DockedTabControl && m_DockedTabControl->TabCount() > 0) return false;
if ( m_Left && !m_Left->IsEmpty() ) return false;
if ( m_Right && !m_Right->IsEmpty() ) return false;
if ( m_Top && !m_Top->IsEmpty() ) return false;
if ( m_Bottom && !m_Bottom->IsEmpty() ) return false;
if (m_Left && !m_Left->IsEmpty()) return false;
if (m_Right && !m_Right->IsEmpty()) return false;
if (m_Top && !m_Top->IsEmpty()) return false;
if (m_Bottom && !m_Bottom->IsEmpty()) return false;
return true;
}
void DockBase::OnTabRemoved( Gwen::Controls::Base* /*pControl*/ )
void DockBase::OnTabRemoved(Gwen::Controls::Base* /*pControl*/)
{
DoRedundancyCheck();
DoConsolidateCheck();
@@ -192,72 +192,72 @@ void DockBase::OnTabRemoved( Gwen::Controls::Base* /*pControl*/ )
void DockBase::DoRedundancyCheck()
{
if ( !IsEmpty() ) return;
if (!IsEmpty()) return;
DockBase* pDockParent = GetParent()->DynamicCastDockBase();
if ( !pDockParent ) return;
if (!pDockParent) return;
pDockParent->OnRedundantChildDock( this );
pDockParent->OnRedundantChildDock(this);
}
void DockBase::DoConsolidateCheck()
{
if ( IsEmpty() ) return;
if ( !m_DockedTabControl ) return;
if ( m_DockedTabControl->TabCount() > 0 ) return;
if (IsEmpty()) return;
if (!m_DockedTabControl) return;
if (m_DockedTabControl->TabCount() > 0) return;
if ( m_Bottom && !m_Bottom->IsEmpty() )
if (m_Bottom && !m_Bottom->IsEmpty())
{
m_Bottom->m_DockedTabControl->MoveTabsTo( m_DockedTabControl );
m_Bottom->m_DockedTabControl->MoveTabsTo(m_DockedTabControl);
return;
}
if ( m_Top && !m_Top->IsEmpty() )
if (m_Top && !m_Top->IsEmpty())
{
m_Top->m_DockedTabControl->MoveTabsTo( m_DockedTabControl );
m_Top->m_DockedTabControl->MoveTabsTo(m_DockedTabControl);
return;
}
if ( m_Left && !m_Left->IsEmpty() )
if (m_Left && !m_Left->IsEmpty())
{
m_Left->m_DockedTabControl->MoveTabsTo( m_DockedTabControl );
m_Left->m_DockedTabControl->MoveTabsTo(m_DockedTabControl);
return;
}
if ( m_Right && !m_Right->IsEmpty() )
if (m_Right && !m_Right->IsEmpty())
{
m_Right->m_DockedTabControl->MoveTabsTo( m_DockedTabControl );
m_Right->m_DockedTabControl->MoveTabsTo(m_DockedTabControl);
return;
}
}
void DockBase::OnRedundantChildDock( DockBase* pDockBase )
void DockBase::OnRedundantChildDock(DockBase* pDockBase)
{
pDockBase->SetHidden( true );
pDockBase->SetHidden(true);
DoRedundancyCheck();
DoConsolidateCheck();
}
void DockBase::DragAndDrop_HoverEnter( Gwen::DragAndDrop::Package* /*pPackage*/, int /*x*/, int /*y*/ )
void DockBase::DragAndDrop_HoverEnter(Gwen::DragAndDrop::Package* /*pPackage*/, int /*x*/, int /*y*/)
{
m_bDrawHover = true;
}
void DockBase::DragAndDrop_HoverLeave( Gwen::DragAndDrop::Package* /*pPackage*/ )
void DockBase::DragAndDrop_HoverLeave(Gwen::DragAndDrop::Package* /*pPackage*/)
{
m_bDrawHover = false;
}
void DockBase::DragAndDrop_Hover( Gwen::DragAndDrop::Package* /*pPackage*/, int x, int y )
void DockBase::DragAndDrop_Hover(Gwen::DragAndDrop::Package* /*pPackage*/, int x, int y)
{
Gwen::Point pPos = CanvasPosToLocal( Gwen::Point( x, y ) );
int dir = GetDroppedTabDirection( pPos.x, pPos.y );
Gwen::Point pPos = CanvasPosToLocal(Gwen::Point(x, y));
int dir = GetDroppedTabDirection(pPos.x, pPos.y);
if ( dir == Pos::Fill )
if (dir == Pos::Fill)
{
if ( !m_DockedTabControl )
if (!m_DockedTabControl)
{
m_HoverRect = Gwen::Rect( 0, 0, 0, 0 );
m_HoverRect = Gwen::Rect(0, 0, 0, 0);
return;
}
@@ -269,75 +269,75 @@ void DockBase::DragAndDrop_Hover( Gwen::DragAndDrop::Package* /*pPackage*/, int
int HelpBarWidth = 0;
if ( dir == Pos::Left )
if (dir == Pos::Left)
{
HelpBarWidth = m_HoverRect.w * 0.25f;
m_HoverRect.w = HelpBarWidth;
}
if ( dir == Pos::Right )
if (dir == Pos::Right)
{
HelpBarWidth = m_HoverRect.w * 0.25f;
m_HoverRect.x = m_HoverRect.w - HelpBarWidth;
m_HoverRect.w = HelpBarWidth;
}
if ( dir == Pos::Top )
if (dir == Pos::Top)
{
HelpBarWidth = m_HoverRect.h * 0.25f;
m_HoverRect.h = HelpBarWidth;
}
if ( dir == Pos::Bottom )
if (dir == Pos::Bottom)
{
HelpBarWidth = m_HoverRect.h * 0.25f;
m_HoverRect.y = m_HoverRect.h - HelpBarWidth;
m_HoverRect.h = HelpBarWidth;
}
if ( (dir == Pos::Top || dir == Pos::Bottom ) && !m_bDropFar )
if ((dir == Pos::Top || dir == Pos::Bottom) && !m_bDropFar)
{
if ( m_Left && m_Left->Visible() )
if (m_Left && m_Left->Visible())
{
m_HoverRect.x += m_Left->Width();
m_HoverRect.w -= m_Left->Width();
}
if ( m_Right && m_Right->Visible() )
if (m_Right && m_Right->Visible())
{
m_HoverRect.w -= m_Right->Width();
}
}
if ( (dir == Pos::Left || dir == Pos::Right ) && !m_bDropFar )
if ((dir == Pos::Left || dir == Pos::Right) && !m_bDropFar)
{
if ( m_Top && m_Top->Visible() )
if (m_Top && m_Top->Visible())
{
m_HoverRect.y += m_Top->Height();
m_HoverRect.h -= m_Top->Height();
}
if ( m_Bottom && m_Bottom->Visible() )
if (m_Bottom && m_Bottom->Visible())
{
m_HoverRect.h -= m_Bottom->Height();
}
}
}
void DockBase::RenderOver( Skin::Base* skin )
void DockBase::RenderOver(Skin::Base* skin)
{
if ( !m_bDrawHover ) return;
if (!m_bDrawHover) return;
Gwen::Renderer::Base* render = skin->GetRender();
render->SetDrawColor( Gwen::Color( 255, 100, 255, 20 ) );
render->DrawFilledRect( GetRenderBounds() );
render->SetDrawColor(Gwen::Color(255, 100, 255, 20));
render->DrawFilledRect(GetRenderBounds());
if ( m_HoverRect.w == 0 ) return;
if (m_HoverRect.w == 0) return;
render->SetDrawColor( Gwen::Color( 255, 100, 255, 100 ) );
render->DrawFilledRect( m_HoverRect );
render->SetDrawColor(Gwen::Color(255, 100, 255, 100));
render->DrawFilledRect(m_HoverRect);
render->SetDrawColor( Gwen::Color( 255, 100, 255, 200 ) );
render->DrawLinedRect( m_HoverRect );
render->SetDrawColor(Gwen::Color(255, 100, 255, 200));
render->DrawLinedRect(m_HoverRect);
}

View File

@@ -11,67 +11,64 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/Button.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class DockedTabControl;
class TabControl;
namespace Controls
{
class DockedTabControl;
class TabControl;
class GWEN_EXPORT DockBase : public Base
{
public:
class GWEN_EXPORT DockBase : public Base
{
public:
GWEN_CONTROL(DockBase, Base);
GWEN_CONTROL( DockBase, Base );
virtual void Render(Skin::Base* skin);
virtual void RenderOver(Skin::Base* skin);
virtual bool IsEmpty();
virtual void Render( Skin::Base* skin );
virtual void RenderOver( Skin::Base* skin );
virtual bool IsEmpty();
virtual TabControl* GetTabControl();
virtual TabControl* GetTabControl();
virtual DockBase* GetRight() { return GetChildDock(Pos::Right); }
virtual DockBase* GetLeft() { return GetChildDock(Pos::Left); }
virtual DockBase* GetTop() { return GetChildDock(Pos::Top); }
virtual DockBase* GetBottom() { return GetChildDock(Pos::Bottom); }
virtual DockBase* GetRight(){ return GetChildDock( Pos::Right ); }
virtual DockBase* GetLeft(){ return GetChildDock( Pos::Left ); }
virtual DockBase* GetTop(){ return GetChildDock( Pos::Top ); }
virtual DockBase* GetBottom(){ return GetChildDock( Pos::Bottom ); }
// No action on space (default button action is to press)
virtual bool OnKeySpace(bool /*bDown*/) { return false; }
// No action on space (default button action is to press)
virtual bool OnKeySpace( bool /*bDown*/ ){ return false; }
private:
private:
// Drag n Drop
virtual bool DragAndDrop_HandleDrop(Gwen::DragAndDrop::Package* pPackage, int x, int y);
virtual bool DragAndDrop_CanAcceptPackage(Gwen::DragAndDrop::Package* pPackage);
virtual void DragAndDrop_HoverEnter(Gwen::DragAndDrop::Package* pPackage, int x, int y);
virtual void DragAndDrop_HoverLeave(Gwen::DragAndDrop::Package* pPackage);
virtual void DragAndDrop_Hover(Gwen::DragAndDrop::Package* pPackage, int x, int y);
// Drag n Drop
virtual bool DragAndDrop_HandleDrop( Gwen::DragAndDrop::Package* pPackage, int x, int y );
virtual bool DragAndDrop_CanAcceptPackage( Gwen::DragAndDrop::Package* pPackage );
virtual void DragAndDrop_HoverEnter( Gwen::DragAndDrop::Package* pPackage, int x, int y );
virtual void DragAndDrop_HoverLeave( Gwen::DragAndDrop::Package* pPackage );
virtual void DragAndDrop_Hover( Gwen::DragAndDrop::Package* pPackage, int x, int y );
virtual void SetupChildDock(int iPos);
virtual void SetupChildDock( int iPos );
virtual void DoRedundancyCheck();
virtual void DoConsolidateCheck();
virtual void OnRedundantChildDock(DockBase* pDockBase);
virtual void DoRedundancyCheck();
virtual void DoConsolidateCheck();
virtual void OnRedundantChildDock( DockBase* pDockBase );
virtual int GetDroppedTabDirection(int x, int y);
virtual void OnTabRemoved(Gwen::Controls::Base* pControl);
virtual int GetDroppedTabDirection( int x, int y );
virtual void OnTabRemoved( Gwen::Controls::Base* pControl );
DockBase* GetChildDock(int iPos);
DockBase** GetChildDockPtr(int iPos);
DockBase* GetChildDock( int iPos );
DockBase** GetChildDockPtr( int iPos );
DockBase* m_Left;
DockBase* m_Right;
DockBase* m_Top;
DockBase* m_Bottom;
DockBase* m_Left;
DockBase* m_Right;
DockBase* m_Top;
DockBase* m_Bottom;
// Only CHILD dockpanels have a tabcontrol.
DockedTabControl* m_DockedTabControl;
// Only CHILD dockpanels have a tabcontrol.
DockedTabControl* m_DockedTabControl;
bool m_bDrawHover;
bool m_bDropFar;
Gwen::Rect m_HoverRect;
};
}
}
bool m_bDrawHover;
bool m_bDropFar;
Gwen::Rect m_HoverRect;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/DockedTabControl.h"
@@ -15,51 +14,50 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( DockedTabControl )
GWEN_CONTROL_CONSTRUCTOR(DockedTabControl)
{
m_WindowControl = NULL;
Dock( Pos::Fill );
m_pTitleBar = new TabTitleBar( this );
m_pTitleBar->Dock( Pos::Top );
m_pTitleBar->SetHidden( true );
Dock(Pos::Fill);
m_pTitleBar = new TabTitleBar(this);
m_pTitleBar->Dock(Pos::Top);
m_pTitleBar->SetHidden(true);
}
void DockedTabControl::Layout( Skin::Base* skin )
void DockedTabControl::Layout(Skin::Base* skin)
{
GetTabStrip()->SetHidden( TabCount() <= 1 );
GetTabStrip()->SetHidden(TabCount() <= 1);
UpdateTitleBar();
BaseClass::Layout( skin );
BaseClass::Layout(skin);
}
void DockedTabControl::UpdateTitleBar()
{
if ( !GetCurrentButton() ) return;
{
if (!GetCurrentButton()) return;
m_pTitleBar->UpdateFromTab( GetCurrentButton() );
m_pTitleBar->UpdateFromTab(GetCurrentButton());
}
void DockedTabControl::DragAndDrop_StartDragging( Gwen::DragAndDrop::Package* pPackage, int x, int y )
void DockedTabControl::DragAndDrop_StartDragging(Gwen::DragAndDrop::Package* pPackage, int x, int y)
{
BaseClass::DragAndDrop_StartDragging( pPackage, x, y );
BaseClass::DragAndDrop_StartDragging(pPackage, x, y);
SetHidden( true );
SetHidden(true);
// This hiding our parent thing is kind of lousy.
GetParent()->SetHidden( true );
GetParent()->SetHidden(true);
}
void DockedTabControl::DragAndDrop_EndDragging( bool bSuccess, int /*x*/, int /*y*/ )
void DockedTabControl::DragAndDrop_EndDragging(bool bSuccess, int /*x*/, int /*y*/)
{
SetHidden( false );
SetHidden(false);
if ( !bSuccess )
if (!bSuccess)
{
GetParent()->SetHidden( false );
GetParent()->SetHidden(false);
}
/*
/*
if ( !bSuccess )
{
// Create our window control
@@ -77,15 +75,15 @@ void DockedTabControl::DragAndDrop_EndDragging( bool bSuccess, int /*x*/, int /*
*/
}
void DockedTabControl::MoveTabsTo( DockedTabControl* pTarget )
void DockedTabControl::MoveTabsTo(DockedTabControl* pTarget)
{
Base::List Children = GetTabStrip()->Children;
for (Base::List::iterator iter = Children.begin(); iter != Children.end(); ++iter)
{
TabButton* pButton = (*iter)->DynamicCastTabButton();
if ( !pButton ) continue;
if (!pButton) continue;
pTarget->AddPage( pButton );
pTarget->AddPage(pButton);
}
Invalidate();

View File

@@ -11,32 +11,29 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/TabControl.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT DockedTabControl : public TabControl
{
public:
namespace Controls
{
class GWEN_EXPORT DockedTabControl : public TabControl
{
public:
GWEN_CONTROL(DockedTabControl, TabControl);
GWEN_CONTROL( DockedTabControl, TabControl );
void SetShowTitlebar(bool bShow) { m_pTitleBar->SetHidden(!bShow); }
void SetShowTitlebar( bool bShow ){ m_pTitleBar->SetHidden( !bShow ); }
void Layout(Skin::Base* skin);
void UpdateTitleBar();
void Layout( Skin::Base* skin );
void UpdateTitleBar();
virtual void DragAndDrop_StartDragging(Gwen::DragAndDrop::Package* pPackage, int x, int y);
virtual void DragAndDrop_EndDragging(bool bSuccess, int x, int y);
virtual void DragAndDrop_StartDragging( Gwen::DragAndDrop::Package* pPackage, int x, int y );
virtual void DragAndDrop_EndDragging( bool bSuccess, int x, int y );
void MoveTabsTo(DockedTabControl* pTarget);
void MoveTabsTo( DockedTabControl* pTarget );
private:
TabTitleBar* m_pTitleBar;
Base* m_WindowControl;
};
}
}
private:
TabTitleBar* m_pTitleBar;
Base* m_WindowControl;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,29 +4,26 @@
See license in Gwen.h
*/
#include "Gwen/Controls/Dragger.h"
using namespace Gwen;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( Dragger )
GWEN_CONTROL_CONSTRUCTOR(Dragger)
{
m_pTarget = NULL;
SetMouseInputEnabled( true );
SetMouseInputEnabled(true);
m_bDepressed = false;
}
void Dragger::OnMouseClickLeft( int x, int y, bool bDown )
void Dragger::OnMouseClickLeft(int x, int y, bool bDown)
{
if ( !m_pTarget ) return;
if (!m_pTarget) return;
if ( bDown )
if (bDown)
{
m_bDepressed = true;
m_HoldPos = m_pTarget->CanvasPosToLocal( Gwen::Point( x, y ) );
m_HoldPos = m_pTarget->CanvasPosToLocal(Gwen::Point(x, y));
Gwen::MouseFocus = this;
}
else
@@ -37,23 +34,23 @@ void Dragger::OnMouseClickLeft( int x, int y, bool bDown )
}
}
void Dragger::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
void Dragger::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
{
if ( !m_pTarget ) return;
if ( !m_bDepressed ) return;
if (!m_pTarget) return;
if (!m_bDepressed) return;
Gwen::Point p = Gwen::Point(x - m_HoldPos.x, y - m_HoldPos.y);
Gwen::Point p = Gwen::Point( x - m_HoldPos.x, y - m_HoldPos.y );
// Translate to parent
if ( m_pTarget->GetParent() )
p = m_pTarget->GetParent()->CanvasPosToLocal( p );
if (m_pTarget->GetParent())
p = m_pTarget->GetParent()->CanvasPosToLocal(p);
//m_pTarget->SetPosition( p.x, p.y );
m_pTarget->MoveTo( p.x, p.y );
onDragged.Call( this );
m_pTarget->MoveTo(p.x, p.y);
onDragged.Call(this);
}
void Dragger::Render( Skin::Base* /*skin*/ )
void Dragger::Render(Skin::Base* /*skin*/)
{
//skin->DrawButton(this,false,false);
}

View File

@@ -12,32 +12,29 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
{
class GWEN_EXPORT Dragger : public Controls::Base
{
public:
namespace ControlsInternal
{
class GWEN_EXPORT Dragger : public Controls::Base
{
public:
GWEN_CONTROL(Dragger, Controls::Base);
GWEN_CONTROL( Dragger, Controls::Base );
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
virtual void OnMouseMoved( int x, int y, int deltaX, int deltaY );
virtual void OnMouseClickLeft(int x, int y, bool bDown);
virtual void Render(Skin::Base* skin);
virtual void OnMouseClickLeft( int x, int y, bool bDown );
virtual void Render( Skin::Base* skin );
virtual void SetTarget(Controls::Base* pBase) { m_pTarget = pBase; }
virtual void SetTarget( Controls::Base* pBase ){ m_pTarget = pBase; }
Gwen::Event::Caller onDragged;
Gwen::Event::Caller onDragged;
protected:
bool m_bDepressed;
Gwen::Point m_HoldPos;
Controls::Base* m_pTarget;
};
}
}
protected:
bool m_bDepressed;
Gwen::Point m_HoldPos;
Controls::Base* m_pTarget;
};
} // namespace ControlsInternal
} // namespace Gwen
#endif

View File

@@ -4,39 +4,35 @@
See license in Gwen.h
*/
#include "Gwen/Controls/GroupBox.h"
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( GroupBox )
GWEN_CONTROL_CONSTRUCTOR(GroupBox)
{
// Set to true, because it's likely that our
// Set to true, because it's likely that our
// children will want mouse input, and they
// can't get it without us..
SetMouseInputEnabled( true );
SetMouseInputEnabled(true);
SetTextPadding( Padding( 10, 0, 0, 0 ) );
SetTextPadding(Padding(10, 0, 0, 0));
SetAlignment( Pos::Top | Pos::Left );
SetAlignment(Pos::Top | Pos::Left);
Invalidate();
m_InnerPanel = new Base( this );
m_InnerPanel->Dock( Pos::Fill );
m_InnerPanel = new Base(this);
m_InnerPanel->Dock(Pos::Fill);
}
void GroupBox::Layout( Skin::Base* skin )
void GroupBox::Layout(Skin::Base* skin)
{
m_InnerPanel->SetMargin( Margin( TextHeight() + 3, 6, 6, 6 ) );
m_InnerPanel->SetMargin(Margin(TextHeight() + 3, 6, 6, 6));
BaseClass::Layout( skin );
BaseClass::Layout(skin);
}
void GroupBox::Render( Skin::Base* skin )
void GroupBox::Render(Skin::Base* skin)
{
skin->DrawGroupBox( this, TextX(), TextHeight(), TextWidth() );
skin->DrawGroupBox(this, TextX(), TextHeight(), TextWidth());
}

View File

@@ -13,22 +13,18 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
namespace Controls
{
class GWEN_EXPORT GroupBox : public Label
{
public:
GWEN_CONTROL(GroupBox, Label);
class GWEN_EXPORT GroupBox : public Label
{
public:
GWEN_CONTROL( GroupBox, Label );
virtual void Render( Skin::Base* skin );
virtual void Layout( Skin::Base* skin );
};
}
}
virtual void Render(Skin::Base* skin);
virtual void Layout(Skin::Base* skin);
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/HSVColorPicker.h"
#include "Gwen/Controls/ColorControls.h"
#include "Gwen/Controls/ColorPicker.h"
@@ -16,141 +15,134 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( HSVColorPicker )
GWEN_CONTROL_CONSTRUCTOR(HSVColorPicker)
{
SetMouseInputEnabled( true );
SetSize( 256, 128 );
SetMouseInputEnabled(true);
SetSize(256, 128);
SetCacheToTexture();
m_LerpBox = new Gwen::Controls::ColorLerpBox( this );
m_LerpBox->onSelectionChanged.Add( this, &HSVColorPicker::ColorBoxChanged );
m_LerpBox->SetPos( 5, 5 );
m_LerpBox = new Gwen::Controls::ColorLerpBox(this);
m_LerpBox->onSelectionChanged.Add(this, &HSVColorPicker::ColorBoxChanged);
m_LerpBox->SetPos(5, 5);
m_ColorSlider = new Gwen::Controls::ColorSlider( this );
m_ColorSlider->SetPos( m_LerpBox->Width() + 15, 5 );
m_ColorSlider->onSelectionChanged.Add( this, &HSVColorPicker::ColorSliderChanged );
m_ColorSlider = new Gwen::Controls::ColorSlider(this);
m_ColorSlider->SetPos(m_LerpBox->Width() + 15, 5);
m_ColorSlider->onSelectionChanged.Add(this, &HSVColorPicker::ColorSliderChanged);
m_After = new Gwen::ControlsInternal::ColorDisplay( this );
m_After->SetSize( 48, 24 );
m_After->SetPos( m_ColorSlider->X() + m_ColorSlider->Width() + 15, 5 );
m_After = new Gwen::ControlsInternal::ColorDisplay(this);
m_After->SetSize(48, 24);
m_After->SetPos(m_ColorSlider->X() + m_ColorSlider->Width() + 15, 5);
m_Before = new Gwen::ControlsInternal::ColorDisplay( this );
m_Before->SetSize( 48, 24 );
m_Before->SetPos( m_After->X(), 28 );
m_Before = new Gwen::ControlsInternal::ColorDisplay(this);
m_Before->SetSize(48, 24);
m_Before->SetPos(m_After->X(), 28);
int x = m_Before->X();
int y = m_Before->Y() + 30;
{
Label* label = new Label( this );
Label* label = new Label(this);
label->SetText(L"R:");
label->SizeToContents();
label->SetPos( x, y );
TextBoxNumeric* numeric = new TextBoxNumeric( this );
numeric->SetName( "RedBox" );
numeric->SetPos( x + 15, y -1 );
numeric->SetSize( 26, 16 );
numeric->SetSelectAllOnFocus( true );
numeric->onTextChanged.Add( this, &HSVColorPicker::NumericTyped );
label->SetPos(x, y);
TextBoxNumeric* numeric = new TextBoxNumeric(this);
numeric->SetName("RedBox");
numeric->SetPos(x + 15, y - 1);
numeric->SetSize(26, 16);
numeric->SetSelectAllOnFocus(true);
numeric->onTextChanged.Add(this, &HSVColorPicker::NumericTyped);
}
y+= 20;
y += 20;
{
Label* label = new Label( this );
Label* label = new Label(this);
label->SetText(L"G:");
label->SizeToContents();
label->SetPos( x, y );
label->SetPos(x, y);
TextBoxNumeric* numeric = new TextBoxNumeric( this );
numeric->SetName( "GreenBox" );
numeric->SetPos( x + 15, y -1 );
numeric->SetSize( 26, 16 );
numeric->SetSelectAllOnFocus( true );
numeric->onTextChanged.Add( this, &HSVColorPicker::NumericTyped );
TextBoxNumeric* numeric = new TextBoxNumeric(this);
numeric->SetName("GreenBox");
numeric->SetPos(x + 15, y - 1);
numeric->SetSize(26, 16);
numeric->SetSelectAllOnFocus(true);
numeric->onTextChanged.Add(this, &HSVColorPicker::NumericTyped);
}
y+= 20;
y += 20;
{
Label* label = new Label( this );
Label* label = new Label(this);
label->SetText(L"B:");
label->SizeToContents();
label->SetPos( x, y );
label->SetPos(x, y);
TextBoxNumeric* numeric = new TextBoxNumeric( this );
numeric->SetName( "BlueBox" );
numeric->SetPos( x + 15, y -1 );
numeric->SetSize( 26, 16 );
numeric->SetSelectAllOnFocus( true );
numeric->onTextChanged.Add( this, &HSVColorPicker::NumericTyped );
TextBoxNumeric* numeric = new TextBoxNumeric(this);
numeric->SetName("BlueBox");
numeric->SetPos(x + 15, y - 1);
numeric->SetSize(26, 16);
numeric->SetSelectAllOnFocus(true);
numeric->onTextChanged.Add(this, &HSVColorPicker::NumericTyped);
}
}
void HSVColorPicker::NumericTyped( Gwen::Controls::Base* control )
void HSVColorPicker::NumericTyped(Gwen::Controls::Base* control)
{
TextBoxNumeric* box = control->DynamicCastTextBoxNumeric();
if ( !box ) return;
if (!box) return;
if ( box->GetText() == L"" ) return;
if (box->GetText() == L"") return;
int textValue = atoi( Gwen::Utility::UnicodeToString( box->GetText()).c_str() );
if ( textValue < 0 ) textValue = 0;
if ( textValue > 255 ) textValue = 255;
int textValue = atoi(Gwen::Utility::UnicodeToString(box->GetText()).c_str());
if (textValue < 0) textValue = 0;
if (textValue > 255) textValue = 255;
Gwen::Color newColor = GetColor();
if ( box->GetName().find( "Red" ) != Gwen::String::npos )
if (box->GetName().find("Red") != Gwen::String::npos)
{
newColor.r = textValue;
}
else if ( box->GetName().find( "Green" ) != Gwen::String::npos )
else if (box->GetName().find("Green") != Gwen::String::npos)
{
newColor.g = textValue;
}
else if ( box->GetName().find( "Blue" ) != Gwen::String::npos )
else if (box->GetName().find("Blue") != Gwen::String::npos)
{
newColor.b = textValue;
}
else if ( box->GetName().find( "Alpha" ) != Gwen::String::npos )
else if (box->GetName().find("Alpha") != Gwen::String::npos)
{
newColor.a = textValue;
}
SetColor( newColor );
SetColor(newColor);
}
void HSVColorPicker::UpdateControls(Gwen::Color color)
{
TextBoxNumeric* redBox = FindChildByName( "RedBox", false )->DynamicCastTextBoxNumeric();
if ( redBox ) redBox->SetText( Gwen::Utility::ToString( (int)color.r), false );
TextBoxNumeric* redBox = FindChildByName("RedBox", false)->DynamicCastTextBoxNumeric();
if (redBox) redBox->SetText(Gwen::Utility::ToString((int)color.r), false);
TextBoxNumeric* greenBox = FindChildByName( "GreenBox", false )->DynamicCastTextBoxNumeric();
if ( greenBox ) greenBox->SetText( Gwen::Utility::ToString( (int)color.g ), false );
TextBoxNumeric* greenBox = FindChildByName("GreenBox", false)->DynamicCastTextBoxNumeric();
if (greenBox) greenBox->SetText(Gwen::Utility::ToString((int)color.g), false);
TextBoxNumeric* blueBox = FindChildByName( "BlueBox", false )->DynamicCastTextBoxNumeric();
if ( blueBox ) blueBox->SetText( Gwen::Utility::ToString( (int)color.b ), false );
TextBoxNumeric* blueBox = FindChildByName("BlueBox", false)->DynamicCastTextBoxNumeric();
if (blueBox) blueBox->SetText(Gwen::Utility::ToString((int)color.b), false);
m_After->SetColor( color );
m_After->SetColor(color);
}
void HSVColorPicker::SetColor( Gwen::Color color, bool onlyHue, bool reset )
void HSVColorPicker::SetColor(Gwen::Color color, bool onlyHue, bool reset)
{
UpdateControls(color);
UpdateControls( color );
if (reset)
m_Before->SetColor(color);
if ( reset )
m_Before->SetColor( color );
m_ColorSlider->SetColor( color );
m_LerpBox->SetColor( color, onlyHue );
m_After->SetColor( color );
m_ColorSlider->SetColor(color);
m_LerpBox->SetColor(color, onlyHue);
m_After->SetColor(color);
}
Gwen::Color HSVColorPicker::GetColor()
@@ -158,15 +150,15 @@ Gwen::Color HSVColorPicker::GetColor()
return m_LerpBox->GetSelectedColor();
}
void HSVColorPicker::ColorBoxChanged( Gwen::Controls::Base* /*pControl*/ )
void HSVColorPicker::ColorBoxChanged(Gwen::Controls::Base* /*pControl*/)
{
onColorChanged.Call( this );
UpdateControls( GetColor() );
onColorChanged.Call(this);
UpdateControls(GetColor());
Invalidate();
}
void HSVColorPicker::ColorSliderChanged( Gwen::Controls::Base* /*pControl*/ )
void HSVColorPicker::ColorSliderChanged(Gwen::Controls::Base* /*pControl*/)
{
if ( m_LerpBox )
m_LerpBox->SetColor( m_ColorSlider->GetSelectedColor(), true );
if (m_LerpBox)
m_LerpBox->SetColor(m_ColorSlider->GetSelectedColor(), true);
Invalidate();
}

View File

@@ -14,34 +14,33 @@
#include "Gwen/Controls/ColorControls.h"
#include "Gwen/Controls/ColorPicker.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT HSVColorPicker : public Controls::Base
{
public:
GWEN_CONTROL( HSVColorPicker, Controls::Base );
namespace Controls
{
class GWEN_EXPORT HSVColorPicker : public Controls::Base
{
public:
GWEN_CONTROL(HSVColorPicker, Controls::Base);
Gwen::Color GetColor();
Gwen::Color GetDefaultColor() { return m_Before->GetColor(); }
void SetColor( Gwen::Color color, bool onlyHue = false, bool reset = false );
Gwen::Color GetColor();
Gwen::Color GetDefaultColor() { return m_Before->GetColor(); }
void SetColor(Gwen::Color color, bool onlyHue = false, bool reset = false);
void ColorBoxChanged( Gwen::Controls::Base* pControl );
void ColorSliderChanged( Gwen::Controls::Base* pControl );
void NumericTyped( Gwen::Controls::Base* control );
void ColorBoxChanged(Gwen::Controls::Base* pControl);
void ColorSliderChanged(Gwen::Controls::Base* pControl);
void NumericTyped(Gwen::Controls::Base* control);
void UpdateControls( Gwen::Color newColor );
Event::Caller onColorChanged;
void UpdateControls(Gwen::Color newColor);
protected:
ColorLerpBox* m_LerpBox;
ColorSlider* m_ColorSlider;
ControlsInternal::ColorDisplay* m_Before;
ControlsInternal::ColorDisplay* m_After;
};
}
}
Event::Caller onColorChanged;
protected:
ColorLerpBox* m_LerpBox;
ColorSlider* m_ColorSlider;
ControlsInternal::ColorDisplay* m_Before;
ControlsInternal::ColorDisplay* m_After;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -12,25 +12,23 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
namespace ControlsInternal
{
class GWEN_EXPORT Highlight : public Controls::Base
{
public:
GWEN_CONTROL_INLINE(Highlight, Controls::Base)
{
class GWEN_EXPORT Highlight : public Controls::Base
{
public:
GWEN_CONTROL_INLINE( Highlight, Controls::Base )
{
}
void Render( Skin::Base* skin )
{
skin->DrawHighlight( this );
}
};
}
}
void Render(Skin::Base* skin)
{
skin->DrawHighlight(this);
}
};
} // namespace ControlsInternal
} // namespace Gwen
#endif

View File

@@ -4,99 +4,96 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ScrollBar.h"
#include "Gwen/Controls/HorizontalScrollBar.h"
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( HorizontalScrollBar )
GWEN_CONTROL_CONSTRUCTOR(HorizontalScrollBar)
{
m_Bar->SetHorizontal();
m_ScrollButton[SCROLL_BUTTON_LEFT]->SetDirectionLeft();
m_ScrollButton[SCROLL_BUTTON_LEFT]->onPress.Add( this, &HorizontalScrollBar::NudgeLeft );
m_ScrollButton[SCROLL_BUTTON_LEFT]->onPress.Add(this, &HorizontalScrollBar::NudgeLeft);
m_ScrollButton[SCROLL_BUTTON_RIGHT]->SetDirectionRight();
m_ScrollButton[SCROLL_BUTTON_RIGHT]->onPress.Add( this, &HorizontalScrollBar::NudgeRight );
m_ScrollButton[SCROLL_BUTTON_RIGHT]->onPress.Add(this, &HorizontalScrollBar::NudgeRight);
m_Bar->onDragged.Add( this, &HorizontalScrollBar::OnBarMoved );
m_Bar->onDragged.Add(this, &HorizontalScrollBar::OnBarMoved);
}
void HorizontalScrollBar::Layout( Skin::Base* skin )
void HorizontalScrollBar::Layout(Skin::Base* skin)
{
BaseClass::Layout( skin );
BaseClass::Layout(skin);
m_ScrollButton[SCROLL_BUTTON_LEFT]->SetWidth( Height() );
m_ScrollButton[SCROLL_BUTTON_LEFT]->SetWidth(Height());
m_ScrollButton[SCROLL_BUTTON_LEFT]->Dock(Pos::Left);
m_ScrollButton[SCROLL_BUTTON_RIGHT]->SetWidth( Height() );
m_ScrollButton[SCROLL_BUTTON_RIGHT]->SetWidth(Height());
m_ScrollButton[SCROLL_BUTTON_RIGHT]->Dock(Pos::Right);
m_Bar->SetHeight( GetButtonSize() );
m_Bar->SetPadding( Padding( GetButtonSize(), 0, GetButtonSize(), 0 ) );
m_Bar->SetHeight(GetButtonSize());
m_Bar->SetPadding(Padding(GetButtonSize(), 0, GetButtonSize(), 0));
float barWidth = (m_fViewableContentSize / m_fContentSize) * (Width() - (GetButtonSize() * 2));
if ( barWidth < GetButtonSize() * 0.5 )
if (barWidth < GetButtonSize() * 0.5)
barWidth = GetButtonSize() * 0.5;
m_Bar->SetWidth(barWidth);
m_Bar->SetHidden( Width() - (GetButtonSize() * 2) <= barWidth );
m_Bar->SetHidden(Width() - (GetButtonSize() * 2) <= barWidth);
//Based on our last scroll amount, produce a position for the bar
if ( !m_Bar->IsDepressed() )
if (!m_Bar->IsDepressed())
{
SetScrolledAmount( GetScrolledAmount(), true );
SetScrolledAmount(GetScrolledAmount(), true);
}
}
void HorizontalScrollBar::NudgeLeft( Base* /*control*/ )
void HorizontalScrollBar::NudgeLeft(Base* /*control*/)
{
if ( !IsDisabled() )
SetScrolledAmount( GetScrolledAmount() - GetNudgeAmount(), true);
if (!IsDisabled())
SetScrolledAmount(GetScrolledAmount() - GetNudgeAmount(), true);
}
void HorizontalScrollBar::NudgeRight( Base* /*control*/ )
void HorizontalScrollBar::NudgeRight(Base* /*control*/)
{
if ( !IsDisabled() )
SetScrolledAmount( GetScrolledAmount() + GetNudgeAmount(), true);
if (!IsDisabled())
SetScrolledAmount(GetScrolledAmount() + GetNudgeAmount(), true);
}
void HorizontalScrollBar::ScrollToLeft()
{
SetScrolledAmount( 0, true);
SetScrolledAmount(0, true);
}
void HorizontalScrollBar::ScrollToRight()
{
SetScrolledAmount( 1, true);
SetScrolledAmount(1, true);
}
float HorizontalScrollBar::GetNudgeAmount()
{
if ( m_bDepressed )
if (m_bDepressed)
return m_fViewableContentSize / m_fContentSize;
else
else
return BaseClass::GetNudgeAmount();
}
void HorizontalScrollBar::OnMouseClickLeft( int x, int y, bool bDown )
void HorizontalScrollBar::OnMouseClickLeft(int x, int y, bool bDown)
{
if ( bDown )
if (bDown)
{
m_bDepressed = true;
Gwen::MouseFocus = this;
}
else
{
Gwen::Point clickPos = CanvasPosToLocal( Gwen::Point( x, y ) );
if ( clickPos.x < m_Bar->X() )
NudgeLeft( this );
else if ( clickPos.x > m_Bar->X() + m_Bar->Width() )
NudgeRight( this );
Gwen::Point clickPos = CanvasPosToLocal(Gwen::Point(x, y));
if (clickPos.x < m_Bar->X())
NudgeLeft(this);
else if (clickPos.x > m_Bar->X() + m_Bar->Width())
NudgeRight(this);
m_bDepressed = false;
Gwen::MouseFocus = NULL;
@@ -105,30 +102,30 @@ void HorizontalScrollBar::OnMouseClickLeft( int x, int y, bool bDown )
float HorizontalScrollBar::CalculateScrolledAmount()
{
return (float)(m_Bar->X() - GetButtonSize()) / (float)(Width() - m_Bar->Width() - (GetButtonSize() * 2 ));
return (float)(m_Bar->X() - GetButtonSize()) / (float)(Width() - m_Bar->Width() - (GetButtonSize() * 2));
}
bool HorizontalScrollBar::SetScrolledAmount( float amount, bool forceUpdate )
bool HorizontalScrollBar::SetScrolledAmount(float amount, bool forceUpdate)
{
amount = Gwen::Clamp( amount, 0, 1 );
amount = Gwen::Clamp(amount, 0, 1);
if ( !BaseClass::SetScrolledAmount( amount, forceUpdate ) )
if (!BaseClass::SetScrolledAmount(amount, forceUpdate))
return false;
if ( forceUpdate )
if (forceUpdate)
{
int newX = GetButtonSize() + (amount * ((Width() - m_Bar->Width()) - (GetButtonSize()*2)));
m_Bar->MoveTo( newX, m_Bar->Y() );
int newX = GetButtonSize() + (amount * ((Width() - m_Bar->Width()) - (GetButtonSize() * 2)));
m_Bar->MoveTo(newX, m_Bar->Y());
}
return true;
}
void HorizontalScrollBar::OnBarMoved( Controls::Base* control )
void HorizontalScrollBar::OnBarMoved(Controls::Base* control)
{
if ( m_Bar->IsDepressed() )
if (m_Bar->IsDepressed())
{
SetScrolledAmount( CalculateScrolledAmount(), false );
SetScrolledAmount(CalculateScrolledAmount(), false);
BaseClass::OnBarMoved(control);
}
else

View File

@@ -15,35 +15,34 @@
#include "Gwen/Controls/Dragger.h"
#include "Gwen/Controls/ScrollBar.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT HorizontalScrollBar : public BaseScrollBar
{
public:
namespace Controls
{
class GWEN_EXPORT HorizontalScrollBar : public BaseScrollBar
{
public:
GWEN_CONTROL(HorizontalScrollBar, BaseScrollBar);
GWEN_CONTROL( HorizontalScrollBar, BaseScrollBar );
virtual void Layout(Skin::Base* skin);
virtual void Layout( Skin::Base* skin );
virtual void OnMouseClickLeft(int x, int y, bool bDown);
virtual void OnBarMoved(Controls::Base* control);
virtual void OnMouseClickLeft( int x, int y, bool bDown );
virtual void OnBarMoved( Controls::Base* control );
virtual int GetBarSize() { return m_Bar->Width(); }
virtual int GetBarPos() { return m_Bar->X() - Height(); }
virtual void SetBarSize(int size) { m_Bar->SetWidth(size); }
virtual int GetButtonSize() { return Height(); }
virtual int GetBarSize() { return m_Bar->Width(); }
virtual int GetBarPos() { return m_Bar->X() - Height(); }
virtual void SetBarSize( int size ) { m_Bar->SetWidth( size ); }
virtual int GetButtonSize() { return Height(); }
virtual void ScrollToLeft();
virtual void ScrollToRight();
virtual void NudgeLeft(Base* control);
virtual void NudgeRight(Base* control);
virtual float GetNudgeAmount();
virtual void ScrollToLeft();
virtual void ScrollToRight();
virtual void NudgeLeft( Base* control );
virtual void NudgeRight( Base* control );
virtual float GetNudgeAmount();
virtual float CalculateScrolledAmount();
virtual bool SetScrolledAmount(float amount, bool forceUpdate);
};
}
}
virtual float CalculateScrolledAmount();
virtual bool SetScrolledAmount(float amount, bool forceUpdate);
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/Slider.h"
#include "Gwen/Controls/HorizontalSlider.h"
@@ -12,34 +11,33 @@ using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( HorizontalSlider )
GWEN_CONTROL_CONSTRUCTOR(HorizontalSlider)
{
}
float HorizontalSlider::CalculateValue()
{
return (float)m_SliderBar->X() / (float)( Width() - m_SliderBar->Width() );
return (float)m_SliderBar->X() / (float)(Width() - m_SliderBar->Width());
}
void HorizontalSlider::UpdateBarFromValue()
{
m_SliderBar->MoveTo( ( Width() - m_SliderBar->Width() ) * ( m_fValue ), m_SliderBar->Y() );
m_SliderBar->MoveTo((Width() - m_SliderBar->Width()) * (m_fValue), m_SliderBar->Y());
}
void HorizontalSlider::OnMouseClickLeft( int x, int y, bool bDown )
void HorizontalSlider::OnMouseClickLeft(int x, int y, bool bDown)
{
m_SliderBar->MoveTo( CanvasPosToLocal( Gwen::Point( x, y ) ).x - m_SliderBar->Width() * 0.5, m_SliderBar->Y() );
m_SliderBar->OnMouseClickLeft( x, y, bDown );
OnMoved( m_SliderBar );
m_SliderBar->MoveTo(CanvasPosToLocal(Gwen::Point(x, y)).x - m_SliderBar->Width() * 0.5, m_SliderBar->Y());
m_SliderBar->OnMouseClickLeft(x, y, bDown);
OnMoved(m_SliderBar);
}
void HorizontalSlider::Layout(Skin::Base* /*skin*/)
{
m_SliderBar->SetSize( 10, Height() );
m_SliderBar->SetSize(10, Height());
}
void HorizontalSlider::Render( Skin::Base* skin )
void HorizontalSlider::Render(Skin::Base* skin)
{
skin->DrawSlider( this, true, m_bClampToNotches ? m_iNumNotches : 0, m_SliderBar->Width() );
skin->DrawSlider(this, true, m_bClampToNotches ? m_iNumNotches : 0, m_SliderBar->Width());
}

View File

@@ -15,21 +15,21 @@
#include "Gwen/Skin.h"
#include "Gwen/Controls/Slider.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT HorizontalSlider : public Slider
{
GWEN_CONTROL( HorizontalSlider, Slider );
namespace Controls
{
class GWEN_EXPORT HorizontalSlider : public Slider
{
GWEN_CONTROL(HorizontalSlider, Slider);
virtual void Layout( Skin::Base* skin );
virtual void Render( Skin::Base* skin );
virtual void Layout(Skin::Base* skin);
virtual void Render(Skin::Base* skin);
virtual float CalculateValue();
virtual void UpdateBarFromValue();
virtual void OnMouseClickLeft( int x, int y, bool bDown );
};
}
}
virtual float CalculateValue();
virtual void UpdateBarFromValue();
virtual void OnMouseClickLeft(int x, int y, bool bDown);
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,5 +4,4 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ImagePanel.h"

View File

@@ -13,66 +13,63 @@
#include "Gwen/BaseRender.h"
#include "Gwen/Texture.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT ImagePanel : public Controls::Base
{
public:
GWEN_CONTROL_INLINE(ImagePanel, Controls::Base)
{
class GWEN_EXPORT ImagePanel : public Controls::Base
{
public:
GWEN_CONTROL_INLINE( ImagePanel, Controls::Base )
{
SetUV( 0, 0, 1, 1 );
SetMouseInputEnabled( false );
m_DrawColor = Colors::White;
}
virtual ~ImagePanel()
{
m_Texture.Release( GetSkin()->GetRender() );
}
virtual void SetUV( float u1, float v1, float u2, float v2 )
{
m_uv[0] = u1;
m_uv[1] = v1;
m_uv[2] = u2;
m_uv[3] = v2;
}
virtual void SetImage( const TextObject& imageName )
{
m_Texture.Load( imageName, GetSkin()->GetRender() );
}
virtual const TextObject& GetImageName()
{
return m_Texture.name;
}
virtual void Render( Skin::Base* skin )
{
skin->GetRender()->SetDrawColor( m_DrawColor );
skin->GetRender()->DrawTexturedRect( &m_Texture, GetRenderBounds(), m_uv[0], m_uv[1], m_uv[2], m_uv[3] );
}
virtual void SizeToContents()
{
SetSize( m_Texture.width, m_Texture.height );
}
virtual void SetDrawColor( Gwen::Color& color )
{
m_DrawColor = color;
}
Texture m_Texture;
float m_uv[4];
Gwen::Color m_DrawColor;
};
SetUV(0, 0, 1, 1);
SetMouseInputEnabled(false);
m_DrawColor = Colors::White;
}
}
virtual ~ImagePanel()
{
m_Texture.Release(GetSkin()->GetRender());
}
virtual void SetUV(float u1, float v1, float u2, float v2)
{
m_uv[0] = u1;
m_uv[1] = v1;
m_uv[2] = u2;
m_uv[3] = v2;
}
virtual void SetImage(const TextObject& imageName)
{
m_Texture.Load(imageName, GetSkin()->GetRender());
}
virtual const TextObject& GetImageName()
{
return m_Texture.name;
}
virtual void Render(Skin::Base* skin)
{
skin->GetRender()->SetDrawColor(m_DrawColor);
skin->GetRender()->DrawTexturedRect(&m_Texture, GetRenderBounds(), m_uv[0], m_uv[1], m_uv[2], m_uv[3]);
}
virtual void SizeToContents()
{
SetSize(m_Texture.width, m_Texture.height);
}
virtual void SetDrawColor(Gwen::Color& color)
{
m_DrawColor = color;
}
Texture m_Texture;
float m_uv[4];
Gwen::Color m_DrawColor;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Label.h"
#include "Gwen/Utility.h"
@@ -12,62 +11,59 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( Label )
GWEN_CONTROL_CONSTRUCTOR(Label)
{
m_Text = new ControlsInternal::Text( this );
m_Text->SetFont( GetSkin()->GetDefaultFont() );
m_Text = new ControlsInternal::Text(this);
m_Text->SetFont(GetSkin()->GetDefaultFont());
SetMouseInputEnabled( false );
SetBounds( 0, 0, 100, 10 );
SetAlignment( Gwen::Pos::Left | Gwen::Pos::Top );
SetMouseInputEnabled(false);
SetBounds(0, 0, 100, 10);
SetAlignment(Gwen::Pos::Left | Gwen::Pos::Top);
}
void Label::Layout( Skin::Base* /*skin*/ )
void Label::Layout(Skin::Base* /*skin*/)
{
int iAlign = m_iAlign;
int x = m_rTextPadding.left + m_Padding.left;
int y = m_rTextPadding.top + m_Padding.top;
if ( iAlign & Pos::Right ) x = Width() - m_Text->Width() - m_rTextPadding.right - m_Padding.right;
if ( iAlign & Pos::CenterH ) x = (m_rTextPadding.left + m_Padding.left) + ((Width() - m_Text->Width() ) * 0.5f) - m_rTextPadding.right - m_Padding.right;
if (iAlign & Pos::Right) x = Width() - m_Text->Width() - m_rTextPadding.right - m_Padding.right;
if (iAlign & Pos::CenterH) x = (m_rTextPadding.left + m_Padding.left) + ((Width() - m_Text->Width()) * 0.5f) - m_rTextPadding.right - m_Padding.right;
if ( iAlign & Pos::CenterV ) y = (m_rTextPadding.top + m_Padding.top) + ((Height() - m_Text->Height()) * 0.5f) - m_rTextPadding.bottom - m_Padding.bottom;
if ( iAlign & Pos::Bottom ) y = Height() - m_Text->Height() - m_rTextPadding.bottom - m_Padding.bottom;
if (iAlign & Pos::CenterV) y = (m_rTextPadding.top + m_Padding.top) + ((Height() - m_Text->Height()) * 0.5f) - m_rTextPadding.bottom - m_Padding.bottom;
if (iAlign & Pos::Bottom) y = Height() - m_Text->Height() - m_rTextPadding.bottom - m_Padding.bottom;
m_Text->SetPos( x, y );
m_Text->SetPos(x, y);
}
void Label::SetText( const UnicodeString& str, bool bDoEvents )
{
if ( m_Text->GetText() == str ) return;
void Label::SetText(const UnicodeString& str, bool bDoEvents)
{
if (m_Text->GetText() == str) return;
m_Text->SetString( str );
m_Text->SetString(str);
Redraw();
if ( bDoEvents )
if (bDoEvents)
OnTextChanged();
}
void Label::SetText( const String& str, bool bDoEvents )
{
SetText( Gwen::Utility::StringToUnicode( str ), bDoEvents );
void Label::SetText(const String& str, bool bDoEvents)
{
SetText(Gwen::Utility::StringToUnicode(str), bDoEvents);
}
void Label::SizeToContents()
{
m_Text->SetPos( m_rTextPadding.left + m_Padding.left, m_rTextPadding.top + m_Padding.top );
m_Text->SetPos(m_rTextPadding.left + m_Padding.left, m_rTextPadding.top + m_Padding.top);
m_Text->RefreshSize();
SetSize( m_Text->Width() + m_Padding.left + m_Padding.right + m_rTextPadding.left + m_rTextPadding.right, m_Text->Height() + m_Padding.top + m_Padding.bottom + m_rTextPadding.top + m_rTextPadding.bottom );
SetSize(m_Text->Width() + m_Padding.left + m_Padding.right + m_rTextPadding.left + m_rTextPadding.right, m_Text->Height() + m_Padding.top + m_Padding.bottom + m_rTextPadding.top + m_rTextPadding.bottom);
}
Gwen::Point Label::GetCharacterPosition( int iChar )
{
Gwen::Point p = m_Text->GetCharacterPosition( iChar );
Gwen::Point Label::GetCharacterPosition(int iChar)
{
Gwen::Point p = m_Text->GetCharacterPosition(iChar);
p.x += m_Text->X();
p.y += m_Text->Y();

View File

@@ -12,59 +12,61 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/Text.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT Label : public Controls::Base
{
public:
GWEN_CONTROL(Label, Controls::Base);
virtual void SetText(const UnicodeString& str, bool bDoEvents = true);
virtual void SetText(const String& str, bool bDoEvents = true);
virtual const UnicodeString& GetText() const { return m_Text->GetText(); }
virtual void Render(Skin::Base* /*skin*/) {}
virtual void Layout(Skin::Base* skin);
virtual void SizeToContents();
virtual void SetAlignment(int iAlign) { m_iAlign = iAlign; }
virtual void SetFont(Gwen::Font* pFont) { m_Text->SetFont(pFont); }
virtual Gwen::Font* GetFont() { return m_Text->GetFont(); }
virtual void SetTextColor(const Gwen::Color& col) { m_Text->SetTextColor(col); }
inline const Gwen::Color& TextColor() const { return m_Text->TextColor(); }
virtual int TextWidth() { return m_Text->Width(); }
virtual int TextRight() { return m_Text->Right(); }
virtual int TextHeight() { return m_Text->Height(); }
virtual int TextX() { return m_Text->X(); }
virtual int TextY() { return m_Text->Y(); }
virtual int TextLength() { return m_Text->Length(); }
Gwen::Point GetCharacterPosition(int iChar);
virtual void SetTextPadding(const Padding& padding)
{
class GWEN_EXPORT Label : public Controls::Base
{
public:
GWEN_CONTROL( Label, Controls::Base );
virtual void SetText( const UnicodeString& str, bool bDoEvents = true );
virtual void SetText( const String& str, bool bDoEvents = true );
virtual const UnicodeString& GetText() const { return m_Text->GetText(); }
virtual void Render( Skin::Base* /*skin*/ ){}
virtual void Layout( Skin::Base* skin );
virtual void SizeToContents();
virtual void SetAlignment( int iAlign ){ m_iAlign = iAlign; }
virtual void SetFont( Gwen::Font* pFont ){ m_Text->SetFont( pFont ); }
virtual Gwen::Font* GetFont(){ return m_Text->GetFont(); }
virtual void SetTextColor( const Gwen::Color& col ){ m_Text->SetTextColor( col ); }
inline const Gwen::Color &TextColor() const { return m_Text->TextColor(); }
virtual int TextWidth() { return m_Text->Width(); }
virtual int TextRight() { return m_Text->Right(); }
virtual int TextHeight() { return m_Text->Height(); }
virtual int TextX() { return m_Text->X(); }
virtual int TextY() { return m_Text->Y(); }
virtual int TextLength() { return m_Text->Length(); }
Gwen::Point GetCharacterPosition( int iChar );
virtual void SetTextPadding( const Padding& padding ){ m_rTextPadding = padding; Invalidate(); InvalidateParent(); }
virtual const Padding& GetTextPadding(){ return m_rTextPadding; }
virtual Gwen::UnicodeString GetText() { return m_Text->GetText(); }
inline int Alignment() const { return m_iAlign; }
protected:
virtual void OnTextChanged(){};
Padding m_rTextPadding;
ControlsInternal::Text* m_Text;
int m_iAlign;
};
m_rTextPadding = padding;
Invalidate();
InvalidateParent();
}
}
virtual const Padding& GetTextPadding() { return m_rTextPadding; }
virtual Gwen::UnicodeString GetText() { return m_Text->GetText(); }
inline int Alignment() const { return m_iAlign; }
protected:
virtual void OnTextChanged(){};
Padding m_rTextPadding;
ControlsInternal::Text* m_Text;
int m_iAlign;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/LabelClickable.h"
@@ -12,14 +11,14 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( LabelClickable )
GWEN_CONTROL_CONSTRUCTOR(LabelClickable)
{
SetIsToggle( false );
SetIsToggle(false);
SetAlignment( Gwen::Pos::Left | Gwen::Pos::CenterV );
SetAlignment(Gwen::Pos::Left | Gwen::Pos::CenterV);
}
void LabelClickable::Render( Skin::Base* /*skin*/ )
void LabelClickable::Render(Skin::Base* /*skin*/)
{
//skin->DrawButton( this, IsDepressed(), IsToggle() && GetToggleState() );
}

View File

@@ -11,19 +11,17 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/Button.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT LabelClickable : public Button
{
public:
namespace Controls
{
class GWEN_EXPORT LabelClickable : public Button
{
public:
GWEN_CONTROL(LabelClickable, Button);
GWEN_CONTROL( LabelClickable, Button );
virtual void Render( Skin::Base* skin );
};
}
}
virtual void Render(Skin::Base* skin);
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,84 +4,79 @@
See license in Gwen.h
*/
#pragma once
#ifndef GWEN_CONTROLS_LAYOUT_SPLITTER_H
#define GWEN_CONTROLS_LAYOUT_SPLITTER_H
#include "Gwen/Controls/Base.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
namespace Layout
{
class GWEN_EXPORT Splitter : public Base
{
public:
typedef Base BaseClass;
Splitter(Base* pParent) : BaseClass(pParent)
{
namespace Layout
for (int i = 0; i < 2; i++)
m_pPanel[i] = NULL;
}
void SetPanel(int i, Base* pPanel)
{
if (i < 0 || i > 1) return;
m_pPanel[i] = pPanel;
if (m_pPanel[i])
{
class GWEN_EXPORT Splitter : public Base
{
public:
typedef Base BaseClass;
Splitter( Base* pParent ) : BaseClass( pParent )
{
for ( int i=0; i<2; i++ )
m_pPanel[i] = NULL;
}
void SetPanel( int i, Base* pPanel )
{
if ( i < 0 || i > 1 ) return;
m_pPanel[i] = pPanel;
if ( m_pPanel[i] )
{
m_pPanel[i] ->SetParent( this );
}
}
Base* GetPanel( int i ) const
{
if ( i < 0 || i > 1 ) return NULL;
return m_pPanel[i];
}
void Layout( Skin::Base* skin )
{
LayoutVertical( skin );
}
private:
void LayoutVertical( Skin::Base* /*skin*/ )
{
int w = Width();
int h = Height();
if ( m_pPanel[0] )
{
const Margin& m = m_pPanel[0]->GetMargin();
m_pPanel[0]->SetBounds( m.left, m.top, w-m.left-m.right, (h * 0.5) - m.top - m.bottom );
}
if ( m_pPanel[1] )
{
const Margin& m = m_pPanel[1]->GetMargin();
m_pPanel[1]->SetBounds( m.left, m.top + (h * 0.5f), w-m.left-m.right, (h * 0.5f) - m.top - m.bottom );
}
}
void LayoutHorizontal( Skin::Base* /*skin*/ )
{
// Todo.
}
Base* m_pPanel[2];
};
m_pPanel[i]->SetParent(this);
}
}
}
Base* GetPanel(int i) const
{
if (i < 0 || i > 1) return NULL;
return m_pPanel[i];
}
void Layout(Skin::Base* skin)
{
LayoutVertical(skin);
}
private:
void LayoutVertical(Skin::Base* /*skin*/)
{
int w = Width();
int h = Height();
if (m_pPanel[0])
{
const Margin& m = m_pPanel[0]->GetMargin();
m_pPanel[0]->SetBounds(m.left, m.top, w - m.left - m.right, (h * 0.5) - m.top - m.bottom);
}
if (m_pPanel[1])
{
const Margin& m = m_pPanel[1]->GetMargin();
m_pPanel[1]->SetBounds(m.left, m.top + (h * 0.5f), w - m.left - m.right, (h * 0.5f) - m.top - m.bottom);
}
}
void LayoutHorizontal(Skin::Base* /*skin*/)
{
// Todo.
}
Base* m_pPanel[2];
};
} // namespace Layout
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -11,307 +11,299 @@
#include "Gwen/Controls/Label.h"
#include "Gwen/Utility.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
namespace Layout
{
class Table;
class GWEN_EXPORT TableRow : public Base
{
static const int MaxColumns = 5;
GWEN_CONTROL_INLINE(TableRow, Base)
{
namespace Layout
for (int i = 0; i < MaxColumns; i++)
m_Columns[i] = NULL;
m_ColumnCount = 0;
}
virtual class TableRow* DynamicCastLayoutTableRow()
{
return this;
}
virtual const class TableRow* DynamicCastLayoutTableRow() const
{
return this;
}
void SetColumnCount(int iCount)
{
if (iCount == m_ColumnCount) return;
if (iCount >= MaxColumns)
m_ColumnCount = MaxColumns;
for (int i = 0; i < MaxColumns; i++)
{
class Table;
class GWEN_EXPORT TableRow : public Base
if (i < iCount)
{
static const int MaxColumns = 5;
GWEN_CONTROL_INLINE( TableRow, Base )
if (!m_Columns[i])
{
for ( int i=0; i<MaxColumns; i++ )
m_Columns[i] = NULL;
m_ColumnCount = 0;
m_Columns[i] = new Label(this);
m_Columns[i]->Dock(Pos::Left);
m_Columns[i]->SetPadding(Padding(3, 3, 3, 3));
}
virtual class TableRow* DynamicCastLayoutTableRow()
{
return this;
}
virtual const class TableRow* DynamicCastLayoutTableRow() const
{
return this;
}
void SetColumnCount( int iCount )
{
if ( iCount == m_ColumnCount ) return;
if ( iCount >= MaxColumns )
m_ColumnCount = MaxColumns;
for ( int i=0; i<MaxColumns; i++ )
{
if ( i < iCount )
{
if ( !m_Columns[i] )
{
m_Columns[i] = new Label( this );
m_Columns[i]->Dock( Pos::Left );
m_Columns[i]->SetPadding( Padding( 3, 3, 3, 3 ) );
}
}
else if ( m_Columns[i] )
{
m_Columns[i]->DelayedDelete();
m_Columns[i] = NULL;
}
m_ColumnCount = iCount;
}
}
void SetColumnWidth( int i, int iWidth )
{
if ( !m_Columns[i] ) return;
if ( m_Columns[i]->Width() == iWidth ) return;
m_Columns[i]->SetWidth( iWidth );
}
template <typename T>
void SetCellText( int i, const T& strString )
{
if ( !m_Columns[i] ) return;
m_Columns[i]->SetText( strString );
}
void SetCellContents( int i, Base* pControl, bool bEnableMouseInput = false )
{
if ( !m_Columns[i] ) return;
pControl->SetParent( m_Columns[i] );
m_Columns[i]->SetMouseInputEnabled( bEnableMouseInput );
}
Label* GetCellContents( int i )
{
return m_Columns[i];
}
void SizeToContents()
{
int iHeight = 0;
for ( int i=0; i<m_ColumnCount; i++ )
{
if ( !m_Columns[i] ) continue;
// Note, more than 1 child here, because the
// label has a child built in ( The Text )
if ( m_Columns[i]->NumChildren() > 1 )
{
m_Columns[i]->SizeToChildren();
}
else
{
m_Columns[i]->SizeToContents();
}
iHeight = Utility::Max( iHeight, m_Columns[i]->Height() );
}
SetHeight( iHeight );
}
void SetTextColor( const Gwen::Color& color )
{
for ( int i=0; i<m_ColumnCount; i++ )
{
if ( !m_Columns[i] ) continue;
m_Columns[i]->SetTextColor( color );
}
}
//You might hate this. Actually I know you will
virtual UnicodeString GetText( int i )
{
return m_Columns[i]->GetText();
}
virtual void SetSelected( bool /*b*/ ) {}
//
// This is sometimes called by derivatives.
//
Gwen::Event::Caller onRowSelected;
private:
int m_ColumnCount;
Label* m_Columns[MaxColumns];
friend class Table;
};
class GWEN_EXPORT Table : public Base
}
else if (m_Columns[i])
{
public:
m_Columns[i]->DelayedDelete();
m_Columns[i] = NULL;
}
GWEN_CONTROL_INLINE( Table, Base )
{
m_iColumnCount = 1;
m_iDefaultRowHeight = 22;
for (int i=0; i<TableRow::MaxColumns; i++)
{
m_ColumnWidth[i] = 20;
}
m_bSizeToContents = false;
}
void SetColumnCount( int i )
{
if ( m_iColumnCount == i ) return;
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
{
if (!*it)
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if ( !pRow ) continue;
pRow->SetColumnCount( i );
}
m_iColumnCount = i;
}
void SetColumnWidth( int i, int iWidth )
{
if ( m_ColumnWidth[i] == iWidth ) return;
m_ColumnWidth[i] = iWidth;
Invalidate();
}
TableRow* AddRow()
{
TableRow* row = new TableRow( this );
row->SetColumnCount( m_iColumnCount );
row->SetHeight( m_iDefaultRowHeight );
row->Dock( Pos::Top );
return row;
}
void AddRow( TableRow* pRow )
{
pRow->SetParent( this );
pRow->SetColumnCount( m_iColumnCount );
pRow->SetHeight( m_iDefaultRowHeight );
pRow->Dock( Pos::Top );
}
void Remove( TableRow* pRow )
{
pRow->DelayedDelete();
}
void Clear()
{
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
{
if (!(*it))
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if ( !pRow ) continue;
Remove( pRow );
}
}
void Layout( Skin::Base* skin )
{
BaseClass::Layout( skin );
if ( m_bSizeToContents )
{
DoSizeToContents();
}
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
{
if (!*it)
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if ( !pRow ) continue;
for (int i=0; i<TableRow::MaxColumns && i < m_iColumnCount; i++)
{
pRow->SetColumnWidth( i, m_ColumnWidth[i] );
}
}
}
void PostLayout( Skin::Base* /*skin*/ )
{
if ( m_bSizeToContents )
{
SizeToChildren();
m_bSizeToContents = false;
}
}
void SizeToContents()
{
m_bSizeToContents = true;
Invalidate();
}
void DoSizeToContents()
{
for (int i=0; i<TableRow::MaxColumns; i++)
{
m_ColumnWidth[i] = 10;
}
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
{
if (!*it)
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if ( !pRow ) continue;
pRow->SizeToContents();
for (int i=0; i<TableRow::MaxColumns; i++)
{
if ( pRow->m_Columns[i] )
{
m_ColumnWidth[i] = Utility::Max( m_ColumnWidth[i], pRow->m_Columns[i]->Width() );
}
}
//iBottom += pRow->Height();
}
InvalidateParent();
}
private:
bool m_bSizeToContents;
int m_iColumnCount;
int m_iDefaultRowHeight;
int m_ColumnWidth[ TableRow::MaxColumns ];
};
m_ColumnCount = iCount;
}
}
}
void SetColumnWidth(int i, int iWidth)
{
if (!m_Columns[i]) return;
if (m_Columns[i]->Width() == iWidth) return;
m_Columns[i]->SetWidth(iWidth);
}
template <typename T>
void SetCellText(int i, const T& strString)
{
if (!m_Columns[i]) return;
m_Columns[i]->SetText(strString);
}
void SetCellContents(int i, Base* pControl, bool bEnableMouseInput = false)
{
if (!m_Columns[i]) return;
pControl->SetParent(m_Columns[i]);
m_Columns[i]->SetMouseInputEnabled(bEnableMouseInput);
}
Label* GetCellContents(int i)
{
return m_Columns[i];
}
void SizeToContents()
{
int iHeight = 0;
for (int i = 0; i < m_ColumnCount; i++)
{
if (!m_Columns[i]) continue;
// Note, more than 1 child here, because the
// label has a child built in ( The Text )
if (m_Columns[i]->NumChildren() > 1)
{
m_Columns[i]->SizeToChildren();
}
else
{
m_Columns[i]->SizeToContents();
}
iHeight = Utility::Max(iHeight, m_Columns[i]->Height());
}
SetHeight(iHeight);
}
void SetTextColor(const Gwen::Color& color)
{
for (int i = 0; i < m_ColumnCount; i++)
{
if (!m_Columns[i]) continue;
m_Columns[i]->SetTextColor(color);
}
}
//You might hate this. Actually I know you will
virtual UnicodeString GetText(int i)
{
return m_Columns[i]->GetText();
}
virtual void SetSelected(bool /*b*/) {}
//
// This is sometimes called by derivatives.
//
Gwen::Event::Caller onRowSelected;
private:
int m_ColumnCount;
Label* m_Columns[MaxColumns];
friend class Table;
};
class GWEN_EXPORT Table : public Base
{
public:
GWEN_CONTROL_INLINE(Table, Base)
{
m_iColumnCount = 1;
m_iDefaultRowHeight = 22;
for (int i = 0; i < TableRow::MaxColumns; i++)
{
m_ColumnWidth[i] = 20;
}
m_bSizeToContents = false;
}
void SetColumnCount(int i)
{
if (m_iColumnCount == i) return;
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
if (!*it)
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if (!pRow) continue;
pRow->SetColumnCount(i);
}
m_iColumnCount = i;
}
void SetColumnWidth(int i, int iWidth)
{
if (m_ColumnWidth[i] == iWidth) return;
m_ColumnWidth[i] = iWidth;
Invalidate();
}
TableRow* AddRow()
{
TableRow* row = new TableRow(this);
row->SetColumnCount(m_iColumnCount);
row->SetHeight(m_iDefaultRowHeight);
row->Dock(Pos::Top);
return row;
}
void AddRow(TableRow* pRow)
{
pRow->SetParent(this);
pRow->SetColumnCount(m_iColumnCount);
pRow->SetHeight(m_iDefaultRowHeight);
pRow->Dock(Pos::Top);
}
void Remove(TableRow* pRow)
{
pRow->DelayedDelete();
}
void Clear()
{
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
if (!(*it))
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if (!pRow) continue;
Remove(pRow);
}
}
void Layout(Skin::Base* skin)
{
BaseClass::Layout(skin);
if (m_bSizeToContents)
{
DoSizeToContents();
}
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
if (!*it)
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if (!pRow) continue;
for (int i = 0; i < TableRow::MaxColumns && i < m_iColumnCount; i++)
{
pRow->SetColumnWidth(i, m_ColumnWidth[i]);
}
}
}
void PostLayout(Skin::Base* /*skin*/)
{
if (m_bSizeToContents)
{
SizeToChildren();
m_bSizeToContents = false;
}
}
void SizeToContents()
{
m_bSizeToContents = true;
Invalidate();
}
void DoSizeToContents()
{
for (int i = 0; i < TableRow::MaxColumns; i++)
{
m_ColumnWidth[i] = 10;
}
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
if (!*it)
continue;
TableRow* pRow = (*it)->DynamicCastLayoutTableRow();
if (!pRow) continue;
pRow->SizeToContents();
for (int i = 0; i < TableRow::MaxColumns; i++)
{
if (pRow->m_Columns[i])
{
m_ColumnWidth[i] = Utility::Max(m_ColumnWidth[i], pRow->m_Columns[i]->Width());
}
}
//iBottom += pRow->Height();
}
InvalidateParent();
}
private:
bool m_bSizeToContents;
int m_iColumnCount;
int m_iDefaultRowHeight;
int m_ColumnWidth[TableRow::MaxColumns];
};
} // namespace Layout
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ListBox.h"
#include "Gwen/Controls/ScrollControl.h"
#include "Gwen/InputHandler.h"
@@ -14,15 +13,15 @@ using namespace Gwen::Controls;
class ListBoxRow : public Layout::TableRow
{
GWEN_CONTROL_INLINE( ListBoxRow, Layout::TableRow )
GWEN_CONTROL_INLINE(ListBoxRow, Layout::TableRow)
{
SetMouseInputEnabled( true );
SetSelected( false );
SetMouseInputEnabled(true);
SetSelected(false);
}
void Render( Skin::Base* skin )
void Render(Skin::Base* skin)
{
skin->DrawListBoxLine( this, IsSelected() );
skin->DrawListBoxLine(this, IsSelected());
}
bool IsSelected() const
@@ -30,108 +29,106 @@ class ListBoxRow : public Layout::TableRow
return m_bSelected;
}
void OnMouseClickLeft( int /*x*/, int /*y*/, bool bDown )
void OnMouseClickLeft(int /*x*/, int /*y*/, bool bDown)
{
if ( bDown && !m_bSelected )
if (bDown && !m_bSelected)
{
SetSelected( true );
onRowSelected.Call( this );
SetSelected(true);
onRowSelected.Call(this);
}
}
void SetSelected( bool b )
void SetSelected(bool b)
{
m_bSelected = b;
// TODO: Get these values from the skin.
if ( b )
SetTextColor( Gwen::Colors::White );
if (b)
SetTextColor(Gwen::Colors::White);
else
SetTextColor( Gwen::Colors::Black );
SetTextColor(Gwen::Colors::Black);
}
private:
bool m_bSelected;
private:
bool m_bSelected;
};
GWEN_CONTROL_CONSTRUCTOR( ListBox )
GWEN_CONTROL_CONSTRUCTOR(ListBox)
{
m_ScrollControl = new ScrollControl( this );
m_ScrollControl->Dock( Pos::Fill );
m_ScrollControl->SetScroll( false, true );
m_ScrollControl->SetAutoHideBars( true );
m_ScrollControl->SetMargin( Margin( 1, 1, 1, 1 ) );
m_ScrollControl = new ScrollControl(this);
m_ScrollControl->Dock(Pos::Fill);
m_ScrollControl->SetScroll(false, true);
m_ScrollControl->SetAutoHideBars(true);
m_ScrollControl->SetMargin(Margin(1, 1, 1, 1));
m_InnerPanel = m_ScrollControl;
m_Table = new Controls::Layout::Table( this );
m_Table->Dock( Pos::Top );
m_Table->SetColumnCount( 1 );
m_Table = new Controls::Layout::Table(this);
m_Table->Dock(Pos::Top);
m_Table->SetColumnCount(1);
m_bMultiSelect = false;
}
void ListBox::OnChildBoundsChanged( Gwen::Rect /*oldChildBounds*/, Base* /*pChild*/ )
void ListBox::OnChildBoundsChanged(Gwen::Rect /*oldChildBounds*/, Base* /*pChild*/)
{
m_ScrollControl->UpdateScrollBars();
}
Layout::TableRow* ListBox::AddItem( const String& strLabel, const String& strName )
Layout::TableRow* ListBox::AddItem(const String& strLabel, const String& strName)
{
return AddItem( Utility::StringToUnicode( strLabel ), strName );
return AddItem(Utility::StringToUnicode(strLabel), strName);
}
Layout::TableRow* ListBox::AddItem( const UnicodeString& strLabel, const String& strName )
Layout::TableRow* ListBox::AddItem(const UnicodeString& strLabel, const String& strName)
{
ListBoxRow* pRow = new ListBoxRow( this );
m_Table->AddRow( pRow );
ListBoxRow* pRow = new ListBoxRow(this);
m_Table->AddRow(pRow);
pRow->SetCellText( 0, strLabel );
pRow->SetName( strName );
pRow->SetCellText(0, strLabel);
pRow->SetName(strName);
pRow->onRowSelected.Add( this, &ListBox::OnRowSelected );
pRow->onRowSelected.Add(this, &ListBox::OnRowSelected);
m_Table->SizeToContents();
return pRow;
}
void ListBox::Render( Skin::Base* skin )
void ListBox::Render(Skin::Base* skin)
{
skin->DrawListBox( this );
skin->DrawListBox(this);
}
void ListBox::UnselectAll()
{
std::list<Layout::TableRow*>::iterator it = m_SelectedRows.begin();
while ( it != m_SelectedRows.end() )
while (it != m_SelectedRows.end())
{
ListBoxRow* pRow = static_cast<ListBoxRow*>(*it);
it = m_SelectedRows.erase( it );
it = m_SelectedRows.erase(it);
pRow->SetSelected( false );
pRow->SetSelected(false);
}
}
void ListBox::OnRowSelected( Base* pControl )
void ListBox::OnRowSelected(Base* pControl)
{
ListBoxRow* pRow = static_cast<ListBoxRow*>(pControl);
if ( !AllowMultiSelect() || !Gwen::Input::IsShiftDown() )
if (!AllowMultiSelect() || !Gwen::Input::IsShiftDown())
{
UnselectAll();
}
m_SelectedRows.push_back( pRow );
onRowSelected.Call( this );
m_SelectedRows.push_back(pRow);
onRowSelected.Call(this);
}
Layout::TableRow* ListBox::GetSelectedRow()
{
if ( m_SelectedRows.empty() ) return NULL;
{
if (m_SelectedRows.empty()) return NULL;
return *m_SelectedRows.begin();
}

View File

@@ -12,56 +12,52 @@
#include "Gwen/Controls/Layout/Table.h"
#include "Gwen/Controls/ScrollControl.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class ScrollControl;
namespace Controls
{
class ScrollControl;
class GWEN_EXPORT ListBox : public Base
{
public:
GWEN_CONTROL( ListBox, Base );
class GWEN_EXPORT ListBox : public Base
{
public:
GWEN_CONTROL(ListBox, Base);
typedef std::list<Layout::TableRow*> Rows;
typedef std::list<Layout::TableRow*> Rows;
Layout::TableRow* AddItem( const String& strLabel, const String& strName = "" );
Layout::TableRow* AddItem( const UnicodeString& strLabel, const String& strName = "" );
Layout::TableRow* AddItem(const String& strLabel, const String& strName = "");
Layout::TableRow* AddItem(const UnicodeString& strLabel, const String& strName = "");
void Render( Skin::Base* skin );
void Render(Skin::Base* skin);
void UnselectAll();
void UnselectAll();
void SetColumnCount( int iCount ) { m_Table->SetColumnCount( iCount ); }
void SetColumnCount(int iCount) { m_Table->SetColumnCount(iCount); }
void SetAllowMultiSelect( bool bMultiSelect ){ m_bMultiSelect = bMultiSelect; }
bool AllowMultiSelect() const { return m_bMultiSelect; }
void SetAllowMultiSelect(bool bMultiSelect) { m_bMultiSelect = bMultiSelect; }
bool AllowMultiSelect() const { return m_bMultiSelect; }
const ListBox::Rows& GetSelectedRows(){ return m_SelectedRows; }
Layout::TableRow* GetSelectedRow();
const ListBox::Rows& GetSelectedRows() { return m_SelectedRows; }
Layout::TableRow* GetSelectedRow();
Gwen::Controls::ScrollControl* Scroller() { return m_ScrollControl; }
Gwen::Controls::ScrollControl* Scroller() { return m_ScrollControl; }
void OnChildBoundsChanged( Gwen::Rect oldChildBounds, Base* pChild );
Gwen::Event::Caller onRowSelected;
void OnChildBoundsChanged(Gwen::Rect oldChildBounds, Base* pChild);
Controls::Layout::Table* GetTable() { return m_Table; }
virtual void Clear();
Gwen::Event::Caller onRowSelected;
protected:
Controls::Layout::Table* GetTable() { return m_Table; }
virtual void Clear();
void OnRowSelected( Base* pControl );
Controls::Layout::Table* m_Table;
ListBox::Rows m_SelectedRows;
Controls::ScrollControl* m_ScrollControl;
protected:
void OnRowSelected(Base* pControl);
bool m_bMultiSelect;
};
}
}
Controls::Layout::Table* m_Table;
ListBox::Rows m_SelectedRows;
Controls::ScrollControl* m_ScrollControl;
bool m_bMultiSelect;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Menu.h"
#include "Gwen/Skin.h"
@@ -13,107 +12,102 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( Menu )
GWEN_CONTROL_CONSTRUCTOR(Menu)
{
SetBounds( 0, 0, 10, 10 );
SetPadding( Padding( 2, 2, 2, 2 ) );
SetBounds(0, 0, 10, 10);
SetPadding(Padding(2, 2, 2, 2));
SetDisableIconMargin( false );
SetDisableIconMargin(false);
SetAutoHideBars( true );
SetScroll( false, true );
SetAutoHideBars(true);
SetScroll(false, true);
}
void Menu::Render( Skin::Base* skin )
void Menu::Render(Skin::Base* skin)
{
skin->DrawMenu( this, IconMarginDisabled() );
skin->DrawMenu(this, IconMarginDisabled());
}
void Menu::RenderUnder( Skin::Base* skin )
void Menu::RenderUnder(Skin::Base* skin)
{
BaseClass::RenderUnder( skin );
skin->DrawShadow( this );
BaseClass::RenderUnder(skin);
skin->DrawShadow(this);
}
void Menu::Layout( Skin::Base* skin )
void Menu::Layout(Skin::Base* skin)
{
int childrenHeight = 0;
for ( Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it )
for (Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it)
{
Base* pChild = (*it);
if ( !pChild )
if (!pChild)
continue;
childrenHeight += pChild->Height();
}
if ( Y() + childrenHeight > GetCanvas()->Height() )
if (Y() + childrenHeight > GetCanvas()->Height())
childrenHeight = GetCanvas()->Height() - Y();
SetSize( Width(), childrenHeight );
SetSize(Width(), childrenHeight);
BaseClass::Layout( skin );
BaseClass::Layout(skin);
}
MenuItem* Menu::AddItem( const Gwen::UnicodeString& strName, const UnicodeString& strIconName, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::Function fn )
MenuItem* Menu::AddItem(const Gwen::UnicodeString& strName, const UnicodeString& strIconName, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::Function fn)
{
MenuItem* pItem = new MenuItem( this );
pItem->SetText( strName );
pItem->SetImage( strIconName );
MenuItem* pItem = new MenuItem(this);
pItem->SetText(strName);
pItem->SetImage(strIconName);
if ( fn && pHandler )
{
pItem->onMenuItemSelected.Add( pHandler, fn );
}
OnAddItem( pItem );
if (fn && pHandler)
{
pItem->onMenuItemSelected.Add(pHandler, fn);
}
OnAddItem(pItem);
return pItem;
}
void Menu::OnAddItem( MenuItem* item )
void Menu::OnAddItem(MenuItem* item)
{
item->Dock( Pos::Top );
item->SetTextPadding( Padding( IconMarginDisabled() ? 0 : 24, 0, 16, 0 ) );
item->SetPadding( Padding( 4, 4, 4, 4 ) );
item->Dock(Pos::Top);
item->SetTextPadding(Padding(IconMarginDisabled() ? 0 : 24, 0, 16, 0));
item->SetPadding(Padding(4, 4, 4, 4));
item->SizeToContents();
item->SetAlignment( Pos::CenterV | Pos::Left );
item->onHoverEnter.Add( this, &Menu::OnHoverItem );
item->SetAlignment(Pos::CenterV | Pos::Left);
item->onHoverEnter.Add(this, &Menu::OnHoverItem);
// Do this here - after Top Docking these values mean nothing in layout
int w = item->Width() + 10 + 32;
if ( w < Width() ) w = Width();
SetSize( w, Height() );
if (w < Width()) w = Width();
SetSize(w, Height());
}
void Menu::ClearItems()
{
for ( Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it )
for (Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it)
{
Base* pChild = *it;
if ( !pChild ) continue;
if (!pChild) continue;
pChild->DelayedDelete();
}
}
MenuItem* Menu::AddItem( const Gwen::String& strName, const String& strIconName, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::Function fn )
MenuItem* Menu::AddItem(const Gwen::String& strName, const String& strIconName, Gwen::Event::Handler* pHandler, Gwen::Event::Handler::Function fn)
{
return AddItem( Gwen::Utility::StringToUnicode( strName ), Gwen::Utility::StringToUnicode( strIconName ), pHandler, fn );
return AddItem(Gwen::Utility::StringToUnicode(strName), Gwen::Utility::StringToUnicode(strIconName), pHandler, fn);
}
void Menu::CloseAll()
{
for ( Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it )
for (Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it)
{
Base* pChild = *it;
MenuItem* pItem = pChild->DynamicCastMenuItem();
if ( !pItem ) continue;
if (!pItem) continue;
pItem->CloseMenu();
}
@@ -121,26 +115,26 @@ void Menu::CloseAll()
bool Menu::IsMenuOpen()
{
for ( Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it )
for (Base::List::iterator it = m_InnerPanel->Children.begin(); it != m_InnerPanel->Children.end(); ++it)
{
Base* pChild = *it;
MenuItem* pItem = pChild->DynamicCastMenuItem();
if ( !pItem ) continue;
if (!pItem) continue;
if ( pItem->IsMenuOpen() )
if (pItem->IsMenuOpen())
return true;
}
return false;
}
void Menu::OnHoverItem( Gwen::Controls::Base* pControl )
void Menu::OnHoverItem(Gwen::Controls::Base* pControl)
{
if ( !ShouldHoverOpenMenu() ) return;
if (!ShouldHoverOpenMenu()) return;
MenuItem* pItem = pControl->DynamicCastMenuItem();
if (!pItem) return;
if ( pItem->IsMenuOpen() ) return;
if (pItem->IsMenuOpen()) return;
CloseAll();
pItem->OpenMenu();
@@ -148,7 +142,7 @@ void Menu::OnHoverItem( Gwen::Controls::Base* pControl )
void Menu::Close()
{
SetHidden( true );
SetHidden(true);
}
void Menu::CloseMenus()
@@ -161,12 +155,12 @@ void Menu::CloseMenus()
void Menu::AddDivider()
{
MenuDivider* divider = new MenuDivider( this );
divider->Dock( Pos::Top );
divider->SetMargin( Margin( IconMarginDisabled() ? 0 : 24, 0, 4, 0 ) );
MenuDivider* divider = new MenuDivider(this);
divider->Dock(Pos::Top);
divider->SetMargin(Margin(IconMarginDisabled() ? 0 : 24, 0, 4, 0));
}
void MenuDivider::Render( Gwen::Skin::Base* skin )
void MenuDivider::Render(Gwen::Skin::Base* skin)
{
skin->DrawMenuDivider( this );
skin->DrawMenuDivider(this);
}

View File

@@ -13,74 +13,71 @@
#include "Gwen/Controls/MenuItem.h"
#include "Gwen/Controls/ScrollControl.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class MenuItem;
class GWEN_EXPORT Menu : public ScrollControl
{
public:
GWEN_CONTROL(Menu, ScrollControl);
virtual void Render(Skin::Base* skin);
virtual void RenderUnder(Skin::Base* skin);
virtual void Layout(Skin::Base* skin);
virtual MenuItem* AddItem(const Gwen::UnicodeString& strName, const UnicodeString& strIconName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL);
virtual MenuItem* AddItem(const Gwen::UnicodeString& strName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL)
{
class MenuItem;
class GWEN_EXPORT Menu : public ScrollControl
{
public:
GWEN_CONTROL( Menu, ScrollControl );
virtual void Render( Skin::Base* skin );
virtual void RenderUnder( Skin::Base* skin );
virtual void Layout( Skin::Base* skin );
virtual MenuItem* AddItem( const Gwen::UnicodeString& strName, const UnicodeString& strIconName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL );
virtual MenuItem* AddItem( const Gwen::UnicodeString& strName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL )
{
return AddItem( strName, L"", pHandler, fn );
}
virtual MenuItem* AddItem( const Gwen::String& strName, const String& strIconName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL );
virtual MenuItem* AddItem( const Gwen::String& strName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL )
{
return AddItem( strName, "", pHandler, fn );
}
virtual void AddDivider();
void OnHoverItem( Gwen::Controls::Base* pControl );
void CloseAll();
bool IsMenuOpen();
void ClearItems();
virtual void Close();
virtual bool IsMenuComponent(){ return true; }
virtual void CloseMenus();
bool IconMarginDisabled() { return m_bDisableIconMargin; }
void SetDisableIconMargin( bool bDisable ) { m_bDisableIconMargin = bDisable; }
virtual bool ShouldClip(){ return false; }
protected:
virtual bool ShouldHoverOpenMenu(){ return true; }
virtual void OnAddItem( MenuItem* item );
bool m_bDisableIconMargin;
};
class GWEN_EXPORT MenuDivider : public Base
{
public:
GWEN_CONTROL_INLINE( MenuDivider, Base )
{
SetHeight( 1 );
}
void Render( Gwen::Skin::Base* skin );
};
return AddItem(strName, L"", pHandler, fn);
}
}
virtual MenuItem* AddItem(const Gwen::String& strName, const String& strIconName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL);
virtual MenuItem* AddItem(const Gwen::String& strName, Gwen::Event::Handler* pHandler = NULL, Gwen::Event::Handler::Function fn = NULL)
{
return AddItem(strName, "", pHandler, fn);
}
virtual void AddDivider();
void OnHoverItem(Gwen::Controls::Base* pControl);
void CloseAll();
bool IsMenuOpen();
void ClearItems();
virtual void Close();
virtual bool IsMenuComponent() { return true; }
virtual void CloseMenus();
bool IconMarginDisabled() { return m_bDisableIconMargin; }
void SetDisableIconMargin(bool bDisable) { m_bDisableIconMargin = bDisable; }
virtual bool ShouldClip() { return false; }
protected:
virtual bool ShouldHoverOpenMenu() { return true; }
virtual void OnAddItem(MenuItem* item);
bool m_bDisableIconMargin;
};
class GWEN_EXPORT MenuDivider : public Base
{
public:
GWEN_CONTROL_INLINE(MenuDivider, Base)
{
SetHeight(1);
}
void Render(Gwen::Skin::Base* skin);
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/MenuItem.h"
#include "Gwen/Skin.h"
@@ -12,44 +11,42 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( MenuItem )
GWEN_CONTROL_CONSTRUCTOR(MenuItem)
{
m_Menu = NULL;
m_bOnStrip = false;
m_SubmenuArrow = NULL;
SetTabable( false );
SetCheckable( false );
SetCheck( false );
SetTabable(false);
SetCheckable(false);
SetCheck(false);
}
MenuItem::~MenuItem()
{
}
void MenuItem::Render( Skin::Base* skin )
void MenuItem::Render(Skin::Base* skin)
{
skin->DrawMenuItem( this, IsMenuOpen(), m_bCheckable ? m_bChecked : false );
skin->DrawMenuItem(this, IsMenuOpen(), m_bCheckable ? m_bChecked : false);
}
void MenuItem::Layout( Skin::Base* skin )
void MenuItem::Layout(Skin::Base* skin)
{
BaseClass::Layout( skin );
BaseClass::Layout(skin);
}
Menu* MenuItem::GetMenu()
{
if ( !m_Menu )
if (!m_Menu)
{
m_Menu = new Menu( GetCanvas() );
m_Menu->SetHidden( true );
m_Menu = new Menu(GetCanvas());
m_Menu->SetHidden(true);
if ( !m_bOnStrip )
if (!m_bOnStrip)
{
m_SubmenuArrow = new Symbol::Arrow( this );
m_SubmenuArrow->Dock( Pos::Right );
m_SubmenuArrow->SetSize( 20, 20 );
m_SubmenuArrow = new Symbol::Arrow(this);
m_SubmenuArrow->Dock(Pos::Right);
m_SubmenuArrow->SetSize(20, 20);
}
Invalidate();
@@ -58,31 +55,31 @@ Menu* MenuItem::GetMenu()
return m_Menu;
}
void MenuItem::SetCheck( bool bCheck )
void MenuItem::SetCheck(bool bCheck)
{
if ( bCheck == m_bChecked)
if (bCheck == m_bChecked)
return;
m_bChecked = bCheck;
onCheckChange.Call( this );
onCheckChange.Call(this);
if ( bCheck )
onChecked.Call( this );
if (bCheck)
onChecked.Call(this);
else
onUnChecked.Call( this );
onUnChecked.Call(this);
}
void MenuItem::OnPress()
{
if ( m_Menu )
if (m_Menu)
{
ToggleMenu();
}
else if ( !m_bOnStrip )
else if (!m_bOnStrip)
{
SetCheck( !GetChecked() );
onMenuItemSelected.Call( this );
SetCheck(!GetChecked());
onMenuItemSelected.Call(this);
GetCanvas()->CloseMenus();
}
@@ -91,47 +88,47 @@ void MenuItem::OnPress()
void MenuItem::ToggleMenu()
{
if ( IsMenuOpen() ) CloseMenu();
else OpenMenu();
if (IsMenuOpen())
CloseMenu();
else
OpenMenu();
}
bool MenuItem::IsMenuOpen()
{
if ( !m_Menu ) return false;
if (!m_Menu) return false;
return !m_Menu->Hidden();
}
void MenuItem::OpenMenu()
{
if ( !m_Menu ) return;
if (!m_Menu) return;
m_Menu->SetHidden( false );
m_Menu->SetHidden(false);
m_Menu->BringToFront();
Gwen::Point p = LocalPosToCanvas( Gwen::Point( 0, 0 ) );
Gwen::Point p = LocalPosToCanvas(Gwen::Point(0, 0));
// Strip menus open downwards
if ( m_bOnStrip )
if (m_bOnStrip)
{
m_Menu->SetPos( p.x, p.y + Height() + 1 );
m_Menu->SetPos(p.x, p.y + Height() + 1);
}
// Submenus open sidewards
else
{
m_Menu->SetPos( p.x + Width(), p.y);
m_Menu->SetPos(p.x + Width(), p.y);
}
// TODO: Option this.
// TODO: Make sure on screen, open the other side of the
// TODO: Make sure on screen, open the other side of the
// parent if it's better...
}
void MenuItem::CloseMenu()
{
if ( !m_Menu ) return;
if (!m_Menu) return;
m_Menu->Close();
m_Menu->CloseAll();
}

View File

@@ -14,56 +14,52 @@
#include "Gwen/Controls/Menu.h"
#include "Gwen/Controls/Symbol.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class Menu;
namespace Controls
{
class Menu;
class GWEN_EXPORT MenuItem : public Button
{
public:
class GWEN_EXPORT MenuItem : public Button
{
public:
GWEN_CONTROL(MenuItem, Button);
GWEN_CONTROL( MenuItem, Button );
virtual ~MenuItem();
virtual ~MenuItem();
virtual void Render(Skin::Base* skin);
virtual void Layout(Skin::Base* skin);
virtual void Render( Skin::Base* skin );
virtual void Layout( Skin::Base* skin );
virtual void OnPress();
virtual void OnPress();
Menu* GetMenu();
Menu* GetMenu();
bool IsMenuOpen();
void OpenMenu();
void CloseMenu();
void ToggleMenu();
bool IsMenuOpen();
void OpenMenu();
void CloseMenu();
void ToggleMenu();
void SetOnStrip(bool b) { m_bOnStrip = b; }
bool OnStrip() { return m_bOnStrip; }
void SetOnStrip( bool b ){ m_bOnStrip = b;}
bool OnStrip(){ return m_bOnStrip; }
virtual void SetCheckable(bool bCheck) { m_bCheckable = bCheck; }
virtual void SetCheck(bool bCheck);
virtual bool GetChecked() { return m_bChecked; }
virtual void SetCheckable( bool bCheck ) { m_bCheckable = bCheck; }
virtual void SetCheck( bool bCheck );
virtual bool GetChecked() { return m_bChecked; }
Gwen::Event::Caller onMenuItemSelected;
Gwen::Event::Caller onChecked;
Gwen::Event::Caller onUnChecked;
Gwen::Event::Caller onCheckChange;
Gwen::Event::Caller onMenuItemSelected;
Gwen::Event::Caller onChecked;
Gwen::Event::Caller onUnChecked;
Gwen::Event::Caller onCheckChange;
private:
Menu* m_Menu;
bool m_bOnStrip;
bool m_bCheckable;
bool m_bChecked;
private:
Symbol::Arrow* m_SubmenuArrow;
};
} // namespace Controls
Menu* m_Menu;
bool m_bOnStrip;
bool m_bCheckable;
bool m_bChecked;
Symbol::Arrow * m_SubmenuArrow;
};
}
}
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/MenuStrip.h"
#include "Gwen/Skin.h"
@@ -12,30 +11,30 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( MenuStrip )
GWEN_CONTROL_CONSTRUCTOR(MenuStrip)
{
SetBounds( 0, 0, 200, 22 );
Dock( Pos::Top );
m_InnerPanel->SetPadding( Padding( 5, 2, 2, 2 ) );
SetBounds(0, 0, 200, 22);
Dock(Pos::Top);
m_InnerPanel->SetPadding(Padding(5, 2, 2, 2));
}
void MenuStrip::Render( Skin::Base* skin )
void MenuStrip::Render(Skin::Base* skin)
{
skin->DrawMenuStrip( this );
skin->DrawMenuStrip(this);
}
void MenuStrip::Layout( Skin::Base* /*skin*/ )
void MenuStrip::Layout(Skin::Base* /*skin*/)
{
//TODO: We don't want to do vertical sizing the same as Menu, do nothing for now
}
void MenuStrip::OnAddItem( MenuItem* item )
void MenuStrip::OnAddItem(MenuItem* item)
{
item->Dock( Pos::Left );
item->SetPadding( Padding( 5, 0, 5, 0 ) );
item->Dock(Pos::Left);
item->SetPadding(Padding(5, 0, 5, 0));
item->SizeToContents();
item->SetOnStrip( true );
item->onHoverEnter.Add( this, &Menu::OnHoverItem );
item->SetOnStrip(true);
item->onHoverEnter.Add(this, &Menu::OnHoverItem);
}
bool MenuStrip::ShouldHoverOpenMenu()

View File

@@ -13,27 +13,24 @@
#include "Gwen/Controls/Menu.h"
#include "Gwen/Controls/MenuItem.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT MenuStrip : public Menu
{
GWEN_CONTROL( MenuStrip, Menu );
namespace Controls
{
class GWEN_EXPORT MenuStrip : public Menu
{
GWEN_CONTROL(MenuStrip, Menu);
virtual void Render( Skin::Base* skin );
virtual void RenderUnder( Skin::Base* /*skin*/ ){}
virtual void Layout( Skin::Base* skin );
virtual void Render(Skin::Base* skin);
virtual void RenderUnder(Skin::Base* /*skin*/) {}
virtual void Layout(Skin::Base* skin);
protected:
protected:
virtual void OnAddItem(MenuItem* item);
virtual bool ShouldHoverOpenMenu();
virtual void Close() {}
};
} // namespace Controls
virtual void OnAddItem( MenuItem* item );
virtual bool ShouldHoverOpenMenu();
virtual void Close() {}
};
}
}
} // namespace Gwen
#endif

View File

@@ -6,32 +6,31 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
namespace ControlsInternal
{
class Modal : public Controls::Base
{
GWEN_CONTROL_INLINE(Modal, Controls::Base)
{
class Modal : public Controls::Base
{
GWEN_CONTROL_INLINE( Modal, Controls::Base )
{
SetKeyboardInputEnabled( true );
SetMouseInputEnabled( true );
SetShouldDrawBackground( true );
}
virtual void Layout( Skin::Base* /*skin*/ )
{
SetBounds( 0, 0, GetCanvas()->Width(), GetCanvas()->Height() );
}
virtual void Render( Skin::Base* skin )
{
if ( !ShouldDrawBackground() ) return;
skin->DrawModalControl( this );
}
};
SetKeyboardInputEnabled(true);
SetMouseInputEnabled(true);
SetShouldDrawBackground(true);
}
}
virtual void Layout(Skin::Base* /*skin*/)
{
SetBounds(0, 0, GetCanvas()->Width(), GetCanvas()->Height());
}
virtual void Render(Skin::Base* skin)
{
if (!ShouldDrawBackground()) return;
skin->DrawModalControl(this);
}
};
} // namespace ControlsInternal
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Utility.h"
#include "Gwen/Skin.h"
@@ -14,83 +13,79 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( NumericUpDown )
GWEN_CONTROL_CONSTRUCTOR(NumericUpDown)
{
SetSize( 100, 20 );
SetSize(100, 20);
Layout::Splitter* pSplitter = new Layout::Splitter( this );
pSplitter->Dock( Pos::Right );
pSplitter->SetSize( 13, 13 );
Layout::Splitter* pSplitter = new Layout::Splitter(this);
pSplitter->Dock(Pos::Right);
pSplitter->SetSize(13, 13);
NumericUpDownButton_Up* pButtonUp = new NumericUpDownButton_Up( pSplitter );
pButtonUp->onPress.Add( this, &NumericUpDown::OnButtonUp );
pButtonUp->SetTabable( false );
NumericUpDownButton_Up* pButtonUp = new NumericUpDownButton_Up(pSplitter);
pButtonUp->onPress.Add(this, &NumericUpDown::OnButtonUp);
pButtonUp->SetTabable(false);
pSplitter->SetPanel( 0, pButtonUp );
pSplitter->SetPanel(0, pButtonUp);
NumericUpDownButton_Down* pButtonDown = new NumericUpDownButton_Down( pSplitter );
pButtonDown->onPress.Add( this, &NumericUpDown::OnButtonDown );
pButtonDown->SetTabable( false );
pButtonUp->SetPadding( Padding( 0, 1, 1, 0 ) );
NumericUpDownButton_Down* pButtonDown = new NumericUpDownButton_Down(pSplitter);
pButtonDown->onPress.Add(this, &NumericUpDown::OnButtonDown);
pButtonDown->SetTabable(false);
pButtonUp->SetPadding(Padding(0, 1, 1, 0));
pSplitter->SetPanel( 1, pButtonDown );
pSplitter->SetPanel(1, pButtonDown);
m_iMax = 100;
m_iMin = 0;
m_iNumber = 0;
SetText( "0" );
SetText("0");
}
void NumericUpDown::OnButtonUp( Base* /*control*/ )
void NumericUpDown::OnButtonUp(Base* /*control*/)
{
SyncNumberFromText();
SetValue( m_iNumber + 1 );
SetValue(m_iNumber + 1);
}
void NumericUpDown::OnButtonDown( Base* /*control*/ )
void NumericUpDown::OnButtonDown(Base* /*control*/)
{
SyncNumberFromText();
SetValue( m_iNumber - 1 );
SetValue(m_iNumber - 1);
}
void NumericUpDown::SyncTextFromNumber()
{
SetText( Utility::ToString( m_iNumber ) );
SetText(Utility::ToString(m_iNumber));
}
void NumericUpDown::SyncNumberFromText()
{
SetValue( (int) GetFloatFromText() );
SetValue((int)GetFloatFromText());
}
void NumericUpDown::SetMin( int i )
void NumericUpDown::SetMin(int i)
{
m_iMin = i;
}
void NumericUpDown::SetMax( int i )
void NumericUpDown::SetMax(int i)
{
m_iMax = i;
}
void NumericUpDown::SetValue( int i )
void NumericUpDown::SetValue(int i)
{
if ( i > m_iMax ) i = m_iMax;
if ( i < m_iMin ) i = m_iMin;
if (i > m_iMax) i = m_iMax;
if (i < m_iMin) i = m_iMin;
if ( m_iNumber == i )
{
if (m_iNumber == i)
{
return;
}
m_iNumber = i;
// Don't update the text if we're typing in it..
if ( !HasFocus() )
if (!HasFocus())
{
SyncTextFromNumber();
}
@@ -100,7 +95,7 @@ void NumericUpDown::SetValue( int i )
void NumericUpDown::OnChange()
{
onChanged.Call( this );
onChanged.Call(this);
}
void NumericUpDown::OnTextChanged()

View File

@@ -12,64 +12,67 @@
#include "Gwen/Controls/Button.h"
#include "Gwen/Controls/TextBox.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT NumericUpDownButton_Up : public Button
{
GWEN_CONTROL_INLINE(NumericUpDownButton_Up, Button) {}
virtual void Render(Skin::Base* skin)
{
class GWEN_EXPORT NumericUpDownButton_Up : public Button
{
GWEN_CONTROL_INLINE( NumericUpDownButton_Up, Button ){}
virtual void Render( Skin::Base* skin )
{
skin->DrawNumericUpDownButton( this, m_bDepressed, true );
}
};
class GWEN_EXPORT NumericUpDownButton_Down : public Button
{
GWEN_CONTROL_INLINE( NumericUpDownButton_Down, Button ){}
virtual void Render( Skin::Base* skin )
{
skin->DrawNumericUpDownButton( this, m_bDepressed, false );
}
};
class GWEN_EXPORT NumericUpDown : public TextBoxNumeric
{
public:
GWEN_CONTROL( NumericUpDown, TextBoxNumeric );
virtual void SetMin( int i );
virtual void SetMax( int i );
virtual void SetValue( int i );
Event::Caller onChanged;
private:
virtual void OnEnter();
virtual void OnChange();
virtual void OnTextChanged();
virtual void OnButtonUp( Base* control );
virtual void OnButtonDown( Base* control );
virtual bool OnKeyUp( bool bDown ) { if ( bDown ) OnButtonUp( NULL ); return true; }
virtual bool OnKeyDown( bool bDown ){ if ( bDown ) OnButtonDown( NULL ); return true; }
virtual void SyncTextFromNumber();
virtual void SyncNumberFromText();
int m_iNumber;
int m_iMax;
int m_iMin;
};
skin->DrawNumericUpDownButton(this, m_bDepressed, true);
}
}
};
class GWEN_EXPORT NumericUpDownButton_Down : public Button
{
GWEN_CONTROL_INLINE(NumericUpDownButton_Down, Button) {}
virtual void Render(Skin::Base* skin)
{
skin->DrawNumericUpDownButton(this, m_bDepressed, false);
}
};
class GWEN_EXPORT NumericUpDown : public TextBoxNumeric
{
public:
GWEN_CONTROL(NumericUpDown, TextBoxNumeric);
virtual void SetMin(int i);
virtual void SetMax(int i);
virtual void SetValue(int i);
Event::Caller onChanged;
private:
virtual void OnEnter();
virtual void OnChange();
virtual void OnTextChanged();
virtual void OnButtonUp(Base* control);
virtual void OnButtonDown(Base* control);
virtual bool OnKeyUp(bool bDown)
{
if (bDown) OnButtonUp(NULL);
return true;
}
virtual bool OnKeyDown(bool bDown)
{
if (bDown) OnButtonDown(NULL);
return true;
}
virtual void SyncTextFromNumber();
virtual void SyncNumberFromText();
int m_iNumber;
int m_iMax;
int m_iMin;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,7 @@
using namespace Gwen;
using namespace Controls;
GWEN_CONTROL_CONSTRUCTOR( PanelListPanel )
GWEN_CONTROL_CONSTRUCTOR(PanelListPanel)
{
m_bVertical = false;
m_bSizeToChildren = true;
@@ -13,7 +13,7 @@ GWEN_CONTROL_CONSTRUCTOR( PanelListPanel )
m_bWrapping = true;
}
void PanelListPanel::Render( Gwen::Skin::Base* /*skin*/ )
void PanelListPanel::Render(Gwen::Skin::Base* /*skin*/)
{
}
@@ -22,17 +22,17 @@ Gwen::Point PanelListPanel::GetBiggestChildSize()
int width = 0;
int height = 0;
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
Controls::Base* pChild = *it;
if ( pChild->Width() > width )
if (pChild->Width() > width)
width = pChild->Width();
if ( pChild->Height() > height )
if (pChild->Height() > height)
height = pChild->Height();
}
return Gwen::Point( width, height );
return Gwen::Point(width, height);
}
void PanelListPanel::DoVerticalLayout()
@@ -45,11 +45,11 @@ void PanelListPanel::DoVerticalLayout()
Gwen::Point childSize = GetBiggestChildSize();
//Lay my children out accordingly
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
Controls::Base* pChild = *it;
testWrap = lastPanelY + m_iControlSpacing + childSize.y;
if ( m_bWrapping && testWrap > Height() - GetPadding().bottom )
if (m_bWrapping && testWrap > Height() - GetPadding().bottom)
{
panelY = GetPadding().top;
panelX = GetPadding().left + panelWidth + m_iLineSpacing;
@@ -61,16 +61,16 @@ void PanelListPanel::DoVerticalLayout()
lastPanelY = testWrap;
}
pChild->SetPos( panelX, panelY );
pChild->SetPos(panelX, panelY);
if (pChild->X() + childSize.x > panelWidth )
if (pChild->X() + childSize.x > panelWidth)
panelWidth = pChild->X() + childSize.x;
}
if ( m_bSizeToChildren )
if (m_bSizeToChildren)
{
Gwen::Point childrenSizeTotal = ChildrenSize();
SetSize( childrenSizeTotal.x, Height());
SetSize(childrenSizeTotal.x, Height());
}
}
@@ -84,40 +84,40 @@ void PanelListPanel::DoHorizontalLayout()
Gwen::Point childSize = GetBiggestChildSize();
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
Controls::Base* pChild = *it;
testWrap = lastPanelX + m_iControlSpacing + childSize.x;
if ( m_bWrapping && testWrap > Width() - GetPadding().right )
{
panelX = GetPadding().left;
panelY = GetPadding().top + panelHeight + m_iLineSpacing;
lastPanelX = panelX + m_iControlSpacing + childSize.x;
}
else
{
panelX = lastPanelX;
lastPanelX = testWrap;
}
testWrap = lastPanelX + m_iControlSpacing + childSize.x;
if (m_bWrapping && testWrap > Width() - GetPadding().right)
{
panelX = GetPadding().left;
panelY = GetPadding().top + panelHeight + m_iLineSpacing;
lastPanelX = panelX + m_iControlSpacing + childSize.x;
}
else
{
panelX = lastPanelX;
lastPanelX = testWrap;
}
pChild->SetPos( panelX, panelY );
pChild->SetPos(panelX, panelY);
if (pChild->Y() + childSize.y > panelHeight )
panelHeight = pChild->Y() + childSize.y;
if (pChild->Y() + childSize.y > panelHeight)
panelHeight = pChild->Y() + childSize.y;
}
if ( m_bSizeToChildren )
if (m_bSizeToChildren)
{
Gwen::Point childrenSizeTotal = ChildrenSize();
SetSize( Width(), childrenSizeTotal.y);
SetSize(Width(), childrenSizeTotal.y);
}
}
void PanelListPanel::Layout( Skin::Base* skin )
void PanelListPanel::Layout(Skin::Base* skin)
{
BaseClass::Layout( skin );
if ( IsHorizontalLayout() )
BaseClass::Layout(skin);
if (IsHorizontalLayout())
DoHorizontalLayout();
else
DoVerticalLayout();

View File

@@ -5,42 +5,48 @@
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Base.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT PanelListPanel : public Controls::Base
{
public:
GWEN_CONTROL(PanelListPanel, Controls::Base);
void Render(Gwen::Skin::Base* skin);
void Layout(Skin::Base* skin);
void DoHorizontalLayout();
void DoVerticalLayout();
bool IsVerticalLayout() { return m_bVertical; }
bool IsHorizontalLayout() { return !m_bVertical; }
void SetVertical()
{
class GWEN_EXPORT PanelListPanel : public Controls::Base
{
public:
GWEN_CONTROL( PanelListPanel, Controls::Base );
void Render( Gwen::Skin::Base* skin );
void Layout( Skin::Base* skin );
void DoHorizontalLayout();
void DoVerticalLayout();
bool IsVerticalLayout() { return m_bVertical; }
bool IsHorizontalLayout() { return !m_bVertical; }
void SetVertical() { m_bVertical = true; Invalidate(); }
void SetHorizontal() { m_bVertical = false; Invalidate(); }
void SetSizeToChildren( bool bShould ) { m_bSizeToChildren = bShould; }
void SetControlSpacing( int spacing ) { m_iControlSpacing = spacing; }
void SetLineSpacing( int spacing ) { m_iLineSpacing = spacing; }
void SetWrapping( bool wrap ) { m_bWrapping = wrap; }
Gwen::Point GetBiggestChildSize();
protected:
bool m_bVertical;
bool m_bSizeToChildren;
int m_iControlSpacing;
int m_iLineSpacing;
bool m_bWrapping;
};
m_bVertical = true;
Invalidate();
}
}
void SetHorizontal()
{
m_bVertical = false;
Invalidate();
}
void SetSizeToChildren(bool bShould) { m_bSizeToChildren = bShould; }
void SetControlSpacing(int spacing) { m_iControlSpacing = spacing; }
void SetLineSpacing(int spacing) { m_iLineSpacing = spacing; }
void SetWrapping(bool wrap) { m_bWrapping = wrap; }
Gwen::Point GetBiggestChildSize();
protected:
bool m_bVertical;
bool m_bSizeToChildren;
int m_iControlSpacing;
int m_iLineSpacing;
bool m_bWrapping;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ScrollControl.h"
#include "Gwen/Controls/ProgressBar.h"
#include "Gwen/Utility.h"
@@ -12,15 +11,14 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( ProgressBar )
GWEN_CONTROL_CONSTRUCTOR(ProgressBar)
{
SetMouseInputEnabled( true );
SetBounds( Gwen::Rect( 0, 0, 128, 32 ) );
SetTextPadding( Padding( 3, 3, 3, 3 ) );
SetMouseInputEnabled(true);
SetBounds(Gwen::Rect(0, 0, 128, 32));
SetTextPadding(Padding(3, 3, 3, 3));
SetHorizontal();
SetAlignment( Gwen::Pos::Center );
SetAlignment(Gwen::Pos::Center);
m_fProgress = 0.0f;
m_bAutoLabel = true;
@@ -28,22 +26,22 @@ GWEN_CONTROL_CONSTRUCTOR( ProgressBar )
void ProgressBar::SetValue(float val)
{
if ( val < 0 )
if (val < 0)
val = 0;
if ( val > 1 )
if (val > 1)
val = 1;
m_fProgress = val;
if ( m_bAutoLabel )
if (m_bAutoLabel)
{
int displayVal = m_fProgress * 100;
SetText( Utility::ToString( displayVal ) + "%" );
SetText(Utility::ToString(displayVal) + "%");
}
}
void ProgressBar::Render( Skin::Base* skin )
void ProgressBar::Render(Skin::Base* skin)
{
skin->DrawProgressBar( this, m_bHorizontal, m_fProgress);
skin->DrawProgressBar(this, m_bHorizontal, m_fProgress);
}

View File

@@ -12,34 +12,31 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT ProgressBar : public Label
{
public:
namespace Controls
{
class GWEN_EXPORT ProgressBar : public Label
{
public:
GWEN_CONTROL(ProgressBar, Label);
GWEN_CONTROL( ProgressBar, Label );
virtual void Render(Skin::Base* skin);
virtual void Render( Skin::Base* skin );
virtual void SetVertical() { m_bHorizontal = false; }
virtual void SetHorizontal() { m_bHorizontal = true; }
virtual void SetVertical() { m_bHorizontal = false; }
virtual void SetHorizontal(){ m_bHorizontal = true; }
virtual void SetValue(float val);
virtual float GetValue() const { return m_fProgress; }
virtual void SetValue( float val );
virtual float GetValue() const { return m_fProgress; }
virtual void SetAutoLabel(bool b) { m_bAutoLabel = b; }
virtual void SetAutoLabel( bool b ){ m_bAutoLabel = b; }
protected:
float m_fProgress;
protected:
float m_fProgress;
bool m_bHorizontal;
bool m_bAutoLabel;
};
}
}
bool m_bHorizontal;
bool m_bAutoLabel;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/Properties.h"
@@ -13,28 +12,28 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( Properties )
GWEN_CONTROL_CONSTRUCTOR(Properties)
{
m_SplitterBar = new SplitterBar( this );
m_SplitterBar->SetPos( 80, 0 );
m_SplitterBar->SetCursor( Gwen::CursorType::SizeWE );
m_SplitterBar->onDragged.Add( this, &Properties::OnSplitterMoved );
m_SplitterBar->SetShouldDrawBackground( false );
m_SplitterBar = new SplitterBar(this);
m_SplitterBar->SetPos(80, 0);
m_SplitterBar->SetCursor(Gwen::CursorType::SizeWE);
m_SplitterBar->onDragged.Add(this, &Properties::OnSplitterMoved);
m_SplitterBar->SetShouldDrawBackground(false);
}
void Properties::PostLayout( Gwen::Skin::Base* /*skin*/ )
void Properties::PostLayout(Gwen::Skin::Base* /*skin*/)
{
m_SplitterBar->SetHeight( 0 );
m_SplitterBar->SetHeight(0);
if ( SizeToChildren( false, true ) )
if (SizeToChildren(false, true))
{
InvalidateParent();
}
m_SplitterBar->SetSize( 3, Height() );
m_SplitterBar->SetSize(3, Height());
}
void Properties::OnSplitterMoved( Controls::Base * /*control*/ )
void Properties::OnSplitterMoved(Controls::Base* /*control*/)
{
InvalidateChildren();
}
@@ -44,82 +43,81 @@ int Properties::GetSplitWidth()
return m_SplitterBar->X();
}
PropertyRow* Properties::Add( const UnicodeString& text, const UnicodeString& value )
PropertyRow* Properties::Add(const UnicodeString& text, const UnicodeString& value)
{
Property::Base* pProp = new Property::Text( this );
pProp->SetPropertyValue( value );
Property::Base* pProp = new Property::Text(this);
pProp->SetPropertyValue(value);
return Add( text, pProp );
return Add(text, pProp);
}
PropertyRow* Properties::Add( const String& text, const String& value )
PropertyRow* Properties::Add(const String& text, const String& value)
{
return Add( Gwen::Utility::StringToUnicode( text ), Gwen::Utility::StringToUnicode( value ) );
return Add(Gwen::Utility::StringToUnicode(text), Gwen::Utility::StringToUnicode(value));
}
PropertyRow* Properties::Add( const UnicodeString& text, Property::Base* pProp )
PropertyRow* Properties::Add(const UnicodeString& text, Property::Base* pProp)
{
PropertyRow* row = new PropertyRow( this );
row->Dock( Pos::Top );
row->GetLabel()->SetText( text );
row->SetProperty( pProp );
PropertyRow* row = new PropertyRow(this);
row->Dock(Pos::Top);
row->GetLabel()->SetText(text);
row->SetProperty(pProp);
m_SplitterBar->BringToFront();
return row;
}
PropertyRow* Properties::Add( const String& text, Property::Base* pProp )
PropertyRow* Properties::Add(const String& text, Property::Base* pProp)
{
return Add( Gwen::Utility::StringToUnicode( text ), pProp );
return Add(Gwen::Utility::StringToUnicode(text), pProp);
}
void Properties::Clear()
{
Base::List ChildListCopy = Children;
for ( Base::List::iterator it = ChildListCopy.begin(); it != ChildListCopy.end(); ++it )
for (Base::List::iterator it = ChildListCopy.begin(); it != ChildListCopy.end(); ++it)
{
PropertyRow* row = (*it)->DynamicCastPropertyRow();
if ( !row ) continue;
if (!row) continue;
row->DelayedDelete();
}
}
GWEN_CONTROL_CONSTRUCTOR( PropertyRow )
GWEN_CONTROL_CONSTRUCTOR(PropertyRow)
{
m_Property = NULL;
m_Label = new Label( this );
m_Label->SetAlignment( Pos::CenterV | Pos::Left );
m_Label->Dock( Pos::Left );
m_Label->SetMargin( Margin( 2, 0, 0, 0 ) );
m_Label = new Label(this);
m_Label->SetAlignment(Pos::CenterV | Pos::Left);
m_Label->Dock(Pos::Left);
m_Label->SetMargin(Margin(2, 0, 0, 0));
SetHeight( 16 );
}
void PropertyRow::Render( Gwen::Skin::Base* skin )
{
skin->DrawPropertyRow( this, m_Label->Right(), m_Property->IsEditing() );
SetHeight(16);
}
void PropertyRow::Layout( Gwen::Skin::Base* /*skin*/ )
void PropertyRow::Render(Gwen::Skin::Base* skin)
{
skin->DrawPropertyRow(this, m_Label->Right(), m_Property->IsEditing());
}
void PropertyRow::Layout(Gwen::Skin::Base* /*skin*/)
{
Properties* pParent = GetParent()->DynamicCastProperties();
if ( !pParent ) return;
if (!pParent) return;
m_Label->SetWidth( pParent->GetSplitWidth() );
m_Label->SetWidth(pParent->GetSplitWidth());
}
void PropertyRow::SetProperty( Property::Base* prop )
void PropertyRow::SetProperty(Property::Base* prop)
{
m_Property = prop;
m_Property->SetParent( this );
m_Property->Dock( Pos::Fill );
m_Property->onChange.Add( this, &ThisClass::OnPropertyValueChanged );
m_Property->SetParent(this);
m_Property->Dock(Pos::Fill);
m_Property->onChange.Add(this, &ThisClass::OnPropertyValueChanged);
}
void PropertyRow::OnPropertyValueChanged( Gwen::Controls::Base* /*control*/ )
void PropertyRow::OnPropertyValueChanged(Gwen::Controls::Base* /*control*/)
{
onChange.Call( this );
onChange.Call(this);
}

View File

@@ -16,62 +16,54 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
namespace Controls
{
class PropertyRow;
class PropertyRow;
class GWEN_EXPORT Properties : public Base
{
public:
GWEN_CONTROL(Properties, Base);
class GWEN_EXPORT Properties : public Base
{
public:
virtual void PostLayout(Gwen::Skin::Base* skin);
GWEN_CONTROL( Properties, Base );
PropertyRow* Add(const UnicodeString& text, const UnicodeString& value = L"");
PropertyRow* Add(const String& text, const String& value = "");
PropertyRow* Add(const UnicodeString& text, Property::Base* pProp);
PropertyRow* Add(const String& text, Property::Base* pProp);
virtual void PostLayout( Gwen::Skin::Base* skin );
virtual int GetSplitWidth();
PropertyRow* Add( const UnicodeString& text, const UnicodeString& value = L"" );
PropertyRow* Add( const String& text, const String& value = "" );
PropertyRow* Add( const UnicodeString& text, Property::Base* pProp );
PropertyRow* Add( const String& text, Property::Base* pProp );
virtual void Clear();
virtual int GetSplitWidth();
protected:
virtual void OnSplitterMoved(Controls::Base* control);
virtual void Clear();
Controls::SplitterBar* m_SplitterBar;
};
protected:
class GWEN_EXPORT PropertyRow : public Base
{
public:
GWEN_CONTROL(PropertyRow, Base);
virtual void OnSplitterMoved( Controls::Base * control );
virtual Label* GetLabel() { return m_Label; }
virtual void SetProperty(Property::Base* prop);
virtual Property::Base* GetProperty() { return m_Property; }
Controls::SplitterBar* m_SplitterBar;
virtual void Layout(Gwen::Skin::Base* skin);
virtual void Render(Gwen::Skin::Base* skin);
};
Event::Caller onChange;
class GWEN_EXPORT PropertyRow : public Base
{
public:
protected:
void OnPropertyValueChanged(Gwen::Controls::Base* control);
GWEN_CONTROL( PropertyRow, Base );
virtual Label* GetLabel(){ return m_Label; }
virtual void SetProperty( Property::Base* prop );
virtual Property::Base* GetProperty(){ return m_Property; }
virtual void Layout( Gwen::Skin::Base* skin );
virtual void Render( Gwen::Skin::Base* skin );
Event::Caller onChange;
protected:
void OnPropertyValueChanged( Gwen::Controls::Base* control );
Label* m_Label;
Property::Base* m_Property;
};
}
}
Label* m_Label;
Property::Base* m_Property;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -13,48 +13,46 @@
#include "Gwen/Skin.h"
#include "Gwen/Utility.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
namespace Property
{
class GWEN_EXPORT Base : public Gwen::Controls::Base
{
public:
GWEN_CONTROL_INLINE(Base, Gwen::Controls::Base) {}
virtual String GetPropertyValueAnsi()
{
namespace Property
{
class GWEN_EXPORT Base : public Gwen::Controls::Base
{
public:
GWEN_CONTROL_INLINE( Base, Gwen::Controls::Base ){}
virtual String GetPropertyValueAnsi()
{
return Gwen::Utility::UnicodeToString( GetPropertyValue() );
}
virtual void SetPropertyValue( const String& v, bool bFireChangeEvents = false )
{
SetPropertyValue( Gwen::Utility::StringToUnicode( v ), bFireChangeEvents );
}
virtual UnicodeString GetPropertyValue() = 0;
virtual void SetPropertyValue( const UnicodeString& v, bool bFireChangeEvents = false ) = 0;
virtual bool IsEditing() = 0;
virtual void DoChanged()
{
onChange.Call( this );
}
virtual void OnPropertyValueChanged( Gwen::Controls::Base* /*control*/ )
{
DoChanged();
}
Event::Caller onChange;
};
}
return Gwen::Utility::UnicodeToString(GetPropertyValue());
}
}
virtual void SetPropertyValue(const String& v, bool bFireChangeEvents = false)
{
SetPropertyValue(Gwen::Utility::StringToUnicode(v), bFireChangeEvents);
}
virtual UnicodeString GetPropertyValue() = 0;
virtual void SetPropertyValue(const UnicodeString& v, bool bFireChangeEvents = false) = 0;
virtual bool IsEditing() = 0;
virtual void DoChanged()
{
onChange.Call(this);
}
virtual void OnPropertyValueChanged(Gwen::Controls::Base* /*control*/)
{
DoChanged();
}
Event::Caller onChange;
};
} // namespace Property
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -6,75 +6,74 @@
#include "Gwen/Controls/WindowControl.h"
#include "Gwen/Controls/HSVColorPicker.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
namespace Property
{
class ColorSelector : public Property::Text
{
public:
GWEN_CONTROL_INLINE(ColorSelector, Property::Text)
{
namespace Property
{
class ColorSelector : public Property::Text
{
public:
GWEN_CONTROL_INLINE( ColorSelector, Property::Text )
{
m_Button = new Button( this );
m_Button->Dock( Pos::Right );
m_Button->SetWidth( 20 );
m_Button->onPress.Add( this, &ThisClass::OnButtonPress );
}
void OnButtonPress( Controls::Base* control )
{
Gwen::Controls::WindowControl* wind = new Gwen::Controls::WindowControl( GetCanvas() );
wind->SetTitle( L"Color Selection" );
wind->SetSize( 256, 180 );
wind->SetPos( GetCanvas()->Width() * 0.5 - 128, GetCanvas()->Height()* 0.5 - 128 );
wind->SetDeleteOnClose( true );
wind->DisableResizing();
wind->MakeModal( true );
Gwen::Controls::HSVColorPicker* picker = new Gwen::Controls::HSVColorPicker( wind );
picker->SetName( "picker" );
float defaultColor[3];
Gwen::Utility::Strings::To::Floats( Gwen::Utility::UnicodeToString( m_TextBox->GetText() ), defaultColor, 3);
picker->SetColor( Gwen::Color( defaultColor[0], defaultColor[1], defaultColor[2], 255 ), false, true );
picker->onColorChanged.Add( this, &ThisClass::ColorChanged );
}
void ColorChanged( Controls::Base* control )
{
Gwen::Controls::HSVColorPicker* picker = control->DynamicCastHSVColorPicker();
Gwen::String colorStr;
colorStr += Gwen::Utility::ToString( ( int )picker->GetColor().r ) + " ";
colorStr += Gwen::Utility::ToString( ( int )picker->GetColor().g ) + " ";
colorStr += Gwen::Utility::ToString( ( int )picker->GetColor().b );
m_TextBox->SetText( colorStr );
DoChanged();
}
virtual UnicodeString GetPropertyValue()
{
return m_TextBox->GetText();
}
virtual void SetPropertyValue( const UnicodeString& v, bool bFireChangeEvents )
{
m_TextBox->SetText( v, bFireChangeEvents );
}
virtual bool IsEditing()
{
return m_TextBox == Gwen::KeyboardFocus;
}
Button* m_Button;
};
}
m_Button = new Button(this);
m_Button->Dock(Pos::Right);
m_Button->SetWidth(20);
m_Button->onPress.Add(this, &ThisClass::OnButtonPress);
}
}
void OnButtonPress(Controls::Base* control)
{
Gwen::Controls::WindowControl* wind = new Gwen::Controls::WindowControl(GetCanvas());
wind->SetTitle(L"Color Selection");
wind->SetSize(256, 180);
wind->SetPos(GetCanvas()->Width() * 0.5 - 128, GetCanvas()->Height() * 0.5 - 128);
wind->SetDeleteOnClose(true);
wind->DisableResizing();
wind->MakeModal(true);
Gwen::Controls::HSVColorPicker* picker = new Gwen::Controls::HSVColorPicker(wind);
picker->SetName("picker");
float defaultColor[3];
Gwen::Utility::Strings::To::Floats(Gwen::Utility::UnicodeToString(m_TextBox->GetText()), defaultColor, 3);
picker->SetColor(Gwen::Color(defaultColor[0], defaultColor[1], defaultColor[2], 255), false, true);
picker->onColorChanged.Add(this, &ThisClass::ColorChanged);
}
void ColorChanged(Controls::Base* control)
{
Gwen::Controls::HSVColorPicker* picker = control->DynamicCastHSVColorPicker();
Gwen::String colorStr;
colorStr += Gwen::Utility::ToString((int)picker->GetColor().r) + " ";
colorStr += Gwen::Utility::ToString((int)picker->GetColor().g) + " ";
colorStr += Gwen::Utility::ToString((int)picker->GetColor().b);
m_TextBox->SetText(colorStr);
DoChanged();
}
virtual UnicodeString GetPropertyValue()
{
return m_TextBox->GetText();
}
virtual void SetPropertyValue(const UnicodeString& v, bool bFireChangeEvents)
{
m_TextBox->SetText(v, bFireChangeEvents);
}
virtual bool IsEditing()
{
return m_TextBox == Gwen::KeyboardFocus;
}
Button* m_Button;
};
} // namespace Property
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -11,42 +11,41 @@
#include "Gwen/Controls/Property/BaseProperty.h"
#include "Gwen/Controls/TextBox.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
namespace Property
{
class GWEN_EXPORT Text : public Property::Base
{
public:
GWEN_CONTROL_INLINE(Text, Property::Base)
{
namespace Property
{
class GWEN_EXPORT Text : public Property::Base
{
public:
GWEN_CONTROL_INLINE( Text, Property::Base )
{
m_TextBox = new TextBox( this );
m_TextBox->Dock( Pos::Fill );
m_TextBox->SetShouldDrawBackground( false );
m_TextBox->onTextChanged.Add( this, &BaseClass::OnPropertyValueChanged );
}
virtual UnicodeString GetPropertyValue()
{
return m_TextBox->GetText();
}
virtual void SetPropertyValue( const UnicodeString& v, bool bFireChangeEvents )
{
m_TextBox->SetText( v, bFireChangeEvents );
}
virtual bool IsEditing()
{
return m_TextBox->HasFocus();
}
TextBox* m_TextBox;
};
}
m_TextBox = new TextBox(this);
m_TextBox->Dock(Pos::Fill);
m_TextBox->SetShouldDrawBackground(false);
m_TextBox->onTextChanged.Add(this, &BaseClass::OnPropertyValueChanged);
}
}
virtual UnicodeString GetPropertyValue()
{
return m_TextBox->GetText();
}
virtual void SetPropertyValue(const UnicodeString& v, bool bFireChangeEvents)
{
m_TextBox->SetText(v, bFireChangeEvents);
}
virtual bool IsEditing()
{
return m_TextBox->HasFocus();
}
TextBox* m_TextBox;
};
} // namespace Property
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -15,48 +15,43 @@
#include "Gwen/Controls/TreeControl.h"
#include "Gwen/Controls/Properties.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class PropertyTreeNode : public TreeNode
{
public:
GWEN_CONTROL_INLINE(PropertyTreeNode, TreeNode)
{
class PropertyTreeNode : public TreeNode
{
public:
GWEN_CONTROL_INLINE( PropertyTreeNode, TreeNode )
{
}
virtual void Render( Skin::Base* skin )
{
skin->DrawPropertyTreeNode( this, m_InnerPanel->X(), m_InnerPanel->Y() );
}
};
class PropertyTree : public TreeControl
{
public:
GWEN_CONTROL_INLINE( PropertyTree, TreeControl )
{
}
Properties* Add( const UnicodeString& text )
{
TreeNode* node = new PropertyTreeNode( this );
node->SetText( text );
node->Dock( Pos::Top );
Properties* props = new Properties( node );
props->Dock( Pos::Top );
return props;
}
};
}
}
virtual void Render(Skin::Base* skin)
{
skin->DrawPropertyTreeNode(this, m_InnerPanel->X(), m_InnerPanel->Y());
}
};
class PropertyTree : public TreeControl
{
public:
GWEN_CONTROL_INLINE(PropertyTree, TreeControl)
{
}
Properties* Add(const UnicodeString& text)
{
TreeNode* node = new PropertyTreeNode(this);
node->SetText(text);
node->Dock(Pos::Top);
Properties* props = new Properties(node);
props->Dock(Pos::Top);
return props;
}
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,21 +4,19 @@
See license in Gwen.h
*/
#include "Gwen/Controls/RadioButton.h"
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( RadioButton )
GWEN_CONTROL_CONSTRUCTOR(RadioButton)
{
SetSize( 11, 11 );
SetMouseInputEnabled( true );
SetTabable( false );
SetSize(11, 11);
SetMouseInputEnabled(true);
SetTabable(false);
}
void RadioButton::Render( Skin::Base* skin )
void RadioButton::Render(Skin::Base* skin)
{
skin->DrawRadioButton( this, IsChecked(), IsDepressed() );
skin->DrawRadioButton(this, IsChecked(), IsDepressed());
}

View File

@@ -16,63 +16,64 @@
#include "Gwen/Controls/CheckBox.h"
#include "Gwen/Controls/LabelClickable.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT RadioButton : public CheckBox
{
GWEN_CONTROL(RadioButton, CheckBox);
virtual void Render(Skin::Base* skin);
private:
// From CheckBox
virtual bool AllowUncheck() { return false; }
};
class GWEN_EXPORT LabeledRadioButton : public Base
{
public:
GWEN_CONTROL_INLINE(LabeledRadioButton, Base)
{
class GWEN_EXPORT RadioButton : public CheckBox
{
GWEN_CONTROL( RadioButton, CheckBox );
virtual void Render( Skin::Base* skin );
SetSize(200, 19);
private:
m_RadioButton = new RadioButton(this);
m_RadioButton->Dock(Pos::Left);
m_RadioButton->SetMargin(Margin(0, 4, 2, 4));
m_RadioButton->SetTabable(false);
m_RadioButton->SetKeyboardInputEnabled(false);
// From CheckBox
virtual bool AllowUncheck(){ return false; }
};
class GWEN_EXPORT LabeledRadioButton : public Base
{
public:
GWEN_CONTROL_INLINE( LabeledRadioButton, Base )
{
SetSize( 200, 19 );
m_RadioButton = new RadioButton( this );
m_RadioButton->Dock( Pos::Left );
m_RadioButton->SetMargin( Margin( 0, 4, 2, 4 ) );
m_RadioButton->SetTabable( false );
m_RadioButton->SetKeyboardInputEnabled( false );
m_Label = new LabelClickable( this );
m_Label->SetAlignment( Pos::CenterV | Pos::Left );
m_Label->SetText( "Radio Button" );
m_Label->Dock( Pos::Fill );
m_Label->onPress.Add( m_RadioButton, &CheckBox::ReceiveEventPress );
m_Label->SetTabable( false );
m_Label->SetKeyboardInputEnabled( false );
}
void RenderFocus( Gwen::Skin::Base* skin )
{
if ( Gwen::KeyboardFocus != this ) return;
if ( !IsTabable() ) return;
skin->DrawKeyboardHighlight( this, GetRenderBounds(), 0 );
}
virtual RadioButton* GetRadioButton() { return m_RadioButton; }
virtual LabelClickable* GetLabel(){ return m_Label; }
virtual bool OnKeySpace(bool bDown) { if ( bDown ) m_RadioButton->SetChecked( !m_RadioButton->IsChecked() ); return true; }
virtual void Select(){ m_RadioButton->SetChecked( true ); }
private:
RadioButton* m_RadioButton;
LabelClickable* m_Label;
};
m_Label = new LabelClickable(this);
m_Label->SetAlignment(Pos::CenterV | Pos::Left);
m_Label->SetText("Radio Button");
m_Label->Dock(Pos::Fill);
m_Label->onPress.Add(m_RadioButton, &CheckBox::ReceiveEventPress);
m_Label->SetTabable(false);
m_Label->SetKeyboardInputEnabled(false);
}
}
void RenderFocus(Gwen::Skin::Base* skin)
{
if (Gwen::KeyboardFocus != this) return;
if (!IsTabable()) return;
skin->DrawKeyboardHighlight(this, GetRenderBounds(), 0);
}
virtual RadioButton* GetRadioButton() { return m_RadioButton; }
virtual LabelClickable* GetLabel() { return m_Label; }
virtual bool OnKeySpace(bool bDown)
{
if (bDown) m_RadioButton->SetChecked(!m_RadioButton->IsChecked());
return true;
}
virtual void Select() { m_RadioButton->SetChecked(true); }
private:
RadioButton* m_RadioButton;
LabelClickable* m_Label;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/RadioButtonController.h"
#include "Gwen/Controls/RadioButton.h"
#include "Gwen/Utility.h"
@@ -12,15 +11,14 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( RadioButtonController )
GWEN_CONTROL_CONSTRUCTOR(RadioButtonController)
{
m_Selected = NULL;
SetTabable( false );
SetKeyboardInputEnabled( false );
SetTabable(false);
SetKeyboardInputEnabled(false);
}
void RadioButtonController::OnRadioClicked( Gwen::Controls::Base* pFromPanel )
void RadioButtonController::OnRadioClicked(Gwen::Controls::Base* pFromPanel)
{
RadioButton* pCheckedRadioButton = pFromPanel->DynamicCastRadioButton();
@@ -29,16 +27,16 @@ void RadioButtonController::OnRadioClicked( Gwen::Controls::Base* pFromPanel )
{
Base* pChild = *iter;
LabeledRadioButton* pLRB = pChild->DynamicCastLabeledRadioButton();
if ( pLRB )
if (pLRB)
{
RadioButton* pChildRadioButton = pLRB->GetRadioButton();
if ( pChildRadioButton == pCheckedRadioButton )
if (pChildRadioButton == pCheckedRadioButton)
{
m_Selected = pLRB;
}
else
{
pLRB->GetRadioButton()->SetChecked( false );
pLRB->GetRadioButton()->SetChecked(false);
}
}
}
@@ -48,25 +46,25 @@ void RadioButtonController::OnRadioClicked( Gwen::Controls::Base* pFromPanel )
void RadioButtonController::OnChange()
{
onSelectionChange.Call( this );
onSelectionChange.Call(this);
}
LabeledRadioButton* RadioButtonController::AddOption( const Gwen::String& strText, const Gwen::String& strOptionName )
LabeledRadioButton* RadioButtonController::AddOption(const Gwen::String& strText, const Gwen::String& strOptionName)
{
return AddOption( Gwen::Utility::StringToUnicode( strText ), strOptionName );
return AddOption(Gwen::Utility::StringToUnicode(strText), strOptionName);
}
LabeledRadioButton* RadioButtonController::AddOption( const Gwen::UnicodeString& strText, const Gwen::String& strOptionName )
LabeledRadioButton* RadioButtonController::AddOption(const Gwen::UnicodeString& strText, const Gwen::String& strOptionName)
{
LabeledRadioButton* lrb = new LabeledRadioButton( this );
LabeledRadioButton* lrb = new LabeledRadioButton(this);
lrb->SetName( strOptionName );
lrb->GetLabel()->SetText( strText );
lrb->GetRadioButton()->onChecked.Add( this, &RadioButtonController::OnRadioClicked );
lrb->Dock( Pos::Top );
lrb->SetMargin( Margin( 0, 1, 0, 1 ) );
lrb->SetKeyboardInputEnabled( false );
lrb->SetTabable( false );
lrb->SetName(strOptionName);
lrb->GetLabel()->SetText(strText);
lrb->GetRadioButton()->onChecked.Add(this, &RadioButtonController::OnRadioClicked);
lrb->Dock(Pos::Top);
lrb->SetMargin(Margin(0, 1, 0, 1));
lrb->SetKeyboardInputEnabled(false);
lrb->SetTabable(false);
Invalidate();

View File

@@ -12,37 +12,33 @@
#include "Gwen/Controls/Label.h"
#include "Gwen/Controls/RadioButton.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
namespace Controls
{
class GWEN_EXPORT RadioButtonController : public Base
{
public:
GWEN_CONTROL(RadioButtonController, Base);
class GWEN_EXPORT RadioButtonController : public Base
{
public:
virtual void Render(Skin::Base* /*skin*/){};
virtual void OnRadioClicked(Base* pFromPanel);
GWEN_CONTROL( RadioButtonController, Base );
virtual void OnChange();
virtual void Render( Skin::Base* /*skin*/ ){};
virtual void OnRadioClicked( Base* pFromPanel );
virtual LabeledRadioButton* AddOption(const Gwen::String& strText, const Gwen::String& strOptionName = "");
virtual LabeledRadioButton* AddOption(const Gwen::UnicodeString& strText, const Gwen::String& strOptionName = "");
virtual void OnChange();
virtual LabeledRadioButton* GetSelected() { return m_Selected; }
virtual LabeledRadioButton* AddOption( const Gwen::String& strText, const Gwen::String& strOptionName = "" );
virtual LabeledRadioButton* AddOption( const Gwen::UnicodeString& strText, const Gwen::String& strOptionName = "" );
virtual String GetSelectedName() { return m_Selected->GetName(); }
virtual UnicodeString GetSelectedLabel() { return m_Selected->GetLabel()->GetText(); }
virtual LabeledRadioButton* GetSelected(){ return m_Selected; }
Event::Caller onSelectionChange;
virtual String GetSelectedName(){ return m_Selected->GetName(); }
virtual UnicodeString GetSelectedLabel(){ return m_Selected->GetLabel()->GetText(); }
Event::Caller onSelectionChange;
private:
LabeledRadioButton* m_Selected;
};
}
}
private:
LabeledRadioButton* m_Selected;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ImagePanel.h"
#include "Gwen/Controls/Label.h"
#include "Gwen/Controls/Resizer.h"
@@ -14,97 +13,97 @@ using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( ResizableControl )
GWEN_CONTROL_CONSTRUCTOR(ResizableControl)
{
m_bResizable = true;
m_MinimumSize = Gwen::Point( 5, 5 );
m_MinimumSize = Gwen::Point(5, 5);
m_bClampMovement = false;
Resizer* resizerBottom = new Resizer (this );
resizerBottom->Dock( Pos::Bottom );
resizerBottom->SetResizeDir( Pos::Bottom );
resizerBottom->SetTarget( this );
resizerBottom->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerBottom = new Resizer(this);
resizerBottom->Dock(Pos::Bottom);
resizerBottom->SetResizeDir(Pos::Bottom);
resizerBottom->SetTarget(this);
resizerBottom->onResize.Add(this, &ResizableControl::OnResizedInternal);
Resizer* resizerBottomLeft = new Resizer( resizerBottom );
resizerBottomLeft->Dock( Pos::Left );
resizerBottomLeft->SetResizeDir( Pos::Bottom | Pos::Left );
resizerBottomLeft->SetTarget(this );
resizerBottomLeft->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerBottomLeft = new Resizer(resizerBottom);
resizerBottomLeft->Dock(Pos::Left);
resizerBottomLeft->SetResizeDir(Pos::Bottom | Pos::Left);
resizerBottomLeft->SetTarget(this);
resizerBottomLeft->onResize.Add(this, &ResizableControl::OnResizedInternal);
Resizer* resizerBottomRight = new Resizer( resizerBottom );
resizerBottomRight->Dock( Pos::Right);
resizerBottomRight->SetResizeDir( Pos::Bottom | Pos::Right );
resizerBottomRight->SetTarget( this );
resizerBottomRight->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerBottomRight = new Resizer(resizerBottom);
resizerBottomRight->Dock(Pos::Right);
resizerBottomRight->SetResizeDir(Pos::Bottom | Pos::Right);
resizerBottomRight->SetTarget(this);
resizerBottomRight->onResize.Add(this, &ResizableControl::OnResizedInternal);
Resizer* resizerTop = new Resizer( this );
resizerTop->Dock( Pos::Top );
resizerTop->SetResizeDir( Pos::Top );
resizerTop->SetTarget( this );
resizerTop->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerTop = new Resizer(this);
resizerTop->Dock(Pos::Top);
resizerTop->SetResizeDir(Pos::Top);
resizerTop->SetTarget(this);
resizerTop->onResize.Add(this, &ResizableControl::OnResizedInternal);
Resizer* resizerTopLeft = new Resizer( resizerTop );
resizerTopLeft->Dock( Pos::Left );
resizerTopLeft->SetResizeDir( Pos::Top | Pos::Left );
resizerTopLeft->SetTarget( this );
resizerTopLeft->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerTopLeft = new Resizer(resizerTop);
resizerTopLeft->Dock(Pos::Left);
resizerTopLeft->SetResizeDir(Pos::Top | Pos::Left);
resizerTopLeft->SetTarget(this);
resizerTopLeft->onResize.Add(this, &ResizableControl::OnResizedInternal);
Resizer* resizerTopRight = new Resizer( resizerTop );
resizerTopRight->Dock( Pos::Right );
resizerTopRight->SetResizeDir( Pos::Top| Pos::Right );
resizerTopRight->SetTarget( this );
resizerTopRight->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerTopRight = new Resizer(resizerTop);
resizerTopRight->Dock(Pos::Right);
resizerTopRight->SetResizeDir(Pos::Top | Pos::Right);
resizerTopRight->SetTarget(this);
resizerTopRight->onResize.Add(this, &ResizableControl::OnResizedInternal);
Resizer* resizerLeft = new Resizer( this );
resizerLeft->Dock( Pos::Left );
resizerLeft->SetResizeDir( Pos::Left );
resizerLeft->SetTarget( this );
resizerLeft->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerLeft = new Resizer(this);
resizerLeft->Dock(Pos::Left);
resizerLeft->SetResizeDir(Pos::Left);
resizerLeft->SetTarget(this);
resizerLeft->onResize.Add(this, &ResizableControl::OnResizedInternal);
Resizer* resizerRight = new Resizer( this );
resizerRight->Dock( Pos::Right );
resizerRight->SetResizeDir( Pos::Right );
resizerRight->SetTarget( this );
resizerRight->onResize.Add( this, &ResizableControl::OnResizedInternal );
Resizer* resizerRight = new Resizer(this);
resizerRight->Dock(Pos::Right);
resizerRight->SetResizeDir(Pos::Right);
resizerRight->SetTarget(this);
resizerRight->onResize.Add(this, &ResizableControl::OnResizedInternal);
}
void ResizableControl::DisableResizing()
{
for ( Base::List::iterator it = Children.begin(); it != Children.end(); ++it )
for (Base::List::iterator it = Children.begin(); it != Children.end(); ++it)
{
Resizer* resizer = (*it)->DynamicCastResizer();
if ( !resizer ) continue;
resizer->SetMouseInputEnabled( false );
resizer->SetHidden( true );
SetPadding( Padding( resizer->Width(), resizer->Width(), resizer->Width(), resizer->Width() ) );
if (!resizer) continue;
resizer->SetMouseInputEnabled(false);
resizer->SetHidden(true);
SetPadding(Padding(resizer->Width(), resizer->Width(), resizer->Width(), resizer->Width()));
}
}
bool ResizableControl::SetBounds( int x, int y, int w, int h )
bool ResizableControl::SetBounds(int x, int y, int w, int h)
{
Gwen::Point minSize = GetMinimumSize();
// Clamp Minimum Size
if ( w < minSize.x ) w = minSize.x;
if ( h < minSize.y ) h = minSize.y;
if (w < minSize.x) w = minSize.x;
if (h < minSize.y) h = minSize.y;
// Clamp to parent's window
Base* pParent = GetParent();
if ( pParent && m_bClampMovement )
if (pParent && m_bClampMovement)
{
if ( x + w > pParent->Width() ) x = pParent->Width() - w;
if ( x < 0 ) x = 0;
if ( y + h > pParent->Height() ) y = pParent->Height() - h;
if ( y < 0 ) y = 0;
if (x + w > pParent->Width()) x = pParent->Width() - w;
if (x < 0) x = 0;
if (y + h > pParent->Height()) y = pParent->Height() - h;
if (y < 0) y = 0;
}
return BaseClass::SetBounds( x, y, w, h );
return BaseClass::SetBounds(x, y, w, h);
}
void ResizableControl::OnResizedInternal( Controls::Base* /*pControl*/ )
void ResizableControl::OnResizedInternal(Controls::Base* /*pControl*/)
{
onResize.Call( this );
onResize.Call(this);
OnResized();
}

View File

@@ -16,40 +16,36 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT ResizableControl : public Base
{
public:
namespace Controls
{
class GWEN_EXPORT ResizableControl : public Base
{
public:
GWEN_CONTROL(ResizableControl, Base);
GWEN_CONTROL( ResizableControl, Base );
virtual void SetClampMovement(bool shouldClamp) { m_bClampMovement = shouldClamp; }
virtual bool GetClampMovement() { return m_bClampMovement; }
virtual void SetClampMovement( bool shouldClamp ) { m_bClampMovement = shouldClamp; }
virtual bool GetClampMovement() { return m_bClampMovement; }
virtual void SetMinimumSize(const Gwen::Point& minSize) { m_MinimumSize = minSize; }
virtual Gwen::Point GetMinimumSize() { return m_MinimumSize; }
virtual void SetMinimumSize( const Gwen::Point& minSize ) { m_MinimumSize = minSize; }
virtual Gwen::Point GetMinimumSize() { return m_MinimumSize; }
virtual void DisableResizing();
virtual void DisableResizing();
virtual bool SetBounds(int x, int y, int w, int h);
virtual bool SetBounds( int x, int y, int w, int h );
virtual void OnResized(){};
virtual void OnResized(){};
Event::Caller onResize;
Event::Caller onResize;
protected:
void OnResizedInternal(Controls::Base* pControl);
protected:
void OnResizedInternal( Controls::Base* pControl );
Gwen::Point m_MinimumSize;
bool m_bClampMovement;
bool m_bResizable;
};
}
}
Gwen::Point m_MinimumSize;
bool m_bClampMovement;
bool m_bResizable;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,37 +4,35 @@
See license in Gwen.h
*/
#include "Gwen/Controls/Resizer.h"
using namespace Gwen;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( Resizer )
GWEN_CONTROL_CONSTRUCTOR(Resizer)
{
m_iResizeDir = Pos::Left;
SetMouseInputEnabled( true );
SetSize( 6, 6 );
SetMouseInputEnabled(true);
SetSize(6, 6);
}
void Resizer::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
void Resizer::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
{
if ( !m_pTarget ) return;
if ( !m_bDepressed ) return;
if (!m_pTarget) return;
if (!m_bDepressed) return;
// Gwen::Rect oldBounds = m_pTarget->GetBounds();
// Gwen::Rect oldBounds = m_pTarget->GetBounds();
Gwen::Rect pBounds = m_pTarget->GetBounds();
Gwen::Point pntMin = m_pTarget->GetMinimumSize();
Gwen::Point pCursorPos = m_pTarget->CanvasPosToLocal( Gwen::Point( x, y ) );
Gwen::Point pCursorPos = m_pTarget->CanvasPosToLocal(Gwen::Point(x, y));
Gwen::Point pDelta = m_pTarget->LocalPosToCanvas( m_HoldPos );
pDelta.x -= x;
pDelta.y -= y;
Gwen::Point pDelta = m_pTarget->LocalPosToCanvas(m_HoldPos);
pDelta.x -= x;
pDelta.y -= y;
if ( m_iResizeDir & Pos::Left )
if (m_iResizeDir & Pos::Left)
{
pBounds.x -= pDelta.x;
pBounds.w += pDelta.x;
@@ -42,16 +40,15 @@ void Resizer::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
// Conform to minimum size here so we don't
// go all weird when we snap it in the base conrt
if ( pBounds.w < pntMin.x )
if (pBounds.w < pntMin.x)
{
int diff = pntMin.x - pBounds.w;
pBounds.w += diff;
pBounds.x -= diff;
}
}
if ( m_iResizeDir & Pos::Top )
if (m_iResizeDir & Pos::Top)
{
pBounds.y -= pDelta.y;
pBounds.h += pDelta.y;
@@ -59,16 +56,15 @@ void Resizer::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
// Conform to minimum size here so we don't
// go all weird when we snap it in the base conrt
if ( pBounds.h < pntMin.y )
if (pBounds.h < pntMin.y)
{
int diff = pntMin.y - pBounds.h;
pBounds.h += diff;
pBounds.y -= diff;
}
}
if ( m_iResizeDir & Pos::Right )
if (m_iResizeDir & Pos::Right)
{
// This is complicated.
// Basically we want to use the HoldPos, so it doesn't snap to the edge of the control
@@ -78,43 +74,42 @@ void Resizer::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
int woff = pBounds.w - m_HoldPos.x;
int diff = pBounds.w;
pBounds.w = pCursorPos.x + woff;
if ( pBounds.w < pntMin.x ) pBounds.w = pntMin.x;
pBounds.w = pCursorPos.x + woff;
if (pBounds.w < pntMin.x) pBounds.w = pntMin.x;
diff -= pBounds.w;
m_HoldPos.x -= diff;
}
if ( m_iResizeDir & Pos::Bottom )
if (m_iResizeDir & Pos::Bottom)
{
int hoff = pBounds.h - m_HoldPos.y;
int diff = pBounds.h;
pBounds.h = pCursorPos.y + hoff;
if ( pBounds.h < pntMin.y ) pBounds.h = pntMin.y;
pBounds.h = pCursorPos.y + hoff;
if (pBounds.h < pntMin.y) pBounds.h = pntMin.y;
diff -= pBounds.h;
m_HoldPos.y -= diff;
}
m_pTarget->SetBounds( pBounds );
m_pTarget->SetBounds(pBounds);
onResize.Call( this );
onResize.Call(this);
}
void Resizer::SetResizeDir( int dir )
void Resizer::SetResizeDir(int dir)
{
m_iResizeDir = dir;
if ( (dir & Pos::Left && dir & Pos::Top) || (dir & Pos::Right && dir & Pos::Bottom) )
return SetCursor( Gwen::CursorType::SizeNWSE );
if ((dir & Pos::Left && dir & Pos::Top) || (dir & Pos::Right && dir & Pos::Bottom))
return SetCursor(Gwen::CursorType::SizeNWSE);
if ( (dir & Pos::Right && dir & Pos::Top) || (dir & Pos::Left && dir & Pos::Bottom) )
return SetCursor( Gwen::CursorType::SizeNESW );
if ((dir & Pos::Right && dir & Pos::Top) || (dir & Pos::Left && dir & Pos::Bottom))
return SetCursor(Gwen::CursorType::SizeNESW);
if ( dir & Pos::Right || dir & Pos::Left )
return SetCursor( Gwen::CursorType::SizeWE );
if (dir & Pos::Right || dir & Pos::Left)
return SetCursor(Gwen::CursorType::SizeWE);
if ( dir & Pos::Top || dir & Pos::Bottom )
return SetCursor( Gwen::CursorType::SizeNS );
if (dir & Pos::Top || dir & Pos::Bottom)
return SetCursor(Gwen::CursorType::SizeNS);
}

View File

@@ -13,27 +13,23 @@
#include "Gwen/Skin.h"
#include "Gwen/Controls/Dragger.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
{
class GWEN_EXPORT Resizer : public Dragger
{
public:
namespace ControlsInternal
{
class GWEN_EXPORT Resizer : public Dragger
{
public:
GWEN_CONTROL(Resizer, Dragger);
GWEN_CONTROL( Resizer, Dragger );
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
virtual void SetResizeDir(int dir);
virtual void OnMouseMoved( int x, int y, int deltaX, int deltaY );
virtual void SetResizeDir( int dir );
Event::Caller onResize;
Event::Caller onResize;
protected:
int m_iResizeDir;
};
}
}
protected:
int m_iResizeDir;
};
} // namespace ControlsInternal
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/RichLabel.h"
#include "Gwen/Controls/Label.h"
@@ -16,7 +15,7 @@ using namespace Gwen::Controls;
const unsigned char Type_Text = 0;
const unsigned char Type_Newline = 1;
GWEN_CONTROL_CONSTRUCTOR( RichLabel )
GWEN_CONTROL_CONSTRUCTOR(RichLabel)
{
m_bNeedsRebuild = false;
}
@@ -26,19 +25,19 @@ void RichLabel::AddLineBreak()
DividedText t;
t.type = Type_Newline;
m_TextBlocks.push_back( t );
m_TextBlocks.push_back(t);
}
void RichLabel::AddText( const Gwen::TextObject& text, Gwen::Color color, Gwen::Font* font )
void RichLabel::AddText(const Gwen::TextObject& text, Gwen::Color color, Gwen::Font* font)
{
if ( text.m_Data.size() == 0 ) return;
if (text.m_Data.size() == 0) return;
Gwen::Utility::Strings::UnicodeList lst;
Gwen::Utility::Strings::Split( text.GetUnicode(), L"\n", lst, false );
Gwen::Utility::Strings::Split(text.GetUnicode(), L"\n", lst, false);
for (size_t i=0; i<lst.size(); i++ )
for (size_t i = 0; i < lst.size(); i++)
{
if ( i > 0 ) AddLineBreak();
if (i > 0) AddLineBreak();
DividedText t;
t.type = Type_Text;
@@ -46,120 +45,120 @@ void RichLabel::AddText( const Gwen::TextObject& text, Gwen::Color color, Gwen::
t.color = color;
t.font = font;
m_TextBlocks.push_back( t );
m_TextBlocks.push_back(t);
m_bNeedsRebuild = true;
Invalidate();
}
}
bool RichLabel::SizeToChildren( bool w, bool h )
bool RichLabel::SizeToChildren(bool w, bool h)
{
Rebuild();
return BaseClass::SizeToChildren( w, h );
return BaseClass::SizeToChildren(w, h);
}
void RichLabel::SplitLabel( const Gwen::UnicodeString& text, Gwen::Font* pFont, const DividedText& txt, int& x, int& y, int& lineheight )
void RichLabel::SplitLabel(const Gwen::UnicodeString& text, Gwen::Font* pFont, const DividedText& txt, int& x, int& y, int& lineheight)
{
Gwen::Utility::Strings::UnicodeList lst;
Gwen::Utility::Strings::Split( text, L" ", lst, true );
if ( lst.size() == 0 ) return;
Gwen::Utility::Strings::Split(text, L" ", lst, true);
if (lst.size() == 0) return;
int iSpaceLeft = Width() - x;
// Does the whole word fit in?
{
Gwen::Point StringSize = GetSkin()->GetRender()->MeasureText( pFont, text );
if ( iSpaceLeft > StringSize.x )
Gwen::Point StringSize = GetSkin()->GetRender()->MeasureText(pFont, text);
if (iSpaceLeft > StringSize.x)
{
return CreateLabel( text, txt, x, y, lineheight, true );
return CreateLabel(text, txt, x, y, lineheight, true);
}
}
// If the first word is bigger than the line, just give up.
{
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText( pFont, lst[0] );
if ( WordSize.x >= iSpaceLeft )
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText(pFont, lst[0]);
if (WordSize.x >= iSpaceLeft)
{
CreateLabel( lst[0], txt, x, y, lineheight, true );
if ( lst[0].size() >= text.size() ) return;
CreateLabel(lst[0], txt, x, y, lineheight, true);
if (lst[0].size() >= text.size()) return;
Gwen::UnicodeString LeftOver = text.substr( lst[0].size() + 1 );
return SplitLabel( LeftOver, pFont, txt, x, y, lineheight );
Gwen::UnicodeString LeftOver = text.substr(lst[0].size() + 1);
return SplitLabel(LeftOver, pFont, txt, x, y, lineheight);
}
}
Gwen::UnicodeString strNewString = L"";
for ( size_t i=0; i<lst.size(); i++ )
for (size_t i = 0; i < lst.size(); i++)
{
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText( pFont, strNewString + lst[i] );
if ( WordSize.x > iSpaceLeft )
Gwen::Point WordSize = GetSkin()->GetRender()->MeasureText(pFont, strNewString + lst[i]);
if (WordSize.x > iSpaceLeft)
{
CreateLabel( strNewString, txt, x, y, lineheight, true );
CreateLabel(strNewString, txt, x, y, lineheight, true);
x = 0;
y += lineheight;
break;;
break;
;
}
strNewString += lst[i];
}
Gwen::UnicodeString LeftOver = text.substr( strNewString.size() + 1 );
return SplitLabel( LeftOver, pFont, txt, x, y, lineheight );
Gwen::UnicodeString LeftOver = text.substr(strNewString.size() + 1);
return SplitLabel(LeftOver, pFont, txt, x, y, lineheight);
}
void RichLabel::CreateLabel( const Gwen::UnicodeString& text, const DividedText& txt, int& x, int& y, int& lineheight, bool NoSplit )
void RichLabel::CreateLabel(const Gwen::UnicodeString& text, const DividedText& txt, int& x, int& y, int& lineheight, bool NoSplit)
{
//
// Use default font or is one set?
//
Gwen::Font* pFont = GetSkin()->GetDefaultFont();
if ( txt.font ) pFont = txt.font;
if (txt.font) pFont = txt.font;
//
// This string is too long for us, split it up.
//
Gwen::Point p = GetSkin()->GetRender()->MeasureText( pFont, text );
Gwen::Point p = GetSkin()->GetRender()->MeasureText(pFont, text);
if ( lineheight == -1 )
if (lineheight == -1)
{
lineheight = p.y;
}
if ( !NoSplit )
if (!NoSplit)
{
if ( x + p.x > Width() )
if (x + p.x > Width())
{
return SplitLabel( text, pFont, txt, x, y, lineheight );
return SplitLabel(text, pFont, txt, x, y, lineheight);
}
}
//
// Wrap
//
if ( x + p.x >= Width() )
if (x + p.x >= Width())
{
CreateNewline( x, y, lineheight );
CreateNewline(x, y, lineheight);
}
Gwen::Controls::Label* pLabel = new Gwen::Controls::Label( this );
pLabel->SetText( x == 0 ? Gwen::Utility::Strings::TrimLeft<Gwen::UnicodeString>( text, L" " ) : text );
pLabel->SetTextColor( txt.color );
pLabel->SetFont( pFont );
Gwen::Controls::Label* pLabel = new Gwen::Controls::Label(this);
pLabel->SetText(x == 0 ? Gwen::Utility::Strings::TrimLeft<Gwen::UnicodeString>(text, L" ") : text);
pLabel->SetTextColor(txt.color);
pLabel->SetFont(pFont);
pLabel->SizeToContents();
pLabel->SetPos( x, y );
pLabel->SetPos(x, y);
//lineheight = (lineheight + pLabel->Height()) / 2;
//lineheight = (lineheight + pLabel->Height()) / 2;
x += pLabel->Width();
if ( x >= Width() )
if (x >= Width())
{
CreateNewline( x, y, lineheight );
CreateNewline(x, y, lineheight);
}
}
void RichLabel::CreateNewline( int& x, int& y, int& lineheight )
void RichLabel::CreateNewline(int& x, int& y, int& lineheight)
{
x = 0;
y += lineheight;
@@ -172,37 +171,36 @@ void RichLabel::Rebuild()
int x = 0;
int y = 0;
int lineheight = -1;
for ( DividedText::List::iterator it = m_TextBlocks.begin(); it != m_TextBlocks.end(); ++it )
for (DividedText::List::iterator it = m_TextBlocks.begin(); it != m_TextBlocks.end(); ++it)
{
if ( it->type == Type_Newline )
if (it->type == Type_Newline)
{
CreateNewline( x, y, lineheight );
CreateNewline(x, y, lineheight);
continue;
}
if ( it->type == Type_Text )
if (it->type == Type_Text)
{
CreateLabel( (*it).text, *it, x, y, lineheight, false );
CreateLabel((*it).text, *it, x, y, lineheight, false);
continue;
}
}
m_bNeedsRebuild = false;
}
void RichLabel::OnBoundsChanged( Gwen::Rect oldBounds )
void RichLabel::OnBoundsChanged(Gwen::Rect oldBounds)
{
BaseClass::OnBoundsChanged( oldBounds );
BaseClass::OnBoundsChanged(oldBounds);
Rebuild();
}
void RichLabel::Layout( Gwen::Skin::Base* skin )
void RichLabel::Layout(Gwen::Skin::Base* skin)
{
BaseClass::Layout( skin );
BaseClass::Layout(skin);
if ( m_bNeedsRebuild )
if (m_bNeedsRebuild)
{
Rebuild();
}

View File

@@ -13,50 +13,47 @@
#include "Gwen/Controls/Text.h"
#include "Gwen/TextObject.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT RichLabel : public Controls::Base
{
public:
GWEN_CONTROL(RichLabel, Gwen::Controls::Base);
void AddLineBreak();
void AddText(const Gwen::TextObject& text, Gwen::Color color, Gwen::Font* font = NULL);
virtual bool SizeToChildren(bool w = true, bool h = true);
protected:
struct DividedText
{
class GWEN_EXPORT RichLabel : public Controls::Base
typedef std::list<DividedText> List;
DividedText()
{
public:
type = 0;
font = NULL;
}
GWEN_CONTROL( RichLabel, Gwen::Controls::Base );
void AddLineBreak();
void AddText( const Gwen::TextObject& text, Gwen::Color color, Gwen::Font* font = NULL );
unsigned char type;
Gwen::UnicodeString text;
Gwen::Color color;
Gwen::Font* font;
};
virtual bool SizeToChildren( bool w = true, bool h = true );
void Layout(Gwen::Skin::Base* skin);
void SplitLabel(const Gwen::UnicodeString& text, Gwen::Font* pFont, const DividedText& txt, int& x, int& y, int& lineheight);
void CreateNewline(int& x, int& y, int& lineheight);
void CreateLabel(const Gwen::UnicodeString& text, const DividedText& txt, int& x, int& y, int& lineheight, bool NoSplit);
void Rebuild();
protected:
void OnBoundsChanged(Gwen::Rect oldBounds);
struct DividedText
{
typedef std::list<DividedText> List;
DividedText()
{
type = 0;
font = NULL;
}
unsigned char type;
Gwen::UnicodeString text;
Gwen::Color color;
Gwen::Font* font;
};
void Layout( Gwen::Skin::Base* skin );
void SplitLabel( const Gwen::UnicodeString& text, Gwen::Font* pFont, const DividedText& txt, int& x, int& y, int& lineheight );
void CreateNewline( int& x, int& y, int& lineheight );
void CreateLabel( const Gwen::UnicodeString& text, const DividedText& txt, int& x, int& y, int& lineheight, bool NoSplit );
void Rebuild();
void OnBoundsChanged( Gwen::Rect oldBounds );
DividedText::List m_TextBlocks;
bool m_bNeedsRebuild;
};
}
}
DividedText::List m_TextBlocks;
bool m_bNeedsRebuild;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ScrollBar.h"
#include "Gwen/Controls/ScrollBarButton.h"
#include "Gwen/Controls/ScrollBarBar.h"
@@ -13,71 +12,63 @@ using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( BaseScrollBar )
GWEN_CONTROL_CONSTRUCTOR(BaseScrollBar)
{
for (int i = 0; i < 2; i++)
{
m_ScrollButton[i] = new ScrollBarButton( this );
m_ScrollButton[i] = new ScrollBarButton(this);
}
m_Bar = new ScrollBarBar( this );
SetBounds( 0, 0, 15, 15 );
m_Bar = new ScrollBarBar(this);
SetBounds(0, 0, 15, 15);
m_bDepressed = false;
m_fScrolledAmount = 0;
m_fContentSize = 0;
m_fViewableContentSize = 0;
SetNudgeAmount( 20 );
SetNudgeAmount(20);
}
void BaseScrollBar::Render( Skin::Base* skin )
void BaseScrollBar::Render(Skin::Base* skin)
{
skin->DrawScrollBar( this, false, m_bDepressed );
skin->DrawScrollBar(this, false, m_bDepressed);
}
void BaseScrollBar::OnBarMoved( Controls::Base* /*control*/ )
void BaseScrollBar::OnBarMoved(Controls::Base* /*control*/)
{
onBarMoved.Call( this );
onBarMoved.Call(this);
}
void BaseScrollBar::BarMovedNotification()
{
OnBarMoved( this );
OnBarMoved(this);
}
void BaseScrollBar::SetContentSize( float size )
void BaseScrollBar::SetContentSize(float size)
{
if ( m_fContentSize != size )
if (m_fContentSize != size)
{
Invalidate();
}
m_fContentSize = size;
}
void BaseScrollBar::SetViewableContentSize( float size )
void BaseScrollBar::SetViewableContentSize(float size)
{
if ( m_fViewableContentSize != size )
if (m_fViewableContentSize != size)
Invalidate();
m_fViewableContentSize = size;
}
bool BaseScrollBar::SetScrolledAmount( float amount, bool /*forceUpdate*/ )
bool BaseScrollBar::SetScrolledAmount(float amount, bool /*forceUpdate*/)
{
if ( m_fScrolledAmount == amount ) return false;
if (m_fScrolledAmount == amount) return false;
m_fScrolledAmount = amount;
Invalidate();
BarMovedNotification();
return true;
}

View File

@@ -13,75 +13,71 @@
#include "Gwen/Controls/ScrollBarButton.h"
#include "Gwen/Gwen.h"
#define SCROLL_BUTTON_UP 0
#define SCROLL_BUTTON_LEFT 0
#define SCROLL_BUTTON_DOWN 1
#define SCROLL_BUTTON_RIGHT 1
#define NUDGE_DIST 10
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT BaseScrollBar : public Base
{
public:
GWEN_CONTROL(BaseScrollBar, Base);
virtual void Render(Skin::Base* skin);
virtual void SetBarSize(int size) = 0;
virtual int GetBarSize() = 0;
virtual int GetBarPos() = 0;
virtual void OnBarMoved(Controls::Base* control);
virtual void OnMouseClickLeft(int /*x*/, int /*y*/, bool /*bDown*/) {}
virtual void ScrollToLeft() {}
virtual void ScrollToRight() {}
virtual void ScrollToTop() {}
virtual void ScrollToBottom() {}
virtual float GetNudgeAmount() { return m_fNudgeAmount / m_fContentSize; }
virtual void SetNudgeAmount(float nudge) { m_fNudgeAmount = nudge; }
virtual void BarMovedNotification();
virtual float CalculateScrolledAmount() { return 0; }
virtual int CalculateBarSize() { return 0; }
virtual bool SetScrolledAmount(float amount, bool forceUpdate);
virtual void SetContentSize(float size);
virtual void SetViewableContentSize(float size);
virtual int GetButtonSize() { return 0; }
virtual float GetScrolledAmount() { return m_fScrolledAmount; }
Gwen::Event::Caller onBarMoved;
float getContentSize()
{
class GWEN_EXPORT BaseScrollBar : public Base
{
public:
GWEN_CONTROL( BaseScrollBar, Base );
virtual void Render( Skin::Base* skin );
virtual void SetBarSize(int size) = 0;
virtual int GetBarSize() = 0;
virtual int GetBarPos() = 0;
virtual void OnBarMoved( Controls::Base* control);
virtual void OnMouseClickLeft( int /*x*/, int /*y*/, bool /*bDown*/ ){}
virtual void ScrollToLeft(){}
virtual void ScrollToRight(){}
virtual void ScrollToTop(){}
virtual void ScrollToBottom(){}
virtual float GetNudgeAmount() { return m_fNudgeAmount / m_fContentSize; }
virtual void SetNudgeAmount( float nudge ) { m_fNudgeAmount = nudge; }
virtual void BarMovedNotification();
virtual float CalculateScrolledAmount() { return 0; }
virtual int CalculateBarSize() { return 0; }
virtual bool SetScrolledAmount(float amount, bool forceUpdate);
virtual void SetContentSize(float size);
virtual void SetViewableContentSize(float size);
virtual int GetButtonSize() { return 0; }
virtual float GetScrolledAmount() { return m_fScrolledAmount; }
Gwen::Event::Caller onBarMoved;
float getContentSize()
{
return m_fContentSize;
}
float getViewableContentSize() const
{
return m_fViewableContentSize;
}
protected:
ControlsInternal::ScrollBarButton* m_ScrollButton[2];
ControlsInternal::ScrollBarBar * m_Bar;
bool m_bDepressed;
float m_fScrolledAmount;
float m_fContentSize;
float m_fViewableContentSize;
float m_fNudgeAmount;
};
return m_fContentSize;
}
}
float getViewableContentSize() const
{
return m_fViewableContentSize;
}
protected:
ControlsInternal::ScrollBarButton* m_ScrollButton[2];
ControlsInternal::ScrollBarBar* m_Bar;
bool m_bDepressed;
float m_fScrolledAmount;
float m_fContentSize;
float m_fViewableContentSize;
float m_fNudgeAmount;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ScrollBar.h"
#include "Gwen/Controls/ScrollBarBar.h"
@@ -14,44 +13,44 @@ using namespace Gwen::ControlsInternal;
//Actual bar representing height of parent
GWEN_CONTROL_CONSTRUCTOR( ScrollBarBar )
GWEN_CONTROL_CONSTRUCTOR(ScrollBarBar)
{
RestrictToParent( true );
SetTarget( this );
RestrictToParent(true);
SetTarget(this);
}
void ScrollBarBar::Render( Skin::Base* skin )
void ScrollBarBar::Render(Skin::Base* skin)
{
skin->DrawScrollBarBar(this, m_bDepressed, IsHovered(), m_bHorizontal );
BaseClass::Render( skin );
skin->DrawScrollBarBar(this, m_bDepressed, IsHovered(), m_bHorizontal);
BaseClass::Render(skin);
}
void ScrollBarBar::OnMouseMoved( int x, int y, int deltaX, int deltaY )
void ScrollBarBar::OnMouseMoved(int x, int y, int deltaX, int deltaY)
{
BaseClass::OnMouseMoved( x, y, deltaX, deltaY );
BaseClass::OnMouseMoved(x, y, deltaX, deltaY);
if ( !m_bDepressed )
if (!m_bDepressed)
return;
InvalidateParent();
}
void ScrollBarBar::OnMouseClickLeft( int x, int y, bool bDown )
void ScrollBarBar::OnMouseClickLeft(int x, int y, bool bDown)
{
BaseClass::OnMouseClickLeft( x, y, bDown );
BaseClass::OnMouseClickLeft(x, y, bDown);
InvalidateParent();
}
void ScrollBarBar::Layout( Skin::Base* /*skin*/ )
void ScrollBarBar::Layout(Skin::Base* /*skin*/)
{
if ( !GetParent() )
if (!GetParent())
return;
//Move to our current position to force clamping - is this a hack?
MoveTo( X(), Y() );
MoveTo(X(), Y());
}
void ScrollBarBar::MoveTo( int x, int y )
void ScrollBarBar::MoveTo(int x, int y)
{
BaseClass::MoveTo( x, y );
BaseClass::MoveTo(x, y);
}

View File

@@ -12,35 +12,32 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
{
class GWEN_EXPORT ScrollBarBar : public ControlsInternal::Dragger
{
public:
namespace ControlsInternal
{
class GWEN_EXPORT ScrollBarBar : public ControlsInternal::Dragger
{
public:
GWEN_CONTROL(ScrollBarBar, ControlsInternal::Dragger);
GWEN_CONTROL( ScrollBarBar, ControlsInternal::Dragger );
virtual void Render(Skin::Base* skin);
virtual void Layout(Skin::Base* skin);
virtual void Render( Skin::Base* skin );
virtual void Layout( Skin::Base* skin );
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
virtual void OnMouseClickLeft(int x, int y, bool bDown);
virtual void OnMouseMoved( int x, int y, int deltaX, int deltaY );
virtual void OnMouseClickLeft( int x, int y, bool bDown );
virtual void MoveTo(int x, int y);
virtual void MoveTo(int x, int y);
virtual void SetHorizontal() { m_bHorizontal = true; }
virtual void SetVertical() { m_bHorizontal = false; }
virtual bool IsVertical() { return !m_bHorizontal; }
virtual bool IsHorizontal() { return m_bHorizontal; }
virtual bool IsDepressed() { return m_bDepressed; }
virtual void SetHorizontal() { m_bHorizontal = true; }
virtual void SetVertical() { m_bHorizontal = false; }
virtual bool IsVertical() { return !m_bHorizontal; }
virtual bool IsHorizontal() { return m_bHorizontal; }
virtual bool IsDepressed() { return m_bDepressed; }
protected:
bool m_bHorizontal;
};
}
}
protected:
bool m_bHorizontal;
};
} // namespace ControlsInternal
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ScrollBar.h"
#include "Gwen/Controls/ScrollBarButton.h"
@@ -12,11 +11,10 @@ using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( ScrollBarButton )
GWEN_CONTROL_CONSTRUCTOR(ScrollBarButton)
{
m_iDirection = 0;
SetBounds(0,0,0,0);
SetBounds(0, 0, 0, 0);
}
void ScrollBarButton::SetDirectionUp()
@@ -39,7 +37,7 @@ void ScrollBarButton::SetDirectionRight()
m_iDirection = Pos::Right;
}
void ScrollBarButton::Render( Skin::Base* skin )
void ScrollBarButton::Render(Skin::Base* skin)
{
skin->DrawScrollButton( this, m_iDirection, m_bDepressed );
skin->DrawScrollButton(this, m_iDirection, m_bDepressed);
}

View File

@@ -10,27 +10,25 @@
#include "Gwen/Controls/Button.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
{
class GWEN_EXPORT ScrollBarButton : public Controls::Button
{
public:
namespace ControlsInternal
{
class GWEN_EXPORT ScrollBarButton : public Controls::Button
{
public:
GWEN_CONTROL(ScrollBarButton, Controls::Button);
GWEN_CONTROL( ScrollBarButton, Controls::Button );
void Render(Skin::Base* skin);
void Render( Skin::Base* skin );
void SetDirectionUp();
void SetDirectionDown();
void SetDirectionLeft();
void SetDirectionRight();
void SetDirectionUp();
void SetDirectionDown();
void SetDirectionLeft();
void SetDirectionRight();
protected:
int m_iDirection;
};
}
}
protected:
int m_iDirection;
};
} // namespace ControlsInternal
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Controls/ScrollControl.h"
#include "Gwen/Controls/ScrollBar.h"
#include "Gwen/Controls/VerticalScrollBar.h"
@@ -15,84 +14,83 @@ using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( ScrollControl )
GWEN_CONTROL_CONSTRUCTOR(ScrollControl)
{
SetMouseInputEnabled( false );
SetMouseInputEnabled(false);
m_VerticalScrollBar = new VerticalScrollBar( this );
m_VerticalScrollBar = new VerticalScrollBar(this);
m_VerticalScrollBar->Dock(Pos::Right);
m_VerticalScrollBar->onBarMoved.Add( this, &ScrollControl::VBarMoved );
m_VerticalScrollBar->SetNudgeAmount( 30 );
m_VerticalScrollBar->onBarMoved.Add(this, &ScrollControl::VBarMoved);
m_VerticalScrollBar->SetNudgeAmount(30);
m_bCanScrollV = true;
m_HorizontalScrollBar = new HorizontalScrollBar( this );
m_HorizontalScrollBar->Dock( Pos::Bottom );
m_HorizontalScrollBar->onBarMoved.Add( this, &ScrollControl::HBarMoved );
m_bCanScrollH = true;
m_HorizontalScrollBar->SetNudgeAmount( 30 );
m_InnerPanel = new Base( this );
m_HorizontalScrollBar = new HorizontalScrollBar(this);
m_HorizontalScrollBar->Dock(Pos::Bottom);
m_HorizontalScrollBar->onBarMoved.Add(this, &ScrollControl::HBarMoved);
m_bCanScrollH = true;
m_HorizontalScrollBar->SetNudgeAmount(30);
m_InnerPanel = new Base(this);
m_InnerPanel->SetPos(0, 0);
m_InnerPanel->SetMargin( Margin(5,5,5,5));
m_InnerPanel->SetMargin(Margin(5, 5, 5, 5));
m_InnerPanel->SendToBack();
m_InnerPanel->SetMouseInputEnabled( false );
m_InnerPanel->SetMouseInputEnabled(false);
m_bAutoHideBars = false;
}
void ScrollControl::SetScroll( bool h, bool v )
void ScrollControl::SetScroll(bool h, bool v)
{
m_bCanScrollV = v;
m_bCanScrollH = h;
m_VerticalScrollBar->SetHidden( !m_bCanScrollV );
m_HorizontalScrollBar->SetHidden( !m_bCanScrollH );
m_VerticalScrollBar->SetHidden(!m_bCanScrollV);
m_HorizontalScrollBar->SetHidden(!m_bCanScrollH);
}
void ScrollControl::SetInnerSize( int w, int h )
void ScrollControl::SetInnerSize(int w, int h)
{
m_InnerPanel->SetSize( w, h );
m_InnerPanel->SetSize(w, h);
}
void ScrollControl::VBarMoved( Controls::Base * /*control*/ )
void ScrollControl::VBarMoved(Controls::Base* /*control*/)
{
Invalidate();
}
void ScrollControl::HBarMoved( Controls::Base * /*control*/ )
void ScrollControl::HBarMoved(Controls::Base* /*control*/)
{
Invalidate();
}
void ScrollControl::OnChildBoundsChanged( Gwen::Rect /*oldChildBounds*/, Base* /*pChild*/ )
void ScrollControl::OnChildBoundsChanged(Gwen::Rect /*oldChildBounds*/, Base* /*pChild*/)
{
UpdateScrollBars();
}
void ScrollControl::Layout( Skin::Base* skin )
void ScrollControl::Layout(Skin::Base* skin)
{
UpdateScrollBars();
BaseClass::Layout(skin);
}
bool ScrollControl::OnMouseWheeled( int iDelta )
bool ScrollControl::OnMouseWheeled(int iDelta)
{
if ( CanScrollV() && m_VerticalScrollBar->Visible() )
if (CanScrollV() && m_VerticalScrollBar->Visible())
{
if ( m_VerticalScrollBar->SetScrolledAmount( m_VerticalScrollBar->GetScrolledAmount() - m_VerticalScrollBar->GetNudgeAmount() * ( (float)iDelta / 60.0f ), true) )
if (m_VerticalScrollBar->SetScrolledAmount(m_VerticalScrollBar->GetScrolledAmount() - m_VerticalScrollBar->GetNudgeAmount() * ((float)iDelta / 60.0f), true))
return true;
}
if ( CanScrollH() && m_HorizontalScrollBar->Visible() )
if (CanScrollH() && m_HorizontalScrollBar->Visible())
{
if ( m_HorizontalScrollBar->SetScrolledAmount( m_HorizontalScrollBar->GetScrolledAmount() - m_HorizontalScrollBar->GetNudgeAmount() * ( (float)iDelta / 60.0f ), true) )
return true;
if (m_HorizontalScrollBar->SetScrolledAmount(m_HorizontalScrollBar->GetScrolledAmount() - m_HorizontalScrollBar->GetNudgeAmount() * ((float)iDelta / 60.0f), true))
return true;
}
return false;
}
void ScrollControl::Render( Skin::Base* skin )
void ScrollControl::Render(Skin::Base* skin)
{
#if 0
// Debug render - this shouldn't render ANYTHING REALLY - it should be up to the parent!
@@ -108,110 +106,108 @@ void ScrollControl::Render( Skin::Base* skin )
render->RenderText( skin->GetDefaultFont(), Gwen::Point( 0, 0 ), Utility::Format( L"Offset: %i %i", m_InnerPanel->X(), m_InnerPanel->Y() ) );
#else //0
#else //0
(void)skin;
#endif //0
#endif //0
}
void ScrollControl::UpdateScrollBars()
{
if ( !m_InnerPanel )
{
if (!m_InnerPanel)
return;
int childrenWidth = 0;
int childrenHeight = 0;
//Get the max size of all our children together
for ( Base::List::iterator iter = m_InnerPanel->Children.begin(); iter != m_InnerPanel->Children.end(); ++iter )
for (Base::List::iterator iter = m_InnerPanel->Children.begin(); iter != m_InnerPanel->Children.end(); ++iter)
{
Base* pChild = *iter;
childrenWidth = Utility::Max( childrenWidth, pChild->Right() );
childrenHeight = Utility::Max( childrenHeight, pChild->Bottom() );
childrenWidth = Utility::Max(childrenWidth, pChild->Right());
childrenHeight = Utility::Max(childrenHeight, pChild->Bottom());
}
m_InnerPanel->SetSize( Utility::Max(Width(), childrenWidth), Utility::Max(Height(), childrenHeight));
m_InnerPanel->SetSize(Utility::Max(Width(), childrenWidth), Utility::Max(Height(), childrenHeight));
float hg = (float)(childrenWidth + (m_VerticalScrollBar->Hidden() ? 0 : m_VerticalScrollBar->Width()));
if (hg==0.f)
if (hg == 0.f)
hg = 0.00001f;
float wPercent = (float)Width() / hg;
float wPercent = (float)Width() / hg;
hg = (float)(childrenHeight + (m_HorizontalScrollBar->Hidden() ? 0 : m_HorizontalScrollBar->Height()));
if (hg==0.f)
if (hg == 0.f)
hg = 0.00001f;
float hPercent = (float)Height() / hg;
if ( m_bCanScrollV )
SetVScrollRequired( hPercent >= 1 );
if (m_bCanScrollV)
SetVScrollRequired(hPercent >= 1);
else
m_VerticalScrollBar->SetHidden( true );
m_VerticalScrollBar->SetHidden(true);
if ( m_bCanScrollH )
SetHScrollRequired( wPercent >= 1 );
if (m_bCanScrollH)
SetHScrollRequired(wPercent >= 1);
else
m_HorizontalScrollBar->SetHidden( true );
m_HorizontalScrollBar->SetHidden(true);
m_VerticalScrollBar->SetContentSize(m_InnerPanel->Height());
m_VerticalScrollBar->SetViewableContentSize(Height() - (m_HorizontalScrollBar->Hidden() ? 0 : m_HorizontalScrollBar->Height()));
m_VerticalScrollBar->SetContentSize( m_InnerPanel->Height() );
m_VerticalScrollBar->SetViewableContentSize( Height() - (m_HorizontalScrollBar->Hidden() ? 0 : m_HorizontalScrollBar->Height()));
m_HorizontalScrollBar->SetContentSize( m_InnerPanel->Width() );
m_HorizontalScrollBar->SetViewableContentSize( Width() - (m_VerticalScrollBar->Hidden() ? 0 : m_VerticalScrollBar->Width()) );
m_HorizontalScrollBar->SetContentSize(m_InnerPanel->Width());
m_HorizontalScrollBar->SetViewableContentSize(Width() - (m_VerticalScrollBar->Hidden() ? 0 : m_VerticalScrollBar->Width()));
int newInnerPanelPosX = 0;
int newInnerPanelPosY = 0;
if ( CanScrollV() && !m_VerticalScrollBar->Hidden() )
if (CanScrollV() && !m_VerticalScrollBar->Hidden())
{
newInnerPanelPosY = -( ( m_InnerPanel->Height() ) - Height() + (m_HorizontalScrollBar->Hidden() ? 0 : m_HorizontalScrollBar->Height()) ) * m_VerticalScrollBar->GetScrolledAmount();
newInnerPanelPosY = -((m_InnerPanel->Height()) - Height() + (m_HorizontalScrollBar->Hidden() ? 0 : m_HorizontalScrollBar->Height())) * m_VerticalScrollBar->GetScrolledAmount();
}
if ( CanScrollH() && !m_HorizontalScrollBar->Hidden() )
if (CanScrollH() && !m_HorizontalScrollBar->Hidden())
{
newInnerPanelPosX = - ( ( m_InnerPanel->Width() ) - Width() + (m_VerticalScrollBar->Hidden() ? 0 : m_VerticalScrollBar->Width())) * m_HorizontalScrollBar->GetScrolledAmount();
newInnerPanelPosX = -((m_InnerPanel->Width()) - Width() + (m_VerticalScrollBar->Hidden() ? 0 : m_VerticalScrollBar->Width())) * m_HorizontalScrollBar->GetScrolledAmount();
}
m_InnerPanel->SetPos( newInnerPanelPosX , newInnerPanelPosY );
m_InnerPanel->SetPos(newInnerPanelPosX, newInnerPanelPosY);
}
void ScrollControl::SetVScrollRequired(bool req)
{
if ( req )
if (req)
{
m_VerticalScrollBar->SetScrolledAmount( 0, true );
m_VerticalScrollBar->SetDisabled( true );
m_VerticalScrollBar->SetScrolledAmount(0, true);
m_VerticalScrollBar->SetDisabled(true);
if ( m_bAutoHideBars )
m_VerticalScrollBar->SetHidden( true );
if (m_bAutoHideBars)
m_VerticalScrollBar->SetHidden(true);
}
else
{
m_VerticalScrollBar->SetHidden( false );
m_VerticalScrollBar->SetDisabled( false );
m_VerticalScrollBar->SetHidden(false);
m_VerticalScrollBar->SetDisabled(false);
}
}
void ScrollControl::SetHScrollRequired(bool req)
{
if ( req )
if (req)
{
m_HorizontalScrollBar->SetScrolledAmount( 0, true );
m_HorizontalScrollBar->SetDisabled( true );
if ( m_bAutoHideBars )
m_HorizontalScrollBar->SetHidden( true );
m_HorizontalScrollBar->SetScrolledAmount(0, true);
m_HorizontalScrollBar->SetDisabled(true);
if (m_bAutoHideBars)
m_HorizontalScrollBar->SetHidden(true);
}
else
{
m_HorizontalScrollBar->SetHidden( false );
m_HorizontalScrollBar->SetDisabled( true );
m_HorizontalScrollBar->SetHidden(false);
m_HorizontalScrollBar->SetDisabled(true);
}
}
void ScrollControl::ScrollToBottom()
{
if ( CanScrollV() )
if (CanScrollV())
{
UpdateScrollBars();
m_VerticalScrollBar->ScrollToBottom();
@@ -219,7 +215,7 @@ void ScrollControl::ScrollToBottom()
}
void ScrollControl::ScrollToTop()
{
if ( CanScrollV() )
if (CanScrollV())
{
UpdateScrollBars();
m_VerticalScrollBar->ScrollToTop();
@@ -227,7 +223,7 @@ void ScrollControl::ScrollToTop()
}
void ScrollControl::ScrollToLeft()
{
if ( CanScrollH() )
if (CanScrollH())
{
UpdateScrollBars();
m_HorizontalScrollBar->ScrollToLeft();
@@ -235,8 +231,8 @@ void ScrollControl::ScrollToLeft()
}
void ScrollControl::ScrollToRight()
{
if ( CanScrollH() )
{
if (CanScrollH())
{
UpdateScrollBars();
m_HorizontalScrollBar->ScrollToRight();
}

View File

@@ -16,55 +16,52 @@
#include "Gwen/Controls/VerticalScrollBar.h"
#include "Gwen/Controls/HorizontalScrollBar.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT ScrollControl : public Base
{
public:
namespace Controls
{
class GWEN_EXPORT ScrollControl : public Base
{
public:
GWEN_CONTROL(ScrollControl, Base);
GWEN_CONTROL( ScrollControl, Base );
virtual void Layout(Skin::Base* skin);
virtual void Render(Skin::Base* skin);
virtual void Layout( Skin::Base* skin );
virtual void Render( Skin::Base* skin );
virtual void SetScroll(bool h, bool v);
virtual void SetAutoHideBars(bool should) { m_bAutoHideBars = should; }
virtual bool CanScrollH() { return m_bCanScrollH; }
virtual bool CanScrollV() { return m_bCanScrollV; }
virtual void OnChildBoundsChanged(Gwen::Rect oldChildBounds, Base* pChild);
virtual void UpdateScrollBars();
virtual void SetScroll( bool h, bool v );
virtual void SetAutoHideBars(bool should) { m_bAutoHideBars = should; }
virtual bool CanScrollH() { return m_bCanScrollH; }
virtual bool CanScrollV() { return m_bCanScrollV; }
virtual void OnChildBoundsChanged( Gwen::Rect oldChildBounds, Base* pChild );
virtual void UpdateScrollBars();
virtual void SetVScrollRequired(bool req);
virtual void SetHScrollRequired(bool req);
virtual void SetVScrollRequired(bool req);
virtual void SetHScrollRequired(bool req);
virtual void SetInnerSize(int w, int h);
virtual void SetInnerSize( int w, int h );
virtual void VBarMoved(Controls::Base* control);
virtual void HBarMoved(Controls::Base* control);
virtual void VBarMoved(Controls::Base * control);
virtual void HBarMoved(Controls::Base * control);
virtual bool OnMouseWheeled(int iDelta);
virtual bool OnMouseWheeled( int iDelta );
virtual void ScrollToBottom();
virtual void ScrollToTop();
virtual void ScrollToLeft();
virtual void ScrollToRight();
virtual void ScrollToBottom();
virtual void ScrollToTop();
virtual void ScrollToLeft();
virtual void ScrollToRight();
virtual void Clear();
virtual void Clear();
protected:
bool m_bCanScrollH;
bool m_bCanScrollV;
protected:
bool m_bAutoHideBars;
bool m_bCanScrollH;
bool m_bCanScrollV;
bool m_bAutoHideBars;
public:
Controls::BaseScrollBar* m_VerticalScrollBar;
Controls::BaseScrollBar* m_HorizontalScrollBar;
};
}
}
public:
Controls::BaseScrollBar* m_VerticalScrollBar;
Controls::BaseScrollBar* m_HorizontalScrollBar;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include <math.h>
#include "Gwen/Controls/Slider.h"
@@ -12,24 +11,23 @@ using namespace Gwen;
using namespace Gwen::Controls;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( SliderBar )
GWEN_CONTROL_CONSTRUCTOR(SliderBar)
{
SetTarget( this );
RestrictToParent( true );
SetTarget(this);
RestrictToParent(true);
}
void SliderBar::Render( Skin::Base* skin )
void SliderBar::Render(Skin::Base* skin)
{
skin->DrawButton( this, m_bDepressed, IsHovered() );
skin->DrawButton(this, m_bDepressed, IsHovered());
}
Slider::Slider( Controls::Base* pParent ) : BaseClass( pParent )
Slider::Slider(Controls::Base* pParent) : BaseClass(pParent)
{
SetBounds( Gwen::Rect( 0, 0, 32, 128) );
SetBounds(Gwen::Rect(0, 0, 32, 128));
m_SliderBar = new SliderBar( this );
m_SliderBar->onDragged.Add( this, &Slider::OnMoved );
m_SliderBar = new SliderBar(this);
m_SliderBar->onDragged.Add(this, &Slider::OnMoved);
m_fMin = 0.0f;
m_fMax = 1.0f;
@@ -38,18 +36,17 @@ Slider::Slider( Controls::Base* pParent ) : BaseClass( pParent )
m_iNumNotches = 5;
m_fValue = 0.0f;
SetTabable( true );
SetTabable(true);
}
void Slider::OnMoved( Controls::Base * /*control*/ )
void Slider::OnMoved(Controls::Base* /*control*/)
{
SetValueInternal( CalculateValue() );
SetValueInternal(CalculateValue());
}
void Slider::Layout( Skin::Base* skin )
void Slider::Layout(Skin::Base* skin)
{
BaseClass::Layout( skin );
BaseClass::Layout(skin);
}
float Slider::CalculateValue()
@@ -57,31 +54,31 @@ float Slider::CalculateValue()
return 0;
}
void Slider::SetValue( float val, bool /*forceUpdate*/ )
void Slider::SetValue(float val, bool /*forceUpdate*/)
{
if (val < m_fMin) val = m_fMin;
if (val > m_fMax) val = m_fMax;
// Normalize Value
val = (val - m_fMin) / (m_fMax - m_fMin);
SetValueInternal( val );
SetValueInternal(val);
Redraw();
}
void Slider::SetValueInternal( float val )
void Slider::SetValueInternal(float val)
{
if ( m_bClampToNotches )
if (m_bClampToNotches)
{
val = floor( (val * (float)m_iNumNotches) + 0.5f );
val /= (float) m_iNumNotches;
val = floor((val * (float)m_iNumNotches) + 0.5f);
val /= (float)m_iNumNotches;
}
if ( m_fValue != val )
if (m_fValue != val)
{
m_fValue = val;
onValueChanged.Call( this );
onValueChanged.Call(this);
}
UpdateBarFromValue();
UpdateBarFromValue();
}
float Slider::GetValue()
@@ -89,16 +86,16 @@ float Slider::GetValue()
return m_fMin + (m_fValue * (m_fMax - m_fMin));
}
void Slider::SetRange( float fMin, float fMax )
void Slider::SetRange(float fMin, float fMax)
{
m_fMin = fMin;
m_fMax = fMax;
}
void Slider::RenderFocus( Gwen::Skin::Base* skin )
void Slider::RenderFocus(Gwen::Skin::Base* skin)
{
if ( Gwen::KeyboardFocus != this ) return;
if ( !IsTabable() ) return;
if (Gwen::KeyboardFocus != this) return;
if (!IsTabable()) return;
skin->DrawKeyboardHighlight( this, GetRenderBounds(), 0 );
skin->DrawKeyboardHighlight(this, GetRenderBounds(), 0);
}

View File

@@ -14,75 +14,87 @@
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
{
class GWEN_EXPORT SliderBar : public ControlsInternal::Dragger
{
GWEN_CONTROL( SliderBar, ControlsInternal::Dragger );
namespace ControlsInternal
{
class GWEN_EXPORT SliderBar : public ControlsInternal::Dragger
{
GWEN_CONTROL(SliderBar, ControlsInternal::Dragger);
virtual void Render( Skin::Base* skin );
};
virtual void Render(Skin::Base* skin);
};
} // namespace ControlsInternal
namespace Controls
{
class GWEN_EXPORT Slider : public Base
{
GWEN_CONTROL(Slider, Base);
virtual void Render(Skin::Base* skin) = 0;
virtual void Layout(Skin::Base* skin);
virtual void SetClampToNotches(bool bClamp) { m_bClampToNotches = bClamp; }
virtual void SetNotchCount(int num) { m_iNumNotches = num; }
virtual int GetNotchCount() { return m_iNumNotches; }
virtual void SetRange(float fMin, float fMax);
virtual float GetRangeMin() const
{
return m_fMin;
}
virtual float GetRangeMax() const
{
return m_fMax;
}
virtual float GetValue();
virtual void SetValue(float val, bool forceUpdate = true);
virtual float CalculateValue();
virtual void OnMoved(Controls::Base* control);
virtual void OnMouseClickLeft(int /*x*/, int /*y*/, bool /*bDown*/){};
virtual bool OnKeyRight(bool bDown)
{
if (bDown) SetValue(GetValue() + 1, true);
return true;
}
virtual bool OnKeyLeft(bool bDown)
{
if (bDown) SetValue(GetValue() - 1, true);
return true;
}
virtual bool OnKeyUp(bool bDown)
{
if (bDown) SetValue(GetValue() + 1, true);
return true;
}
virtual bool OnKeyDown(bool bDown)
{
if (bDown) SetValue(GetValue() - 1, true);
return true;
}
namespace Controls
{
virtual void RenderFocus(Gwen::Skin::Base* skin);
class GWEN_EXPORT Slider : public Base
{
GWEN_CONTROL( Slider, Base );
Gwen::Event::Caller onValueChanged;
virtual void Render( Skin::Base* skin ) = 0;
virtual void Layout( Skin::Base* skin );
protected:
virtual void SetValueInternal(float fVal);
virtual void UpdateBarFromValue() = 0;
virtual void SetClampToNotches( bool bClamp ) { m_bClampToNotches = bClamp; }
ControlsInternal::SliderBar* m_SliderBar;
bool m_bClampToNotches;
int m_iNumNotches;
float m_fValue;
virtual void SetNotchCount( int num ) { m_iNumNotches = num; }
virtual int GetNotchCount() { return m_iNumNotches; }
float m_fMin;
float m_fMax;
};
} // namespace Controls
virtual void SetRange( float fMin, float fMax );
virtual float GetRangeMin() const
{
return m_fMin;
}
virtual float GetRangeMax() const
{
return m_fMax;
}
virtual float GetValue();
virtual void SetValue( float val, bool forceUpdate = true );
virtual float CalculateValue();
virtual void OnMoved( Controls::Base * control );
virtual void OnMouseClickLeft( int /*x*/, int /*y*/, bool /*bDown*/ ){};
virtual bool OnKeyRight( bool bDown ) { if ( bDown ) SetValue( GetValue() + 1, true ); return true; }
virtual bool OnKeyLeft( bool bDown ) { if ( bDown ) SetValue( GetValue() - 1, true ); return true; }
virtual bool OnKeyUp( bool bDown ) { if ( bDown ) SetValue( GetValue() + 1, true ); return true; }
virtual bool OnKeyDown( bool bDown ) { if ( bDown ) SetValue( GetValue() - 1, true ); return true; }
virtual void RenderFocus( Gwen::Skin::Base* skin);
Gwen::Event::Caller onValueChanged;
protected:
virtual void SetValueInternal( float fVal );
virtual void UpdateBarFromValue() = 0;
ControlsInternal::SliderBar * m_SliderBar;
bool m_bClampToNotches;
int m_iNumNotches;
float m_fValue;
float m_fMin;
float m_fMax;
};
}
}
} // namespace Gwen
#endif

View File

@@ -5,19 +5,19 @@
using namespace Gwen;
using namespace Controls;
GWEN_CONTROL_CONSTRUCTOR( SplitterBar )
GWEN_CONTROL_CONSTRUCTOR(SplitterBar)
{
SetTarget( this );
RestrictToParent( true );
SetTarget(this);
RestrictToParent(true);
}
void SplitterBar::Render( Skin::Base* skin )
void SplitterBar::Render(Skin::Base* skin)
{
if ( ShouldDrawBackground() )
skin->DrawButton( this, true, false );
if (ShouldDrawBackground())
skin->DrawButton(this, true, false);
}
void SplitterBar::Layout( Skin::Base* /*skin*/ )
void SplitterBar::Layout(Skin::Base* /*skin*/)
{
MoveTo( X(), Y() );
MoveTo(X(), Y());
}

View File

@@ -6,19 +6,18 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/Dragger.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class GWEN_EXPORT SplitterBar : public ControlsInternal::Dragger
{
public:
namespace Controls
{
class GWEN_EXPORT SplitterBar : public ControlsInternal::Dragger
{
public:
GWEN_CONTROL(SplitterBar, ControlsInternal::Dragger);
GWEN_CONTROL( SplitterBar, ControlsInternal::Dragger );
void Render( Skin::Base* skin );
void Layout( Skin::Base* skin );
};
}
}
void Render(Skin::Base* skin);
void Layout(Skin::Base* skin);
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -5,32 +5,31 @@
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Base.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class StatusBar : public Controls::Base
{
public:
GWEN_CONTROL_INLINE(StatusBar, Controls::Base)
{
class StatusBar : public Controls::Base
{
public:
GWEN_CONTROL_INLINE( StatusBar, Controls::Base )
{
SetBounds( 0, 0, 200, 22 );
Dock( Pos::Bottom );
SetPadding( Padding( 2, 2, 2, 2 ) );
}
virtual void AddControl( Controls::Base* pCtrl, bool bRight)
{
pCtrl->SetParent( this );
pCtrl->Dock( bRight ? Pos::Right : Pos::Left );
}
virtual void Render( Skin::Base* skin )
{
skin->DrawStatusBar( this );
}
};
SetBounds(0, 0, 200, 22);
Dock(Pos::Bottom);
SetPadding(Padding(2, 2, 2, 2));
}
}
virtual void AddControl(Controls::Base* pCtrl, bool bRight)
{
pCtrl->SetParent(this);
pCtrl->Dock(bRight ? Pos::Right : Pos::Left);
}
virtual void Render(Skin::Base* skin)
{
skin->DrawStatusBar(this);
}
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -12,42 +12,37 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
namespace Symbol
{
class GWEN_EXPORT Base : public Controls::Base
{
public:
GWEN_CONTROL_INLINE(Base, Controls::Base)
{
SetMouseInputEnabled(false);
}
};
namespace Symbol
{
class GWEN_EXPORT Base : public Controls::Base
{
public:
GWEN_CONTROL_INLINE( Base, Controls::Base )
{
SetMouseInputEnabled( false );
}
};
class GWEN_EXPORT Arrow : public Base
{
public:
Arrow( Gwen::Controls::Base* pnl ) : Base( pnl )
{
}
virtual void Render( Gwen::Skin::Base* pSkin )
{
Gwen::Rect r( Width() / 2 - 2, Height() / 2 - 2, 5, 5 );
pSkin->DrawArrowRight( r );
}
};
}
class GWEN_EXPORT Arrow : public Base
{
public:
Arrow(Gwen::Controls::Base* pnl) : Base(pnl)
{
}
}
virtual void Render(Gwen::Skin::Base* pSkin)
{
Gwen::Rect r(Width() / 2 - 2, Height() / 2 - 2, 5, 5);
pSkin->DrawArrowRight(r);
}
};
} // namespace Symbol
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/TabButton.h"
@@ -15,33 +14,30 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( TabButton )
GWEN_CONTROL_CONSTRUCTOR(TabButton)
{
m_Page = NULL;
m_Control = NULL;
SetPadding( Padding( 2, 2, 2, 2 ) );
SetPadding(Padding(2, 2, 2, 2));
DragAndDrop_SetPackage( true, "TabButtonMove" );
SetAlignment( Pos::Top | Pos::Left );
SetTextPadding( Padding( 5, 3, 3, 3 ) );
DragAndDrop_SetPackage(true, "TabButtonMove");
SetAlignment(Pos::Top | Pos::Left);
SetTextPadding(Padding(5, 3, 3, 3));
}
void TabButton::Render( Skin::Base* skin )
void TabButton::Render(Skin::Base* skin)
{
skin->DrawTabButton( this, m_Page && m_Page->Visible() );
skin->DrawTabButton(this, m_Page && m_Page->Visible());
}
void TabButton::SetTabControl( TabControl* ctrl )
void TabButton::SetTabControl(TabControl* ctrl)
{
if ( m_Control == ctrl ) return;
if (m_Control == ctrl) return;
if ( m_Control )
if (m_Control)
{
m_Control->OnLoseTab( this );
m_Control->OnLoseTab(this);
}
m_Control = ctrl;
@@ -52,47 +48,44 @@ bool TabButton::DragAndDrop_ShouldStartDrag()
return m_Control->DoesAllowDrag();
}
bool TabButton::OnKeyUp( bool bDown )
bool TabButton::OnKeyUp(bool bDown)
{
OnKeyLeft( bDown );
OnKeyLeft(bDown);
return true;
}
bool TabButton::OnKeyDown( bool bDown )
bool TabButton::OnKeyDown(bool bDown)
{
OnKeyRight( bDown );
OnKeyRight(bDown);
return true;
}
bool TabButton::OnKeyLeft( bool bDown )
bool TabButton::OnKeyLeft(bool bDown)
{
if ( bDown )
if (bDown)
{
Base::List::reverse_iterator it = std::find( m_Parent->Children.rbegin(), m_Parent->Children.rend(), this );
if ( it != m_Parent->Children.rend() && (++it != m_Parent->Children.rend()) )
Base::List::reverse_iterator it = std::find(m_Parent->Children.rbegin(), m_Parent->Children.rend(), this);
if (it != m_Parent->Children.rend() && (++it != m_Parent->Children.rend()))
{
Base* pNextTab = *it;
GetTabControl()->OnTabPressed( pNextTab );
GetTabControl()->OnTabPressed(pNextTab);
Gwen::KeyboardFocus = pNextTab;
}
}
return true;
}
bool TabButton::OnKeyRight( bool bDown )
bool TabButton::OnKeyRight(bool bDown)
{
if ( bDown )
if (bDown)
{
Base::List::iterator it = std::find( m_Parent->Children.begin(), m_Parent->Children.end(), this );
if ( it != m_Parent->Children.end() && (++it != m_Parent->Children.end()) )
Base::List::iterator it = std::find(m_Parent->Children.begin(), m_Parent->Children.end(), this);
if (it != m_Parent->Children.end() && (++it != m_Parent->Children.end()))
{
Base* pNextTab = *it;
GetTabControl()->OnTabPressed( pNextTab );
GetTabControl()->OnTabPressed(pNextTab);
Gwen::KeyboardFocus = pNextTab;
}
}
return true;
}

View File

@@ -11,44 +11,40 @@
#include "Gwen/Controls/Base.h"
#include "Gwen/Controls/Button.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
class TabControl;
namespace Controls
{
class TabControl;
class GWEN_EXPORT TabButton : public Button
{
public:
class GWEN_EXPORT TabButton : public Button
{
public:
GWEN_CONTROL(TabButton, Button);
virtual void Render(Skin::Base* skin);
GWEN_CONTROL( TabButton, Button );
virtual void Render( Skin::Base* skin );
void SetPage(Base* page) { m_Page = page; }
Base* GetPage() { return m_Page; }
void SetPage( Base* page ){ m_Page = page; }
Base* GetPage(){ return m_Page; }
void SetTabControl(TabControl* ctrl);
TabControl* GetTabControl() { return m_Control; }
void SetTabControl( TabControl* ctrl );
TabControl* GetTabControl(){ return m_Control; }
bool IsActive() { return m_Page && m_Page->Visible(); }
bool IsActive() { return m_Page && m_Page->Visible(); }
virtual bool DragAndDrop_ShouldStartDrag();
virtual void DragAndDrop_StartDragging(Gwen::DragAndDrop::Package* /*pPackage*/, int /*x*/, int /*y*/) { SetHidden(true); }
virtual void DragAndDrop_EndDragging(bool /*bSuccess*/, int /*x*/, int /*y*/) { SetHidden(false); }
virtual bool DragAndDrop_ShouldStartDrag();
virtual void DragAndDrop_StartDragging( Gwen::DragAndDrop::Package* /*pPackage*/, int /*x*/, int /*y*/ ){ SetHidden( true ); }
virtual void DragAndDrop_EndDragging( bool /*bSuccess*/, int /*x*/, int /*y*/ ){ SetHidden( false ); }
virtual bool OnKeyLeft(bool bDown);
virtual bool OnKeyRight(bool bDown);
virtual bool OnKeyUp(bool bDown);
virtual bool OnKeyDown(bool bDown);
virtual bool OnKeyLeft( bool bDown );
virtual bool OnKeyRight( bool bDown );
virtual bool OnKeyUp( bool bDown );
virtual bool OnKeyDown( bool bDown );
private:
Base* m_Page;
TabControl* m_Control;
};
private:
Base* m_Page;
TabControl* m_Control;
};
}
}
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/TabControl.h"
@@ -13,190 +12,183 @@
#include "Gwen/Controls/WindowControl.h"
#include "Gwen/Controls/ScrollBarButton.h"
namespace Gwen
{
namespace Controls
namespace Controls
{
class TabControlInner : public Base
{
public:
GWEN_CONTROL_INLINE(TabControlInner, Base)
{
class TabControlInner : public Base
{
public:
m_ButtonRect = Gwen::Rect(0, 0, 0, 0);
}
GWEN_CONTROL_INLINE( TabControlInner, Base )
{
m_ButtonRect = Gwen::Rect( 0, 0, 0, 0 );
}
void Render(Skin::Base* skin)
{
skin->DrawTabControl(this, m_ButtonRect);
}
void Render( Skin::Base* skin )
{
skin->DrawTabControl( this, m_ButtonRect );
}
void UpdateCurrentButton(Gwen::Rect rct)
{
m_ButtonRect = rct;
}
void UpdateCurrentButton( Gwen::Rect rct )
{
m_ButtonRect = rct;
}
Gwen::Rect m_ButtonRect;
};
};
Gwen::Rect m_ButtonRect;
};
}; // namespace Controls
}; // namespace Gwen
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( TabControl )
GWEN_CONTROL_CONSTRUCTOR(TabControl)
{
m_iScrollOffset = 0;
m_pCurrentButton = NULL;
m_TabStrip = new TabStrip( this );
m_TabStrip->Dock( Pos::Top );
m_TabStrip->SetWidth( 100 );
m_TabStrip->SetHeight( 20 );
m_TabStrip = new TabStrip(this);
m_TabStrip->Dock(Pos::Top);
m_TabStrip->SetWidth(100);
m_TabStrip->SetHeight(20);
// Make this some special control?
m_pScroll[0] = new ControlsInternal::ScrollBarButton( this );
m_pScroll[0] = new ControlsInternal::ScrollBarButton(this);
m_pScroll[0]->SetDirectionLeft();
m_pScroll[0]->onPress.Add( this, &TabControl::ScrollPressLeft );
m_pScroll[0]->SetSize( 14, 16 );
m_pScroll[0]->onPress.Add(this, &TabControl::ScrollPressLeft);
m_pScroll[0]->SetSize(14, 16);
m_pScroll[1] = new ControlsInternal::ScrollBarButton( this );
m_pScroll[1] = new ControlsInternal::ScrollBarButton(this);
m_pScroll[1]->SetDirectionRight();
m_pScroll[1]->onPress.Add( this, &TabControl::ScrollPressRight );
m_pScroll[1]->SetSize( 14, 16 );
m_pScroll[1]->onPress.Add(this, &TabControl::ScrollPressRight);
m_pScroll[1]->SetSize(14, 16);
m_InnerPanel = new TabControlInner( this );
m_InnerPanel->Dock( Pos::Fill );
m_InnerPanel = new TabControlInner(this);
m_InnerPanel->Dock(Pos::Fill);
SetTabable( false );
SetTabable(false);
}
TabButton* TabControl::AddPage( const UnicodeString& strText, Controls::Base* pPage )
TabButton* TabControl::AddPage(const UnicodeString& strText, Controls::Base* pPage)
{
if ( !pPage )
if (!pPage)
{
pPage = new Base( this );
pPage = new Base(this);
}
else
{
pPage->SetParent( this );
pPage->SetParent(this);
}
TabButton* pButton = new TabButton( m_TabStrip );
pButton->SetText( strText );
pButton->SetPage( pPage );
pButton->SetTabable( false );
TabButton* pButton = new TabButton(m_TabStrip);
pButton->SetText(strText);
pButton->SetPage(pPage);
pButton->SetTabable(false);
AddPage( pButton );
AddPage(pButton);
return pButton;
}
void TabControl::AddPage( TabButton* pButton )
void TabControl::AddPage(TabButton* pButton)
{
Base* pPage = pButton->GetPage();
pPage->SetParent( this );
pPage->SetHidden( true );
pPage->SetMargin( Margin( 6, 6, 6, 6 ) );
pPage->Dock( Pos::Fill );
pPage->SetParent(this);
pPage->SetHidden(true);
pPage->SetMargin(Margin(6, 6, 6, 6));
pPage->Dock(Pos::Fill);
pButton->SetParent( m_TabStrip );
pButton->Dock( Pos::Left );
pButton->SetParent(m_TabStrip);
pButton->Dock(Pos::Left);
pButton->SizeToContents();
if ( pButton->GetTabControl() ) pButton->onPress.RemoveHandler( pButton->GetTabControl() );
pButton->SetTabControl( this );
pButton->onPress.Add( this, &TabControl::OnTabPressed );
if (pButton->GetTabControl()) pButton->onPress.RemoveHandler(pButton->GetTabControl());
pButton->SetTabControl(this);
pButton->onPress.Add(this, &TabControl::OnTabPressed);
if ( !m_pCurrentButton )
if (!m_pCurrentButton)
{
pButton->OnPress();
}
onAddTab.Call( this );
onAddTab.Call(this);
Invalidate();
}
void TabControl::OnTabPressed( Controls::Base* control )
void TabControl::OnTabPressed(Controls::Base* control)
{
if (!control)
return;
TabButton* pButton = control->DynamicCastTabButton();
if ( !pButton ) return;
if (!pButton) return;
Base* pPage = pButton->GetPage();
if ( !pPage ) return;
if (!pPage) return;
if ( m_pCurrentButton == pButton)
if (m_pCurrentButton == pButton)
return;
if ( m_pCurrentButton )
if (m_pCurrentButton)
{
Base* pPage = m_pCurrentButton->GetPage();
if ( pPage )
if (pPage)
{
pPage->SetHidden( true );
pPage->SetHidden(true);
}
m_pCurrentButton = NULL;
}
m_pCurrentButton = pButton;
pPage->SetHidden( false );
pPage->SetHidden(false);
m_TabStrip->Invalidate();
Invalidate();
Invalidate();
}
void TabControl::PostLayout( Skin::Base* skin )
void TabControl::PostLayout(Skin::Base* skin)
{
BaseClass::PostLayout( skin );
BaseClass::PostLayout(skin);
HandleOverflow();
if ( m_TabStrip->Hidden() )
if (m_TabStrip->Hidden())
{
m_InnerPanel->DynamicCastTabControlInner()->UpdateCurrentButton( Gwen::Rect( 0, 0, 0, 0 ) );
m_InnerPanel->DynamicCastTabControlInner()->UpdateCurrentButton(Gwen::Rect(0, 0, 0, 0));
}
else if ( m_pCurrentButton )
else if (m_pCurrentButton)
{
Gwen::Rect rct;
Gwen::Point p = m_pCurrentButton->LocalPosToCanvas( Gwen::Point( 0, 0 ) );
p = m_InnerPanel->CanvasPosToLocal( p );
Gwen::Point p = m_pCurrentButton->LocalPosToCanvas(Gwen::Point(0, 0));
p = m_InnerPanel->CanvasPosToLocal(p);
rct = Gwen::Rect( p.x+1, p.y+1, m_pCurrentButton->Width()-2, m_pCurrentButton->Height()-2 );
m_InnerPanel->DynamicCastTabControlInner()->UpdateCurrentButton( rct );
rct = Gwen::Rect(p.x + 1, p.y + 1, m_pCurrentButton->Width() - 2, m_pCurrentButton->Height() - 2);
m_InnerPanel->DynamicCastTabControlInner()->UpdateCurrentButton(rct);
}
}
void TabControl::OnLoseTab( TabButton* pButton )
void TabControl::OnLoseTab(TabButton* pButton)
{
if ( m_pCurrentButton == pButton )
if (m_pCurrentButton == pButton)
m_pCurrentButton = NULL;
//TODO: Select a tab if any exist.
onLoseTab.Call( this );
onLoseTab.Call(this);
Invalidate();
Invalidate();
}
int TabControl::TabCount( void )
int TabControl::TabCount(void)
{
return m_TabStrip->NumChildren();
}
void TabControl::SetTabStripPosition( int iDock )
void TabControl::SetTabStripPosition(int iDock)
{
m_TabStrip->SetTabPosition( iDock );
m_TabStrip->SetTabPosition(iDock);
}
bool TabControl::DoesAllowDrag()
@@ -210,18 +202,18 @@ void TabControl::HandleOverflow()
// Only enable the scrollers if the tabs are at the top.
// This is a limitation we should explore.
// Really TabControl should have derivitives for tabs placed elsewhere where we could specialize
// Really TabControl should have derivitives for tabs placed elsewhere where we could specialize
// some functions like this for each direction.
bool bNeeded = TabsSize.x > Width() && m_TabStrip->GetDock() == Pos::Top;
m_pScroll[0]->SetHidden( !bNeeded );
m_pScroll[1]->SetHidden( !bNeeded );
m_pScroll[0]->SetHidden(!bNeeded);
m_pScroll[1]->SetHidden(!bNeeded);
if ( !bNeeded ) return;
if (!bNeeded) return;
m_iScrollOffset = Gwen::Clamp( m_iScrollOffset, 0, TabsSize.x - Width() + 32 );
m_iScrollOffset = Gwen::Clamp(m_iScrollOffset, 0, TabsSize.x - Width() + 32);
#if 0
#if 0
//
// This isn't frame rate independent.
// Could be better. Get rid of m_iScrollOffset and just use m_TabStrip->GetMargin().left ?
@@ -230,20 +222,20 @@ void TabControl::HandleOverflow()
//
m_TabStrip->SetMargin( Margin( Gwen::Approach( m_TabStrip->GetMargin().left, m_iScrollOffset * -1, 2 ), 0, 0, 0 ) );
InvalidateParent();
#else
m_TabStrip->SetMargin( Margin( m_iScrollOffset * -1, 0, 0, 0 ) );
#endif
#else
m_TabStrip->SetMargin(Margin(m_iScrollOffset * -1, 0, 0, 0));
#endif
m_pScroll[0]->SetPos( Width() - 30 , 5 );
m_pScroll[1]->SetPos( m_pScroll[0]->Right(), 5 );
m_pScroll[0]->SetPos(Width() - 30, 5);
m_pScroll[1]->SetPos(m_pScroll[0]->Right(), 5);
}
void TabControl::ScrollPressLeft( Base* pFrom )
void TabControl::ScrollPressLeft(Base* pFrom)
{
m_iScrollOffset -= 120;
}
void TabControl::ScrollPressRight( Base* pFrom )
void TabControl::ScrollPressRight(Base* pFrom)
{
m_iScrollOffset += 120;
}

View File

@@ -14,54 +14,51 @@
#include "Gwen/Controls/TabStrip.h"
#include "Gwen/Controls/TabTitleBar.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
{
class ScrollBarButton;
}
namespace Controls
{
class GWEN_EXPORT TabControl : public Base
{
GWEN_CONTROL( TabControl, Base );
virtual TabButton* AddPage( const UnicodeString& strText, Controls::Base* pPage = NULL );
virtual void AddPage( TabButton* pButton );
virtual void OnTabPressed( Controls::Base* control );
virtual void OnLoseTab( TabButton* pButton );
virtual int TabCount( void );
virtual TabButton* GetCurrentButton(){ return m_pCurrentButton; }
virtual TabStrip* GetTabStrip(){ return m_TabStrip; }
virtual void SetTabStripPosition( int iDock );
virtual bool DoesAllowDrag();
virtual void SetAllowReorder( bool b ){ GetTabStrip()->SetAllowReorder( b ); }
Gwen::Event::Caller onLoseTab;
Gwen::Event::Caller onAddTab;
private:
virtual void PostLayout( Skin::Base* skin );
void HandleOverflow();
void ScrollPressLeft( Base* pFrom );
void ScrollPressRight( Base* pFrom );
TabStrip* m_TabStrip;
TabButton* m_pCurrentButton;
ControlsInternal::ScrollBarButton* m_pScroll[2];
int m_iScrollOffset;
};
}
namespace ControlsInternal
{
class ScrollBarButton;
}
namespace Controls
{
class GWEN_EXPORT TabControl : public Base
{
GWEN_CONTROL(TabControl, Base);
virtual TabButton* AddPage(const UnicodeString& strText, Controls::Base* pPage = NULL);
virtual void AddPage(TabButton* pButton);
virtual void OnTabPressed(Controls::Base* control);
virtual void OnLoseTab(TabButton* pButton);
virtual int TabCount(void);
virtual TabButton* GetCurrentButton() { return m_pCurrentButton; }
virtual TabStrip* GetTabStrip() { return m_TabStrip; }
virtual void SetTabStripPosition(int iDock);
virtual bool DoesAllowDrag();
virtual void SetAllowReorder(bool b) { GetTabStrip()->SetAllowReorder(b); }
Gwen::Event::Caller onLoseTab;
Gwen::Event::Caller onAddTab;
private:
virtual void PostLayout(Skin::Base* skin);
void HandleOverflow();
void ScrollPressLeft(Base* pFrom);
void ScrollPressRight(Base* pFrom);
TabStrip* m_TabStrip;
TabButton* m_pCurrentButton;
ControlsInternal::ScrollBarButton* m_pScroll[2];
int m_iScrollOffset;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Skin.h"
#include "Gwen/Controls/TabStrip.h"
@@ -16,35 +15,34 @@
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( TabStrip )
GWEN_CONTROL_CONSTRUCTOR(TabStrip)
{
m_TabDragControl = NULL;
m_bAllowReorder = false;
}
bool TabStrip::DragAndDrop_HandleDrop( Gwen::DragAndDrop::Package* /*pPackage*/, int x, int y )
bool TabStrip::DragAndDrop_HandleDrop(Gwen::DragAndDrop::Package* /*pPackage*/, int x, int y)
{
Gwen::Point LocalPos = CanvasPosToLocal( Gwen::Point( x, y ) );
Gwen::Point LocalPos = CanvasPosToLocal(Gwen::Point(x, y));
Base* el = DragAndDrop::SourceControl;
TabButton* pButton = el? el->DynamicCastTabButton() : 0;
TabControl* pTabControl = GetParent()? GetParent()->DynamicCastTabControl() : 0;
if ( pTabControl && pButton )
TabButton* pButton = el ? el->DynamicCastTabButton() : 0;
TabControl* pTabControl = GetParent() ? GetParent()->DynamicCastTabControl() : 0;
if (pTabControl && pButton)
{
if ( pButton->GetTabControl() != pTabControl )
if (pButton->GetTabControl() != pTabControl)
{
// We've moved tab controls!
pTabControl->AddPage( pButton );
pTabControl->AddPage(pButton);
}
}
Base* DroppedOn = GetControlAt( LocalPos.x, LocalPos.y );
if ( DroppedOn )
Base* DroppedOn = GetControlAt(LocalPos.x, LocalPos.y);
if (DroppedOn)
{
Gwen::Point DropPos = DroppedOn->CanvasPosToLocal( Gwen::Point( x, y ) );
DragAndDrop::SourceControl->BringNextToControl( DroppedOn, DropPos.x > DroppedOn->Width() / 2 );
Gwen::Point DropPos = DroppedOn->CanvasPosToLocal(Gwen::Point(x, y));
DragAndDrop::SourceControl->BringNextToControl(DroppedOn, DropPos.x > DroppedOn->Width() / 2);
}
else
{
@@ -53,29 +51,29 @@ bool TabStrip::DragAndDrop_HandleDrop( Gwen::DragAndDrop::Package* /*pPackage*/,
return true;
}
bool TabStrip::DragAndDrop_CanAcceptPackage( Gwen::DragAndDrop::Package* pPackage )
bool TabStrip::DragAndDrop_CanAcceptPackage(Gwen::DragAndDrop::Package* pPackage)
{
if ( !m_bAllowReorder )
if (!m_bAllowReorder)
return false;
if ( pPackage->name == "TabButtonMove" )
if (pPackage->name == "TabButtonMove")
return true;
return false;
}
void TabStrip::Layout( Skin::Base* skin )
void TabStrip::Layout(Skin::Base* skin)
{
Gwen::Point pLargestTab( 5, 5 );
Gwen::Point pLargestTab(5, 5);
int iNum = 0;
for ( Base::List::iterator iter = Children.begin(); iter != Children.end(); ++iter )
for (Base::List::iterator iter = Children.begin(); iter != Children.end(); ++iter)
{
if (!*iter)
continue;
TabButton* pButton = (*iter)->DynamicCastTabButton();
if ( !pButton ) continue;
if (!pButton) continue;
pButton->SizeToContents();
@@ -84,98 +82,98 @@ void TabStrip::Layout( Skin::Base* skin )
int iNotFirst = iNum > 0 ? -1 : 0;
int iControlOverhang = -3;
if ( m_iDock == Pos::Top )
if (m_iDock == Pos::Top)
{
m.top = iActive;
m.left = iNotFirst;
m.bottom = iControlOverhang;
pButton->Dock( Pos::Left );
pButton->Dock(Pos::Left);
}
if ( m_iDock == Pos::Left )
if (m_iDock == Pos::Left)
{
m.left = iActive * 2;
m.right = iControlOverhang;
m.top = iNotFirst;
pButton->Dock( Pos::Top );
pButton->Dock(Pos::Top);
}
if ( m_iDock == Pos::Right )
if (m_iDock == Pos::Right)
{
m.right = iActive * 2;
m.left = iControlOverhang;
m.top = iNotFirst;
pButton->Dock( Pos::Top );
pButton->Dock(Pos::Top);
}
if ( m_iDock == Pos::Bottom )
if (m_iDock == Pos::Bottom)
{
m.bottom = iActive;
m.left = iNotFirst;
m.top = iControlOverhang;
pButton->Dock( Pos::Left );
pButton->Dock(Pos::Left);
}
pLargestTab.x = Utility::Max( pLargestTab.x, pButton->Width() );
pLargestTab.y = Utility::Max( pLargestTab.y, pButton->Height() );
pLargestTab.x = Utility::Max(pLargestTab.x, pButton->Width());
pLargestTab.y = Utility::Max(pLargestTab.y, pButton->Height());
pButton->SetMargin( m );
pButton->SetMargin(m);
iNum++;
}
if ( m_iDock == Pos::Top || m_iDock == Pos::Bottom )
SetSize( Width(), pLargestTab.y );
if (m_iDock == Pos::Top || m_iDock == Pos::Bottom)
SetSize(Width(), pLargestTab.y);
if ( m_iDock == Pos::Left || m_iDock == Pos::Right )
SetSize( pLargestTab.x, Height() );
if (m_iDock == Pos::Left || m_iDock == Pos::Right)
SetSize(pLargestTab.x, Height());
BaseClass::Layout( skin );
BaseClass::Layout(skin);
}
void TabStrip::DragAndDrop_HoverEnter( Gwen::DragAndDrop::Package* /*pPackage*/, int /*x*/, int /*y*/ )
void TabStrip::DragAndDrop_HoverEnter(Gwen::DragAndDrop::Package* /*pPackage*/, int /*x*/, int /*y*/)
{
if ( m_TabDragControl )
if (m_TabDragControl)
{
Debug::Msg( "ERROR! TabStrip::DragAndDrop_HoverEnter\n" );
Debug::Msg("ERROR! TabStrip::DragAndDrop_HoverEnter\n");
}
m_TabDragControl = new ControlsInternal::Highlight( this );
m_TabDragControl->SetMouseInputEnabled( false );
m_TabDragControl->SetSize( 3, Height() );
m_TabDragControl = new ControlsInternal::Highlight(this);
m_TabDragControl->SetMouseInputEnabled(false);
m_TabDragControl->SetSize(3, Height());
}
void TabStrip::DragAndDrop_HoverLeave( Gwen::DragAndDrop::Package* /*pPackage*/ )
void TabStrip::DragAndDrop_HoverLeave(Gwen::DragAndDrop::Package* /*pPackage*/)
{
delete m_TabDragControl;
m_TabDragControl = NULL;
}
void TabStrip::DragAndDrop_Hover( Gwen::DragAndDrop::Package* /*pPackage*/, int x, int y )
void TabStrip::DragAndDrop_Hover(Gwen::DragAndDrop::Package* /*pPackage*/, int x, int y)
{
Gwen::Point LocalPos = CanvasPosToLocal( Gwen::Point( x, y ) );
Gwen::Point LocalPos = CanvasPosToLocal(Gwen::Point(x, y));
Base* DroppedOn = GetControlAt( LocalPos.x, LocalPos.y );
if ( DroppedOn && DroppedOn != this )
Base* DroppedOn = GetControlAt(LocalPos.x, LocalPos.y);
if (DroppedOn && DroppedOn != this)
{
Gwen::Point DropPos = DroppedOn->CanvasPosToLocal( Gwen::Point( x, y ) );
m_TabDragControl->SetBounds( Gwen::Rect( 0, 0, 3, Height() ) );
Gwen::Point DropPos = DroppedOn->CanvasPosToLocal(Gwen::Point(x, y));
m_TabDragControl->SetBounds(Gwen::Rect(0, 0, 3, Height()));
m_TabDragControl->BringToFront();
m_TabDragControl->SetPos( DroppedOn->X() - 1, 0 );
m_TabDragControl->SetPos(DroppedOn->X() - 1, 0);
if ( DropPos.x > DroppedOn->Width() / 2 )
if (DropPos.x > DroppedOn->Width() / 2)
{
m_TabDragControl->MoveBy( DroppedOn->Width()-1, 0 );
m_TabDragControl->MoveBy(DroppedOn->Width() - 1, 0);
}
m_TabDragControl->Dock( Pos::None );
m_TabDragControl->Dock(Pos::None);
}
else
{
m_TabDragControl->Dock( Pos::Left );
m_TabDragControl->Dock(Pos::Left);
m_TabDragControl->BringToFront();
}
}
void TabStrip::SetTabPosition( int iPos )
void TabStrip::SetTabPosition(int iPos)
{
Dock( iPos );
Dock(iPos);
}

View File

@@ -12,38 +12,35 @@
#include "Gwen/Controls/Button.h"
#include "Gwen/Controls/TabButton.h"
namespace Gwen
namespace Gwen
{
namespace Controls
{
//class TabControl;
namespace Controls
{
//class TabControl;
class GWEN_EXPORT TabStrip : public Base
{
public:
class GWEN_EXPORT TabStrip : public Base
{
public:
GWEN_CONTROL(TabStrip, Base);
GWEN_CONTROL( TabStrip, Base );
virtual void Layout(Skin::Base* skin);
virtual void Layout( Skin::Base* skin );
virtual bool DragAndDrop_HandleDrop(Gwen::DragAndDrop::Package* pPackage, int x, int y);
virtual bool DragAndDrop_CanAcceptPackage(Gwen::DragAndDrop::Package* pPackage);
virtual bool DragAndDrop_HandleDrop( Gwen::DragAndDrop::Package* pPackage, int x, int y );
virtual bool DragAndDrop_CanAcceptPackage( Gwen::DragAndDrop::Package* pPackage );
virtual void DragAndDrop_HoverEnter(Gwen::DragAndDrop::Package* pPackage, int x, int y);
virtual void DragAndDrop_HoverLeave(Gwen::DragAndDrop::Package* pPackage);
virtual void DragAndDrop_Hover(Gwen::DragAndDrop::Package* pPackage, int x, int y);
virtual void DragAndDrop_HoverEnter( Gwen::DragAndDrop::Package* pPackage, int x, int y );
virtual void DragAndDrop_HoverLeave( Gwen::DragAndDrop::Package* pPackage );
virtual void DragAndDrop_Hover( Gwen::DragAndDrop::Package* pPackage, int x, int y );
virtual void SetTabPosition(int iPos);
virtual void SetTabPosition( int iPos );
virtual void SetAllowReorder(bool b) { m_bAllowReorder = b; }
virtual bool AllowsTabReorder() { return m_bAllowReorder; }
virtual void SetAllowReorder( bool b ){ m_bAllowReorder = b; }
virtual bool AllowsTabReorder() { return m_bAllowReorder; }
private:
Base* m_TabDragControl;
bool m_bAllowReorder;
};
}
}
private:
Base* m_TabDragControl;
bool m_bAllowReorder;
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -14,43 +14,41 @@
#include "Gwen/DragAndDrop.h"
#include "Gwen/Skin.h"
namespace Gwen
namespace Gwen
{
namespace Controls
namespace Controls
{
class GWEN_EXPORT TabTitleBar : public Label
{
public:
GWEN_CONTROL_INLINE(TabTitleBar, Label)
{
class GWEN_EXPORT TabTitleBar : public Label
{
public:
SetMouseInputEnabled(true);
SetTextPadding(Gwen::Padding(5, 2, 5, 2));
SetPadding(Gwen::Padding(1, 2, 1, 2));
GWEN_CONTROL_INLINE( TabTitleBar, Label )
{
SetMouseInputEnabled( true );
SetTextPadding( Gwen::Padding( 5, 2, 5, 2 ) );
SetPadding( Gwen::Padding( 1, 2, 1, 2 ) );
DragAndDrop_SetPackage( true, "TabWindowMove" );
}
void Render( Skin::Base* skin )
{
skin->DrawTabTitleBar( this );
}
void DragAndDrop_StartDragging( Gwen::DragAndDrop::Package* pPackage, int x, int y )
{
DragAndDrop::SourceControl = GetParent();
DragAndDrop::SourceControl->DragAndDrop_StartDragging( pPackage, x, y );
}
void UpdateFromTab( TabButton* pButton )
{
SetText( pButton->GetText() );
SizeToContents();
}
private:
};
DragAndDrop_SetPackage(true, "TabWindowMove");
}
}
void Render(Skin::Base* skin)
{
skin->DrawTabTitleBar(this);
}
void DragAndDrop_StartDragging(Gwen::DragAndDrop::Package* pPackage, int x, int y)
{
DragAndDrop::SourceControl = GetParent();
DragAndDrop::SourceControl->DragAndDrop_StartDragging(pPackage, x, y);
}
void UpdateFromTab(TabButton* pButton)
{
SetText(pButton->GetText());
SizeToContents();
}
private:
};
} // namespace Controls
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Text.h"
#include "Gwen/Skin.h"
@@ -13,11 +12,11 @@
using namespace Gwen;
using namespace Gwen::ControlsInternal;
GWEN_CONTROL_CONSTRUCTOR( Text )
GWEN_CONTROL_CONSTRUCTOR(Text)
{
m_Font = NULL;
m_Color = Gwen::Colors::Black; // TODO: From skin somehow..
SetMouseInputEnabled( false );
m_Color = Gwen::Colors::Black; // TODO: From skin somehow..
SetMouseInputEnabled(false);
}
Text::~Text()
@@ -28,78 +27,79 @@ Text::~Text()
void Text::RefreshSize()
{
if ( !GetFont() )
if (!GetFont())
{
Debug::AssertCheck( 0, "Text::RefreshSize() - No Font!!\n" );
Debug::AssertCheck(0, "Text::RefreshSize() - No Font!!\n");
return;
}
Gwen::Point p( 1, GetFont()->size );
if ( Length() > 0 )
Gwen::Point p(1, GetFont()->size);
if (Length() > 0)
{
p = GetSkin()->GetRender()->MeasureText( GetFont(), m_String );
p = GetSkin()->GetRender()->MeasureText(GetFont(), m_String);
}
if ( p.x == Width() && p.y == Height() )
if (p.x == Width() && p.y == Height())
return;
SetSize( p.x, p.y );
SetSize(p.x, p.y);
InvalidateParent();
Invalidate();
}
Gwen::Font* Text::GetFont()
{
return m_Font;
}
void Text::SetString( const UnicodeString& str ){ m_String = str; Invalidate(); }
void Text::SetString( const String& str ){ SetString( Gwen::Utility::StringToUnicode( str ) ); }
void Text::Render( Skin::Base* skin )
void Text::SetString(const UnicodeString& str)
{
if ( Length() == 0 || !GetFont() ) return;
m_String = str;
Invalidate();
}
void Text::SetString(const String& str) { SetString(Gwen::Utility::StringToUnicode(str)); }
skin->GetRender()->SetDrawColor( m_Color );
skin->GetRender()->RenderText( GetFont(), Gwen::Point( 0, 0 ), m_String );
void Text::Render(Skin::Base* skin)
{
if (Length() == 0 || !GetFont()) return;
skin->GetRender()->SetDrawColor(m_Color);
skin->GetRender()->RenderText(GetFont(), Gwen::Point(0, 0), m_String);
}
void Text::Layout( Skin::Base* /*skin*/ )
void Text::Layout(Skin::Base* /*skin*/)
{
RefreshSize();
}
Gwen::Point Text::GetCharacterPosition( int iChar )
Gwen::Point Text::GetCharacterPosition(int iChar)
{
if ( Length() == 0 || iChar == 0 )
if (Length() == 0 || iChar == 0)
{
return Gwen::Point( 1, 0 );
return Gwen::Point(1, 0);
}
UnicodeString sub = m_String.substr( 0, iChar );
Gwen::Point p = GetSkin()->GetRender()->MeasureText( GetFont(), sub );
if ( p.y >= m_Font->size )
UnicodeString sub = m_String.substr(0, iChar);
Gwen::Point p = GetSkin()->GetRender()->MeasureText(GetFont(), sub);
if (p.y >= m_Font->size)
p.y -= m_Font->size;
return p;
}
int Text::GetClosestCharacter( Gwen::Point p )
int Text::GetClosestCharacter(Gwen::Point p)
{
int iDistance = 4096;
int iChar = 0;
for ( size_t i=0; i<m_String.length()+1; i++ )
for (size_t i = 0; i < m_String.length() + 1; i++)
{
Gwen::Point cp = GetCharacterPosition( i );
int iDist = abs(cp.x - p.x) + abs(cp.y - p.y); // this isn't proper
Gwen::Point cp = GetCharacterPosition(i);
int iDist = abs(cp.x - p.x) + abs(cp.y - p.y); // this isn't proper
if ( iDist > iDistance ) continue;
if (iDist > iDistance) continue;
iDistance = iDist;
iChar = i;

View File

@@ -11,49 +11,47 @@
#include "Gwen/BaseRender.h"
#include "Gwen/Controls/Base.h"
namespace Gwen
namespace Gwen
{
namespace ControlsInternal
{
class GWEN_EXPORT Text : public Controls::Base
{
public:
namespace ControlsInternal
{
class GWEN_EXPORT Text : public Controls::Base
{
public:
GWEN_CONTROL(Text, Controls::Base);
GWEN_CONTROL( Text, Controls::Base );
virtual ~Text();
Gwen::Font* GetFont();
virtual ~Text();
Gwen::Font* GetFont();
void SetString(const UnicodeString& str);
void SetString(const String& str);
void SetString( const UnicodeString& str );
void SetString( const String& str );
void Render(Skin::Base* skin);
void Layout(Skin::Base* skin);
void Render( Skin::Base* skin );
void Layout( Skin::Base* skin );
void RefreshSize();
void RefreshSize();
void SetFont(Gwen::Font* pFont) { m_Font = pFont; }
void SetFont( Gwen::Font* pFont ){ m_Font = pFont; }
const UnicodeString& GetText() const { return m_String; }
const UnicodeString& GetText() const { return m_String; }
Gwen::Point GetCharacterPosition(int iChar);
int GetClosestCharacter(Gwen::Point p);
Gwen::Point GetCharacterPosition( int iChar );
int GetClosestCharacter( Gwen::Point p );
int Length() const { return (int)m_String.size(); }
int Length() const { return (int)m_String.size(); }
virtual void SetTextColor(const Gwen::Color& col) { m_Color = col; }
virtual void SetTextColor( const Gwen::Color& col ){ m_Color = col; }
virtual void OnScaleChanged();
virtual void OnScaleChanged();
inline const Gwen::Color& TextColor() const { return m_Color; }
inline const Gwen::Color &TextColor() const { return m_Color; }
private:
Gwen::UnicodeString m_String;
Gwen::Font* m_Font;
Gwen::Color m_Color;
};
} // namespace ControlsInternal
private:
Gwen::UnicodeString m_String;
Gwen::Font* m_Font;
Gwen::Color m_Color;
};
}
}
} // namespace Gwen
#endif

View File

@@ -4,7 +4,6 @@
See license in Gwen.h
*/
#include "Gwen/Gwen.h"
#include "Gwen/Controls/TextBox.h"
#include "Gwen/Skin.h"
@@ -13,91 +12,89 @@
#include <math.h>
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( TextBox )
GWEN_CONTROL_CONSTRUCTOR(TextBox)
{
SetSize( 200, 20 );
SetSize(200, 20);
SetMouseInputEnabled( true );
SetKeyboardInputEnabled( true );
SetMouseInputEnabled(true);
SetKeyboardInputEnabled(true);
SetAlignment( Pos::Left | Pos::CenterV );
SetTextPadding( Padding( 4, 2, 4, 2 ) );
SetAlignment(Pos::Left | Pos::CenterV);
SetTextPadding(Padding(4, 2, 4, 2));
m_iCursorPos = 0;
m_iCursorEnd = 0;
m_bSelectAll = false;
SetTextColor( Gwen::Color( 50, 50, 50, 255 ) ); // TODO: From Skin
SetTextColor(Gwen::Color(50, 50, 50, 255)); // TODO: From Skin
SetTabable( true );
SetTabable(true);
AddAccelerator( L"Ctrl + c", &TextBox::OnCopy );
AddAccelerator( L"Ctrl + x", &TextBox::OnCut );
AddAccelerator( L"Ctrl + v", &TextBox::OnPaste );
AddAccelerator( L"Ctrl + a", &TextBox::OnSelectAll );
AddAccelerator(L"Ctrl + c", &TextBox::OnCopy);
AddAccelerator(L"Ctrl + x", &TextBox::OnCut);
AddAccelerator(L"Ctrl + v", &TextBox::OnPaste);
AddAccelerator(L"Ctrl + a", &TextBox::OnSelectAll);
}
bool TextBox::OnChar( Gwen::UnicodeChar c )
bool TextBox::OnChar(Gwen::UnicodeChar c)
{
if ( c == '\t' ) return false;
if (c == '\t') return false;
Gwen::UnicodeString str;
str += c;
InsertText( str );
InsertText(str);
return true;
}
void TextBox::InsertText( const Gwen::UnicodeString& strInsert )
void TextBox::InsertText(const Gwen::UnicodeString& strInsert)
{
// TODO: Make sure fits (implement maxlength)
if ( HasSelection() )
if (HasSelection())
{
EraseSelection();
}
if ( m_iCursorPos > TextLength() ) m_iCursorPos = TextLength();
if (m_iCursorPos > TextLength()) m_iCursorPos = TextLength();
if ( !IsTextAllowed( strInsert, m_iCursorPos ) )
if (!IsTextAllowed(strInsert, m_iCursorPos))
return;
UnicodeString str = GetText();
str.insert( m_iCursorPos, strInsert );
SetText( str );
str.insert(m_iCursorPos, strInsert);
SetText(str);
m_iCursorPos += (int) strInsert.size();
m_iCursorPos += (int)strInsert.size();
m_iCursorEnd = m_iCursorPos;
RefreshCursorBounds();
}
void TextBox::Render( Skin::Base* skin )
void TextBox::Render(Skin::Base* skin)
{
if ( ShouldDrawBackground() )
skin->DrawTextBox( this );
if (ShouldDrawBackground())
skin->DrawTextBox(this);
if ( !HasFocus() ) return;
if (!HasFocus()) return;
// Draw selection.. if selected..
if ( m_iCursorPos != m_iCursorEnd )
if (m_iCursorPos != m_iCursorEnd)
{
skin->GetRender()->SetDrawColor( Gwen::Color( 50, 170, 255, 200 ) );
skin->GetRender()->DrawFilledRect( m_rectSelectionBounds );
skin->GetRender()->SetDrawColor(Gwen::Color(50, 170, 255, 200));
skin->GetRender()->DrawFilledRect(m_rectSelectionBounds);
}
// Draw caret
if ( fmod( Gwen::Platform::GetTimeInSeconds()-m_fLastInputTime, 1.0f ) > 0.5f )
skin->GetRender()->SetDrawColor( Gwen::Color( 255, 255, 255, 255 ) );
if (fmod(Gwen::Platform::GetTimeInSeconds() - m_fLastInputTime, 1.0f) > 0.5f)
skin->GetRender()->SetDrawColor(Gwen::Color(255, 255, 255, 255));
else
skin->GetRender()->SetDrawColor( Gwen::Color( 0, 0, 0, 255 ) );
skin->GetRender()->SetDrawColor(Gwen::Color(0, 0, 0, 255));
skin->GetRender()->DrawFilledRect( m_rectCaretBounds );
skin->GetRender()->DrawFilledRect(m_rectCaretBounds);
}
void TextBox::RefreshCursorBounds()
@@ -106,44 +103,43 @@ void TextBox::RefreshCursorBounds()
MakeCaratVisible();
Gwen::Point pA = GetCharacterPosition( m_iCursorPos );
Gwen::Point pB = GetCharacterPosition( m_iCursorEnd );
Gwen::Point pA = GetCharacterPosition(m_iCursorPos);
Gwen::Point pB = GetCharacterPosition(m_iCursorEnd);
m_rectSelectionBounds.x = Utility::Min( pA.x, pB.x );
m_rectSelectionBounds.x = Utility::Min(pA.x, pB.x);
m_rectSelectionBounds.y = m_Text->Y() - 1;
m_rectSelectionBounds.w = Utility::Max( pA.x, pB.x ) - m_rectSelectionBounds.x;
m_rectSelectionBounds.w = Utility::Max(pA.x, pB.x) - m_rectSelectionBounds.x;
m_rectSelectionBounds.h = m_Text->Height() + 2;
m_rectCaretBounds.x = pA.x;
m_rectCaretBounds.y = m_Text->Y() - 1;
m_rectCaretBounds.w = 1;
m_rectCaretBounds.h = m_Text->Height() + 2;
Redraw();
}
void TextBox::OnPaste( Gwen::Controls::Base* /*pCtrl*/ )
void TextBox::OnPaste(Gwen::Controls::Base* /*pCtrl*/)
{
InsertText( Platform::GetClipboardText() );
InsertText(Platform::GetClipboardText());
}
void TextBox::OnCopy( Gwen::Controls::Base* /*pCtrl*/ )
void TextBox::OnCopy(Gwen::Controls::Base* /*pCtrl*/)
{
if ( !HasSelection() ) return;
if (!HasSelection()) return;
Platform::SetClipboardText( GetSelection() );
Platform::SetClipboardText(GetSelection());
}
void TextBox::OnCut( Gwen::Controls::Base* /*pCtrl*/ )
void TextBox::OnCut(Gwen::Controls::Base* /*pCtrl*/)
{
if ( !HasSelection() ) return;
if (!HasSelection()) return;
Platform::SetClipboardText( GetSelection() );
Platform::SetClipboardText(GetSelection());
EraseSelection();
}
void TextBox::OnSelectAll( Gwen::Controls::Base* /*pCtrl*/ )
void TextBox::OnSelectAll(Gwen::Controls::Base* /*pCtrl*/)
{
m_iCursorEnd = 0;
m_iCursorPos = TextLength();
@@ -151,33 +147,33 @@ void TextBox::OnSelectAll( Gwen::Controls::Base* /*pCtrl*/ )
RefreshCursorBounds();
}
void TextBox::OnMouseDoubleClickLeft( int /*x*/, int /*y*/ )
{
OnSelectAll( this );
void TextBox::OnMouseDoubleClickLeft(int /*x*/, int /*y*/)
{
OnSelectAll(this);
}
UnicodeString TextBox::GetSelection()
{
if ( !HasSelection() ) return L"";
if (!HasSelection()) return L"";
int iStart = Utility::Min( m_iCursorPos, m_iCursorEnd );
int iEnd = Utility::Max( m_iCursorPos, m_iCursorEnd );
int iStart = Utility::Min(m_iCursorPos, m_iCursorEnd);
int iEnd = Utility::Max(m_iCursorPos, m_iCursorEnd);
const UnicodeString& str = GetText();
return str.substr( iStart, iEnd - iStart );
return str.substr(iStart, iEnd - iStart);
}
bool TextBox::OnKeyReturn( bool bDown )
bool TextBox::OnKeyReturn(bool bDown)
{
if ( bDown ) return true;
if (bDown) return true;
OnEnter();
// Try to move to the next control, as if tab had been pressed
OnKeyTab( true );
OnKeyTab(true);
// If we still have focus, blur it.
if ( HasFocus() )
if (HasFocus())
{
Blur();
}
@@ -185,46 +181,46 @@ bool TextBox::OnKeyReturn( bool bDown )
return true;
}
bool TextBox::OnKeyBackspace( bool bDown )
bool TextBox::OnKeyBackspace(bool bDown)
{
if ( !bDown ) return true;
if ( HasSelection() )
if (!bDown) return true;
if (HasSelection())
{
EraseSelection();
return true;
}
if ( m_iCursorPos == 0 ) return true;
if (m_iCursorPos == 0) return true;
DeleteText( m_iCursorPos-1, 1 );
DeleteText(m_iCursorPos - 1, 1);
return true;
}
bool TextBox::OnKeyDelete( bool bDown )
bool TextBox::OnKeyDelete(bool bDown)
{
if ( !bDown ) return true;
if ( HasSelection() )
if (!bDown) return true;
if (HasSelection())
{
EraseSelection();
return true;
}
if ( m_iCursorPos >= TextLength() ) return true;
if (m_iCursorPos >= TextLength()) return true;
DeleteText( m_iCursorPos, 1 );
DeleteText(m_iCursorPos, 1);
return true;
}
bool TextBox::OnKeyLeft( bool bDown )
bool TextBox::OnKeyLeft(bool bDown)
{
if ( !bDown ) return true;
if (!bDown) return true;
if ( m_iCursorPos > 0 )
if (m_iCursorPos > 0)
m_iCursorPos--;
if ( !Gwen::Input::IsShiftDown() )
if (!Gwen::Input::IsShiftDown())
{
m_iCursorEnd = m_iCursorPos;
}
@@ -233,14 +229,14 @@ bool TextBox::OnKeyLeft( bool bDown )
return true;
}
bool TextBox::OnKeyRight( bool bDown )
bool TextBox::OnKeyRight(bool bDown)
{
if ( !bDown ) return true;
if (!bDown) return true;
if ( m_iCursorPos < TextLength() )
if (m_iCursorPos < TextLength())
m_iCursorPos++;
if ( !Gwen::Input::IsShiftDown() )
if (!Gwen::Input::IsShiftDown())
{
m_iCursorEnd = m_iCursorPos;
}
@@ -249,12 +245,12 @@ bool TextBox::OnKeyRight( bool bDown )
return true;
}
bool TextBox::OnKeyHome( bool bDown )
bool TextBox::OnKeyHome(bool bDown)
{
if ( !bDown ) return true;
if (!bDown) return true;
m_iCursorPos = 0;
if ( !Gwen::Input::IsShiftDown() )
if (!Gwen::Input::IsShiftDown())
{
m_iCursorEnd = m_iCursorPos;
}
@@ -263,11 +259,11 @@ bool TextBox::OnKeyHome( bool bDown )
return true;
}
bool TextBox::OnKeyEnd( bool /*bDown*/ )
bool TextBox::OnKeyEnd(bool /*bDown*/)
{
m_iCursorPos = TextLength();
if ( !Gwen::Input::IsShiftDown() )
if (!Gwen::Input::IsShiftDown())
{
m_iCursorEnd = m_iCursorPos;
}
@@ -276,35 +272,34 @@ bool TextBox::OnKeyEnd( bool /*bDown*/ )
return true;
}
void TextBox::SetCursorPos( int i )
void TextBox::SetCursorPos(int i)
{
if ( m_iCursorPos == i ) return;
if (m_iCursorPos == i) return;
m_iCursorPos = i;
RefreshCursorBounds();
}
void TextBox::SetCursorEnd( int i )
void TextBox::SetCursorEnd(int i)
{
if ( m_iCursorEnd == i ) return;
if (m_iCursorEnd == i) return;
m_iCursorEnd = i;
RefreshCursorBounds();
}
void TextBox::DeleteText( int iStartPos, int iLength )
void TextBox::DeleteText(int iStartPos, int iLength)
{
UnicodeString str = GetText();
str.erase( iStartPos, iLength );
SetText( str );
str.erase(iStartPos, iLength);
SetText(str);
if ( m_iCursorPos > iStartPos )
if (m_iCursorPos > iStartPos)
{
SetCursorPos( m_iCursorPos - iLength );
SetCursorPos(m_iCursorPos - iLength);
}
SetCursorEnd( m_iCursorPos );
SetCursorEnd(m_iCursorPos);
}
bool TextBox::HasSelection()
@@ -314,98 +309,98 @@ bool TextBox::HasSelection()
void TextBox::EraseSelection()
{
int iStart = Utility::Min( m_iCursorPos, m_iCursorEnd );
int iEnd = Utility::Max( m_iCursorPos, m_iCursorEnd );
int iStart = Utility::Min(m_iCursorPos, m_iCursorEnd);
int iEnd = Utility::Max(m_iCursorPos, m_iCursorEnd);
DeleteText( iStart, iEnd - iStart );
DeleteText(iStart, iEnd - iStart);
// Move the cursor to the start of the selection,
// Move the cursor to the start of the selection,
// since the end is probably outside of the string now.
m_iCursorPos = iStart;
m_iCursorEnd = iStart;
}
void TextBox::OnMouseClickLeft( int x, int y, bool bDown )
void TextBox::OnMouseClickLeft(int x, int y, bool bDown)
{
if ( m_bSelectAll )
if (m_bSelectAll)
{
OnSelectAll( this );
OnSelectAll(this);
m_bSelectAll = false;
return;
}
int iChar = m_Text->GetClosestCharacter( m_Text->CanvasPosToLocal( Gwen::Point( x, y ) ) );
int iChar = m_Text->GetClosestCharacter(m_Text->CanvasPosToLocal(Gwen::Point(x, y)));
if ( bDown )
if (bDown)
{
SetCursorPos( iChar );
SetCursorPos(iChar);
if ( !Gwen::Input::IsShiftDown() )
SetCursorEnd( iChar );
if (!Gwen::Input::IsShiftDown())
SetCursorEnd(iChar);
Gwen::MouseFocus = this;
}
else
{
if ( Gwen::MouseFocus == this )
if (Gwen::MouseFocus == this)
{
SetCursorPos( iChar );
SetCursorPos(iChar);
Gwen::MouseFocus = NULL;
}
}
}
void TextBox::OnMouseMoved( int x, int y, int /*deltaX*/, int /*deltaY*/ )
void TextBox::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
{
if ( Gwen::MouseFocus != this ) return;
if (Gwen::MouseFocus != this) return;
int iChar = m_Text->GetClosestCharacter( m_Text->CanvasPosToLocal( Gwen::Point( x, y ) ) );
int iChar = m_Text->GetClosestCharacter(m_Text->CanvasPosToLocal(Gwen::Point(x, y)));
SetCursorPos( iChar );
SetCursorPos(iChar);
}
void TextBox::MakeCaratVisible()
{
int iCaratPos = m_Text->GetCharacterPosition( m_iCursorPos ).x;
int iCaratPos = m_Text->GetCharacterPosition(m_iCursorPos).x;
// If the carat is already in a semi-good position, leave it.
{
int iRealCaratPos = iCaratPos + m_Text->X();
if ( iRealCaratPos > Width() * 0.1f && iRealCaratPos < Width() * 0.9f )
if (iRealCaratPos > Width() * 0.1f && iRealCaratPos < Width() * 0.9f)
return;
}
// The ideal position is for the carat to be right in the middle
int idealx = -iCaratPos + Width() * 0.5f;;
int idealx = -iCaratPos + Width() * 0.5f;
;
// Don't show too much whitespace to the right
if ( idealx + m_Text->Width() < Width() - m_rTextPadding.right )
idealx = -m_Text->Width() + (Width() - m_rTextPadding.right );
if (idealx + m_Text->Width() < Width() - m_rTextPadding.right)
idealx = -m_Text->Width() + (Width() - m_rTextPadding.right);
// Or the left
if ( idealx > m_rTextPadding.left )
if (idealx > m_rTextPadding.left)
idealx = m_rTextPadding.left;
m_Text->SetPos( idealx, m_Text->Y() );
m_Text->SetPos(idealx, m_Text->Y());
}
void TextBox::Layout( Skin::Base* skin )
void TextBox::Layout(Skin::Base* skin)
{
BaseClass::Layout( skin );
BaseClass::Layout(skin);
RefreshCursorBounds();
}
void TextBox::OnTextChanged()
{
if ( m_iCursorPos > TextLength() ) m_iCursorPos = TextLength();
if ( m_iCursorEnd > TextLength() ) m_iCursorEnd = TextLength();
if (m_iCursorPos > TextLength()) m_iCursorPos = TextLength();
if (m_iCursorEnd > TextLength()) m_iCursorEnd = TextLength();
onTextChanged.Call( this );
onTextChanged.Call(this);
}
void TextBox::OnEnter()
{
onReturnPressed.Call( this );
onReturnPressed.Call(this);
}

Some files were not shown because too many files have changed in this diff Show More