Skip to content

Commit

Permalink
Traktor: ColorControl resizable. Fixed icons for FileDialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Apr 30, 2024
1 parent e1a8f8a commit 73adf8d
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 1,802 deletions.
67 changes: 45 additions & 22 deletions code/Ui/ColorPicker/ColorControl.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 @@ -12,17 +12,15 @@
#include "Ui/Bitmap.h"
#include "Ui/ColorPicker/ColorControl.h"

namespace traktor
namespace traktor::ui
{
namespace ui
namespace
{
namespace
{

const Unit c_width = 32_ut;
const Unit c_height = 24_ut;

}
}

T_IMPLEMENT_RTTI_CLASS(L"traktor.ui.ColorControl", ColorControl, Widget)

Expand All @@ -31,6 +29,7 @@ bool ColorControl::create(Widget* parent, int style)
if (!Widget::create(parent, style))
return false;

addEventHandler< SizeEvent >(this, &ColorControl::eventSize);
addEventHandler< PaintEvent >(this, &ColorControl::eventPaint);

const int32_t width = pixel(c_width);
Expand All @@ -44,17 +43,49 @@ bool ColorControl::create(Widget* parent, int style)
}

void ColorControl::setColor(const Color4ub& color)
{
m_color = color;
updatePreview();
update();
}

Color4ub ColorControl::getColor() const
{
return m_color;
}

Size ColorControl::getPreferredSize(const Size& hint) const
{
const int32_t width = pixel(c_width);
const int32_t height = pixel(c_height);
return Size(width, height);
}

m_color = color;
for (int32_t y = 0; y < height; ++y)
void ColorControl::updatePreview()
{
const Size sz = getInnerRect().getSize();

if (m_previewImage)
{
for (int32_t x = 0; x < width; ++x)
if (m_previewImage->getWidth() != sz.cx || m_previewImage->getHeight() != sz.cy)
{
Color4ub checkerColor = (((x >> 2) & 1) ^ ((y >> 2) & 1)) ? Color4ub(180, 180, 180) : Color4ub(80, 80, 80);
Color4ub previewColor = lerp(checkerColor, color, color.a / 255.0f);
m_previewImage = nullptr;
m_previewBitmap = nullptr;
}
}

if (!m_previewImage)
{
m_previewImage = new drawing::Image(drawing::PixelFormat::getR8G8B8(), sz.cx, sz.cy);
m_previewBitmap = new ui::Bitmap(sz.cx, sz.cy);
}

for (int32_t y = 0; y < sz.cy; ++y)
{
for (int32_t x = 0; x < sz.cx; ++x)
{
const Color4ub checkerColor = (((x >> 2) & 1) ^ ((y >> 2) & 1)) ? Color4ub(180, 180, 180) : Color4ub(80, 80, 80);
const Color4ub previewColor = lerp(checkerColor, m_color, m_color.a / 255.0f);

float rgba[4];
previewColor.getRGBA32F(rgba);
Expand All @@ -64,19 +95,12 @@ void ColorControl::setColor(const Color4ub& color)
}

m_previewBitmap->copyImage(m_previewImage);
update();
}

Color4ub ColorControl::getColor() const
void ColorControl::eventSize(SizeEvent* event)
{
return m_color;
}

Size ColorControl::getPreferredSize(const Size& hint) const
{
const int32_t width = pixel(c_width);
const int32_t height = pixel(c_height);
return Size(width, height);
updatePreview();
update();
}

void ColorControl::eventPaint(PaintEvent* event)
Expand All @@ -93,5 +117,4 @@ void ColorControl::eventPaint(PaintEvent* event)
event->consume();
}

}
}
18 changes: 9 additions & 9 deletions code/Ui/ColorPicker/ColorControl.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 @@ -18,17 +18,15 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::drawing
{
namespace drawing
{

class Image;

}
}

namespace ui
{
namespace traktor::ui
{

class Bitmap;

Expand All @@ -53,9 +51,11 @@ class T_DLLCLASS ColorControl : public Widget
Ref< drawing::Image > m_previewImage;
Ref< Bitmap > m_previewBitmap;

void updatePreview();

void eventSize(SizeEvent* event);

void eventPaint(PaintEvent* event);
};

}
}

90 changes: 47 additions & 43 deletions resources/runtime/themes/Dark/New/Theater/Theater.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 73adf8d

Please sign in to comment.