2017-02-13 21:34:23 +00:00
|
|
|
// Aseprite UI Library
|
2020-07-07 22:06:48 +00:00
|
|
|
// Copyright (C) 2020 Igara Studio S.A.
|
2017-02-13 21:34:23 +00:00
|
|
|
// Copyright (C) 2017 David Capello
|
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ui/style.h"
|
|
|
|
|
2020-07-07 22:06:48 +00:00
|
|
|
#include "os/font.h"
|
|
|
|
|
2017-02-13 21:34:23 +00:00
|
|
|
namespace ui {
|
|
|
|
|
2017-02-17 17:18:47 +00:00
|
|
|
// static
|
|
|
|
gfx::Border Style::UndefinedBorder()
|
|
|
|
{
|
|
|
|
return gfx::Border(-1, -1, -1, -1);
|
|
|
|
}
|
|
|
|
|
2017-02-13 21:34:23 +00:00
|
|
|
Style::Style(const Style* base)
|
|
|
|
: m_insertionPoint(0)
|
2017-02-17 17:18:47 +00:00
|
|
|
, m_margin(base ? base->margin(): Style::UndefinedBorder())
|
|
|
|
, m_border(base ? base->border(): Style::UndefinedBorder())
|
|
|
|
, m_padding(base ? base->padding(): Style::UndefinedBorder())
|
2017-03-08 21:53:36 +00:00
|
|
|
, m_font(nullptr)
|
2017-02-13 21:34:23 +00:00
|
|
|
{
|
|
|
|
if (base)
|
|
|
|
m_layers = base->layers();
|
|
|
|
}
|
|
|
|
|
2020-07-07 22:06:48 +00:00
|
|
|
void Style::setFont(const os::Ref<os::Font>& font)
|
|
|
|
{
|
|
|
|
m_font = font;
|
|
|
|
}
|
|
|
|
|
2017-02-13 21:34:23 +00:00
|
|
|
void Style::addLayer(const Layer& layer)
|
|
|
|
{
|
|
|
|
int i, j = int(m_layers.size());
|
|
|
|
|
|
|
|
for (i=m_insertionPoint; i<int(m_layers.size()); ++i) {
|
|
|
|
if (layer.type() == m_layers[i].type()) {
|
|
|
|
for (j=i+1; j<int(m_layers.size()); ++j) {
|
|
|
|
if (layer.type() != m_layers[j].type())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < int(m_layers.size())) {
|
|
|
|
if (layer.type() == Style::Layer::Type::kNewLayer)
|
|
|
|
m_insertionPoint = i+1;
|
|
|
|
else
|
|
|
|
m_layers.insert(m_layers.begin()+j, layer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_layers.push_back(layer);
|
|
|
|
if (layer.type() == Style::Layer::Type::kNewLayer)
|
|
|
|
m_insertionPoint = int(m_layers.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ui
|