mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-05 14:29:24 +03:00
Some improvements to the UI.
cTextCache setting Color by character fixed. cUIDropDownList now takes the UI_TOUCH_DRAG_ENABLED flag. cUIDropDownList shows the list above the control if the list can't be seen complete dropped below. cUIManager ignores clicks events when some UI_TOUCH_DRAG_ENABLED control was dragging before the click was released.
This commit is contained in:
@@ -84,6 +84,15 @@ class EE_API cUIManager {
|
||||
cUIControl * LossFocusControl() const;
|
||||
|
||||
const bool& IsShootingDown() const;
|
||||
|
||||
/** @return The position of the mouse when the event MouseDown was fired last time.
|
||||
** Useful to compare the mouse position of the MouseClick event
|
||||
*/
|
||||
const eeVector2i& GetMouseDownPos() const;
|
||||
|
||||
void SetControlDragging( bool dragging );
|
||||
|
||||
const bool& IsControlDragging() const;
|
||||
protected:
|
||||
friend class cUIControl;
|
||||
friend class cUIWindow;
|
||||
@@ -105,10 +114,12 @@ class EE_API cUIManager {
|
||||
Uint32 mFlags;
|
||||
eeColorA mHighlightFocusColor;
|
||||
eeColorA mHighlightOverColor;
|
||||
eeVector2i mMouseDownPos;
|
||||
|
||||
bool mInit;
|
||||
bool mFirstPress;
|
||||
bool mShootingDown;
|
||||
bool mControlDragging;
|
||||
|
||||
cUIManager();
|
||||
|
||||
|
||||
@@ -95,10 +95,14 @@ void cTextCache::Color( const eeColorA& color ) {
|
||||
void cTextCache::Color( const eeColorA& color, Uint32 from, Uint32 to ) {
|
||||
std::size_t s = mText.size();
|
||||
|
||||
if ( to >= s ) { to = s - 1; }
|
||||
if ( to >= s ) {
|
||||
to = s - 1;
|
||||
}
|
||||
|
||||
if ( from <= to && from < s && to < s ) {
|
||||
for ( Uint32 i = from * EE_QUAD_VERTEX; i < to * EE_QUAD_VERTEX; i++ ) {
|
||||
if ( from <= to && from < s && to <= s ) {
|
||||
size_t rto = ( to * EE_QUAD_VERTEX ) + EE_QUAD_VERTEX;
|
||||
|
||||
for ( Uint32 i = from * EE_QUAD_VERTEX; i < rto; i++ ) {
|
||||
mColors[ i ] = color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,19 @@ cUIDropDownList::cUIDropDownList( cUIDropDownList::CreateParams& Params ) :
|
||||
ApplyDefaultTheme();
|
||||
|
||||
if ( NULL == mListBox ) {
|
||||
Uint32 flags = UI_CLIP_ENABLE | UI_AUTO_PADDING;
|
||||
|
||||
if ( Params.Flags & UI_TOUCH_DRAG_ENABLED )
|
||||
flags |= UI_TOUCH_DRAG_ENABLED;
|
||||
|
||||
cUITheme * Theme = cUIThemeManager::instance()->DefaultTheme();
|
||||
|
||||
if ( NULL != Theme ) {
|
||||
mListBox = Theme->CreateListBox( NULL, eeSize( mSize.Width(), mMinNumVisibleItems * mSize.Height() ) );
|
||||
mListBox = Theme->CreateListBox( NULL, eeSize( mSize.Width(), mMinNumVisibleItems * mSize.Height() ),eeVector2i(), flags );
|
||||
} else {
|
||||
cUIListBox::CreateParams LBParams;
|
||||
LBParams.Size = eeSize( mSize.Width(), mMinNumVisibleItems * mSize.Height() );
|
||||
LBParams.Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING;
|
||||
LBParams.Flags = flags;
|
||||
LBParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 );
|
||||
mListBox = eeNew( cUIListBox, ( LBParams ) );
|
||||
}
|
||||
@@ -96,8 +101,11 @@ void cUIDropDownList::ShowListBox() {
|
||||
eeVector2i Pos = mScreenPos;
|
||||
Pos.y += mSize.Height();
|
||||
|
||||
mListBox->UpdateScreenPos();
|
||||
mListBox->UpdateQuad();
|
||||
mListBox->Parent()->ScreenToControl( Pos );
|
||||
mListBox->Pos( Pos );
|
||||
mListBox->UpdateQuad();
|
||||
|
||||
if ( mListBox->Count() ) {
|
||||
eeRecti tPadding = mListBox->PaddingContainer();
|
||||
@@ -108,6 +116,18 @@ void cUIDropDownList::ShowListBox() {
|
||||
mListBox->Size( mSize.Width(), (Int32)( mListBox->Count() * mListBox->RowHeight() ) + tPadding.Top + tPadding.Bottom );
|
||||
}
|
||||
|
||||
eeRectf aabb( mListBox->GetPolygon().ToAABB() );
|
||||
eeRecti aabbi( aabb.Left, aabb.Top, aabb.Right, aabb.Bottom );
|
||||
|
||||
if ( !cUIManager::instance()->MainControl()->GetScreenRect().Contains( aabbi ) )
|
||||
{
|
||||
Pos = mScreenPos;
|
||||
Pos.y -= mListBox->Size().Height();
|
||||
|
||||
mListBox->Parent()->ScreenToControl( Pos );
|
||||
mListBox->Pos( Pos );
|
||||
}
|
||||
|
||||
Show();
|
||||
|
||||
mListBox->SetFocus();
|
||||
|
||||
@@ -568,6 +568,7 @@ void cUIGenericGrid::Update() {
|
||||
// Mouse Not Down
|
||||
if ( !( Press & EE_BUTTON_LMASK ) ) {
|
||||
WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 );
|
||||
cUIManager::instance()->SetControlDragging( false );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -581,6 +582,8 @@ void cUIGenericGrid::Update() {
|
||||
mTouchDragAcceleration += Elapsed().AsMilliseconds() * diff.y * mTouchDragDeceleration;
|
||||
|
||||
mTouchDragPoint = Pos;
|
||||
|
||||
cUIManager::instance()->SetControlDragging( true );
|
||||
} else {
|
||||
mTouchDragAcceleration -= Elapsed().AsMilliseconds() * mTouchDragAcceleration * 0.01f;
|
||||
}
|
||||
@@ -598,6 +601,7 @@ void cUIGenericGrid::Update() {
|
||||
// Mouse Up
|
||||
if ( ( LPress & EE_BUTTON_LMASK ) && !( Press & EE_BUTTON_LMASK ) ) {
|
||||
WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 );
|
||||
cUIManager::instance()->SetControlDragging( false );
|
||||
}
|
||||
|
||||
// Deaccelerate
|
||||
|
||||
@@ -960,6 +960,7 @@ void cUIListBox::Update() {
|
||||
// Mouse Not Down
|
||||
if ( !( Press & EE_BUTTON_LMASK ) ) {
|
||||
WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 );
|
||||
cUIManager::instance()->SetControlDragging( false );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -973,6 +974,8 @@ void cUIListBox::Update() {
|
||||
mTouchDragAcceleration += Elapsed().AsMilliseconds() * diff.y * mTouchDragDeceleration;
|
||||
|
||||
mTouchDragPoint = Pos;
|
||||
|
||||
cUIManager::instance()->SetControlDragging( true );
|
||||
} else {
|
||||
mTouchDragAcceleration -= Elapsed().AsMilliseconds() * mTouchDragAcceleration * 0.01f;
|
||||
}
|
||||
@@ -990,6 +993,7 @@ void cUIListBox::Update() {
|
||||
// Mouse Up
|
||||
if ( ( LPress & EE_BUTTON_LMASK ) && !( Press & EE_BUTTON_LMASK ) ) {
|
||||
WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 );
|
||||
cUIManager::instance()->SetControlDragging( false );
|
||||
}
|
||||
|
||||
// Deaccelerate
|
||||
|
||||
@@ -181,6 +181,8 @@ void cUIManager::SendMsg( cUIControl * Ctrl, const Uint32& Msg, const Uint32& Fl
|
||||
void cUIManager::Update() {
|
||||
mElapsed = mWindow->Elapsed();
|
||||
|
||||
bool wasDraggingControl = IsControlDragging();
|
||||
|
||||
mControl->Update();
|
||||
|
||||
cUIControl * pOver = mControl->OverFind( mKM->GetMousePosf() );
|
||||
@@ -204,15 +206,13 @@ void cUIManager::Update() {
|
||||
|
||||
if ( mKM->PressTrigger() ) {
|
||||
if ( NULL != mOverControl ) {
|
||||
if ( mOverControl != mFocusControl )
|
||||
FocusControl( mOverControl );
|
||||
|
||||
mOverControl->OnMouseDown( mKM->GetMousePos(), mKM->PressTrigger() );
|
||||
SendMsg( mOverControl, cUIMessage::MsgMouseDown, mKM->PressTrigger() );
|
||||
}
|
||||
|
||||
if ( !mFirstPress ) {
|
||||
mDownControl = mOverControl;
|
||||
mMouseDownPos = mKM->GetMousePos();
|
||||
|
||||
mFirstPress = true;
|
||||
}
|
||||
@@ -220,16 +220,21 @@ void cUIManager::Update() {
|
||||
|
||||
if ( mKM->ReleaseTrigger() ) {
|
||||
if ( NULL != mFocusControl ) {
|
||||
mFocusControl->OnMouseUp( mKM->GetMousePos(), mKM->ReleaseTrigger() );
|
||||
SendMsg( mFocusControl, cUIMessage::MsgMouseUp, mKM->ReleaseTrigger() );
|
||||
if ( !wasDraggingControl ) {
|
||||
if ( mOverControl != mFocusControl )
|
||||
FocusControl( mOverControl );
|
||||
|
||||
if ( mDownControl == mOverControl && mKM->ClickTrigger() ) {
|
||||
SendMsg( mFocusControl, cUIMessage::MsgClick, mKM->ClickTrigger() );
|
||||
mFocusControl->OnMouseClick( mKM->GetMousePos(), mKM->ClickTrigger() );
|
||||
mFocusControl->OnMouseUp( mKM->GetMousePos(), mKM->ReleaseTrigger() );
|
||||
SendMsg( mFocusControl, cUIMessage::MsgMouseUp, mKM->ReleaseTrigger() );
|
||||
|
||||
if ( mKM->DoubleClickTrigger() ) {
|
||||
SendMsg( mFocusControl, cUIMessage::MsgDoubleClick, mKM->DoubleClickTrigger() );
|
||||
mFocusControl->OnMouseDoubleClick( mKM->GetMousePos(), mKM->DoubleClickTrigger() );
|
||||
if ( mDownControl == mOverControl && mKM->ClickTrigger() ) {
|
||||
SendMsg( mFocusControl, cUIMessage::MsgClick, mKM->ClickTrigger() );
|
||||
mFocusControl->OnMouseClick( mKM->GetMousePos(), mKM->ClickTrigger() );
|
||||
|
||||
if ( mKM->DoubleClickTrigger() ) {
|
||||
SendMsg( mFocusControl, cUIMessage::MsgDoubleClick, mKM->DoubleClickTrigger() );
|
||||
mFocusControl->OnMouseDoubleClick( mKM->GetMousePos(), mKM->DoubleClickTrigger() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,6 +377,10 @@ const bool& cUIManager::IsShootingDown() const {
|
||||
return mShootingDown;
|
||||
}
|
||||
|
||||
const eeVector2i &cUIManager::GetMouseDownPos() const {
|
||||
return mMouseDownPos;
|
||||
}
|
||||
|
||||
void cUIManager::AddToCloseQueue( cUIControl * Ctrl ) {
|
||||
eeASSERT( NULL != Ctrl );
|
||||
|
||||
@@ -425,4 +434,12 @@ void cUIManager::CheckClose() {
|
||||
}
|
||||
}
|
||||
|
||||
void cUIManager::SetControlDragging( bool dragging ) {
|
||||
mControlDragging = dragging;
|
||||
}
|
||||
|
||||
const bool& cUIManager::IsControlDragging() const {
|
||||
return mControlDragging;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user