Avoid creating a VertexBuffer for UIBackgroundDrawables with no radius.

EventDispatcher: Double click is only valid if the second click is near the first one.
Added Input events for file drop and text drop.
InputTextBuffer allows to paste over selected text.
This commit is contained in:
Martín Lucas Golini
2020-05-10 03:38:37 -03:00
parent 9a093fc775
commit 730d0ff30b
9 changed files with 54 additions and 17 deletions

View File

@@ -30,9 +30,9 @@
<item>Test 3</item>
<item>Test 4</item><item>Test 5</item><item>Test 6</item><item>Test 7</item><item>Test 8</item>
</ComboBox>
<TextInput layout_width="300dp" layout_height="wrap_content" margin-top="8dp" text="Testing TextInput&#10;Multi line&#10;Texts" />
<TextInput layout_width="300dp" layout_height="wrap_content" margin-top="8dp" text="Testing TextInput" />
<TextInputPassword layout_width="300dp" layout_height="wrap_content" margin-top="8dp" hint="Password" />
<TextEdit layout_width="300dp" layout_height="60dp" margin-top="8dp" text="Testing TextEdit Text Texted with text as text is the way to test the text.&#10;Multi line&#10;Texts" />
<TextEdit layout_width="300dp" layout_height="100dp" margin-top="8dp" text="Testing TextEdit Text Texted with text as text is the way to test the text.&#10;Multi line&#10;Texts" />
<SelectButton layout_width="wrap_content" layout_height="wrap_content" text="Testing SelectButton" margin-top="8dp" />
<SpinBox id="spinbox" layout_width="200dp" layout_height="wrap_content" margin-top="8dp" />
<!-- <TextureRegion layout_width="32dp" layout_height="32dp" src="" margin-top="8dp" margin-top="8dp" /> -->

View File

