Skip to content

Commit

Permalink
Traktor: Themed caption bar in editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 17, 2024
1 parent 938daf1 commit 98f12d8
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 71 deletions.
9 changes: 7 additions & 2 deletions code/Editor/App/EditorForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "Net/Stream/StreamServer.h"
#include "Ui/Application.h"
#include "Ui/Bitmap.h"
#include "Ui/CaptionBar.h"
#include "Ui/Dock.h"
#include "Ui/DockPane.h"
#include "Ui/FloodLayout.h"
Expand Down Expand Up @@ -474,8 +475,8 @@ bool EditorForm::create(const CommandLine& cmdLine)
c_title,
1280_ut,
900_ut,
ui::WsResizable | ui::Form::WsDefault | ui::WsNoCanvas,
new ui::TableLayout(L"100%", L"*,*,100%,*", 0_ut, 0_ut)
ui::WsResizable | ui::WsSystemBox | ui::WsMinimizeBox | ui::WsMaximizeBox | ui::WsNoCanvas,
new ui::TableLayout(L"100%", L"*,*,*,100%,*", 0_ut, 0_ut)
))
return false;

Expand All @@ -489,6 +490,10 @@ bool EditorForm::create(const CommandLine& cmdLine)
m_shortcutTable->create();
m_shortcutTable->addEventHandler< ui::ShortcutEvent >(this, &EditorForm::eventShortcut);

// Create caption bar.
Ref< ui::CaptionBar > captionBar = new ui::CaptionBar();
captionBar->create(this);

// Create menu bar.
m_menuBar = new ui::ToolBar();
m_menuBar->create(this);
Expand Down
28 changes: 24 additions & 4 deletions code/Ui/CaptionBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ bool CaptionBar::create(Widget* parent, uint32_t style)
return false;

m_buttonMinimize = new MiniButton();
m_buttonMinimize->create(this, new ui::StyleBitmap(L"UI.CaptionMinimize"), MiniButton::WsNoBorder);
m_buttonMinimize->create(this, new ui::StyleBitmap(L"UI.CaptionMinimize"), MiniButton::WsNoBorder | MiniButton::WsNoBackground);
m_buttonMinimize->addEventHandler< ButtonClickEvent >(this, &CaptionBar::eventButtonClick);

m_buttonMaximizeOrRestore = new MiniButton();
m_buttonMaximizeOrRestore->create(this, new ui::StyleBitmap(L"UI.CaptionMaximize"), MiniButton::WsNoBorder);
m_buttonMaximizeOrRestore->create(this, new ui::StyleBitmap(L"UI.CaptionMaximize"), MiniButton::WsNoBorder | MiniButton::WsNoBackground);
m_buttonMaximizeOrRestore->addEventHandler< ButtonClickEvent >(this, &CaptionBar::eventButtonClick);

m_buttonClose = new MiniButton();
m_buttonClose->create(this, new ui::StyleBitmap(L"UI.CaptionClose"), MiniButton::WsNoBorder);
m_buttonClose->create(this, new ui::StyleBitmap(L"UI.CaptionClose"), MiniButton::WsNoBorder | MiniButton::WsNoBackground);
m_buttonClose->addEventHandler< ButtonClickEvent >(this, &CaptionBar::eventButtonClick);

addEventHandler< MouseButtonDownEvent >(this, &CaptionBar::eventMouseButtonDown);
addEventHandler< MouseButtonUpEvent >(this, &CaptionBar::eventMouseButtonUp);
addEventHandler< MouseDoubleClickEvent >(this, &CaptionBar::eventMouseDoubleClick);
addEventHandler< MouseMoveEvent >(this, &CaptionBar::eventMouseMove);
addEventHandler< SizeEvent >(this, &CaptionBar::eventSize);
addEventHandler< PaintEvent >(this, &CaptionBar::eventPaint);
Expand Down Expand Up @@ -95,6 +96,18 @@ void CaptionBar::eventMouseButtonUp(MouseButtonUpEvent* event)
releaseCapture();
}

void CaptionBar::eventMouseDoubleClick(MouseDoubleClickEvent* event)
{
Form* parentForm = dynamic_type_cast< Form* >(getParent());
if (!parentForm)
return;

if (!parentForm->isMaximized())
parentForm->maximize();
else
parentForm->restore();
}

