1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:08:10 +00:00

Applications: Add Presenter

This version can already:
- load all of the defined file format except for the image type and the
  frame-specific stuff
- navigate frames and slides (though frames are mostly stubbed out)
- display text with various common settings
- displays text with various fitting and scaling methods
- scale and position objects correctly no matter the window size
This commit is contained in:
kleines Filmröllchen 2022-10-20 22:30:39 +02:00 committed by Andrew Kaster
parent 295f83e54c
commit de44d6c0a6
12 changed files with 828 additions and 0 deletions

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Slide.h"
#include <AK/JsonObject.h>
#include <AK/NonnullRefPtrVector.h>
#include <LibGUI/Window.h>
#include <LibGfx/Painter.h>
#include <LibGfx/Size.h>
#include <LibGfx/TextAlignment.h>
Slide::Slide(NonnullRefPtrVector<SlideObject> slide_objects, String title)
: m_slide_objects(move(slide_objects))
, m_title(move(title))
{
}
ErrorOr<Slide> Slide::parse_slide(JsonObject const& slide_json, NonnullRefPtr<GUI::Window> window)
{
// FIXME: Use the text with the "title" role for a title, if there is no title given.
auto title = slide_json.get("title"sv).as_string_or("Untitled slide");
auto const& maybe_slide_objects = slide_json.get("objects"sv);
if (!maybe_slide_objects.is_array())
return Error::from_string_view("Slide objects must be an array"sv);
auto const& json_slide_objects = maybe_slide_objects.as_array();
NonnullRefPtrVector<SlideObject> slide_objects;
for (auto const& maybe_slide_object_json : json_slide_objects.values()) {
if (!maybe_slide_object_json.is_object())
return Error::from_string_view("Slides must be objects"sv);
auto const& slide_object_json = maybe_slide_object_json.as_object();
auto slide_object = TRY(SlideObject::parse_slide_object(slide_object_json, window));
slide_objects.append(move(slide_object));
}
return Slide { move(slide_objects), title };
}
void Slide::paint(Gfx::Painter& painter, unsigned int current_frame, Gfx::FloatSize display_scale) const
{
for (auto const& object : m_slide_objects) {
if (object.is_visible_during_frame(current_frame))
object.paint(painter, display_scale);
}
// FIXME: Move this to user settings.
painter.draw_text(painter.clip_rect(), title(), Gfx::TextAlignment::BottomCenter);
}