Skip to content

Commit bdfbe38

Browse files
committed
More tweaks
1 parent 0ff4e7e commit bdfbe38

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

modules/yup_gui/component/yup_Component.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ void Component::setVisible (bool shouldBeVisible)
9595

9696
options.isVisible = shouldBeVisible;
9797

98+
auto bailOutChecker = BailOutChecker (this);
99+
98100
if (options.onDesktop && native != nullptr)
99101
native->setVisible (shouldBeVisible);
100102

101-
auto bailOutChecker = BailOutChecker (this);
103+
if (bailOutChecker.shouldBailOut())
104+
return;
102105

103106
visibilityChanged();
104107

@@ -138,7 +141,7 @@ void Component::setTitle (const String& title)
138141
{
139142
componentTitle = title;
140143

141-
if (options.onDesktop)
144+
if (options.onDesktop && native != nullptr)
142145
native->setTitle (title);
143146
}
144147

@@ -441,7 +444,7 @@ void Component::displayChanged() {}
441444

442445
float Component::getScaleDpi() const
443446
{
444-
if (native != nullptr)
447+
if (options.onDesktop && native != nullptr)
445448
return native->getScaleDpi();
446449

447450
if (parentComponent == nullptr)
@@ -460,7 +463,7 @@ void Component::setOpacity (float newOpacity)
460463

461464
opacity = static_cast<uint8> (newOpacity * 255);
462465

463-
if (native != nullptr)
466+
if (options.onDesktop && native != nullptr)
464467
native->setOpacity (newOpacity);
465468
}
466469

@@ -1251,6 +1254,16 @@ void Component::internalMoved (int xpos, int ypos)
12511254

12521255
//==============================================================================
12531256

1257+
void Component::internalFocusChanged (bool gotFocus)
1258+
{
1259+
if (gotFocus)
1260+
focusGained();
1261+
else
1262+
focusLost();
1263+
}
1264+
1265+
//==============================================================================
1266+
12541267
void Component::internalDisplayChanged() {}
12551268

12561269
//==============================================================================

modules/yup_gui/component/yup_Component.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,9 @@ class JUCE_API Component
906906
void internalKeyDown (const KeyPress& keys, const Point<float>& position);
907907
void internalKeyUp (const KeyPress& keys, const Point<float>& position);
908908
void internalTextInput (const String& text);
909-
void internalMoved (int xpos, int ypos);
910909
void internalResized (int width, int height);
910+
void internalMoved (int xpos, int ypos);
911+
void internalFocusChanged (bool gotFocus);
911912
void internalDisplayChanged();
912913
void internalContentScaleChanged (float dpiScale);
913914
void internalUserTriedToCloseWindow();

modules/yup_gui/native/yup_Windowing_sdl2.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,17 @@ void SDL2ComponentNative::handleFocusChanged (bool gotFocus)
961961

962962
if (! isRendering())
963963
startRendering();
964+
965+
component.internalFocusChanged (true);
964966
}
965967
else
966968
{
969+
component.internalFocusChanged (false);
970+
971+
lastComponentClicked = nullptr;
972+
lastMouseDownPosition.reset();
973+
lastMouseDownTime.reset();
974+
967975
SDL_StopTextInput();
968976

969977
if (updateOnlyWhenFocused)
@@ -1168,6 +1176,8 @@ void SDL2ComponentNative::handleEvent (SDL_Event* event)
11681176

11691177
case SDL_MOUSEMOTION:
11701178
{
1179+
//YUP_WINDOWING_LOG ("SDL_MOUSEMOTION " << event->motion.x << " " << event->motion.y);
1180+
11711181
auto cursorPosition = Point<float> { static_cast<float> (event->motion.x), static_cast<float> (event->motion.y) };
11721182

11731183
if (event->window.windowID == SDL_GetWindowID (window))
@@ -1178,26 +1188,36 @@ void SDL2ComponentNative::handleEvent (SDL_Event* event)
11781188

11791189
case SDL_MOUSEBUTTONDOWN:
11801190
{
1191+
YUP_WINDOWING_LOG ("SDL_MOUSEBUTTONDOWN " << event->button.x << " " << event->button.y);
1192+
11811193
auto cursorPosition = Point<float> { static_cast<float> (event->button.x), static_cast<float> (event->button.y) };
11821194

11831195
if (event->button.windowID == SDL_GetWindowID (window))
11841196
handleMouseDown (cursorPosition, toMouseButton (event->button.button), KeyModifiers (SDL_GetModState()));
1197+
else
1198+
; // TODO - when opening a window in mouse down, mouse up is sent to the other window
11851199

11861200
break;
11871201
}
11881202

11891203
case SDL_MOUSEBUTTONUP:
11901204
{
1205+
YUP_WINDOWING_LOG ("SDL_MOUSEBUTTONUP " << event->button.x << " " << event->button.y);
1206+
11911207
auto cursorPosition = Point<float> { static_cast<float> (event->button.x), static_cast<float> (event->button.y) };
11921208

11931209
if (event->button.windowID == SDL_GetWindowID (window))
11941210
handleMouseUp (cursorPosition, toMouseButton (event->button.button), KeyModifiers (SDL_GetModState()));
1211+
else
1212+
; // TODO - when opening a window in mouse down, mouse up is sent to the other window
11951213

11961214
break;
11971215
}
11981216

11991217
case SDL_MOUSEWHEEL:
12001218
{
1219+
YUP_WINDOWING_LOG ("SDL_MOUSEWHEEL " << event->wheel.x << " " << event->wheel.y);
1220+
12011221
auto cursorPosition = getCursorPosition();
12021222

12031223
if (event->wheel.windowID == SDL_GetWindowID (window))

modules/yup_gui/widgets/yup_PopupMenu.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace yup
2727
namespace
2828
{
2929

30-
static std::vector<Component*> activePopups;
30+
static std::vector<WeakReference<Component>> activePopups;
3131

3232
} // namespace
3333

@@ -211,7 +211,7 @@ class PopupMenu::MenuWindow : public Component
211211
void dismiss (int itemID)
212212
{
213213
selectedItemID = itemID;
214-
setVisible (false);
214+
//setVisible (false);
215215

216216
// Call the owner's callback
217217
if (owner->onItemSelected)
@@ -419,9 +419,9 @@ struct GlobalMouseListener : public MouseListener
419419
Point<float> globalPos = event.getScreenPosition().to<float>();
420420

421421
bool clickedInsidePopup = false;
422-
for (auto* popup : activePopups)
422+
for (const auto& popup : activePopups)
423423
{
424-
if (auto* menuWindow = dynamic_cast<PopupMenu::MenuWindow*> (popup))
424+
if (auto* menuWindow = dynamic_cast<PopupMenu::MenuWindow*> (popup.get()))
425425
{
426426
if (menuWindow->isWithinBounds (globalPos))
427427
{
@@ -474,9 +474,9 @@ void PopupMenu::dismissAllPopups()
474474
// Make a copy to avoid issues with the vector being modified during iteration
475475
auto popupsToClose = std::move (activePopups);
476476

477-
for (auto* popup : popupsToClose)
477+
for (const auto& popup : popupsToClose)
478478
{
479-
if (auto* menuWindow = dynamic_cast<PopupMenu::MenuWindow*> (popup))
479+
if (auto* menuWindow = dynamic_cast<PopupMenu::MenuWindow*> (popup.get()))
480480
menuWindow->dismiss (0);
481481
}
482482

0 commit comments

Comments
 (0)