28 void Window::initialiseOverride()
30 Base::initialiseOverride();
33 setNeedKeyFocus(
true);
36 (std::numeric_limits<int>::min)(),
37 (std::numeric_limits<int>::min)(),
38 (std::numeric_limits<int>::max)(),
39 (std::numeric_limits<int>::max)());
41 bool main_move =
false;
42 if (isUserString(
"MainMove"))
44 setUserString(
"Scale",
"1 1 0 0");
48 if (getClientWidget() !=
nullptr)
52 getClientWidget()->setUserString(
"Scale",
"1 1 0 0");
53 getClientWidget()->eventMouseButtonPressed +=
newDelegate(
this, &Window::notifyMousePressed);
54 getClientWidget()->eventMouseButtonReleased +=
newDelegate(
this, &Window::notifyMouseReleased);
55 getClientWidget()->eventMouseDrag +=
newDelegate(
this, &Window::notifyMouseDrag);
60 assignWidget(mWidgetCaption,
"Caption");
61 if (mWidgetCaption !=
nullptr)
63 mWidgetCaption->setUserString(
"Scale",
"1 1 0 0");
64 mWidgetCaption->eventMouseButtonPressed +=
newDelegate(
this, &Window::notifyMousePressed);
65 mWidgetCaption->eventMouseButtonReleased +=
newDelegate(
this, &Window::notifyMouseReleased);
66 mWidgetCaption->eventMouseDrag +=
newDelegate(
this, &Window::notifyMouseDrag);
70 for (
auto& button : buttons)
72 button->eventMouseButtonClick +=
newDelegate(
this, &Window::notifyPressedButtonEvent);
76 for (
auto&
action : actions)
78 action->eventMouseButtonPressed +=
newDelegate(
this, &Window::notifyMousePressed);
79 action->eventMouseButtonReleased +=
newDelegate(
this, &Window::notifyMouseReleased);
84 constexpr size_t countNames = 8;
85 const std::array<std::pair<std::string_view, std::string_view>, countNames> resizers{
86 {{
"ResizeLeftTop",
"Left Top"},
88 {
"ResizeRightTop",
"Right Top"},
89 {
"ResizeRight",
"Right"},
90 {
"ResizeRightBottom",
"Right Bottom"},
91 {
"ResizeBottom",
"Bottom"},
92 {
"ResizeLeftBottom",
"Left Bottom"},
93 {
"ResizeLeft",
"Left"}}};
95 for (
const auto& resizer : resizers)
97 Widget* widget =
nullptr;
98 assignWidget(widget, resizer.first);
99 if (widget !=
nullptr)
101 widget->eventMouseButtonPressed +=
newDelegate(
this, &Window::notifyMousePressed);
102 widget->eventMouseButtonReleased +=
newDelegate(
this, &Window::notifyMouseReleased);
103 widget->eventMouseDrag +=
newDelegate(
this, &Window::notifyMouseDrag);
104 widget->eventMouseWheel +=
newDelegate(
this, &Window::notifyMouseWheel);
105 widget->setUserString(
"Action", resizer.second);
110 void Window::shutdownOverride()
112 mWidgetCaption =
nullptr;
114 Base::shutdownOverride();
117 void Window::onMouseChangeRootFocus(
bool _focus)
119 mMouseRootFocus = _focus;
122 Base::onMouseChangeRootFocus(_focus);
125 void Window::onKeyChangeRootFocus(
bool _focus)
127 mKeyRootFocus = _focus;
130 Base::onKeyChangeRootFocus(_focus);
133 void Window::onMouseDrag(
int _left,
int _top, MouseButton _id)
136 notifyMouseDrag(
this, _left, _top, _id);
138 Base::onMouseDrag(_left, _top, _id);
141 void Window::onMouseButtonPressed(
int _left,
int _top, MouseButton _id)
143 notifyMousePressed(
this, _left, _top, _id);
145 Base::onMouseButtonPressed(_left, _top, _id);
148 void Window::onMouseButtonReleased(
int _left,
int _top, MouseButton _id)
150 notifyMouseReleased(
this, _left, _top, _id);
152 Base::onMouseButtonReleased(_left, _top, _id);
155 void Window::notifyMousePressed(MyGUI::Widget* _sender,
int _left,
int _top, MouseButton _id)
157 if (MouseButton::Left == _id)
159 mPreActionCoord = mCoord;
160 mCurrentActionScale = _getActionScale(_sender);
161 if (mCurrentActionScale.width != 0 || mCurrentActionScale.height != 0)
162 mPreActionAnchor = localToLayer(getResizeAnchor());
166 void Window::notifyPressedButtonEvent(MyGUI::Widget* _sender)
168 eventWindowButtonPressed(
this, _sender->getUserString(
"Event"));
171 void Window::notifyMouseDrag(MyGUI::Widget*,
int,
int, MouseButton _id)
173 if (_id != MouseButton::Left || mCurrentActionScale.empty())
176 const InputManager& input = InputManager::getInstance();
177 const IntPoint screenDelta = input.getMousePositionByLayer() - input.getLastPressedPosition(MouseButton::Left);
179 const bool moveOnly = mCurrentActionScale.width == 0 && mCurrentActionScale.height == 0;
180 const Widget* axes = moveOnly ? getParent() : this;
181 const IntPoint localDelta = axes ? axes->unrotateVector(screenDelta) : screenDelta;
184 mCurrentActionScale.left * localDelta.left,
185 mCurrentActionScale.top * localDelta.top,
186 mCurrentActionScale.width * localDelta.left,
187 mCurrentActionScale.height * localDelta.top);
188 const IntCoord requestedCoord = mPreActionCoord + coordDelta;
191 setPosition(requestedCoord.point());
192 else if (mCurrentActionScale.left == 0 && mCurrentActionScale.top == 0)
193 setSize(requestedCoord.size());
195 setCoord(requestedCoord);
198 restoreResizeAnchor();
201 eventWindowChangeCoord(
this);
204 void Window::updateAlpha()
212 else if (mMouseRootFocus)
217 ControllerFadeAlpha* controller = createControllerFadeAlpha(alpha,
WINDOW_SPEED_COEF,
true);
218 ControllerManager::getInstance().addItem(
this, controller);
221 void Window::setAutoAlpha(
bool _auto)
223 mIsAutoAlpha = _auto;
230 else if (mMouseRootFocus)
237 void Window::setPosition(
const IntPoint& _point)
243 IntCoord coord(point, mCoord.size());
244 getSnappedCoord(coord, Snap::Position);
245 point = coord.point();
248 Base::setPosition(point);
251 void Window::setSize(
const IntSize& _size)
256 if (size.width < mMinmax.left)
257 size.
width = mMinmax.left;
258 else if (size.width > mMinmax.right)
259 size.width = mMinmax.right;
260 if (size.height < mMinmax.top)
261 size.height = mMinmax.top;
262 else if (size.height > mMinmax.bottom)
263 size.height = mMinmax.bottom;
264 if ((size.width == mCoord.width) && (size.height == mCoord.height))
269 IntCoord coord(mCoord.point(), size);
270 getSnappedCoord(coord, Snap::Size);
277 void Window::setCoord(
const IntCoord& _coord)
282 if (size.width < mMinmax.left)
284 int offset = mMinmax.left - size.width;
285 size.width = mMinmax.left;
286 if ((pos.left - mCoord.left) > offset)
289 pos.left = mCoord.left;
291 else if (size.width > mMinmax.right)
293 int offset = mMinmax.right - size.width;
294 size.width = mMinmax.right;
295 if ((pos.left - mCoord.left) < offset)
298 pos.left = mCoord.left;
300 if (size.height < mMinmax.top)
302 int offset = mMinmax.top - size.height;
303 size.height = mMinmax.top;
304 if ((pos.top - mCoord.top) > offset)
307 pos.top = mCoord.top;
309 else if (size.height > mMinmax.bottom)
311 int offset = mMinmax.bottom - size.height;
312 size.height = mMinmax.bottom;
313 if ((pos.top - mCoord.top) < offset)
316 pos.top = mCoord.top;
323 getSnappedCoord(coord, Snap::Size);
329 Base::setCoord(coord);
332 void Window::setCaption(
const UString& _caption)
334 if (mWidgetCaption !=
nullptr)
335 mWidgetCaption->setCaption(_caption);
337 Base::setCaption(_caption);
340 const UString& Window::getCaption()
const
342 if (mWidgetCaption !=
nullptr)
343 return mWidgetCaption->getCaption();
344 return Base::getCaption();
347 void Window::destroySmooth()
351 ControllerManager::getInstance().addItem(
this, controller);
354 void Window::animateStop(Widget* _widget, ControllerItem* _controller)
358 ControllerManager::getInstance().removeItem(
this);
359 mAnimateSmooth =
false;
363 void Window::setVisible(
bool _visible)
367 ControllerManager::getInstance().removeItem(
this);
368 setAlpha(getAlphaVisible());
369 setEnabledSilent(
true);
370 mAnimateSmooth =
false;
373 Base::setVisible(_visible);
376 float Window::getAlphaVisible()
const
381 void Window::getSnappedCoord(
IntCoord& _coord, Snap snapMode)
const
383 const IntSize view_size = getParentSize();
387 bool nearBottomSide = abs(_coord.top + _coord.height - view_size.height) <=
WINDOW_SNAP_DISTANSE;
398 _coord.left = view_size.width - _coord.width;
400 _coord.top = view_size.height - _coord.height;
405 _coord.width = _coord.right();
410 _coord.height = _coord.bottom();
415 _coord.width = view_size.width - _coord.left;
417 _coord.height = view_size.height - _coord.top;
422 void Window::setVisibleSmooth(
bool _visible)
424 mAnimateSmooth =
true;
425 ControllerManager::getInstance().removeItem(
this);
429 setEnabledSilent(
true);
433 Base::setVisible(
true);
435 ControllerFadeAlpha* controller = createControllerFadeAlpha(getAlphaVisible(),
WINDOW_SPEED_COEF,
true);
436 controller->eventPostAction +=
newDelegate(
this, &Window::animateStop);
437 ControllerManager::getInstance().addItem(
this, controller);
441 setEnabledSilent(
false);
444 ControllerManager::getInstance().addItem(
this, controller);
448 ControllerFadeAlpha* Window::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
450 ControllerItem* item = ControllerManager::getInstance().createItem(ControllerFadeAlpha::getClassTypeName());
451 ControllerFadeAlpha* controller = item->castType<ControllerFadeAlpha>();
453 controller->setAlpha(_alpha);
454 controller->setCoef(_coef);
455 controller->setEnabled(_enable);
460 void Window::setMinSize(
const IntSize& _value)
462 mMinmax.left = _value.width;
463 mMinmax.top = _value.height;
466 IntSize Window::getMinSize()
const
468 return {mMinmax.left, mMinmax.top};
471 void Window::setMaxSize(
const IntSize& _value)
473 mMinmax.right = _value.
width;
474 mMinmax.bottom = _value.height;
477 IntSize Window::getMaxSize()
const
479 return {mMinmax.right, mMinmax.bottom};
482 void Window::setPropertyOverride(std::string_view _key, std::string_view _value)
485 if (_key ==
"AutoAlpha")
489 else if (_key ==
"Snap")
493 else if (_key ==
"MinSize")
497 else if (_key ==
"MaxSize")
501 else if (_key ==
"Movable")
506 Base::setPropertyOverride(_key, _value);
510 eventChangeProperty(
this, _key, _value);
513 const IntCoord& Window::getActionScale()
const
515 return mCurrentActionScale;
518 bool Window::getAutoAlpha()
const
523 TextBox* Window::getCaptionWidget()
const
525 return mWidgetCaption;
528 void Window::setMinSize(
int _width,
int _height)
530 setMinSize(
IntSize(_width, _height));
533 void Window::setMaxSize(
int _width,
int _height)
535 setMaxSize(
IntSize(_width, _height));
538 bool Window::getSnap()
const
543 void Window::setSnap(
bool _value)
548 void Window::notifyMouseReleased(MyGUI::Widget* _sender,
int _left,
int _top, MouseButton _id)
550 if (MouseButton::Left == _id)
552 mCurrentActionScale.clear();
556 IntCoord Window::_getActionScale(Widget* _widget)
const
558 if (_widget->isUserString(
"Scale"))
562 if (result ==
IntCoord(1, 1, 0, 0) && !mMovable)
567 if (_widget->isUserString(
"Action"))
569 std::string_view
action = _widget->getUserString(
"Action");
578 Align align = Align::parse(
action);
585 else if (align.isRight())
595 else if (align.isBottom())
609 (
float)(mCurrentActionScale.width < 0 ? mCoord.width : 0),
610 (
float)(mCurrentActionScale.height < 0 ? mCoord.height : 0));
613 void Window::restoreResizeAnchor()
616 const FloatPoint currentAnchor = localToLayer(getResizeAnchor());
617 const Widget* parent = getParent();
618 const FloatPoint targetInParent = parent ? parent->layerToLocal(mPreActionAnchor) : mPreActionAnchor;
619 const FloatPoint currentInParent = parent ? parent->layerToLocal(currentAnchor) : currentAnchor;
621 (
int)std::lround(targetInParent.left - currentInParent.left),
622 (
int)std::lround(targetInParent.top - currentInParent.top));
626 Base::setPosition(mCoord.point() + correction);
630 void Window::setMovable(
bool _value)
635 bool Window::getMovable()
const
640 void Window::notifyMouseWheel(MyGUI::Widget* _sender,
int _rel)
643 eventMouseWheel(_sender, _rel);
void actionWidgetDestroy(Widget *_widget, ControllerItem *_controller)
void actionWidgetHide(Widget *_widget, ControllerItem *_controller)
T parseValue(std::string_view value)
constexpr float ALPHA_MAX
types::TPoint< int > IntPoint
constexpr float ALPHA_MIN
const float WINDOW_ALPHA_FOCUS
const float WINDOW_SPEED_COEF
const float WINDOW_ALPHA_ACTIVE
types::TPoint< float > FloatPoint
const float WINDOW_ALPHA_DEACTIVE
types::TCoord< int > IntCoord
types::TSize< int > IntSize
const int WINDOW_SNAP_DISTANSE
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
std::vector< Widget * > VectorWidgetPtr
static TCoord< int > parse(std::string_view _value)