1 | // Aseprite UI Library |
---|---|
2 | // Copyright (C) 2020 Igara Studio S.A. |
3 | // Copyright (C) 2017 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "ui/style.h" |
13 | |
14 | #include "os/font.h" |
15 | |
16 | namespace ui { |
17 | |
18 | // static |
19 | gfx::Border Style::UndefinedBorder() |
20 | { |
21 | return gfx::Border(-1, -1, -1, -1); |
22 | } |
23 | |
24 | Style::Style(const Style* base) |
25 | : m_insertionPoint(0) |
26 | , m_margin(base ? base->margin(): Style::UndefinedBorder()) |
27 | , m_border(base ? base->border(): Style::UndefinedBorder()) |
28 | , m_padding(base ? base->padding(): Style::UndefinedBorder()) |
29 | , m_font(nullptr) |
30 | { |
31 | if (base) |
32 | m_layers = base->layers(); |
33 | } |
34 | |
35 | void Style::setFont(const os::Ref<os::Font>& font) |
36 | { |
37 | m_font = font; |
38 | } |
39 | |
40 | void Style::addLayer(const Layer& layer) |
41 | { |
42 | int i, j = int(m_layers.size()); |
43 | |
44 | for (i=m_insertionPoint; i<int(m_layers.size()); ++i) { |
45 | if (layer.type() == m_layers[i].type()) { |
46 | for (j=i+1; j<int(m_layers.size()); ++j) { |
47 | if (layer.type() != m_layers[j].type()) |
48 | break; |
49 | } |
50 | break; |
51 | } |
52 | } |
53 | |
54 | if (i < int(m_layers.size())) { |
55 | if (layer.type() == Style::Layer::Type::kNewLayer) |
56 | m_insertionPoint = i+1; |
57 | else |
58 | m_layers.insert(m_layers.begin()+j, layer); |
59 | } |
60 | else { |
61 | m_layers.push_back(layer); |
62 | if (layer.type() == Style::Layer::Type::kNewLayer) |
63 | m_insertionPoint = int(m_layers.size()); |
64 | } |
65 | } |
66 | |
67 | } // namespace ui |
68 |