Add blinkMode parameter to IGUIEnvironment::addModalScreen, so blinking can be suppressed

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6212 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2021-05-05 13:22:02 +00:00
parent af07435064
commit 678e06baeb
6 changed files with 36 additions and 8 deletions

View File

@ -1,5 +1,6 @@
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- Add blinkMode parameter to IGUIEnvironment::addModalScreen, so blinking can be suppressed
- Speedup: Avoid string copy in CXMLReaderImpl::getAttributeByName - Speedup: Avoid string copy in CXMLReaderImpl::getAttributeByName
- Fix bug in rect::clipAgainst that had caused rects completely outside to the left-top of the rect to be clipped against ending up with both corners outside. - Fix bug in rect::clipAgainst that had caused rects completely outside to the left-top of the rect to be clipped against ending up with both corners outside.
It still worked for UI in most cases as the resulting rectangle still had an area of 0. It still worked for UI in most cases as the resulting rectangle still had an area of 0.

View File

@ -260,10 +260,14 @@ public:
Note that it usually works badly to pass the modal screen already as parent when creating Note that it usually works badly to pass the modal screen already as parent when creating
a new element. It's better to add that new element later to the modal screen with addChild. a new element. It's better to add that new element later to the modal screen with addChild.
\param parent Parent gui element of the modal. \param parent Parent gui element of the modal.
\param blinkMode Bitset of when to blink (can be combined)
0 = never
1 = focus changes
2 = Left mouse button pressed down
\return Pointer to the created modal. Returns 0 if an error occurred. \return Pointer to the created modal. Returns 0 if an error occurred.
This pointer should not be dropped. See IReferenceCounted::drop() for This pointer should not be dropped. See IReferenceCounted::drop() for
more information. */ more information. */
virtual IGUIElement* addModalScreen(IGUIElement* parent) = 0; virtual IGUIElement* addModalScreen(IGUIElement* parent, int blinkMode = 3) = 0;
//! Adds a message box. //! Adds a message box.
/** \param caption Text to be displayed the title of the message box. /** \param caption Text to be displayed the title of the message box.

View File

@ -1073,11 +1073,12 @@ IGUIWindow* CGUIEnvironment::addWindow(const core::rect<s32>& rectangle, bool mo
//! adds a modal screen. The returned pointer must not be dropped. //! adds a modal screen. The returned pointer must not be dropped.
IGUIElement* CGUIEnvironment::addModalScreen(IGUIElement* parent) IGUIElement* CGUIEnvironment::addModalScreen(IGUIElement* parent, int blinkMode)
{ {
parent = parent ? parent : this; parent = parent ? parent : this;
IGUIElement *win = new CGUIModalScreen(this, parent, -1); CGUIModalScreen *win = new CGUIModalScreen(this, parent, -1);
win->setBlinkMode(blinkMode);
win->drop(); win->drop();
return win; return win;

View File

@ -97,7 +97,7 @@ public:
const wchar_t* text=0, IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_; const wchar_t* text=0, IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;
//! adds a modal screen. The returned pointer must not be dropped. //! adds a modal screen. The returned pointer must not be dropped.
virtual IGUIElement* addModalScreen(IGUIElement* parent) _IRR_OVERRIDE_; virtual IGUIElement* addModalScreen(IGUIElement* parent, int blinkMode) _IRR_OVERRIDE_;
//! Adds a message box. //! Adds a message box.
virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0, virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0,

View File

@ -18,6 +18,7 @@ namespace gui
//! constructor //! constructor
CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* parent, s32 id) CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* parent, s32 id)
: IGUIElement(EGUIET_MODAL_SCREEN, environment, parent, id, core::recti(0, 0, parent->getAbsolutePosition().getWidth(), parent->getAbsolutePosition().getHeight()) ), : IGUIElement(EGUIET_MODAL_SCREEN, environment, parent, id, core::recti(0, 0, parent->getAbsolutePosition().getWidth(), parent->getAbsolutePosition().getHeight()) ),
BlinkMode(3),
MouseDownTime(0) MouseDownTime(0)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -90,7 +91,8 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
{ {
Environment->removeFocus(0); // can't setFocus otherwise at it still has focus here Environment->removeFocus(0); // can't setFocus otherwise at it still has focus here
Environment->setFocus(event.GUIEvent.Element); Environment->setFocus(event.GUIEvent.Element);
MouseDownTime = os::Timer::getTime(); if ( BlinkMode&1 )
MouseDownTime = os::Timer::getTime();
return true; return true;
} }
if ( !canTakeFocus(event.GUIEvent.Caller)) if ( !canTakeFocus(event.GUIEvent.Caller))
@ -112,7 +114,7 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
else else
Environment->setFocus(this); Environment->setFocus(this);
} }
else else if ( BlinkMode&1 )
{ {
MouseDownTime = os::Timer::getTime(); MouseDownTime = os::Timer::getTime();
} }
@ -130,7 +132,7 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
} }
break; break;
case EET_MOUSE_INPUT_EVENT: case EET_MOUSE_INPUT_EVENT:
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN && (BlinkMode & 2))
{ {
MouseDownTime = os::Timer::getTime(); MouseDownTime = os::Timer::getTime();
} }
@ -153,7 +155,7 @@ void CGUIModalScreen::draw()
return; return;
u32 now = os::Timer::getTime(); u32 now = os::Timer::getTime();
if (now - MouseDownTime < 300 && (now / 70)%2) if (BlinkMode && now - MouseDownTime < 300 && (now / 70)%2)
{ {
core::list<IGUIElement*>::Iterator it = Children.begin(); core::list<IGUIElement*>::Iterator it = Children.begin();
core::rect<s32> r; core::rect<s32> r;
@ -219,12 +221,16 @@ void CGUIModalScreen::updateAbsolutePosition()
void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
{ {
IGUIElement::serializeAttributes(out,options); IGUIElement::serializeAttributes(out,options);
out->addInt("BlinkMode", BlinkMode );
} }
//! Reads attributes of the element //! Reads attributes of the element
void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
{ {
IGUIElement::deserializeAttributes(in, options); IGUIElement::deserializeAttributes(in, options);
BlinkMode = in->getAttributeAsInt("BlinkMode", BlinkMode);
} }

View File

@ -52,11 +52,27 @@ namespace gui
//! Reads attributes of the element //! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) _IRR_OVERRIDE_; virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) _IRR_OVERRIDE_;
//! Set when to blink.
//! Bitset of following values (can be combined)
//! 0 = never
//! 1 = focus changes
//! 2 = Left mouse button pressed down
void setBlinkMode(u32 blink)
{
BlinkMode = blink;
}
u32 getBlinkMode() const
{
return BlinkMode;
}
protected: protected:
virtual bool canTakeFocus(IGUIElement* target) const; virtual bool canTakeFocus(IGUIElement* target) const;
private: private:
u32 BlinkMode;
u32 MouseDownTime; u32 MouseDownTime;
}; };