Skip to content

Commit 2ab83e7

Browse files
committed
feat: add render recording button, WIP
1 parent 8d7b2cf commit 2ab83e7

File tree

4 files changed

+71
-16
lines changed

4 files changed

+71
-16
lines changed

src/graphics/renderer.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@
55

66
//TODO(Totto): assert return values of all sdl functions
77

8+
9+
Renderer::Renderer(SDL_Renderer* renderer) : m_renderer{ renderer } {
10+
11+
if (m_renderer == nullptr) {
12+
throw helper::InitializationError{ fmt::format("Failed creating a SDL Renderer: {}", SDL_GetError()) };
13+
}
14+
15+
auto result = SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_BLEND);
16+
if (result < 0) {
17+
throw helper::InitializationError{ fmt::format("Failed in setting BlendMode on Renderer: {}", SDL_GetError()) };
18+
}
19+
}
20+
821
Renderer::Renderer(const Window& window, const VSync v_sync)
9-
: m_renderer{ SDL_CreateRenderer(
22+
: Renderer{ SDL_CreateRenderer(
1023
window.get_sdl_window(),
1124
-1,
1225
(v_sync == VSync::Enabled ? SDL_RENDERER_PRESENTVSYNC : 0) | SDL_RENDERER_TARGETTEXTURE
@@ -16,19 +29,20 @@ Renderer::Renderer(const Window& window, const VSync v_sync)
1629
| SDL_RENDERER_ACCELERATED
1730
#endif
1831
) } {
32+
}
1933

20-
if (m_renderer == nullptr) {
21-
throw helper::InitializationError{ fmt::format("Failed creating a SDL Renderer: {}", SDL_GetError()) };
22-
}
34+
Renderer Renderer::get_software_renderer(std::unique_ptr<SDL_Surface>& surface) {
35+
return Renderer{ SDL_CreateSoftwareRenderer(surface.get()) };
36+
}
2337

24-
auto result = SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_BLEND);
25-
if (result < 0) {
26-
throw helper::InitializationError{ fmt::format("Failed in setting BlendMode on Renderer: {}", SDL_GetError()) };
27-
}
38+
Renderer::Renderer(Renderer&& other) noexcept : m_renderer{ other.m_renderer } {
39+
other.m_renderer = nullptr;
2840
}
2941

3042
Renderer::~Renderer() {
31-
SDL_DestroyRenderer(m_renderer);
43+
if (m_renderer != nullptr) {
44+
SDL_DestroyRenderer(m_renderer);
45+
}
3246
}
3347

3448
void Renderer::set_draw_color(const Color& color) const {

src/graphics/renderer.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,22 @@ struct Renderer final {
2222
private:
2323
SDL_Renderer* m_renderer;
2424

25+
OOPETRIS_GRAPHICS_EXPORTED explicit Renderer(SDL_Renderer* renderer);
26+
27+
2528
public:
2629
OOPETRIS_GRAPHICS_EXPORTED explicit Renderer(const Window& window, VSync v_sync);
30+
31+
OOPETRIS_GRAPHICS_EXPORTED static Renderer get_software_renderer(std::unique_ptr<SDL_Surface>& surface);
32+
2733
OOPETRIS_GRAPHICS_EXPORTED Renderer(const Renderer&) = delete;
2834
OOPETRIS_GRAPHICS_EXPORTED Renderer& operator=(const Renderer&) = delete;
35+
36+
37+
OOPETRIS_GRAPHICS_EXPORTED Renderer(Renderer&& other) noexcept;
38+
39+
OOPETRIS_GRAPHICS_EXPORTED Renderer& operator=(Renderer&& other) = default;
40+
2941
OOPETRIS_GRAPHICS_EXPORTED ~Renderer();
3042

3143
OOPETRIS_GRAPHICS_EXPORTED void set_draw_color(const Color& color) const;

src/scenes/recording_selector/recording_component.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "manager/font.hpp"
66
#include "manager/resource_manager.hpp"
77
#include "recording_component.hpp"
8+
#include "ui/components/text_button.hpp"
89
#include "ui/widget.hpp"
910

1011
#include <fmt/format.h>
@@ -20,23 +21,47 @@ custom_ui::RecordingComponent::RecordingComponent(
2021
ui::Focusable{focus_helper.focus_id()},
2122
ui::Hoverable{layout.get_rect()},
2223
m_main_layout{ utils::SizeIdentity<2>(), focus_helper.focus_id(),
23-
ui::Direction::Vertical,
24-
std::array<double, 1>{ 0.6 }, ui::RelativeMargin{layout.get_rect(), ui::Direction::Vertical,0.05}, std::pair<double, double>{ 0.05, 0.03 },
24+
ui::Direction::Horizontal,
25+
std::array<double, 1>{ 0.9 }, ui::RelativeMargin{layout.get_rect(), ui::Direction::Vertical,0.05}, std::pair<double, double>{ 0.05, 0.03 },
2526
layout,false
2627
},m_metadata{std::move(metadata)}{
2728

28-
m_main_layout.add<ui::Label>(
29+
30+
auto text_layout_index = m_main_layout.add<ui::TileLayout>(
31+
utils::SizeIdentity<2>(), focus_helper.focus_id(), ui::Direction::Vertical, std::array<double, 1>{ 0.6 },
32+
ui::RelativeMargin{ layout.get_rect(), ui::Direction::Vertical, 0.05 },
33+
std::pair<double, double>{ 0.05, 0.03 }
34+
);
35+
36+
auto* text_layout = m_main_layout.get<ui::TileLayout>(text_layout_index);
37+
38+
39+
m_main_layout.add<ui::TextButton>(
40+
service_provider, "Render", service_provider->font_manager().get(FontId::Default), Color::white(),
41+
focus_helper.focus_id(),
42+
[](const ui::TextButton&) -> bool {
43+
//TODO
44+
45+
return false;
46+
},
47+
std::pair<double, double>{ 0.95, 0.85 },
48+
ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center },
49+
std::pair<double, double>{ 0.1, 0.1 }
50+
);
51+
52+
text_layout->add<ui::Label>(
2953
service_provider, "name: ?", service_provider->font_manager().get(FontId::Default), Color::white(),
3054
std::pair<double, double>{ 0.5, 0.5 },
3155
ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center }
3256
);
3357

34-
const auto information_layout_index = m_main_layout.add<ui::TileLayout>(
58+
59+
const auto information_layout_index = text_layout->add<ui::TileLayout>(
3560
utils::SizeIdentity<3>(), focus_helper.focus_id(), ui::Direction::Horizontal,
3661
std::array<double, 2>{ 0.33, 0.66 }, ui::AbsolutMargin{ 10 }, std::pair<double, double>{ 0.05, 0.03 }
3762
);
3863

39-
auto* const information_layout = m_main_layout.get<ui::TileLayout>(information_layout_index);
64+
auto* const information_layout = text_layout->get<ui::TileLayout>(information_layout_index);
4065

4166

4267
information_layout->add<ui::Label>(
@@ -104,9 +129,11 @@ helper::BoolWrapper<std::pair<ui::EventHandleType, ui::Widget*>> custom_ui::Reco
104129

105130
[[nodiscard]] std::tuple<ui::Label*, ui::Label*, ui::Label*, ui::Label*> custom_ui::RecordingComponent::get_texts() {
106131

107-
auto* name_text = m_main_layout.get<ui::Label>(0);
132+
auto* text_layout = m_main_layout.get<ui::TileLayout>(0);
133+
134+
auto* name_text = text_layout->get<ui::Label>(0);
108135

109-
auto* information_layout = m_main_layout.get<ui::TileLayout>(1);
136+
auto* information_layout = text_layout->get<ui::TileLayout>(1);
110137

111138
auto* source_text = information_layout->get<ui::Label>(0);
112139
auto* date_text = information_layout->get<ui::Label>(1);

src/scenes/recording_selector/recording_selector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ namespace scenes {
218218

219219
auto focus_helper = ui::FocusHelper{ 3 };
220220

221+
//TODO(Totto): sort by date, get the date from additional information or the file creation date
222+
221223
for (const auto& metadata : metadata_vector) {
222224
scroll_layout->add<custom_ui::RecordingComponent>(
223225
ui::RelativeItemSize{ scroll_layout->layout(), 0.2 }, m_service_provider, std::ref(focus_helper),

0 commit comments

Comments
 (0)