1 | // Aseprite |
2 | // Copyright (C) 2019-2022 Igara Studio S.A. |
3 | // Copyright (C) 2018 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "app/ui/editor/editor_render.h" |
13 | |
14 | #include "app/color_utils.h" |
15 | #include "app/pref/preferences.h" |
16 | #include "app/render/simple_renderer.h" |
17 | |
18 | namespace app { |
19 | |
20 | static doc::ImageBufferPtr g_renderBuffer; |
21 | |
22 | EditorRender::EditorRender() |
23 | : m_renderer(std::make_unique<SimpleRenderer>()) |
24 | { |
25 | m_renderer->setNewBlendMethod( |
26 | Preferences::instance().experimental.newBlend()); |
27 | } |
28 | |
29 | EditorRender::~EditorRender() |
30 | { |
31 | } |
32 | |
33 | void EditorRender::setRefLayersVisiblity(const bool visible) |
34 | { |
35 | m_renderer->setRefLayersVisiblity(visible); |
36 | } |
37 | |
38 | void EditorRender::setNonactiveLayersOpacity(const int opacity) |
39 | { |
40 | m_renderer->setNonactiveLayersOpacity(opacity); |
41 | } |
42 | |
43 | void EditorRender::setNewBlendMethod(const bool newBlend) |
44 | { |
45 | m_renderer->setNewBlendMethod(newBlend); |
46 | } |
47 | |
48 | void EditorRender::setProjection(const render::Projection& projection) |
49 | { |
50 | m_renderer->setProjection(projection); |
51 | } |
52 | |
53 | void EditorRender::setupBackground(Doc* doc, doc::PixelFormat pixelFormat) |
54 | { |
55 | DocumentPreferences& docPref = Preferences::instance().document(doc); |
56 | render::BgType bgType; |
57 | |
58 | gfx::Size tile; |
59 | switch (docPref.bg.type()) { |
60 | case app::gen::BgType::CHECKERED_16x16: |
61 | bgType = render::BgType::CHECKERED; |
62 | tile = gfx::Size(16, 16); |
63 | break; |
64 | case app::gen::BgType::CHECKERED_8x8: |
65 | bgType = render::BgType::CHECKERED; |
66 | tile = gfx::Size(8, 8); |
67 | break; |
68 | case app::gen::BgType::CHECKERED_4x4: |
69 | bgType = render::BgType::CHECKERED; |
70 | tile = gfx::Size(4, 4); |
71 | break; |
72 | case app::gen::BgType::CHECKERED_2x2: |
73 | bgType = render::BgType::CHECKERED; |
74 | tile = gfx::Size(2, 2); |
75 | break; |
76 | case app::gen::BgType::CHECKERED_1x1: |
77 | bgType = render::BgType::CHECKERED; |
78 | tile = gfx::Size(1, 1); |
79 | break; |
80 | case app::gen::BgType::CHECKERED_CUSTOM: |
81 | bgType = render::BgType::CHECKERED; |
82 | tile = docPref.bg.size(); |
83 | break; |
84 | default: |
85 | bgType = render::BgType::TRANSPARENT; |
86 | break; |
87 | } |
88 | |
89 | render::BgOptions bg; |
90 | bg.type = bgType; |
91 | bg.zoom = docPref.bg.zoom(); |
92 | bg.color1 = color_utils::color_for_image_without_alpha(docPref.bg.color1(), pixelFormat); |
93 | bg.color2 = color_utils::color_for_image_without_alpha(docPref.bg.color2(), pixelFormat); |
94 | bg.stripeSize = tile; |
95 | m_renderer->setBgOptions(bg); |
96 | } |
97 | |
98 | void EditorRender::setTransparentBackground() |
99 | { |
100 | m_renderer->setBgOptions(render::BgOptions::MakeTransparent()); |
101 | } |
102 | |
103 | void EditorRender::setSelectedLayer(const doc::Layer* layer) |
104 | { |
105 | m_renderer->setSelectedLayer(layer); |
106 | } |
107 | |
108 | void EditorRender::setPreviewImage(const doc::Layer* layer, |
109 | const doc::frame_t frame, |
110 | const doc::Image* image, |
111 | const doc::Tileset* tileset, |
112 | const gfx::Point& pos, |
113 | const doc::BlendMode blendMode) |
114 | { |
115 | m_renderer->setPreviewImage(layer, frame, image, tileset, |
116 | pos, blendMode); |
117 | } |
118 | |
119 | void EditorRender::removePreviewImage() |
120 | { |
121 | m_renderer->removePreviewImage(); |
122 | } |
123 | |
124 | void EditorRender::( |
125 | render::ExtraType type, |
126 | const doc::Cel* cel, |
127 | const doc::Image* image, |
128 | doc::BlendMode blendMode, |
129 | const doc::Layer* currentLayer, |
130 | doc::frame_t currentFrame) |
131 | { |
132 | m_renderer->setExtraImage(type, cel, image, blendMode, |
133 | currentLayer, currentFrame); |
134 | } |
135 | |
136 | void EditorRender::() |
137 | { |
138 | m_renderer->removeExtraImage(); |
139 | } |
140 | |
141 | void EditorRender::setOnionskin(const render::OnionskinOptions& options) |
142 | { |
143 | m_renderer->setOnionskin(options); |
144 | } |
145 | |
146 | void EditorRender::disableOnionskin() |
147 | { |
148 | m_renderer->disableOnionskin(); |
149 | } |
150 | |
151 | void EditorRender::renderSprite( |
152 | doc::Image* dstImage, |
153 | const doc::Sprite* sprite, |
154 | doc::frame_t frame) |
155 | { |
156 | m_renderer->renderSprite(dstImage, sprite, frame); |
157 | } |
158 | |
159 | void EditorRender::renderSprite( |
160 | doc::Image* dstImage, |
161 | const doc::Sprite* sprite, |
162 | doc::frame_t frame, |
163 | const gfx::ClipF& area) |
164 | { |
165 | m_renderer->renderSprite(dstImage, sprite, frame, area); |
166 | } |
167 | |
168 | void EditorRender::renderCheckeredBackground( |
169 | doc::Image* image, |
170 | const gfx::Clip& area) |
171 | { |
172 | m_renderer->renderCheckeredBackground(image, area); |
173 | } |
174 | |
175 | void EditorRender::renderImage( |
176 | doc::Image* dst_image, |
177 | const doc::Image* src_image, |
178 | const doc::Palette* pal, |
179 | const int x, |
180 | const int y, |
181 | const int opacity, |
182 | const doc::BlendMode blendMode) |
183 | { |
184 | m_renderer->renderImage(dst_image, src_image, pal, |
185 | x, y, opacity, blendMode); |
186 | } |
187 | |
188 | doc::ImageBufferPtr EditorRender::getRenderImageBuffer() |
189 | { |
190 | if (!g_renderBuffer) |
191 | g_renderBuffer.reset(new doc::ImageBuffer); |
192 | return g_renderBuffer; |
193 | } |
194 | |
195 | } // namespace app |
196 | |