Skip to content

Commit

Permalink
Traktor: All UI images are now SVG.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Apr 26, 2024
1 parent 16853be commit a407745
Show file tree
Hide file tree
Showing 364 changed files with 97,850 additions and 387 deletions.
2 changes: 1 addition & 1 deletion code/Spark/Editor/Debug/DebugView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void paintInstance(ui::Canvas& canvas, std::map< void*, DebugView::ShapeCache >&
raster->fill(fs0, fs1, drawing::Raster::FillRule::NonZero);

if (ls >= 0)
raster->stroke(lineStyleBase + ls, lineStyles[ls].getLineWidth() * strokeScale, drawing::Raster::StrokeCap::Square);
raster->stroke(lineStyleBase + ls, lineStyles[ls].getLineWidth() * strokeScale, drawing::Raster::StrokeJoin::Miter, drawing::Raster::StrokeCap::Square);
}

raster->submit();
Expand Down
2 changes: 0 additions & 2 deletions code/Spark/Editor/EditorPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ bool EditorPage::create(ui::Container* parent)
m_toolBarPlay->create(container);
for (int32_t i = 0; i < 6; ++i)
m_toolBarPlay->addImage(new ui::StyleBitmap(L"Flash.Playback", i));
m_toolBarPlay->addImage(new ui::StyleBitmap(L"Flash.Flash", 0));
m_toolBarPlay->addImage(new ui::StyleBitmap(L"Flash.Flash", 1));
m_toolBarPlay->addItem(new ui::ToolBarButton(i18n::Text(L"FLASH_EDITOR_REWIND"), 0, ui::Command(L"Flash.Editor.Rewind")));
m_toolBarPlay->addItem(new ui::ToolBarButton(i18n::Text(L"FLASH_EDITOR_PLAY"), 1, ui::Command(L"Flash.Editor.Play")));
m_toolBarPlay->addItem(new ui::ToolBarButton(i18n::Text(L"FLASH_EDITOR_STOP"), 2, ui::Command(L"Flash.Editor.Stop")));
Expand Down
2 changes: 1 addition & 1 deletion code/Svg/ClassFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void ClassFactory::createClasses(IRuntimeClassRegistrar* registrar) const

auto classParser = new AutoRuntimeClass< Parser >();
classParser->addConstructor();
classParser->addMethod("parse", &Parser::parse);
//classParser->addMethod("parse", &Parser::parse);
registrar->registerClass(classParser);

auto classPath = new AutoRuntimeClass< Path >();
Expand Down
9 changes: 9 additions & 0 deletions code/Svg/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ Ref< Shape > Parser::parse(xml::Document* doc)
return traverse(doc->getDocumentElement());
}

Ref< Shape > Parser::parse(const traktor::Path& fileName)
{
xml::Document xd;
if (xd.loadFromFile(fileName))
return parse(&xd);
else
return nullptr;
}

