mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-18 22:18:38 -04:00
92 lines
3.1 KiB
C++
92 lines
3.1 KiB
C++
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "MeditationTimer.hpp"
|
|
#include "Style.hpp"
|
|
|
|
#include <GuiTimer.hpp>
|
|
#include <purefs/filesystem_paths.hpp>
|
|
#include <service-audio/AudioServiceAPI.hpp>
|
|
#include <apps-common/widgets/ProgressTimerWithBarGraphAndCounter.hpp>
|
|
|
|
#include <gsl/assert>
|
|
|
|
namespace
|
|
{
|
|
constexpr auto meditationTimerName = "MeditationTimer";
|
|
constexpr std::chrono::seconds initialInterval{1};
|
|
} // namespace
|
|
|
|
namespace gui
|
|
{
|
|
MeditationTimer::MeditationTimer(std::uint32_t x,
|
|
std::uint32_t y,
|
|
std::uint32_t width,
|
|
std::uint32_t height,
|
|
app::ApplicationMeditation *app,
|
|
Item *_parent)
|
|
: HBox(_parent, x, y, width, height), application{app}
|
|
{
|
|
setEdges(RectangleEdge::None);
|
|
build();
|
|
}
|
|
|
|
void MeditationTimer::build()
|
|
{
|
|
namespace timerStyle = style::meditation::timer;
|
|
|
|
const Point boxCenter(getX() + (getWidth() / 2), getY() + (getHeight() / 2));
|
|
Circle::ShapeParams params;
|
|
params.setCenterPoint(boxCenter)
|
|
.setRadius(timerStyle::Radius)
|
|
.setBorderColor(timerStyle::BorderColor)
|
|
.setFocusBorderColor(timerStyle::BorderColor)
|
|
.setPenWidth(timerStyle::PenWidth)
|
|
.setFocusPenWidth(timerStyle::PenWidth);
|
|
progressBar = new CircularProgressBar(this, params);
|
|
|
|
text = new Text(progressBar, 0, 0, getWidth(), getHeight());
|
|
text->setEdges(RectangleEdge::None);
|
|
text->setFont(style::window::font::supersizemelight);
|
|
text->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
|
|
text->setEditMode(EditMode::Browse);
|
|
|
|
timer = std::make_unique<app::ProgressTimerWithBarGraphAndCounter>(
|
|
application, *this, meditationTimerName, initialInterval);
|
|
timer->attach(progressBar);
|
|
timer->attach(text);
|
|
timer->registerOnIntervalCallback(std::bind(&MeditationTimer::playSound, this));
|
|
}
|
|
|
|
auto MeditationTimer::onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) -> bool
|
|
{
|
|
setPosition(newDim.x, newDim.y);
|
|
setSize(newDim.w, newDim.h);
|
|
return true;
|
|
}
|
|
|
|
void MeditationTimer::setCounterVisible(bool isVisible) noexcept
|
|
{
|
|
text->setVisible(isVisible);
|
|
}
|
|
|
|
app::TimerWithCallbacks &MeditationTimer::getTimer() noexcept
|
|
{
|
|
Expects(timer != nullptr);
|
|
return *timer;
|
|
}
|
|
|
|
gui::Progress &MeditationTimer::getProgress() noexcept
|
|
{
|
|
Expects(progressBar != nullptr);
|
|
return *progressBar;
|
|
}
|
|
|
|
void MeditationTimer::playSound()
|
|
{
|
|
AudioServiceAPI::PlaybackStart(application,
|
|
audio::PlaybackType::Meditation,
|
|
purefs::dir::getAssetsDirPath() / "audio/meditation/gong.mp3");
|
|
}
|
|
} // namespace gui
|