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

@ -1,5 +1,6 @@
--------------------------
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
- 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.

@ -260,10 +260,14 @@ public:
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.
\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.
This pointer should not be dropped. See IReferenceCounted::drop() for
more information. */
virtual IGUIElement* addModalScreen(IGUIElement* parent) = 0;
virtual IGUIElement* addModalScreen(IGUIElement* parent, int blinkMode = 3) = 0;
//! Adds a message box.
/** \param caption Text to be displayed the title of the message box.

@ -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.
IGUIElement* CGUIEnvironment::addModalScreen(IGUIElement* parent)
IGUIElement* CGUIEnvironment::addModalScreen(IGUIElement* parent, int blinkMode)
{
parent = parent ? parent : this;
IGUIElement *win = new CGUIModalScreen(this, parent, -1);
CGUIModalScreen *win = new CGUIModalScreen(this, parent, -1);
win->setBlinkMode(blinkMode);
win->drop();
return win;

@ -97,7 +97,7 @@ public:
const wchar_t* text=0, IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;
//! 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.
virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0,

@ -18,6 +18,7 @@ namespace gui
//! constructor
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()) ),
BlinkMode(3),
MouseDownTime(0)
{
#ifdef _DEBUG
@ -90,6 +91,7 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
{
Environment->removeFocus(0); // can't setFocus otherwise at it still has focus here
Environment->setFocus(event.GUIEvent.Element);
if ( BlinkMode&1 )
MouseDownTime = os::Timer::getTime();
return true;
}
@ -112,7 +114,7 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
else
Environment->setFocus(this);
}
else
else if ( BlinkMode&1 )
{
MouseDownTime = os::Timer::getTime();
}
@ -130,7 +132,7 @@ bool CGUIModalScreen::OnEvent(const SEvent& event)
}
break;
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();
}
@ -153,7 +155,7 @@ void CGUIModalScreen::draw()
return;
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::rect<s32> r;
@ -219,12 +221,16 @@ void CGUIModalScreen::updateAbsolutePosition()
void CGUIModalScreen::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
{
IGUIElement::serializeAttributes(out,options);
out->addInt("BlinkMode", BlinkMode );
}
//! Reads attributes of the element
void CGUIModalScreen::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
{
IGUIElement::deserializeAttributes(in, options);
BlinkMode = in->getAttributeAsInt("BlinkMode", BlinkMode);
}

@ -52,11 +52,27 @@ namespace gui
//! Reads attributes of the element
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:
virtual bool canTakeFocus(IGUIElement* target) const;
private:
u32 BlinkMode;
u32 MouseDownTime;
};