Ref< Shape > Parser::traverse(xml::Element* elm)
{
Ref< Shape > shape;
Expand Down
3 changes: 3 additions & 0 deletions code/Svg/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string>
#include "Core/Ref.h"
#include "Core/Object.h"
#include "Core/Io/Path.h"
#include "Core/Math/Matrix33.h"

// import/export mechanism.
Expand Down Expand Up @@ -49,6 +50,8 @@ class T_DLLCLASS Parser : public Object

Ref< Shape > parse(xml::Document* doc);

Ref< Shape > parse(const traktor::Path& fileName);

private:
Ref< Style > m_defaultStyle;
std::map< std::wstring, Ref< Gradient > > m_gradients;
Expand Down
8 changes: 4 additions & 4 deletions code/Svg/Rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class LambdaShapeVisitor : public IShapeVisitor

T_IMPLEMENT_RTTI_CLASS(L"traktor.svg.Rasterizer", Rasterizer, Object)

bool Rasterizer::raster(const Document* document, drawing::Image* image) const
bool Rasterizer::raster(const Document* document, drawing::Image* image, float pageOffsetX, float pageOffsetY) const
{
const Aabb2& viewBox = document->getViewBox();

const float sx = image->getWidth() / viewBox.getSize().x;
const float sy = image->getHeight() / viewBox.getSize().y;

const Matrix33 Mview = scale(sx, sy);
const Matrix33 Mview = scale(sx, sy) * translate(-pageOffsetX * viewBox.getSize().x, -pageOffsetY * viewBox.getSize().y);

drawing::Raster raster(image);

Expand Down Expand Up @@ -164,7 +164,7 @@ bool Rasterizer::raster(const Document* document, drawing::Image* image) const
return true;
}

Ref< drawing::Image > Rasterizer::raster(const Document* document, float scale) const
Ref< drawing::Image > Rasterizer::raster(const Document* document, float scale, float pageOffsetX, float pageOffsetY) const
{
const int32_t width = (int32_t)(document->getSize().x * scale);
const int32_t height = (int32_t)(document->getSize().y * scale);
Expand All @@ -174,7 +174,7 @@ Ref< drawing::Image > Rasterizer::raster(const Document* document, float scale)
Ref< drawing::Image > image = new drawing::Image(drawing::PixelFormat::getR8G8B8A8(), width, height);
image->clear(Color4f(1.0f, 1.0f, 1.0f, 0.0f));

if (!raster(document, image))
if (!raster(document, image, pageOffsetX, pageOffsetY))
return nullptr;

return image;
Expand Down
4 changes: 2 additions & 2 deletions code/Svg/Rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class T_DLLCLASS Rasterizer : public Object
T_RTTI_CLASS;

public:
bool raster(const Document* document, drawing::Image* image) const;
bool raster(const Document* document, drawing::Image* image, float pageOffsetX = 0.0f, float pageOffsetY = 0.0f) const;

Ref< drawing::Image > raster(const Document* document, float scale = 1.0f) const;
Ref< drawing::Image > raster(const Document* document, float scale = 1.0f, float pageOffsetX = 0.0f, float pageOffsetY = 0.0f) const;
};

}
34 changes: 23 additions & 11 deletions code/Ui/StyleBitmap.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 @@ -11,6 +11,7 @@
#include "Core/Io/MemoryStream.h"
#include "Core/Io/StreamCopy.h"
#include "Core/Misc/SafeDestroy.h"
#include "Core/Misc/Split.h"
#include "Drawing/Image.h"
#include "Ui/Application.h"
#include "Ui/StyleBitmap.h"
Expand All @@ -21,7 +22,6 @@
#include "Svg/Document.h"
#include "Svg/Parser.h"
#include "Svg/Rasterizer.h"
#include "Xml/Document.h"

namespace traktor::ui
{
Expand Down Expand Up @@ -88,11 +88,27 @@ bool StyleBitmap::resolve(int32_t dpi) const
if (!ss)
return false;

const Path fileName = ss->getValue(m_name);
const std::wstring key = ss->getValue(m_name);

if (m_bitmap != nullptr && dpi == m_dpi && fileName.getPathName() == m_fileName)
if (m_bitmap != nullptr && dpi == m_dpi && key == m_fileName)
return true;

Path fileName;
int32_t pageColumn = 0;
int32_t pageRow = 0;

const size_t sep = key.find(L'|');
if (sep != key.npos)
{
StaticVector< int32_t, 2 > offsets;
Split< std::wstring, int32_t >::any(key.substr(sep + 1), L",;", offsets, false, 2);
pageColumn = offsets.size() >= 1 ? offsets[0] : 0;
pageRow = offsets.size() >= 2 ? offsets[1] : 0;
fileName = key.substr(0, sep);
}
else
fileName = key;

safeDestroy(m_bitmap);
m_fileName = L"";
m_dpi = -1;
Expand All @@ -104,16 +120,12 @@ bool StyleBitmap::resolve(int32_t dpi) const

if (fileName.getExtension() == L"svg")
{
xml::Document xd;
if (!xd.loadFromFile(fileName))
return false;

Ref< svg::Document > sd = dynamic_type_cast< svg::Document* >(svg::Parser().parse(&xd));
Ref< svg::Document > sd = dynamic_type_cast< svg::Document* >(svg::Parser().parse(fileName));
if (!sd)
return false;

const float scale = float(dpi) / 96.0f;
image = svg::Rasterizer().raster(sd, scale);
image = svg::Rasterizer().raster(sd, scale, pageColumn, pageRow);
}
else if (fileName.getExtension() == L"image")
{
Expand Down Expand Up @@ -187,7 +199,7 @@ bool StyleBitmap::resolve(int32_t dpi) const
}

m_bitmap = bm;
m_fileName = fileName.getPathName();
m_fileName = key;
m_dpi = dpi;
return true;
}
Expand Down
Loading

0 comments on commit a407745

Please sign in to comment.