You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

122 lines
3.0 KiB

#include "main-window.hpp"
#include "obs-manager.hpp"
#include <iostream>
#include <string>
#include <gdk/gdkx.h>
using namespace std;
MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
: mBoxMain(Gtk::Orientation::ORIENTATION_VERTICAL, 6),
mBoxSpacer(Gtk::Orientation::ORIENTATION_VERTICAL, 0),
mButtonPreview("View Preview"),
mButtonStart("Start Recording"),
mButtonSettings("Settings"),
mButtonExit("Exit"),
mLabelVersion("Version: "),
mSettingsWindow(obs),
mPreviewWindow(obs)
{
set_title("New Recording");
set_default_size(1048, 720);
set_border_width(10);
mApp = app;
mOBS = obs;
mOBS->sigStartPreview.connect(sigc::mem_fun(*this, &MainWindow::onPreviewStarted));
mOBS->sigStartRecording.connect(sigc::mem_fun(*this, &MainWindow::onRecordingStarted));
mOBS->sigStopRecording.connect(sigc::mem_fun(*this, &MainWindow::onRecordingStopped));
mButtonPreview.signal_clicked().connect(
sigc::mem_fun(*this, &MainWindow::onPreviewClicked));
mButtonStart.signal_clicked().connect(
sigc::mem_fun(*this, &MainWindow::onStartClicked));
mButtonSettings.signal_clicked().connect(
sigc::mem_fun(*this, &MainWindow::onSettingsClicked));
mButtonExit.signal_clicked().connect(
sigc::mem_fun(*this, &MainWindow::onExitClicked));
mButtonStart.set_sensitive(false);
mBoxMain.pack_start(mButtonPreview, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mButtonStart, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mBoxSpacer, Gtk::PACK_EXPAND_WIDGET);
mBoxMain.pack_start(mButtonSettings, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mButtonExit, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mLabelVersion, Gtk::PACK_SHRINK);
add(mBoxMain);
mBoxMain.show_all();
string version;
version.append("OBS Version: ");
version.append(obs->GetVersion());
mLabelVersion.set_text(version);
}
MainWindow::~MainWindow()
{
mOBS->Cleanup();
}
void MainWindow::on_show()
{
Gtk::Widget::on_show();
Gdk::Rectangle rect;
auto screen = get_screen();
auto monitor = screen->get_monitor_at_window(screen->get_active_window());
screen->get_monitor_geometry(monitor, rect);
mOBS->Initialize(rect);
onSettingsClicked();
}
void MainWindow::onPreviewClicked()
{
mPreviewWindow.show();
}
void MainWindow::onStartClicked()
{
if (mOBS->IsRecording())
mOBS->StopRecording();
else
mOBS->StartRecording();
}
void MainWindow::onSettingsClicked()
{
mSettingsWindow.set_transient_for(*this);
mSettingsWindow.show();
}
void MainWindow::onExitClicked()
{
mOBS->sigCleanup.connect(sigc::mem_fun(*this, &MainWindow::onCleanupDone));
mOBS->Cleanup();
}
void MainWindow::onCleanupDone()
{
mApp->quit();
}
void MainWindow::onPreviewStarted()
{
mButtonStart.set_sensitive(true);
}
void MainWindow::onRecordingStarted()
{
mButtonStart.set_label("Stop Recording");
}
void MainWindow::onRecordingStopped()
{
mButtonStart.set_label("Start Recording");
}