void CaptionBar::eventMouseMove(MouseMoveEvent* event)
{
if (!hasCapture())
Expand All @@ -108,7 +121,7 @@ void CaptionBar::eventMouseMove(MouseMoveEvent* event)
void CaptionBar::eventSize(SizeEvent* event)
{
const Rect rc = getInnerRect();
const int32_t pad = pixel(4_ut);
const int32_t pad = pixel(10_ut);

int32_t r = rc.right - pad;
int32_t h = rc.getHeight();
Expand Down Expand Up @@ -154,6 +167,13 @@ void CaptionBar::eventPaint(PaintEvent* event)
rcText.right = rc.right;
canvas.drawText(rcText, text, AnLeft, AnCenter);

#if defined(_WIN32)
// #hack When using Form without a system caption Windows doesn't draw top shadow line.
const Color4ub shadowColor = ss->getColor(this, L"background-color") * Color4ub(128, 128, 128, 255);
canvas.setForeground(shadowColor);
canvas.drawLine(rc.left, rc.top, rc.right, rc.top);
#endif

event->consume();
}

Expand Down
2 changes: 2 additions & 0 deletions code/Ui/CaptionBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class T_DLLCLASS CaptionBar : public Widget

void eventMouseButtonUp(MouseButtonUpEvent* event);

void eventMouseDoubleClick(MouseDoubleClickEvent* event);

void eventMouseMove(MouseMoveEvent* event);

void eventSize(SizeEvent* event);
Expand Down
12 changes: 10 additions & 2 deletions code/Ui/MiniButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bool MiniButton::create(Widget* parent, const std::wstring& text, uint32_t style
return false;

m_border = ((style & WsNoBorder) == 0);
m_background = ((style & WsNoBackground) == 0);
m_pushed = false;
setText(text);

Expand All @@ -38,6 +39,7 @@ bool MiniButton::create(Widget* parent, IBitmap* image, int style)
return false;

m_border = ((style & WsNoBorder) == 0);
m_background = ((style & WsNoBackground) == 0);
m_pushed = false;
m_image = image;

Expand Down Expand Up @@ -99,7 +101,10 @@ void MiniButton::eventPaint(PaintEvent* event)

if (isEnable(true))
{
canvas.setBackground(ss->getColor(this, m_pushed ? L"background-color-pushed" : L"background-color"));
if (m_background)
canvas.setBackground(ss->getColor(this, m_pushed ? L"background-color-pushed" : L"background-color"));
else
canvas.setBackground(ss->getColor(getParent(), L"background-color"));
canvas.fillRect(rcInner);

if (m_border)
Expand All @@ -113,7 +118,10 @@ void MiniButton::eventPaint(PaintEvent* event)
}
else
{
canvas.setBackground(ss->getColor(this, L"background-color-disabled"));
if (m_background)
canvas.setBackground(ss->getColor(this, L"background-color-disabled"));
else
canvas.setBackground(ss->getColor(getParent(), L"background-color"));
canvas.fillRect(rcInner);

if (m_border)
Expand Down
2 changes: 2 additions & 0 deletions code/Ui/MiniButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class T_DLLCLASS MiniButton : public Widget

public:
constexpr static uint32_t WsNoBorder = WsUser;
constexpr static uint32_t WsNoBackground = WsUser << 1;

bool create(Widget* parent, const std::wstring& text, uint32_t style = WsNone);

Expand All @@ -44,6 +45,7 @@ class T_DLLCLASS MiniButton : public Widget
private:
Ref< IBitmap > m_image;
bool m_border;
bool m_background;
bool m_pushed;

void eventButtonDown(MouseButtonDownEvent* event);
Expand Down
36 changes: 34 additions & 2 deletions code/Ui/Win32/FormWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "Ui/Win32/BitmapWin32.h"
#include "Ui/Win32/FormWin32.h"

// https://github.com/grassator/win32-window-custom-titlebar/blob/main/main.c

namespace traktor::ui
{

Expand Down Expand Up @@ -61,6 +63,9 @@ bool FormWin32::create(IWidget* parent, const std::wstring& text, int width, int
//m_hWnd.registerMessageHandler(WM_ACTIVATE, new MethodMessageHandler< FormWin32 >(this, &FormWin32::eventActivate));
m_hWnd.registerMessageHandler(L"TaskbarButtonCreated", new MethodMessageHandler< FormWin32 >(this, &FormWin32::eventTaskBarButtonCreated));

if ((style & WsCaption) == 0)
m_hWnd.registerMessageHandler(WM_NCCALCSIZE, new MethodMessageHandler< FormWin32 >(this, &FormWin32::eventNonClientCalcSize));

m_ownCursor = true;
return true;
}
Expand Down Expand Up @@ -93,13 +98,13 @@ void FormWin32::setIcon(ISystemBitmap* icon)
void FormWin32::maximize()
{
ShowWindow(m_hWnd, SW_MAXIMIZE);
UpdateWindow(m_hWnd);
RedrawWindow(m_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
}

void FormWin32::minimize()
{
ShowWindow(m_hWnd, SW_MINIMIZE);
UpdateWindow(m_hWnd);
RedrawWindow(m_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
}

void FormWin32::restore()
Expand Down Expand Up @@ -166,4 +171,31 @@ LRESULT FormWin32::eventTaskBarButtonCreated(HWND hWnd, UINT message, WPARAM wPa
return 0;
}

LRESULT FormWin32::eventNonClientCalcSize(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& pass)
{
if (!wParam)
{
pass = true;
return 0;
}

const UINT dpi = GetDpiForWindow(hWnd);

const int frameX = GetSystemMetricsForDpi(SM_CXFRAME, dpi);
const int frameY = GetSystemMetricsForDpi(SM_CYFRAME, dpi);
const int padding = GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi);

NCCALCSIZE_PARAMS* params = (NCCALCSIZE_PARAMS*)lParam;
RECT* requestedClientRect = params->rgrc;

requestedClientRect->right -= frameX + padding;
requestedClientRect->left += frameX + padding;
requestedClientRect->bottom -= frameY + padding;

if (isMaximized())
requestedClientRect->top += padding;

return 0;
}

}
2 changes: 2 additions & 0 deletions code/Ui/Win32/FormWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class FormWin32 : public WidgetWin32Impl< IForm >
LRESULT eventDestroy(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& pass);

LRESULT eventTaskBarButtonCreated(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& pass);

LRESULT eventNonClientCalcSize(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& pass);
};

}
Loading

0 comments on commit 98f12d8

Please sign in to comment.