Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Apr 26, 2023
1 parent c25962d commit f1c029d
Show file tree
Hide file tree
Showing 34 changed files with 1,523 additions and 718 deletions.
466 changes: 19 additions & 447 deletions examples/play-glfw/App.cpp

Large diffs are not rendered by default.

53 changes: 7 additions & 46 deletions examples/play-glfw/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Copyright (c) 2021-2023 Darby Johnston
// All rights reserved.

#include <tlApp/IApp.h>
#include <tlGLFWApp/IApp.h>

#include <tlTimeline/IRender.h>
#include <tlTimeline/TimelinePlayer.h>

#include <tlCore/FontSystem.h>

struct GLFWwindow;

namespace tl
Expand All @@ -18,6 +16,8 @@ namespace tl
//! Example GLFW playback application.
namespace play_glfw
{
class MainWindow;

//! HUD elements.
enum class HUDElement
{
Expand All @@ -44,7 +44,7 @@ namespace tl
};

//! Application.
class App : public app::IApp
class App : public glfw::IApp
{
TLRENDER_NON_COPYABLE(App);

Expand All @@ -65,53 +65,14 @@ namespace tl
char* argv[],
const std::shared_ptr<system::Context>&);

//! Run the application.
void run();

//! Exit the application.
void exit();
protected:
void _tick() override;

private:
void _setFullscreenWindow(bool);
void _fullscreenCallback(bool);
static void _frameBufferSizeCallback(GLFWwindow*, int, int);
static void _windowContentScaleCallback(GLFWwindow*, float, float);
static void _keyCallback(GLFWwindow*, int, int, int, int);

void _printShortcutsHelp();

void _tick();

void _hudUpdate();
void _hudCallback(bool);
void _drawHUD();
void _drawHUDLabel(
const std::string& text,
const imaging::FontInfo&,
HUDElement);

void _playbackCallback(timeline::Playback);
void _loopPlaybackCallback(timeline::Loop);

std::string _input;
Options _options;

std::shared_ptr<timeline::TimelinePlayer> _timelinePlayer;

GLFWwindow* _glfwWindow = nullptr;
imaging::Size _windowSize;
math::Vector2i _windowPos;
bool _fullscreen = false;
imaging::Size _frameBufferSize;
math::Vector2f _contentScale = math::Vector2f(1.F, 1.F);
bool _hud = false;
std::shared_ptr<imaging::FontSystem> _fontSystem;
std::shared_ptr<timeline::IRender> _render;
bool _renderDirty = true;
timeline::VideoData _videoData;
std::map<HUDElement, std::string> _hudLabels;

bool _running = true;
std::shared_ptr<MainWindow> _mainWindow;
};
}
}
Expand Down
6 changes: 4 additions & 2 deletions examples/play-glfw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
set(HEADERS
App.h)
App.h
MainWindow.h)

set(SOURCE
App.cpp
MainWindow.cpp
main.cpp)

add_executable(play-glfw ${SOURCE} ${HEADERS})
target_link_libraries(play-glfw tlApp tlGL GLFW)
target_link_libraries(play-glfw tlGLFWApp)
set_target_properties(play-glfw PROPERTIES FOLDER examples)
103 changes: 103 additions & 0 deletions examples/play-glfw/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2021-2023 Darby Johnston
// All rights reserved.

#include "MainWindow.h"

#include <tlUI/ButtonGroup.h>
#include <tlUI/RowLayout.h>
#include <tlUI/ScrollArea.h>
#include <tlUI/TimelineViewport.h>
#include <tlUI/TimelineWidget.h>
#include <tlUI/ToolButton.h>

