Skip to content

Commit

Permalink
Traktor: Widget with focus debug overlay. Widgets which can have focu…
Browse files Browse the repository at this point in the history
…s must now have WsFocus style set.
  • Loading branch information
apistol78 committed May 29, 2024
1 parent 753828d commit bce1715
Show file tree
Hide file tree
Showing 47 changed files with 165 additions and 88 deletions.
2 changes: 1 addition & 1 deletion code/Model/Editor/ModelToolDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ bool ModelToolDialog::create(ui::Widget* parent, const std::wstring& fileName, f
m_modelChildPopup->add(new ui::MenuItem(ui::Command(L"ModelTool.Remove"), i18n::Text(L"MODEL_TOOL_REMOVE")));

m_renderWidget = new ui::Widget();
m_renderWidget->create(splitter, ui::WsNoCanvas);
m_renderWidget->create(splitter, ui::WsFocus | ui::WsNoCanvas);
m_renderWidget->addEventHandler< ui::MouseButtonDownEvent >(this, &ModelToolDialog::eventMouseDown);
m_renderWidget->addEventHandler< ui::MouseButtonUpEvent >(this, &ModelToolDialog::eventMouseUp);
m_renderWidget->addEventHandler< ui::MouseMoveEvent >(this, &ModelToolDialog::eventMouseMove);
Expand Down
2 changes: 1 addition & 1 deletion code/Runtime/Editor/Ui/TargetListControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.runtime.TargetListControl", TargetListControl,

bool TargetListControl::create(ui::Widget* parent)
{
if (!ui::AutoWidget::create(parent, ui::WsDoubleBuffer))
if (!ui::AutoWidget::create(parent, ui::WsFocus | ui::WsDoubleBuffer))
return false;

addEventHandler< ui::MouseButtonDownEvent >(this, &TargetListControl::eventButtonDown);
Expand Down
2 changes: 1 addition & 1 deletion code/Scene/Editor/RenderControls/CameraRenderControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool CameraRenderControl::create(ui::Widget* parent, SceneEditorContext* context
m_containerAspect->create(parent, ui::WsNone, new ui::FloodLayout());

m_renderWidget = new ui::Widget();
if (!m_renderWidget->create(m_containerAspect, ui::WsNoCanvas))
if (!m_renderWidget->create(m_containerAspect, ui::WsFocus | ui::WsNoCanvas))
{
destroy();
return false;
Expand Down
2 changes: 1 addition & 1 deletion code/Scene/Editor/RenderControls/FinalRenderControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool FinalRenderControl::create(ui::Widget* parent, SceneEditorContext* context,
m_containerAspect->create(parent, ui::WsNone, new ui::FloodLayout());

m_renderWidget = new ui::Widget();
if (!m_renderWidget->create(m_containerAspect, ui::WsWantAllInput | ui::WsNoCanvas))
if (!m_renderWidget->create(m_containerAspect, ui::WsFocus | ui::WsWantAllInput | ui::WsNoCanvas))
{
destroy();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool OrthogonalRenderControl::create(ui::Widget* parent, SceneEditorContext* con
m_viewPlane = viewPlane;

m_renderWidget = new ui::Widget();
if (!m_renderWidget->create(parent, ui::WsNoCanvas))
if (!m_renderWidget->create(parent, ui::WsFocus | ui::WsNoCanvas))
{
destroy();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool PerspectiveRenderControl::create(ui::Widget* parent, SceneEditorContext* co
m_containerAspect->create(parent, ui::WsNone, new ui::FloodLayout());

m_renderWidget = new ui::Widget();
if (!m_renderWidget->create(m_containerAspect, ui::WsNoCanvas))
if (!m_renderWidget->create(m_containerAspect, ui::WsFocus | ui::WsNoCanvas))
{
destroy();
return false;
Expand Down
2 changes: 1 addition & 1 deletion code/Sound/Editor/Resound/BankControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.sound.BankControl", BankControl, ui::AutoWidget

bool BankControl::create(ui::Widget* parent)
{
if (!ui::AutoWidget::create(parent, ui::WsDoubleBuffer))
if (!ui::AutoWidget::create(parent, ui::WsFocus | ui::WsDoubleBuffer))
return false;

return true;
Expand Down
2 changes: 1 addition & 1 deletion code/Spark/Editor/PreviewControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool PreviewControl::create(
sound::ISoundPlayer* soundPlayer
)
{
if (!Widget::create(parent, style | ui::WsNoCanvas))
if (!Widget::create(parent, style | ui::WsFocus | ui::WsNoCanvas))
return false;

render::RenderViewEmbeddedDesc desc;
Expand Down
2 changes: 1 addition & 1 deletion code/Spray/Editor/EffectPreviewControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool EffectPreviewControl::create(
sound::AudioSystem* audioSystem
)
{
if (!Widget::create(parent, style | ui::WsNoCanvas))
if (!Widget::create(parent, style | ui::WsFocus | ui::WsNoCanvas))
return false;

ui::Rect innerRect = getInnerRect();
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/BuildChart/BuildChartControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BuildChartControl::BuildChartControl()

bool BuildChartControl::create(Widget* parent, uint32_t laneCount, uint32_t style)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

addEventHandler< MouseButtonDownEvent >(this, &BuildChartControl::eventButtonDown);
Expand Down
6 changes: 3 additions & 3 deletions code/Ui/Button.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -19,7 +19,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.Button", Button, Widget)

bool Button::create(Widget* parent, const std::wstring& text, uint32_t style)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

addEventHandler< MouseTrackEvent >(this, &Button::eventMouseTrack);
Expand All @@ -33,7 +33,7 @@ bool Button::create(Widget* parent, const std::wstring& text, uint32_t style)

Size Button::getPreferredSize(const Size& hint) const
{
// Calculate prefered size from new text.
// Calculate preferred size from new text.
const int32_t marginX = pixel(16_ut);
const int32_t marginY = pixel(4_ut);

Expand Down
2 changes: 1 addition & 1 deletion code/Ui/CheckBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CheckBox::CheckBox()

bool CheckBox::create(Widget* parent, const std::wstring& text, bool checked)
{
if (!Widget::create(parent))
if (!Widget::create(parent, WsFocus))
return false;

setText(text);
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/ColorPicker/ColorControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.ColorControl", ColorControl, Widget)

bool ColorControl::create(Widget* parent, uint32_t style)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

addEventHandler< SizeEvent >(this, &ColorControl::eventSize);
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/ColorPicker/ColorGradientControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.ColorGradientControl", ColorGradientControl,

bool ColorGradientControl::create(Widget* parent, uint32_t style, const Color4ub& primaryColor)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

addEventHandler< MouseButtonDownEvent >(this, &ColorGradientControl::eventButtonDown);
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/ColorPicker/ColorSliderControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.ColorSliderControl", ColorSliderControl, Wid

bool ColorSliderControl::create(Widget* parent, uint32_t style, IGradient* gradient)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

addEventHandler< MouseButtonDownEvent >(this, &ColorSliderControl::eventButtonDown);
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/ComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.ComboBox", ComboBox, Widget)

bool ComboBox::create(Widget* parent, const std::wstring& text, uint32_t style)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

m_buttonArrow = new Button();
Expand Down
8 changes: 1 addition & 7 deletions code/Ui/Dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,15 @@ void Dock::eventButtonDown(MouseButtonDownEvent* event)
pane->showTab(tabIndex);
update();
}

event->consume();
return;
}

if ((pane = m_pane->getSplitterFromPosition(position)) != nullptr)
else if ((pane = m_pane->getSplitterFromPosition(position)) != nullptr)
{
if (pane->hitSplitter(position))
{
m_splittingPane = pane;
setCursor(pane->m_vertical ? Cursor::SizeNS : Cursor::SizeWE);
setCapture();
}
event->consume();
return;
}

event->consume();
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/DropDown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.DropDown", DropDown, Widget)

bool DropDown::create(Widget* parent, uint32_t style)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

m_multiple = (bool)((style & WsMultiple) != 0);
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Edit::Edit()

bool Edit::create(Widget* parent, const std::wstring& text, uint32_t style, const EditValidator* validator)
{
if (!Widget::create(parent, style | WsDoubleBuffer))
if (!Widget::create(parent, style | WsFocus | WsDoubleBuffer))
return false;

if ((m_validator = validator) != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/EditList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ EditList::EditList()

bool EditList::create(Widget* parent, uint32_t style)
{
if (!ListBox::create(parent, style))
if (!ListBox::create(parent, style | WsFocus))
return false;

addEventHandler< MouseDoubleClickEvent >(this, &EditList::eventDoubleClick);
Expand Down
3 changes: 2 additions & 1 deletion code/Ui/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ constexpr static uint32_t WsAcceptFileDrop = 1 << 11;
constexpr static uint32_t WsTabStop = 1 << 12;
constexpr static uint32_t WsWantAllInput = 1 << 13;
constexpr static uint32_t WsNoCanvas = 1 << 14; //!< Don't allocate a graphics canvas; useful for 3d rendering widgets etc.
constexpr static uint32_t WsUser = 1 << 15;
constexpr static uint32_t WsFocus = 1 << 15; //!< Get focus when user press mouse on widget.
constexpr static uint32_t WsUser = 1 << 16;

constexpr static uint32_t MbOk = 1 << 0;
constexpr static uint32_t MbCancel = 1 << 1;
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/Envelope/EnvelopeControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.EnvelopeControl", EnvelopeControl, Widget)

bool EnvelopeControl::create(Widget* parent, EnvelopeEvaluator* evaluator, float minValue, float maxValue, uint32_t style)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

addEventHandler< MouseButtonDownEvent >(this, &EnvelopeControl::eventButtonDown);
Expand Down
3 changes: 2 additions & 1 deletion code/Ui/Events/AllEvents.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022-2023 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -26,6 +26,7 @@
#include "Ui/Events/MouseTrackEvent.h"
#include "Ui/Events/MouseWheelEvent.h"
#include "Ui/Events/MoveEvent.h"
#include "Ui/Events/OverlayPaintEvent.h"
#include "Ui/Events/PaintEvent.h"
#include "Ui/Events/ScrollEvent.h"
#include "Ui/Events/ShowEvent.h"
Expand Down
33 changes: 33 additions & 0 deletions code/Ui/Events/OverlayPaintEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* TRAKTOR
* Copyright (c) 2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Ui/Events/OverlayPaintEvent.h"

namespace traktor::ui
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.OverlayPaintEvent", OverlayPaintEvent, Event)

OverlayPaintEvent::OverlayPaintEvent(EventSubject* sender, Canvas& canvas, const Rect& rc)
: Event(sender)
, m_canvas(canvas)
, m_rc(rc)
{
}

Canvas& OverlayPaintEvent::getCanvas() const
{
return m_canvas;
}

const Rect& OverlayPaintEvent::getUpdateRect() const
{
return m_rc;
}

}
46 changes: 46 additions & 0 deletions code/Ui/Events/OverlayPaintEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* TRAKTOR
* Copyright (c) 2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

#include "Ui/Event.h"
#include "Ui/Rect.h"

// import/export mechanism.
#undef T_DLLCLASS
#if defined(T_UI_EXPORT)
# define T_DLLCLASS T_DLLEXPORT
#else
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor::ui
{

class Canvas;

/*! Paint event.
* \ingroup UI
*/
class T_DLLCLASS OverlayPaintEvent : public Event
{
T_RTTI_CLASS;

public:
explicit OverlayPaintEvent(EventSubject* sender, Canvas& canvas, const Rect& rc);

Canvas& getCanvas() const;

const Rect& getUpdateRect() const;

private:
Canvas& m_canvas;
Rect m_rc;
};

}
7 changes: 2 additions & 5 deletions code/Ui/Events/PaintEvent.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Ui/Events/PaintEvent.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.PaintEvent", PaintEvent, Event)

Expand All @@ -32,5 +30,4 @@ const Rect& PaintEvent::getUpdateRect() const
return m_rc;
}

}
}
8 changes: 2 additions & 6 deletions code/Ui/Events/PaintEvent.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -19,10 +19,8 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::ui
{
namespace ui
{

class Canvas;

Expand All @@ -45,6 +43,4 @@ class T_DLLCLASS PaintEvent : public Event
Rect m_rc;
};

}
}

2 changes: 1 addition & 1 deletion code/Ui/Graph/GraphControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ GraphControl::GraphControl()

bool GraphControl::create(Widget* parent, uint32_t style)
{
if (!Widget::create(parent, style))
if (!Widget::create(parent, style | WsFocus))
return false;

m_paintSettings = PaintSettings(getFont());
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/GridView/GridView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ GridView::GridView()

bool GridView::create(Widget* parent, uint32_t style)
{
if (!AutoWidget::create(parent, style))
if (!AutoWidget::create(parent, style | WsFocus))
return false;

m_autoEdit = bool((style & WsAutoEdit) == WsAutoEdit);
Expand Down
Loading

0 comments on commit bce1715

Please sign in to comment.