mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Added cUIGenericGrid ( for multi-purpose grid, accepts any kind of control ), and cUIGridCell. Added tUIItemContainer, replaced for cUIListBoxContainer, so it can be used as a generic container for listbox, grids, etc.
Added align capabilities to cUIGfx and cUISprite. Fixed some minor bugs. Fixed some friend classes.
This commit is contained in:
2
src/ee.h
2
src/ee.h
@@ -169,5 +169,7 @@
|
||||
#include "ui/cuipopupmenu.hpp"
|
||||
#include "ui/cuisprite.hpp"
|
||||
#include "ui/cuitextedit.hpp"
|
||||
#include "ui/cuigridcell.hpp"
|
||||
#include "ui/cuigenericgrid.hpp"
|
||||
using namespace EE::UI;
|
||||
#endif
|
||||
|
||||
@@ -374,7 +374,7 @@ bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeU
|
||||
}
|
||||
|
||||
void cSprite::Animate( const eeFloat& ElapsedTime ) {
|
||||
if ( mFrames.size() > 1 && SPR_FGET( SPRITE_FLAG_AUTO_ANIM ) && !SPR_FGET( SPRITE_FLAG_ANIM_PAUSED ) ) {
|
||||
if ( mFrames.size() > 1 && SPR_FGET( SPRITE_FLAG_AUTO_ANIM ) && !SPR_FGET( SPRITE_FLAG_ANIM_PAUSED ) && 0.f != ElapsedTime ) {
|
||||
eeUint Size = (eeUint)mFrames.size() - 1;
|
||||
eeFloat Elapsed = ( ElapsedTime != -99999.f ) ? (eeFloat)ElapsedTime : (eeFloat)cEngine::instance()->Elapsed();
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ void cEETest::Init() {
|
||||
Mus = eeNew( cMusic, () );
|
||||
if ( Mus->OpenFromPack( &PAK, "music.ogg" ) ) {
|
||||
Mus->Loop(true);
|
||||
//Mus.Volume( 0.f );
|
||||
Mus->Volume( 0.f );
|
||||
Mus->Play();
|
||||
}
|
||||
|
||||
@@ -662,12 +662,52 @@ void cEETest::CreateUI() {
|
||||
TextEdit->Visible( true );
|
||||
TextEdit->Enabled( true );
|
||||
|
||||
cUIGenericGrid::CreateParams GridParams;
|
||||
GridParams.Parent( C );
|
||||
GridParams.PosSet( 325, 245 );
|
||||
GridParams.SizeSet( 200, 130 );
|
||||
GridParams.Flags = UI_AUTO_PADDING;
|
||||
GridParams.RowHeight = 24;
|
||||
GridParams.CollumnsCount = 3;
|
||||
cUIGenericGrid * mGenGrid = eeNew( cUIGenericGrid, ( GridParams ) );
|
||||
mGenGrid->Visible( true );
|
||||
mGenGrid->Enabled( true );
|
||||
|
||||
cUIGridCell::CreateParams CellParams;
|
||||
CellParams.Parent( mGenGrid->Container() );
|
||||
|
||||
cUITextBox::CreateParams TxtBoxParams;
|
||||
cUITextInput::CreateParams TxtInputParams;
|
||||
TxtInputParams.Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_VALIGN_CENTER;
|
||||
|
||||
cUIGfx::CreateParams TxtGfxParams;
|
||||
TxtGfxParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER;
|
||||
TxtGfxParams.Shape = cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" );
|
||||
|
||||
for ( Uint32 i = 0; i < 10; i++ ) {
|
||||
cUIGridCell * Cell = eeNew( cUIGridCell, ( CellParams ) );
|
||||
cUITextBox * TxtBox = eeNew( cUITextBox, ( TxtBoxParams ) );
|
||||
cUITextInput * TxtInput = eeNew( cUITextInput, ( TxtInputParams ) );
|
||||
cUIGfx * TxtGfx = eeNew( cUIGfx, ( TxtGfxParams ) );
|
||||
|
||||
TxtBox->Text( L"Test " + toWStr( i+1 ) );
|
||||
|
||||
Cell->Cell( 0, TxtBox );
|
||||
Cell->Cell( 1, TxtGfx );
|
||||
Cell->Cell( 2, TxtInput );
|
||||
|
||||
mGenGrid->Add( Cell );
|
||||
}
|
||||
|
||||
mGenGrid->CollumnWidth( 0, 50 );
|
||||
mGenGrid->CollumnWidth( 1, 24 );
|
||||
mGenGrid->CollumnWidth( 2, 100 );
|
||||
|
||||
mBuda = L"El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde.";
|
||||
|
||||
TextEdit->Text( mBuda );
|
||||
|
||||
TTFB->ShrinkText( mBuda, 400 );
|
||||
|
||||
mBudaTC.Create( TTFB, mBuda, eeColorA(255,255,255,255) );
|
||||
mEEText.Create( TTFB, L"Entropia Engine++\nCTRL + 1 = Screen 1 - CTRL + 2 = Screen 2\nCTRL + 3 = Screen 3" );
|
||||
mFBOText.Create( TTFB, L"This is a VBO\nInside of a FBO" );
|
||||
|
||||
@@ -224,8 +224,6 @@ class EE_API cUIControl {
|
||||
void SendCommonEvent( const Uint32& Event );
|
||||
protected:
|
||||
friend class cUIManager;
|
||||
friend class cUIControlAnim;
|
||||
friend class cUIListBoxContainer;
|
||||
|
||||
bool mVisible;
|
||||
bool mEnabled;
|
||||
|
||||
@@ -160,7 +160,7 @@ void cUIControlAnim::StartAlphaAnim( const eeFloat& From, const eeFloat& To, con
|
||||
AnimChild->StartAlphaAnim( From, To, TotalTime, AlphaChilds );
|
||||
}
|
||||
|
||||
CurChild = CurChild->mNext;
|
||||
CurChild = CurChild->NextGet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
495
src/ui/cuigenericgrid.cpp
Normal file
495
src/ui/cuigenericgrid.cpp
Normal file
@@ -0,0 +1,495 @@
|
||||
#include "cuigenericgrid.hpp"
|
||||
#include "cuimanager.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
cUIGenericGrid::cUIGenericGrid( const cUIGenericGrid::CreateParams& Params ) :
|
||||
cUIControlAnim( Params ),
|
||||
mPadding( Params.PaddingContainer ),
|
||||
mSmoothScroll( Params.SmoothScroll ),
|
||||
mContainer( NULL ),
|
||||
mVScrollBar( NULL ),
|
||||
mHScrollBar( NULL ),
|
||||
mVScrollMode( Params.VScrollMode ),
|
||||
mHScrollMode( Params.HScrollMode ),
|
||||
mCollumnsCount( Params.CollumnsCount ),
|
||||
mRowHeight( Params.RowHeight ),
|
||||
mTotalWidth( Params.GridWidth ),
|
||||
mLastPos( 0xFFFFFFFF ),
|
||||
mVisibleFirst(0),
|
||||
mVisibleLast(0),
|
||||
mHScrollInit(0),
|
||||
mItemsNotVisible(0),
|
||||
mSelected(-1),
|
||||
mCollWidthAssigned( false )
|
||||
{
|
||||
mType |= UI_TYPE_GENERICGRID;
|
||||
|
||||
mCollumnsWidth.resize( mCollumnsCount, 0 );
|
||||
mCollumnsPos.resize( mCollumnsCount, 0 );
|
||||
|
||||
cUIComplexControl::CreateParams CParams;
|
||||
CParams.Parent( this );
|
||||
CParams.PosSet( mPadding.Left, mPadding.Top );
|
||||
CParams.Size = eeSize( mSize.Width() - mPadding.Right - mPadding.Left, mSize.Height() - mPadding.Top - mPadding.Bottom );
|
||||
CParams.Flags = Params.Flags;
|
||||
mContainer = eeNew( tUIItemContainer<cUIGenericGrid> , ( CParams ) );
|
||||
mContainer->Visible( true );
|
||||
mContainer->Enabled( true );
|
||||
|
||||
if ( mFlags & UI_CLIP_ENABLE )
|
||||
mFlags &= ~UI_CLIP_ENABLE;
|
||||
|
||||
cUIScrollBar::CreateParams ScrollBarP;
|
||||
ScrollBarP.Parent ( this );
|
||||
ScrollBarP.PosSet ( mSize.Width() - 15, 0 );
|
||||
ScrollBarP.Flags = UI_AUTO_SIZE;
|
||||
ScrollBarP.VerticalScrollBar = true;
|
||||
ScrollBarP.Size = eeSize( 15, mSize.Height() );
|
||||
mVScrollBar = eeNew( cUIScrollBar, ( ScrollBarP ) );
|
||||
|
||||
ScrollBarP.PosSet ( 0, mSize.Height() - 15 );
|
||||
ScrollBarP.Size = eeSize( mSize.Width() - mVScrollBar->Size().Width(), 15 );
|
||||
ScrollBarP.VerticalScrollBar = false;
|
||||
mHScrollBar = eeNew( cUIScrollBar, ( ScrollBarP ) );
|
||||
|
||||
if ( UI_SCROLLBAR_ALWAYS_ON == mHScrollMode ) {
|
||||
mHScrollBar->Visible( true );
|
||||
mHScrollBar->Enabled( true );
|
||||
}
|
||||
|
||||
if ( UI_SCROLLBAR_ALWAYS_ON == mVScrollMode ) {
|
||||
mVScrollBar->Visible( true );
|
||||
mVScrollBar->Enabled( true );
|
||||
}
|
||||
|
||||
mVScrollBar->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIGenericGrid::OnScrollValueChange ) );
|
||||
mHScrollBar->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIGenericGrid::OnScrollValueChange ) );
|
||||
|
||||
ApplyDefaultTheme();
|
||||
}
|
||||
|
||||
cUIGenericGrid::~cUIGenericGrid() {
|
||||
}
|
||||
|
||||
void cUIGenericGrid::SetDefaultCollumnsWidth() {
|
||||
if ( mCollWidthAssigned )
|
||||
return;
|
||||
|
||||
if ( mItemsNotVisible <= 0 ) {
|
||||
Uint32 VisibleItems = mContainer->Size().Height() / mRowHeight;
|
||||
Int32 oItemsNotVisible = (Int32)mItems.size() - VisibleItems;
|
||||
|
||||
if ( oItemsNotVisible > 0 ) {
|
||||
mItemsNotVisible = oItemsNotVisible;
|
||||
|
||||
UpdateVScroll();
|
||||
|
||||
ContainerResize();
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 CollumnWidh = mContainer->Size().Width() / mCollumnsCount;
|
||||
|
||||
for ( Uint32 i = 0; i < mCollumnsCount; i++ ) {
|
||||
mCollumnsWidth[ i ] = CollumnWidh;
|
||||
}
|
||||
|
||||
UpdateSize();
|
||||
UpdateCells();
|
||||
}
|
||||
|
||||
void cUIGenericGrid::OnScrollValueChange( const cUIEvent * Event ) {
|
||||
UpdateScroll( true );
|
||||
}
|
||||
|
||||
void cUIGenericGrid::SetTheme( cUITheme * Theme ) {
|
||||
cUIControl::SetTheme( Theme, "genericgrid" );
|
||||
|
||||
AutoPadding();
|
||||
|
||||
OnSizeChange();
|
||||
}
|
||||
|
||||
void cUIGenericGrid::AutoPadding() {
|
||||
if ( mFlags & UI_AUTO_PADDING ) {
|
||||
mPadding = MakePadding();
|
||||
}
|
||||
}
|
||||
|
||||
void cUIGenericGrid::OnSizeChange() {
|
||||
mVScrollBar->Pos( mSize.Width() - mVScrollBar->Size().Width(), 0 );
|
||||
mVScrollBar->Size( mVScrollBar->Size().Width(), mSize.Height() );
|
||||
|
||||
mHScrollBar->Pos( 0, mSize.Height() - mHScrollBar->Size().Height() );
|
||||
mHScrollBar->Size( mSize.Width() - mVScrollBar->Size().Width(), mHScrollBar->Size().Height() );
|
||||
|
||||
if ( mContainer->IsClipped() && UI_SCROLLBAR_AUTO == mHScrollMode ) {
|
||||
if ( (Int32)mTotalWidth <= mContainer->Size().Width() ) {
|
||||
mHScrollBar->Visible( false );
|
||||
mHScrollBar->Enabled( false );
|
||||
mHScrollInit = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ContainerResize();
|
||||
SetDefaultCollumnsWidth();
|
||||
UpdateScroll();
|
||||
}
|
||||
|
||||
void cUIGenericGrid::ContainerResize() {
|
||||
mContainer->Pos( mPadding.Left, mPadding.Top );
|
||||
|
||||
if( mHScrollBar->Visible() )
|
||||
mContainer->Size( mSize.Width() - mPadding.Right, mSize.Height() - mPadding.Top - mHScrollBar->Size().Height() );
|
||||
else
|
||||
mContainer->Size( mSize.Width() - mPadding.Right, mSize.Height() - mPadding.Bottom - mPadding.Top );
|
||||
|
||||
if ( mVScrollBar->Visible() )
|
||||
mContainer->Size( mContainer->Size().Width() - mVScrollBar->Size().Width(), mContainer->Size().Height() );
|
||||
|
||||
SetDefaultCollumnsWidth();
|
||||
}
|
||||
|
||||
void cUIGenericGrid::UpdateVScroll() {
|
||||
if ( mItemsNotVisible <= 0 ) {
|
||||
if ( UI_SCROLLBAR_ALWAYS_ON == mVScrollMode ) {
|
||||
mVScrollBar->Visible( true );
|
||||
mVScrollBar->Enabled( true );
|
||||
} else {
|
||||
mVScrollBar->Visible( false );
|
||||
mVScrollBar->Enabled( false );
|
||||
}
|
||||
} else {
|
||||
if ( UI_SCROLLBAR_AUTO == mVScrollMode || UI_SCROLLBAR_ALWAYS_ON == mVScrollMode ) {
|
||||
mVScrollBar->Visible( true );
|
||||
mVScrollBar->Enabled( true );
|
||||
} else {
|
||||
mVScrollBar->Visible( false );
|
||||
mVScrollBar->Enabled( false );
|
||||
}
|
||||
}
|
||||
|
||||
ContainerResize();
|
||||
}
|
||||
|
||||
void cUIGenericGrid::UpdateScroll( bool FromScrollChange ) {
|
||||
if ( !mItems.size() )
|
||||
return;
|
||||
|
||||
cUIGridCell * Item;
|
||||
Uint32 i, RelPos = 0, RelPosMax;
|
||||
Int32 ItemPos, ItemPosMax;
|
||||
Int32 tHLastScroll = mHScrollInit;
|
||||
|
||||
Uint32 VisibleItems = mContainer->Size().Height() / mRowHeight;
|
||||
mItemsNotVisible = (Int32)mItems.size() - VisibleItems;
|
||||
bool Clipped = 0 != mContainer->IsClipped();
|
||||
|
||||
UpdateVScroll();
|
||||
|
||||
if ( Clipped && ( UI_SCROLLBAR_AUTO == mHScrollMode || UI_SCROLLBAR_ALWAYS_ON == mHScrollMode ) ) {
|
||||
if ( mContainer->Size().Width() < (Int32)mTotalWidth ) {
|
||||
mHScrollBar->Visible( true );
|
||||
mHScrollBar->Enabled( true );
|
||||
|
||||
ContainerResize();
|
||||
|
||||
Int32 ScrollH = mTotalWidth - mContainer->Size().Width();
|
||||
|
||||
Int32 HScrolleable = (Uint32)( mHScrollBar->Value() * ScrollH );
|
||||
|
||||
mHScrollInit = -HScrolleable;
|
||||
} else {
|
||||
if ( UI_SCROLLBAR_AUTO == mHScrollMode ) {
|
||||
mHScrollBar->Visible( false );
|
||||
mHScrollBar->Enabled( false );
|
||||
|
||||
mHScrollInit = 0;
|
||||
|
||||
ContainerResize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VisibleItems = mContainer->Size().Height() / mRowHeight;
|
||||
mItemsNotVisible = (Uint32)mItems.size() - VisibleItems;
|
||||
Int32 Scrolleable = (Int32)mItems.size() * mRowHeight - mContainer->Size().Height();
|
||||
bool FirstVisible = false;
|
||||
|
||||
if ( Clipped && mSmoothScroll ) {
|
||||
if ( Scrolleable >= 0 )
|
||||
RelPos = (Uint32)( mVScrollBar->Value() * Scrolleable );
|
||||
else
|
||||
RelPos = 0;
|
||||
|
||||
RelPosMax = RelPos + mContainer->Size().Height() + mRowHeight;
|
||||
|
||||
if ( ( FromScrollChange && 0xFFFFFFFF != mLastPos && mLastPos == RelPos ) && ( tHLastScroll == mHScrollInit ) )
|
||||
return;
|
||||
|
||||
mLastPos = RelPos;
|
||||
|
||||
for ( i = 0; i < mItems.size(); i++ ) {
|
||||
Item = mItems[i];
|
||||
ItemPos = mRowHeight * i;
|
||||
ItemPosMax = ItemPos + mRowHeight;
|
||||
|
||||
if ( ( ItemPos >= (Int32)RelPos || ItemPosMax >= (Int32)RelPos ) && ( ItemPos <= (Int32)RelPosMax ) ) {
|
||||
Item->Pos( mHScrollInit, ItemPos - RelPos );
|
||||
Item->Enabled( true );
|
||||
Item->Visible( true );
|
||||
|
||||
if ( !FirstVisible ) {
|
||||
mVisibleFirst = i;
|
||||
FirstVisible = true;
|
||||
}
|
||||
|
||||
mVisibleLast = i;
|
||||
} else {
|
||||
Item->Enabled( false );
|
||||
Item->Visible( false );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
RelPosMax = (Uint32)mItems.size();
|
||||
|
||||
if ( mItemsNotVisible > 0 ) {
|
||||
RelPos = (Uint32)( mVScrollBar->Value() * mItemsNotVisible );
|
||||
RelPosMax = RelPos + VisibleItems;
|
||||
}
|
||||
|
||||
if ( ( FromScrollChange && 0xFFFFFFFF != mLastPos && mLastPos == RelPos ) && ( !Clipped || tHLastScroll == mHScrollInit ) )
|
||||
return;
|
||||
|
||||
mLastPos = RelPos;
|
||||
|
||||
for ( i = 0; i < mItems.size(); i++ ) {
|
||||
Item = mItems[i];
|
||||
ItemPos = mRowHeight * ( i - RelPos );
|
||||
|
||||
if ( i >= RelPos && i < RelPosMax ) {
|
||||
if ( Clipped )
|
||||
Item->Pos( mHScrollInit, ItemPos );
|
||||
else
|
||||
Item->Pos( 0, ItemPos );
|
||||
|
||||
Item->Enabled( true );
|
||||
Item->Visible( true );
|
||||
|
||||
if ( !FirstVisible ) {
|
||||
mVisibleFirst = i;
|
||||
FirstVisible = true;
|
||||
}
|
||||
|
||||
mVisibleLast = i;
|
||||
} else {
|
||||
Item->Enabled( false );
|
||||
Item->Visible( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( mHScrollBar->Visible() && !mVScrollBar->Visible() ) {
|
||||
mHScrollBar->Pos( 0, mSize.Height() - mHScrollBar->Size().Height() );
|
||||
mHScrollBar->Size( mSize.Width(), mHScrollBar->Size().Height() );
|
||||
} else {
|
||||
mHScrollBar->Pos( 0, mSize.Height() - mHScrollBar->Size().Height() );
|
||||
mHScrollBar->Size( mSize.Width() - mVScrollBar->Size().Width(), mHScrollBar->Size().Height() );
|
||||
}
|
||||
}
|
||||
|
||||
void cUIGenericGrid::UpdateSize() {
|
||||
UpdateCollumnsPos();
|
||||
|
||||
mTotalHeight = mItems.size() * mRowHeight;
|
||||
}
|
||||
|
||||
void cUIGenericGrid::Add( cUIGridCell * Cell ) {
|
||||
mItems.push_back( Cell );
|
||||
|
||||
if ( mContainer != Cell->Parent() )
|
||||
Cell->Parent( mContainer );
|
||||
|
||||
SetDefaultCollumnsWidth();
|
||||
|
||||
Cell->AutoSize();
|
||||
|
||||
UpdateSize();
|
||||
|
||||
UpdateScroll();
|
||||
}
|
||||
|
||||
void cUIGenericGrid::Remove( cUIGridCell * Cell ) {
|
||||
|
||||
}
|
||||
|
||||
void cUIGenericGrid::CollumnWidth( const Uint32& CollumnIndex, const Uint32& CollumnWidth ) {
|
||||
eeASSERT( CollumnIndex < mCollumnsCount );
|
||||
|
||||
mCollWidthAssigned = true;
|
||||
|
||||
mCollumnsWidth[ CollumnIndex ] = CollumnWidth;
|
||||
|
||||
UpdateCollumnsPos();
|
||||
UpdateCells();
|
||||
UpdateScroll();
|
||||
}
|
||||
|
||||
Uint32 cUIGenericGrid::Count() const {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
const Uint32& cUIGenericGrid::CollumnsCount() const {
|
||||
return mCollumnsCount;
|
||||
}
|
||||
|
||||
const Uint32& cUIGenericGrid::CollumnWidth( const Uint32& CollumnIndex ) const {
|
||||
eeASSERT( CollumnIndex < mCollumnsCount );
|
||||
|
||||
return mCollumnsWidth[ CollumnIndex ];
|
||||
}
|
||||
|
||||
void cUIGenericGrid::RowHeight( const Uint32& height ) {
|
||||
if ( mRowHeight != height ) {
|
||||
mRowHeight = height;
|
||||
|
||||
UpdateSize();
|
||||
UpdateCells();
|
||||
UpdateScroll();
|
||||
}
|
||||
}
|
||||
|
||||
const Uint32& cUIGenericGrid::RowHeight() const {
|
||||
return mRowHeight;
|
||||
}
|
||||
|
||||
cUIGridCell * cUIGenericGrid::GetCell( const Uint32& CellIndex ) const {
|
||||
eeASSERT( CellIndex < mItems.size() );
|
||||
|
||||
return mItems[ CellIndex ];
|
||||
}
|
||||
|
||||
Uint32 cUIGenericGrid::GetCellPos( const Uint32& CollumnIndex ) {
|
||||
eeASSERT( CollumnIndex < mCollumnsCount );
|
||||
|
||||
return mCollumnsPos[ CollumnIndex ];
|
||||
}
|
||||
|
||||
void cUIGenericGrid::UpdateCells() {
|
||||
for ( Uint32 i = 0; i < mItems.size(); i++ ) {
|
||||
mItems[i]->FixCell();
|
||||
}
|
||||
}
|
||||
|
||||
void cUIGenericGrid::UpdateCollumnsPos() {
|
||||
Uint32 Pos = 0;
|
||||
|
||||
for ( Uint32 i = 0; i < mCollumnsCount; i++ ) {
|
||||
mCollumnsPos[ i ] = Pos;
|
||||
|
||||
Pos += mCollumnsWidth[ i ];
|
||||
}
|
||||
|
||||
mTotalWidth = Pos;
|
||||
}
|
||||
|
||||
|
||||
void cUIGenericGrid::OnAlphaChange() {
|
||||
cUIControlAnim::OnAlphaChange();
|
||||
|
||||
mVScrollBar->Alpha( mAlpha );
|
||||
mHScrollBar->Alpha( mAlpha );
|
||||
}
|
||||
|
||||
void cUIGenericGrid::VerticalScrollMode( const UI_SCROLLBAR_MODE& Mode ) {
|
||||
if ( Mode != mVScrollMode ) {
|
||||
mVScrollMode = Mode;
|
||||
|
||||
UpdateScroll();
|
||||
}
|
||||
}
|
||||
|
||||
const UI_SCROLLBAR_MODE& cUIGenericGrid::VerticalScrollMode() {
|
||||
return mVScrollMode;
|
||||
}
|
||||
|
||||
void cUIGenericGrid::HorizontalScrollMode( const UI_SCROLLBAR_MODE& Mode ) {
|
||||
if ( Mode != mHScrollMode ) {
|
||||
mHScrollMode = Mode;
|
||||
|
||||
if ( UI_SCROLLBAR_ALWAYS_ON == mHScrollMode ) {
|
||||
mHScrollBar->Visible( true );
|
||||
mHScrollBar->Enabled( true );
|
||||
ContainerResize();
|
||||
} else if ( UI_SCROLLBAR_ALWAYS_OFF == mHScrollMode ) {
|
||||
mHScrollBar->Visible( false );
|
||||
mHScrollBar->Enabled( false );
|
||||
ContainerResize();
|
||||
}
|
||||
|
||||
UpdateScroll();
|
||||
}
|
||||
}
|
||||
|
||||
const UI_SCROLLBAR_MODE& cUIGenericGrid::HorizontalScrollMode() {
|
||||
return mHScrollMode;
|
||||
}
|
||||
|
||||
cUIScrollBar * cUIGenericGrid::VerticalScrollBar() const {
|
||||
return mVScrollBar;
|
||||
}
|
||||
|
||||
cUIScrollBar * cUIGenericGrid::HorizontalScrollBar() const {
|
||||
return mHScrollBar;
|
||||
}
|
||||
|
||||
Uint32 cUIGenericGrid::GetItemIndex( cUIGridCell * Item ) {
|
||||
for ( Uint32 i = 0; i < mItems.size(); i++ ) {
|
||||
if ( Item == mItems[i] )
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
Uint32 cUIGenericGrid::OnSelected() {
|
||||
SendCommonEvent( cUIEvent::EventOnSelected );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
cUIGridCell * cUIGenericGrid::GetItemSelected() {
|
||||
if ( -1 != mSelected )
|
||||
return mItems[ mSelected ];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Uint32 cUIGenericGrid::GetItemSelectedIndex() const {
|
||||
return mSelected;
|
||||
}
|
||||
|
||||
Uint32 cUIGenericGrid::OnMessage( const cUIMessage * Msg ) {
|
||||
switch ( Msg->Msg() ) {
|
||||
case cUIMessage::MsgFocusLoss:
|
||||
{
|
||||
cUIControl * FocusCtrl = cUIManager::instance()->FocusControl();
|
||||
|
||||
if ( this != FocusCtrl && !IsParentOf( FocusCtrl ) ) {
|
||||
SendCommonEvent( cUIEvent::EventOnComplexControlFocusLoss );
|
||||
OnComplexControlFocusLoss();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
tUIItemContainer<cUIGenericGrid> * cUIGenericGrid::Container() const {
|
||||
return mContainer;
|
||||
}
|
||||
|
||||
}}
|
||||
137
src/ui/cuigenericgrid.hpp
Normal file
137
src/ui/cuigenericgrid.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
#ifndef EE_UICUIGENERICGRID_HPP
|
||||
#define EE_UICUIGENERICGRID_HPP
|
||||
|
||||
#include "cuicontrolanim.hpp"
|
||||
#include "cuigridcell.hpp"
|
||||
#include "cuiscrollbar.hpp"
|
||||
#include "tuiitemcontainer.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
class EE_API cUIGenericGrid : public cUIControlAnim {
|
||||
public:
|
||||
class CreateParams : public cUIControlAnim::CreateParams {
|
||||
public:
|
||||
inline CreateParams() :
|
||||
cUIControlAnim::CreateParams(),
|
||||
SmoothScroll( true ),
|
||||
VScrollMode( UI_SCROLLBAR_AUTO ),
|
||||
HScrollMode( UI_SCROLLBAR_AUTO ),
|
||||
CollumnsCount(1),
|
||||
RowHeight( 24 ),
|
||||
GridWidth( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
inline ~CreateParams() {};
|
||||
|
||||
bool SmoothScroll;
|
||||
UI_SCROLLBAR_MODE VScrollMode;
|
||||
UI_SCROLLBAR_MODE HScrollMode;
|
||||
Uint32 CollumnsCount;
|
||||
Uint32 RowHeight;
|
||||
Uint32 GridWidth;
|
||||
eeRecti PaddingContainer;
|
||||
};
|
||||
|
||||
cUIGenericGrid( const cUIGenericGrid::CreateParams& Params );
|
||||
|
||||
~cUIGenericGrid();
|
||||
|
||||
virtual void SetTheme( cUITheme * Theme );
|
||||
|
||||
void Add( cUIGridCell * Cell );
|
||||
|
||||
void Remove( cUIGridCell * Cell );
|
||||
|
||||
void CollumnWidth( const Uint32& CollumnIndex, const Uint32& CollumnWidth );
|
||||
|
||||
Uint32 Count() const;
|
||||
|
||||
const Uint32& CollumnsCount() const;
|
||||
|
||||
const Uint32& CollumnWidth( const Uint32& CollumnIndex ) const;
|
||||
|
||||
void RowHeight( const Uint32& height );
|
||||
|
||||
const Uint32& RowHeight() const;
|
||||
|
||||
cUIGridCell * GetCell( const Uint32& CellIndex ) const;
|
||||
|
||||
void VerticalScrollMode( const UI_SCROLLBAR_MODE& Mode );
|
||||
|
||||
const UI_SCROLLBAR_MODE& VerticalScrollMode();
|
||||
|
||||
void HorizontalScrollMode( const UI_SCROLLBAR_MODE& Mode );
|
||||
|
||||
const UI_SCROLLBAR_MODE& HorizontalScrollMode();
|
||||
|
||||
Uint32 GetCellPos( const Uint32& CollumnIndex );
|
||||
|
||||
cUIScrollBar * VerticalScrollBar() const;
|
||||
|
||||
cUIScrollBar * HorizontalScrollBar() const;
|
||||
|
||||
Uint32 GetItemIndex( cUIGridCell * Item );
|
||||
|
||||
cUIGridCell * GetItemSelected();
|
||||
|
||||
Uint32 GetItemSelectedIndex() const;
|
||||
|
||||
Uint32 OnMessage( const cUIMessage * Msg );
|
||||
|
||||
tUIItemContainer<cUIGenericGrid> * Container() const;
|
||||
protected:
|
||||
friend class tUIItemContainer<cUIGenericGrid>;
|
||||
friend class cUIGridCell;
|
||||
|
||||
eeRecti mPadding;
|
||||
bool mSmoothScroll;
|
||||
tUIItemContainer<cUIGenericGrid> * mContainer;
|
||||
cUIScrollBar * mVScrollBar;
|
||||
cUIScrollBar * mHScrollBar;
|
||||
UI_SCROLLBAR_MODE mVScrollMode;
|
||||
UI_SCROLLBAR_MODE mHScrollMode;
|
||||
std::vector<cUIGridCell*> mItems;
|
||||
Uint32 mCollumnsCount;
|
||||
Uint32 mRowHeight;
|
||||
std::vector<Uint32> mCollumnsWidth;
|
||||
std::vector<Uint32> mCollumnsPos;
|
||||
Uint32 mTotalWidth;
|
||||
Uint32 mTotalHeight;
|
||||
Uint32 mLastPos;
|
||||
Uint32 mVisibleFirst;
|
||||
Uint32 mVisibleLast;
|
||||
Int32 mHScrollInit;
|
||||
Int32 mItemsNotVisible;
|
||||
Int32 mSelected;
|
||||
bool mCollWidthAssigned;
|
||||
|
||||
void UpdateCells();
|
||||
|
||||
void UpdateCollumnsPos();
|
||||
|
||||
void AutoPadding();
|
||||
|
||||
virtual void OnSizeChange();
|
||||
|
||||
virtual void OnAlphaChange();
|
||||
|
||||
void ContainerResize();
|
||||
|
||||
void OnScrollValueChange( const cUIEvent * Event );
|
||||
|
||||
void SetDefaultCollumnsWidth();
|
||||
|
||||
void UpdateScroll( bool FromScrollChange = false );
|
||||
|
||||
void UpdateSize();
|
||||
|
||||
virtual Uint32 OnSelected();
|
||||
|
||||
void UpdateVScroll();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,8 @@ cUIGfx::cUIGfx( const cUIGfx::CreateParams& Params ) :
|
||||
cUIComplexControl( Params ),
|
||||
mShape( Params.Shape ),
|
||||
mColor( Params.ShapeColor ),
|
||||
mRender( Params.ShapeRender )
|
||||
mRender( Params.ShapeRender ),
|
||||
mAlignOffset(0,0)
|
||||
{
|
||||
mType |= UI_TYPE_GET(UI_TYPE_GFX);
|
||||
|
||||
@@ -14,6 +15,8 @@ cUIGfx::cUIGfx( const cUIGfx::CreateParams& Params ) :
|
||||
Size( mShape->Size() );
|
||||
|
||||
mColor.Alpha = (Uint8)mAlpha;
|
||||
|
||||
AutoSize();
|
||||
}
|
||||
|
||||
cUIGfx::~cUIGfx() {
|
||||
@@ -22,7 +25,11 @@ cUIGfx::~cUIGfx() {
|
||||
void cUIGfx::Shape( cShape * shape ) {
|
||||
mShape = shape;
|
||||
|
||||
if ( Flags() & UI_AUTO_SIZE ) {
|
||||
AutoSize();
|
||||
}
|
||||
|
||||
void cUIGfx::AutoSize() {
|
||||
if ( mFlags & UI_AUTO_SIZE ) {
|
||||
if ( NULL != mShape ) {
|
||||
Size( mShape->Size() );
|
||||
} else {
|
||||
@@ -36,7 +43,7 @@ void cUIGfx::Draw() {
|
||||
|
||||
if ( mVisible ) {
|
||||
if ( NULL != mShape && 0.f != mAlpha )
|
||||
mShape->Draw( (eeFloat)mScreenPos.x, (eeFloat)mScreenPos.y, mColor, 0.f, 1.f, mBlend, mRender );
|
||||
mShape->Draw( (eeFloat)mScreenPos.x + mAlignOffset.x, (eeFloat)mScreenPos.y + mAlignOffset.y, mColor, 0.f, 1.f, mBlend, mRender );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,13 +73,43 @@ void cUIGfx::RenderType( const EE_RENDERTYPE& render ) {
|
||||
mRender = render;
|
||||
}
|
||||
|
||||
void cUIGfx::OnSizeChange() {
|
||||
if ( NULL != mShape && Flags() & UI_FIT_TO_CONTROL ) {
|
||||
void cUIGfx::FitToControl() {
|
||||
if ( NULL != mShape && mFlags & UI_FIT_TO_CONTROL ) {
|
||||
mShape->DestWidth( (eeFloat)mSize.x );
|
||||
mShape->DestHeight( (eeFloat)mSize.y );
|
||||
}
|
||||
}
|
||||
|
||||
void cUIGfx::AutoAlign() {
|
||||
if ( NULL == mShape )
|
||||
return;
|
||||
|
||||
if ( HAlignGet( mFlags ) == UI_HALIGN_CENTER ) {
|
||||
mAlignOffset.x = mSize.Width() / 2 - mShape->Size().Width() / 2;
|
||||
} else if ( FontHAlignGet( mFlags ) == UI_HALIGN_RIGHT ) {
|
||||
mAlignOffset.x = mSize.Width() - mShape->Size().Width();
|
||||
} else {
|
||||
mAlignOffset.x = 0;
|
||||
}
|
||||
|
||||
if ( VAlignGet( mFlags ) == UI_VALIGN_CENTER ) {
|
||||
mAlignOffset.y = mSize.Height() / 2 - mShape->Size().Height() / 2;
|
||||
} else if ( FontVAlignGet( mFlags ) == UI_VALIGN_BOTTOM ) {
|
||||
mAlignOffset.y = mSize.Height() - mShape->Size().Height();
|
||||
} else {
|
||||
mAlignOffset.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cUIGfx::OnSizeChange() {
|
||||
FitToControl();
|
||||
AutoSize();
|
||||
AutoAlign();
|
||||
cUIControlAnim::OnSizeChange();
|
||||
}
|
||||
|
||||
const eeVector2i& cUIGfx::AlignOffset() const {
|
||||
return mAlignOffset;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -43,12 +43,21 @@ class EE_API cUIGfx : public cUIComplexControl {
|
||||
const EE_RENDERTYPE& RenderType() const;
|
||||
|
||||
void RenderType( const EE_RENDERTYPE& render );
|
||||
|
||||
const eeVector2i& AlignOffset() const;
|
||||
protected:
|
||||
cShape * mShape;
|
||||
eeColorA mColor;
|
||||
EE_RENDERTYPE mRender;
|
||||
eeVector2i mAlignOffset;
|
||||
|
||||
virtual void OnSizeChange();
|
||||
|
||||
void AutoSize();
|
||||
|
||||
void FitToControl();
|
||||
|
||||
void AutoAlign();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
164
src/ui/cuigridcell.cpp
Normal file
164
src/ui/cuigridcell.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
#include "cuigridcell.hpp"
|
||||
#include "cuigenericgrid.hpp"
|
||||
#include "cuimanager.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
cUIGridCell::cUIGridCell( cUIGridCell::CreateParams& Params ) :
|
||||
cUIComplexControl( Params )
|
||||
{
|
||||
mCells.resize( GridParent()->CollumnsCount(), NULL );
|
||||
|
||||
ApplyDefaultTheme();
|
||||
}
|
||||
|
||||
cUIGridCell::~cUIGridCell() {
|
||||
if ( cUIManager::instance()->FocusControl() == this )
|
||||
mParentCtrl->SetFocus();
|
||||
|
||||
if ( cUIManager::instance()->OverControl() == this )
|
||||
cUIManager::instance()->OverControl( mParentCtrl );
|
||||
}
|
||||
|
||||
void cUIGridCell::SetTheme( cUITheme * Theme ) {
|
||||
cUIControl::SetTheme( Theme, "gridcell" );
|
||||
}
|
||||
|
||||
cUIGenericGrid * cUIGridCell::GridParent() const {
|
||||
return reinterpret_cast<cUIGenericGrid*> ( mParentCtrl->Parent() );
|
||||
}
|
||||
|
||||
void cUIGridCell::Cell( const Uint32& CollumnIndex, cUIControl * Ctrl ) {
|
||||
eeASSERT( CollumnIndex < GridParent()->CollumnsCount() );
|
||||
|
||||
cUIGenericGrid * P = GridParent();
|
||||
|
||||
mCells[ CollumnIndex ] = Ctrl;
|
||||
|
||||
if ( Ctrl->Parent() != this )
|
||||
Ctrl->Parent( this );
|
||||
|
||||
Ctrl->Pos ( P->GetCellPos( CollumnIndex ) , 0 );
|
||||
Ctrl->Size ( P->CollumnWidth( CollumnIndex ) , P->RowHeight() );
|
||||
|
||||
Ctrl->Visible( true );
|
||||
Ctrl->Enabled( true );
|
||||
}
|
||||
|
||||
cUIControl * cUIGridCell::Cell( const Uint32& CollumnIndex ) const {
|
||||
eeASSERT( CollumnIndex < GridParent()->CollumnsCount() );
|
||||
|
||||
return mCells[ CollumnIndex ];
|
||||
}
|
||||
|
||||
void cUIGridCell::FixCell() {
|
||||
AutoSize();
|
||||
|
||||
cUIGenericGrid * P = GridParent();
|
||||
|
||||
for ( Uint32 i = 0; i < mCells.size(); i++ ) {
|
||||
mCells[i]->Pos ( P->GetCellPos( i ) , 0 );
|
||||
mCells[i]->Size ( P->CollumnWidth( i ) , P->RowHeight() );
|
||||
}
|
||||
}
|
||||
|
||||
void cUIGridCell::Update() {
|
||||
if ( mEnabled && mVisible ) {
|
||||
cUIGenericGrid * MyParent = reinterpret_cast<cUIGenericGrid*> ( Parent()->Parent() );
|
||||
Uint32 Flags = cUIManager::instance()->GetInput()->ClickTrigger();
|
||||
|
||||
if ( NULL != MyParent && MyParent->Alpha() != mAlpha ) {
|
||||
Alpha( MyParent->Alpha() );
|
||||
|
||||
for ( Uint32 i = 0; i < mCells.size(); i++ ) {
|
||||
if ( NULL != mCells[i] && mCells[i]->IsType( UI_TYPE_CONTROL_ANIM ) ) {
|
||||
reinterpret_cast<cUIControlAnim*>( mCells[i] )->Alpha( MyParent->Alpha() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( IsMouseOverMeOrChilds() ) {
|
||||
if ( Flags & EE_BUTTONS_WUWD && MyParent->VerticalScrollBar()->Visible() )
|
||||
MyParent->VerticalScrollBar()->Slider()->ManageClick( Flags );
|
||||
}
|
||||
|
||||
/*if ( ( mControlFlags & UI_CTRL_FLAG_HAS_FOCUS ) )
|
||||
LBParent->ManageKeyboard();*/
|
||||
}
|
||||
|
||||
cUIComplexControl::Update();
|
||||
}
|
||||
|
||||
|
||||
void cUIGridCell::Select() {
|
||||
cUIGenericGrid * MyParent = reinterpret_cast<cUIGenericGrid*> ( Parent()->Parent() );
|
||||
|
||||
bool wasSelected = 0 != ( mControlFlags & UI_CTRL_FLAG_SELECTED );
|
||||
|
||||
SetSkinState( cUISkinState::StateSelected );
|
||||
|
||||
mControlFlags |= UI_CTRL_FLAG_SELECTED;
|
||||
|
||||
MyParent->mSelected = MyParent->GetItemIndex( this );
|
||||
|
||||
if ( !wasSelected ) {
|
||||
MyParent->OnSelected();
|
||||
}
|
||||
}
|
||||
|
||||
void cUIGridCell::Unselect() {
|
||||
if ( mControlFlags & UI_CTRL_FLAG_SELECTED )
|
||||
mControlFlags &= ~UI_CTRL_FLAG_SELECTED;
|
||||
|
||||
SetSkinState( cUISkinState::StateNormal );
|
||||
}
|
||||
|
||||
bool cUIGridCell::Selected() const {
|
||||
return 0 != ( mControlFlags & UI_CTRL_FLAG_SELECTED );
|
||||
}
|
||||
|
||||
Uint32 cUIGridCell::OnMouseExit( const eeVector2i& Pos, const Uint32 Flags ) {
|
||||
cUIControl::OnMouseExit( Pos, Flags );
|
||||
|
||||
if ( mControlFlags & UI_CTRL_FLAG_SELECTED )
|
||||
SetSkinState( cUISkinState::StateSelected );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Uint32 cUIGridCell::OnMessage( const cUIMessage * Msg ) {
|
||||
switch( Msg->Msg() ) {
|
||||
case cUIMessage::MsgMouseEnter:
|
||||
{
|
||||
OnMouseEnter( eeVector2i(), Msg->Flags() );
|
||||
break;
|
||||
}
|
||||
case cUIMessage::MsgMouseExit:
|
||||
{
|
||||
OnMouseExit( eeVector2i(), Msg->Flags() );
|
||||
break;
|
||||
}
|
||||
case cUIMessage::MsgClick:
|
||||
{
|
||||
if ( Msg->Flags() == EE_BUTTONS_LRM ) {
|
||||
Select();
|
||||
|
||||
cUIMessage tMsg( this, cUIMessage::MsgCellClicked, Msg->Flags() );
|
||||
|
||||
MessagePost( &tMsg );
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cUIGridCell::AutoSize() {
|
||||
cUIGenericGrid * MyParent = reinterpret_cast<cUIGenericGrid*> ( Parent()->Parent() );
|
||||
|
||||
Size( MyParent->mTotalWidth, MyParent->mRowHeight );
|
||||
}
|
||||
|
||||
}}
|
||||
49
src/ui/cuigridcell.hpp
Normal file
49
src/ui/cuigridcell.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef EE_UICUIGRIDCELL_HPP
|
||||
#define EE_UICUIGRIDCELL_HPP
|
||||
|
||||
#include "cuicomplexcontrol.hpp"
|
||||
#include "tuiitemcontainer.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
class cUIGenericGrid;
|
||||
|
||||
class EE_API cUIGridCell : public cUIComplexControl {
|
||||
public:
|
||||
cUIGridCell( cUIGridCell::CreateParams& Params );
|
||||
|
||||
~cUIGridCell();
|
||||
|
||||
virtual void SetTheme( cUITheme * Theme );
|
||||
|
||||
void Cell( const Uint32& CollumnIndex, cUIControl * Ctrl );
|
||||
|
||||
cUIControl * Cell( const Uint32& CollumnIndex ) const;
|
||||
|
||||
virtual void Update();
|
||||
|
||||
bool Selected() const;
|
||||
|
||||
void Unselect();
|
||||
|
||||
void Select();
|
||||
|
||||
Uint32 OnMessage( const cUIMessage * Msg );
|
||||
|
||||
void AutoSize();
|
||||
protected:
|
||||
friend class tUIItemContainer<cUIGenericGrid>;
|
||||
friend class cUIGenericGrid;
|
||||
|
||||
std::vector<cUIControl*> mCells;
|
||||
|
||||
cUIGenericGrid * GridParent() const;
|
||||
|
||||
void FixCell();
|
||||
|
||||
Uint32 OnMouseExit( const eeVector2i& Pos, const Uint32 Flags );
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "cuilistbox.hpp"
|
||||
#include "cuimanager.hpp"
|
||||
#include "cuilistboxitem.hpp"
|
||||
#include "tuiitemcontainer.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
@@ -35,7 +37,7 @@ cUIListBox::cUIListBox( cUIListBox::CreateParams& Params ) :
|
||||
CParams.PosSet( mPaddingContainer.Left, mPaddingContainer.Top );
|
||||
CParams.Size = eeSize( mSize.Width() - mPaddingContainer.Right - mPaddingContainer.Left, mSize.Height() - mPaddingContainer.Top - mPaddingContainer.Bottom );
|
||||
CParams.Flags = Params.Flags;
|
||||
mContainer = eeNew( cUIListBoxContainer, ( CParams ) );
|
||||
mContainer = eeNew( tUIItemContainer<cUIListBox>, ( CParams ) );
|
||||
mContainer->Visible( true );
|
||||
mContainer->Enabled( true );
|
||||
|
||||
@@ -93,11 +95,11 @@ void cUIListBox::AutoPadding() {
|
||||
}
|
||||
}
|
||||
|
||||
cUIScrollBar * cUIListBox::ScrollBar() const {
|
||||
cUIScrollBar * cUIListBox::VerticalScrollBar() const {
|
||||
return mVScrollBar;
|
||||
}
|
||||
|
||||
cUIScrollBar * cUIListBox::HScrollBar() const {
|
||||
cUIScrollBar * cUIListBox::HorizontalScrollBar() const {
|
||||
return mHScrollBar;
|
||||
}
|
||||
|
||||
@@ -752,7 +754,7 @@ void cUIListBox::SelectPrev() {
|
||||
mItems[ mSelected.front() ]->Unselect();
|
||||
|
||||
if ( mItems[ SelIndex ]->Pos().y < 0 ) {
|
||||
ScrollBar()->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) );
|
||||
mVScrollBar->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) );
|
||||
|
||||
mItems[ SelIndex ]->SetFocus();
|
||||
}
|
||||
@@ -776,7 +778,7 @@ void cUIListBox::SelectNext() {
|
||||
mItems[ mSelected.front() ]->Unselect();
|
||||
|
||||
if ( mItems[ SelIndex ]->Pos().y + (Int32)RowHeight() > mContainer->Size().Height() ) {
|
||||
ScrollBar()->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) );
|
||||
mVScrollBar->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) );
|
||||
|
||||
mItems[ SelIndex ]->SetFocus();
|
||||
}
|
||||
@@ -815,7 +817,7 @@ void cUIListBox::ManageKeyboard() {
|
||||
if ( mSelected.front() != 0 ) {
|
||||
mItems[ mSelected.front() ]->Unselect();
|
||||
|
||||
ScrollBar()->Value( 0 );
|
||||
mVScrollBar->Value( 0 );
|
||||
|
||||
mItems[ 0 ]->SetFocus();
|
||||
|
||||
@@ -827,7 +829,7 @@ void cUIListBox::ManageKeyboard() {
|
||||
if ( mSelected.front() != Count() - 1 ) {
|
||||
mItems[ mSelected.front() ]->Unselect();
|
||||
|
||||
ScrollBar()->Value( 1 );
|
||||
mVScrollBar->Value( 1 );
|
||||
|
||||
mItems[ Count() - 1 ]->SetFocus();
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include "cuicontrolanim.hpp"
|
||||
#include "cuiscrollbar.hpp"
|
||||
#include "tuiitemcontainer.hpp"
|
||||
#include "cuilistboxitem.hpp"
|
||||
#include "cuilistboxcontainer.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
@@ -74,9 +74,9 @@ class EE_API cUIListBox : public cUIComplexControl {
|
||||
|
||||
bool IsMultiSelect() const;
|
||||
|
||||
cUIScrollBar * ScrollBar() const;
|
||||
cUIScrollBar * VerticalScrollBar() const;
|
||||
|
||||
cUIScrollBar * HScrollBar() const;
|
||||
cUIScrollBar * HorizontalScrollBar() const;
|
||||
|
||||
cUIListBoxItem * GetItem( const Uint32& Index ) const;
|
||||
|
||||
@@ -141,7 +141,7 @@ class EE_API cUIListBox : public cUIComplexControl {
|
||||
const UI_SCROLLBAR_MODE& HorizontalScrollMode();
|
||||
protected:
|
||||
friend class cUIListBoxItem;
|
||||
friend class cUIListBoxContainer;
|
||||
friend class tUIItemContainer<cUIListBox>;
|
||||
friend class cUIDropDownList;
|
||||
|
||||
Uint32 mRowHeight;
|
||||
@@ -149,7 +149,7 @@ class EE_API cUIListBox : public cUIComplexControl {
|
||||
UI_SCROLLBAR_MODE mHScrollMode;
|
||||
bool mSmoothScroll;
|
||||
eeRecti mPaddingContainer;
|
||||
cUIListBoxContainer * mContainer;
|
||||
tUIItemContainer<cUIListBox> * mContainer;
|
||||
cUIScrollBar * mVScrollBar;
|
||||
cUIScrollBar * mHScrollBar;
|
||||
cFont * mFont;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef EE_UICUILISTBOXCONTAINER_HPP
|
||||
#define EE_UICUILISTBOXCONTAINER_HPP
|
||||
|
||||
#include "cuicontrol.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
class cUIListBoxContainer : public cUIControl {
|
||||
public:
|
||||
cUIListBoxContainer( cUIControl::CreateParams& Params );
|
||||
|
||||
~cUIListBoxContainer();
|
||||
|
||||
void Update();
|
||||
|
||||
void DrawChilds();
|
||||
protected:
|
||||
cUIControl * OverFind( const eeVector2f& Point );
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -82,8 +82,8 @@ void cUIListBoxItem::Update() {
|
||||
Alpha( LBParent->Alpha() );
|
||||
|
||||
if ( IsMouseOver() ) {
|
||||
if ( Flags & EE_BUTTONS_WUWD && LBParent->ScrollBar()->Visible() )
|
||||
LBParent->ScrollBar()->Slider()->ManageClick( Flags );
|
||||
if ( Flags & EE_BUTTONS_WUWD && LBParent->VerticalScrollBar()->Visible() )
|
||||
LBParent->VerticalScrollBar()->Slider()->ManageClick( Flags );
|
||||
}
|
||||
|
||||
if ( ( mControlFlags & UI_CTRL_FLAG_HAS_FOCUS ) )
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
#define EE_UICUILISTBOXITEM_HPP
|
||||
|
||||
#include "cuitextbox.hpp"
|
||||
#include "tuiitemcontainer.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
class cUIListBox;
|
||||
|
||||
class EE_API cUIListBoxItem : public cUITextBox {
|
||||
public:
|
||||
cUIListBoxItem( cUITextBox::CreateParams& Params );
|
||||
@@ -21,6 +24,8 @@ class EE_API cUIListBoxItem : public cUITextBox {
|
||||
|
||||
void Select();
|
||||
protected:
|
||||
friend class tUIItemContainer<cUIListBox>;
|
||||
|
||||
virtual void OnStateChange();
|
||||
|
||||
virtual Uint32 OnMouseClick( const eeVector2i& Pos, const Uint32 Flags );
|
||||
|
||||
@@ -167,7 +167,7 @@ void cUIManager::Update() {
|
||||
|
||||
if ( pOver != mOverControl ) {
|
||||
if ( NULL != mOverControl ) {
|
||||
SendMsg( mOverControl, cUIMessage::MsgMouseEnter );
|
||||
SendMsg( mOverControl, cUIMessage::MsgMouseExit );
|
||||
mOverControl->OnMouseExit( mKM->GetMousePos(), 0 );
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ class EE_API cUIMessage {
|
||||
MsgWindowResize,
|
||||
MsgFocus,
|
||||
MsgFocusLoss,
|
||||
MsgCellClicked,
|
||||
MsgUser,
|
||||
MsgForceDWord = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
cUIMessage( cUIControl * Ctrl, const Uint32& Msg, const Uint32& Flags );
|
||||
cUIMessage( cUIControl * Ctrl, const Uint32& Msg, const Uint32& Flags = MsgForceDWord );
|
||||
|
||||
~cUIMessage();
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ namespace EE { namespace UI {
|
||||
cUISprite::cUISprite( const cUISprite::CreateParams& Params ) :
|
||||
cUIComplexControl( Params ),
|
||||
mSprite( Params.Sprite ),
|
||||
mRender( Params.SpriteRender )
|
||||
mRender( Params.SpriteRender ),
|
||||
mAlignOffset(0,0),
|
||||
mShapeLast(NULL)
|
||||
{
|
||||
mType |= UI_TYPE_GET(UI_TYPE_SPRITE);
|
||||
|
||||
@@ -30,13 +32,21 @@ void cUISprite::Draw() {
|
||||
|
||||
if ( mVisible ) {
|
||||
if ( NULL != mSprite && 0.f != mAlpha ) {
|
||||
UpdateSize();
|
||||
mSprite->Position( (eeFloat)mScreenPos.x, (eeFloat)mScreenPos.y );
|
||||
CheckShapeUpdate();
|
||||
mSprite->Position( (eeFloat)( mScreenPos.x + mAlignOffset.x ), (eeFloat)( mScreenPos.y + mAlignOffset.y ) );
|
||||
mSprite->Draw( mBlend, mRender );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cUISprite::CheckShapeUpdate() {
|
||||
if ( NULL != mSprite && NULL != mSprite->GetCurrentShape() && mSprite->GetCurrentShape() != mShapeLast ) {
|
||||
UpdateSize();
|
||||
AutoAlign();
|
||||
mShapeLast = mSprite->GetCurrentShape();
|
||||
}
|
||||
}
|
||||
|
||||
void cUISprite::Alpha( const eeFloat& alpha ) {
|
||||
cUIControlAnim::Alpha( alpha );
|
||||
|
||||
@@ -79,4 +89,35 @@ void cUISprite::UpdateSize() {
|
||||
}
|
||||
}
|
||||
|
||||
void cUISprite::AutoAlign() {
|
||||
if ( NULL == mSprite || NULL == mSprite->GetCurrentShape() )
|
||||
return;
|
||||
|
||||
cShape * tShape = mSprite->GetCurrentShape();
|
||||
|
||||
if ( HAlignGet( mFlags ) == UI_HALIGN_CENTER ) {
|
||||
mAlignOffset.x = mSize.Width() / 2 - tShape->Size().Width() / 2;
|
||||
} else if ( FontHAlignGet( mFlags ) == UI_HALIGN_RIGHT ) {
|
||||
mAlignOffset.x = mSize.Width() - tShape->Size().Width();
|
||||
} else {
|
||||
mAlignOffset.x = 0;
|
||||
}
|
||||
|
||||
if ( VAlignGet( mFlags ) == UI_VALIGN_CENTER ) {
|
||||
mAlignOffset.y = mSize.Height() / 2 - tShape->Size().Height() / 2;
|
||||
} else if ( FontVAlignGet( mFlags ) == UI_VALIGN_BOTTOM ) {
|
||||
mAlignOffset.y = mSize.Height() - tShape->Size().Height();
|
||||
} else {
|
||||
mAlignOffset.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const eeVector2i& cUISprite::AlignOffset() const {
|
||||
return mAlignOffset;
|
||||
}
|
||||
|
||||
void cUISprite::OnSizeChange() {
|
||||
AutoAlign();
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -41,11 +41,21 @@ class EE_API cUISprite : public cUIComplexControl {
|
||||
const EE_RENDERTYPE& RenderType() const;
|
||||
|
||||
void RenderType( const EE_RENDERTYPE& render );
|
||||
|
||||
const eeVector2i& AlignOffset() const;
|
||||
protected:
|
||||
cSprite * mSprite;
|
||||
EE_RENDERTYPE mRender;
|
||||
eeVector2i mAlignOffset;
|
||||
cShape * mShapeLast;
|
||||
|
||||
void UpdateSize();
|
||||
|
||||
void AutoAlign();
|
||||
|
||||
void CheckShapeUpdate();
|
||||
|
||||
virtual void OnSizeChange();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -58,6 +58,8 @@ static void LoadThemeElements() {
|
||||
UI_THEME_ELEMENTS.push_back( "textedit" );
|
||||
UI_THEME_ELEMENTS.push_back( "textedit_box" );
|
||||
UI_THEME_ELEMENTS.push_back( "tooltip" );
|
||||
UI_THEME_ELEMENTS.push_back( "genericgrid" );
|
||||
UI_THEME_ELEMENTS.push_back( "gridcell" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,39 @@
|
||||
#include "cuilistboxcontainer.hpp"
|
||||
#include "cuilistbox.hpp"
|
||||
#include "cuilistboxitem.hpp"
|
||||
#ifndef EE_UITUIITEMCONTAINER_HPP
|
||||
#define EE_UITUIITEMCONTAINER_HPP
|
||||
|
||||
#include "cuicontrol.hpp"
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
cUIListBoxContainer::cUIListBoxContainer( cUIControl::CreateParams& Params ) :
|
||||
template<class TContainer>
|
||||
class tUIItemContainer : public cUIControl {
|
||||
public:
|
||||
tUIItemContainer( cUIControl::CreateParams& Params );
|
||||
|
||||
~tUIItemContainer();
|
||||
|
||||
void Update();
|
||||
|
||||
void DrawChilds();
|
||||
protected:
|
||||
cUIControl * OverFind( const eeVector2f& Point );
|
||||
};
|
||||
|
||||
template<class TContainer>
|
||||
tUIItemContainer<TContainer>::tUIItemContainer( cUIControl::CreateParams& Params ) :
|
||||
cUIControl( Params )
|
||||
{
|
||||
DisableChildCloseCheck();
|
||||
}
|
||||
|
||||
cUIListBoxContainer::~cUIListBoxContainer()
|
||||
template<class TContainer>
|
||||
tUIItemContainer<TContainer>::~tUIItemContainer()
|
||||
{
|
||||
}
|
||||
|
||||
void cUIListBoxContainer::Update() {
|
||||
cUIListBox * LBParent = reinterpret_cast<cUIListBox*> ( Parent() );
|
||||
template<class TContainer>
|
||||
void tUIItemContainer<TContainer>::Update() {
|
||||
TContainer * LBParent = reinterpret_cast<TContainer*> ( Parent() );
|
||||
|
||||
if ( LBParent->mItems.size() ) {
|
||||
for ( Uint32 i = LBParent->mVisibleFirst; i <= LBParent->mVisibleLast; i++ ) {
|
||||
@@ -25,8 +43,9 @@ void cUIListBoxContainer::Update() {
|
||||
}
|
||||
}
|
||||
|
||||
void cUIListBoxContainer::DrawChilds() {
|
||||
cUIListBox * LBParent = reinterpret_cast<cUIListBox*> ( Parent() );
|
||||
template<class TContainer>
|
||||
void tUIItemContainer<TContainer>::DrawChilds() {
|
||||
TContainer * LBParent = reinterpret_cast<TContainer*> ( Parent() );
|
||||
|
||||
if ( LBParent->mItems.size() ) {
|
||||
for ( Uint32 i = LBParent->mVisibleFirst; i <= LBParent->mVisibleLast; i++ )
|
||||
@@ -35,8 +54,9 @@ void cUIListBoxContainer::DrawChilds() {
|
||||
}
|
||||
}
|
||||
|
||||
cUIControl * cUIListBoxContainer::OverFind( const eeVector2f& Point ) {
|
||||
cUIListBox * LBParent = reinterpret_cast<cUIListBox*> ( Parent() );
|
||||
template<class TContainer>
|
||||
cUIControl * tUIItemContainer<TContainer>::OverFind( const eeVector2f& Point ) {
|
||||
TContainer * LBParent = reinterpret_cast<TContainer*> ( Parent() );
|
||||
|
||||
cUIControl * pOver = NULL;
|
||||
|
||||
@@ -67,3 +87,5 @@ cUIControl * cUIListBoxContainer::OverFind( const eeVector2f& Point ) {
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -82,7 +82,8 @@ enum UI_CONTROL_TYPES {
|
||||
UI_TYPE_MENUSUBMENU = 20,
|
||||
UI_TYPE_SPRITE = 21,
|
||||
UI_TYPE_TEXTEDIT = 22,
|
||||
UI_TYPE_TOOLTIP = 23
|
||||
UI_TYPE_TOOLTIP = 23,
|
||||
UI_TYPE_GENERICGRID = 24
|
||||
};
|
||||
|
||||
#define UI_TYPE_GET(X) ( 1 << (X) )
|
||||
|
||||
Reference in New Issue
Block a user