@@ -92,6 +92,7 @@ class EE_API EventDispatcher {
Vector2i mMousePosi;
Vector2f mLastMousePos;
Vector2i mMouseDownPos;
Vector2i mClickPos;
Int32 mCbId;
bool mFirstPress;
Node* mNodeDragging;

View File

@@ -151,10 +151,10 @@ class EE_API Input {
const Uint32& getDoubleClickTrigger() const;
/** @return The double click interval in milliseconds ( default 500 ms ) */
const Uint32& getDoubleClickInterval() const;
const Time& getDoubleClickInterval() const;
/** Set the double click interval in milliseconds */
void setDoubleClickInterval( const Uint32& Interval );
void setDoubleClickInterval( const Time& Interval );
/** Clean the keyboard and mouse states */
void cleanStates();
@@ -197,8 +197,8 @@ class EE_API Input {
Uint32 mClickTrigger;
Uint32 mDoubleClickTrigger;
Uint32 mInputMod;
Uint32 mDoubleClickInterval; //!< Determine the double click inverval in milliseconds ( default
//!< 500 ms )
Time mDoubleClickInterval; /// Determine the double click inverval in milliseconds ( default 400
/// ms )
Uint32 mLastButtonLeftClicked;
Uint32 mLastButtonRightClicked;
Uint32 mLastButtonMiddleClicked;

View File

@@ -141,6 +141,16 @@ class InputEvent {
Uint8 type;
};
/** File dropped event */
struct FileDroppedEvent {
char* file;
};
/** Text dropped event */
struct TextDroppedEvent {
char* text;
};
/** The "quit requested" event */
struct QuitEvent {
Uint8 type;
@@ -182,6 +192,8 @@ class InputEvent {
SysWM,
VideoResize,
VideoExpose,
FileDropped,
TextDropped,
EventUser,
EventCount = EventUser - 1
};
@@ -203,6 +215,8 @@ class InputEvent {
JoyButtonEvent jbutton;
ResizeEvent resize;
ExposeEvent expose;
FileDroppedEvent file;
TextDroppedEvent textdrop;
QuitEvent quit;
UserEvent user;
SysWMEvent syswm;

View File

@@ -128,12 +128,15 @@ void EventDispatcher::update( const Time& time ) {
lastFocusControl->onMouseClick( mMousePosi, mInput->getClickTrigger() );
sendMsg( lastFocusControl, NodeMessage::Click, mInput->getClickTrigger() );
if ( mInput->getDoubleClickTrigger() ) {
if ( mInput->getDoubleClickTrigger() &&
mClickPos.distance( mMousePosi ) < 10 ) {
lastFocusControl->onMouseDoubleClick( mMousePosi,
mInput->getDoubleClickTrigger() );
sendMsg( lastFocusControl, NodeMessage::DoubleClick,
mInput->getDoubleClickTrigger() );
}
mClickPos = mMousePosi;
}
}
}

View File

@@ -12,7 +12,7 @@ UIBackgroundDrawable* UIBackgroundDrawable::New( UINode* owner ) {
UIBackgroundDrawable::UIBackgroundDrawable( UINode* owner ) :
Drawable( UIBACKGROUNDDRAWABLE ),
mOwner( owner ),
mVertexBuffer( VertexBuffer::NewVertexArray( VERTEX_FLAGS_PRIMITIVE, PRIMITIVE_TRIANGLE_FAN ) ),
mVertexBuffer( nullptr ),
mNeedsUpdate( false ),
mNeedsRadiusUpdate( false ),
mColorNeedsUpdate( false ) {}
@@ -44,7 +44,7 @@ void UIBackgroundDrawable::draw( const Vector2f& position, const Sizef& size ) {
update();
}
if ( hasRadius() ) {
if ( hasRadius() && mVertexBuffer ) {
mVertexBuffer->bind();
mVertexBuffer->draw();
mVertexBuffer->unbind();
@@ -152,7 +152,13 @@ void UIBackgroundDrawable::onPositionChange() {
void UIBackgroundDrawable::update() {
updateRadiuses();
Borders::createBackground( mVertexBuffer, mRadiuses, mPosition, mSize, mColor );
if ( hasRadius() ) {
if ( nullptr == mVertexBuffer ) {
mVertexBuffer =
VertexBuffer::NewVertexArray( VERTEX_FLAGS_PRIMITIVE, PRIMITIVE_TRIANGLE_FAN );
}
Borders::createBackground( mVertexBuffer, mRadiuses, mPosition, mSize, mColor );
}
mColorNeedsUpdate = false;
mNeedsRadiusUpdate = false;
mNeedsUpdate = false;

View File

@@ -308,6 +308,16 @@ void InputSDL::update() {
EEEvent.syswm.msg = (InputEvent::SysWMmsg*)SDLEvent.syswm.msg;
break;
}
case SDL_DROPFILE: {
EEEvent.Type = InputEvent::FileDropped;
EEEvent.file.file = SDLEvent.drop.file;
break;
}
case SDL_DROPTEXT: {
EEEvent.Type = InputEvent::TextDropped;
EEEvent.textdrop.text = SDLEvent.drop.file;
break;
}
default: {
if ( SDLEvent.type >= SDL_USEREVENT && SDLEvent.type < SDL_LASTEVENT ) {
EEEvent.Type = InputEvent::EventUser + SDLEvent.type - SDL_USEREVENT;
@@ -324,6 +334,10 @@ void InputSDL::update() {
if ( InputEvent::NoEvent != EEEvent.Type ) {
processEvent( &EEEvent );
}
if ( InputEvent::FileDropped == EEEvent.Type || InputEvent::TextDropped == EEEvent.Type ) {
SDL_free( SDLEvent.drop.file );
}
}
InputEvent endProcessingEvent;

View File

@@ -11,7 +11,7 @@ Input::Input( EE::Window::Window* window, JoystickManager* joystickmanager ) :
mClickTrigger( 0 ),
mDoubleClickTrigger( 0 ),
mInputMod( 0 ),
mDoubleClickInterval( 400 ),
mDoubleClickInterval( Milliseconds( 400 ) ),
mLastButtonLeftClicked( 0 ),
mLastButtonRightClicked( 0 ),
mLastButtonMiddleClicked( 0 ),
@@ -116,7 +116,7 @@ void Input::processEvent( InputEvent* Event ) {
mTClick = mLastButtonLeftClick - mLastButtonLeftClicked;
if ( mTClick < mDoubleClickInterval && mTClick > 0 ) {
if ( mTClick < mDoubleClickInterval.asMilliseconds() && mTClick > 0 ) {
mDoubleClickTrigger |= EE_BUTTON_MASK( EE_BUTTON_LEFT );
mLastButtonLeftClick = 0;
mLastButtonLeftClicked = 0;
@@ -127,7 +127,7 @@ void Input::processEvent( InputEvent* Event ) {
mTClick = mLastButtonRightClick - mLastButtonRightClicked;
if ( mTClick < mDoubleClickInterval && mTClick > 0 ) {
if ( mTClick < mDoubleClickInterval.asMilliseconds() && mTClick > 0 ) {
mDoubleClickTrigger |= EE_BUTTON_MASK( EE_BUTTON_RIGHT );
mLastButtonRightClick = 0;
mLastButtonRightClicked = 0;
@@ -138,7 +138,7 @@ void Input::processEvent( InputEvent* Event ) {
mTClick = mLastButtonMiddleClick - mLastButtonMiddleClicked;
if ( mTClick < mDoubleClickInterval && mTClick > 0 ) {
if ( mTClick < mDoubleClickInterval.asMilliseconds() && mTClick > 0 ) {
mDoubleClickTrigger |= EE_BUTTON_MASK( EE_BUTTON_MIDDLE );
mLastButtonMiddleClick = 0;
mLastButtonMiddleClicked = 0;
@@ -400,11 +400,11 @@ const Uint32& Input::getDoubleClickTrigger() const {
return mDoubleClickTrigger;
}
const Uint32& Input::getDoubleClickInterval() const {
const Time& Input::getDoubleClickInterval() const {
return mDoubleClickInterval;
}
void Input::setDoubleClickInterval( const Uint32& Interval ) {
void Input::setDoubleClickInterval( const Time& Interval ) {
mDoubleClickInterval = Interval;
}

View File

@@ -319,7 +319,6 @@ void InputTextBuffer::update( InputEvent* Event ) {
Event->key.keysym.sym == KEY_DELETE ) ||
keyChar == KEY_BACKSPACE ) {
removeSelection();
break;
}
}