namespace tl
{
namespace examples
{
namespace play_glfw
{
struct MainWindow::Private
{
std::shared_ptr<ui::TimelineViewport> timelineViewport;
std::shared_ptr<ui::TimelineWidget> timelineWidget;
std::shared_ptr<ui::ButtonGroup> playbackButtonGroup;
std::shared_ptr<ui::RowLayout> layout;
std::shared_ptr<observer::ValueObserver<timeline::Playback> > playbackObserver;
};

void MainWindow::_init(
const std::shared_ptr<timeline::TimelinePlayer>& timelinePlayer,
const std::shared_ptr<system::Context>& context)
{
IWidget::_init("MainWindow", context);
TLRENDER_P();

setBackgroundRole(ui::ColorRole::Window);

p.timelineViewport = ui::TimelineViewport::create(context);
p.timelineViewport->setTimelinePlayers({ timelinePlayer });

p.timelineWidget = ui::TimelineWidget::create(context);
p.timelineWidget->setTimelinePlayer(timelinePlayer);

auto stopButton = ui::ToolButton::create(context);
stopButton->setIcon("PlaybackStop");
auto forwardButton = ui::ToolButton::create(context);
forwardButton->setIcon("PlaybackForward");
auto reverseButton = ui::ToolButton::create(context);
reverseButton->setIcon("PlaybackReverse");
p.playbackButtonGroup = ui::ButtonGroup::create(ui::ButtonGroupType::Radio, context);
p.playbackButtonGroup->addButton(stopButton);
p.playbackButtonGroup->addButton(forwardButton);
p.playbackButtonGroup->addButton(reverseButton);

p.layout = ui::VerticalLayout::create(context, shared_from_this());
p.layout->setSpacingRole(ui::SizeRole::None);
p.timelineViewport->setParent(p.layout);
p.timelineWidget->setParent(p.layout);
auto hLayout = ui::HorizontalLayout::create(context, p.layout);
hLayout->setMarginRole(ui::SizeRole::MarginSmall);
hLayout->setSpacingRole(ui::SizeRole::SpacingTool);
reverseButton->setParent(hLayout);
stopButton->setParent(hLayout);
forwardButton->setParent(hLayout);

p.playbackObserver = observer::ValueObserver<timeline::Playback>::create(
timelinePlayer->observePlayback(),
[this](timeline::Playback value)
{
_p->playbackButtonGroup->setChecked(static_cast<int>(value), true);
});

p.playbackButtonGroup->setCheckedCallback(
[timelinePlayer](int index, bool value)
{
timelinePlayer->setPlayback(static_cast<timeline::Playback>(index));
});
}

MainWindow::MainWindow() :
_p(new Private)
{}

MainWindow::~MainWindow()
{}

std::shared_ptr<MainWindow> MainWindow::create(
const std::shared_ptr<timeline::TimelinePlayer>& timelinePlayer,
const std::shared_ptr<system::Context>& context)
{
auto out = std::shared_ptr<MainWindow>(new MainWindow);
out->_init(timelinePlayer, context);
return out;
}

void MainWindow::setGeometry(const math::BBox2i& value)
{
IWidget::setGeometry(value);
_p->layout->setGeometry(value);
}
}
}
}
41 changes: 41 additions & 0 deletions examples/play-glfw/MainWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2021-2023 Darby Johnston
// All rights reserved.

#include <tlUI/IWidget.h>

#include <tlTimeline/TimelinePlayer.h>

namespace tl
{
namespace examples
{
namespace play_glfw
{
//! Main window.
class MainWindow : public ui::IWidget
{
TLRENDER_NON_COPYABLE(MainWindow);

protected:
void _init(
const std::shared_ptr<timeline::TimelinePlayer>&,
const std::shared_ptr<system::Context>&);

MainWindow();

public:
~MainWindow();

static std::shared_ptr<MainWindow> create(
const std::shared_ptr<timeline::TimelinePlayer>&,
const std::shared_ptr<system::Context>&);

void setGeometry(const math::BBox2i&) override;

private:
TLRENDER_PRIVATE();
};
}
}
}
2 changes: 0 additions & 2 deletions lib/tlGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set(HEADERS
OffscreenBuffer.h
Render.h
Shader.h
State.h
Texture.h
Util.h)
set(PRIVATE_HEADERS
Expand All @@ -18,7 +17,6 @@ set(SOURCE
RenderShaders.cpp
RenderVideo.cpp
Shader.cpp
State.cpp
Texture.cpp
Util.cpp)

Expand Down
1 change: 0 additions & 1 deletion lib/tlGL/RenderVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <tlGL/RenderPrivate.h>

#include <tlGL/Mesh.h>
#include <tlGL/State.h>
#include <tlGL/Util.h>

#include <tlCore/Math.h>
Expand Down
48 changes: 0 additions & 48 deletions lib/tlGL/State.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions lib/tlGL/State.h

This file was deleted.

34 changes: 34 additions & 0 deletions lib/tlGL/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,39 @@ namespace tl
};
return data[static_cast<std::size_t>(value)];
}
struct SetAndRestore::Private
{
unsigned int id = 0;
GLboolean previous = GL_FALSE;
};

SetAndRestore::SetAndRestore(unsigned int id, bool value) :
_p(new Private)
{
_p->id = id;

glGetBooleanv(id, &_p->previous);

if (value)
{
glEnable(id);
}
else
{
glDisable(id);
}
}

SetAndRestore::~SetAndRestore()
{
if (_p->previous)
{
glEnable(_p->id);
}
else
{
glDisable(_p->id);
}
}
}
}
Loading

0 comments on commit f1c029d

Please sign in to comment.