#1 Move UI to classes
This commit is contained in:
@@ -3,7 +3,7 @@ set(CMAKE_CXX_STANDARD 17)
|
|||||||
|
|
||||||
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,)
|
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,)
|
||||||
|
|
||||||
project(PiCamera)
|
project(JAMCS)
|
||||||
|
|
||||||
# Find gtk+-4.0 library
|
# Find gtk+-4.0 library
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
|
add_subdirectory(ui)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
JAMCS
|
JAMCS
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(
|
|
||||||
JAMCS
|
|
||||||
PRIVATE
|
|
||||||
${GTK_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
target_link_directories(
|
|
||||||
JAMCS
|
|
||||||
PRIVATE
|
|
||||||
${GTK_LIBRARY_DIRS}
|
|
||||||
)
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
JAMCS
|
JAMCS
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${GTK_LIBRARIES}
|
UI
|
||||||
)
|
)
|
||||||
|
|
||||||
add_definitions (${GTK_CFLAGS_OTHER})
|
add_definitions (${GTK_CFLAGS_OTHER})
|
||||||
|
|||||||
43
src/main.cpp
43
src/main.cpp
@@ -1,49 +1,18 @@
|
|||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class CloseButton : public Gtk::Button
|
#include "ui/jamcswindow.h"
|
||||||
{
|
|
||||||
private:
|
|
||||||
void on_button_clicked();
|
|
||||||
Glib::RefPtr<Gtk::Application> app;
|
|
||||||
public:
|
|
||||||
CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> app);
|
|
||||||
};
|
|
||||||
|
|
||||||
CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> app)
|
// Default size for JAMCS window
|
||||||
{
|
// Set to match resolution of HyperPixel 4 display
|
||||||
this->app = app;
|
const static int DEFAULT_WINDOW_WIDTH = 800;
|
||||||
|
const static int DEFAULT_WINDOW_HEIGHT = 480;
|
||||||
set_label(label);
|
|
||||||
|
|
||||||
signal_clicked().connect(sigc::mem_fun(*this, &CloseButton::on_button_clicked));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CloseButton::on_button_clicked()
|
|
||||||
{
|
|
||||||
this->app.get()->quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyWindow : public Gtk::Window
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MyWindow();
|
|
||||||
};
|
|
||||||
|
|
||||||
MyWindow::MyWindow()
|
|
||||||
{
|
|
||||||
set_title("Basic application");
|
|
||||||
set_default_size(200, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
auto app = Gtk::Application::create("org.gtkmm.examples.base");
|
auto app = Gtk::Application::create("org.gtkmm.examples.base");
|
||||||
MyWindow window;
|
|
||||||
|
|
||||||
CloseButton button("Close", app);
|
JamcsWindow window(app, "JAMCS", DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
|
||||||
window.add(button);
|
|
||||||
window.show_all();
|
window.show_all();
|
||||||
|
|
||||||
return app->run(window);
|
return app->run(window);
|
||||||
|
|||||||
13
src/ui/CMakeLists.txt
Normal file
13
src/ui/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
add_subdirectory(common)
|
||||||
|
|
||||||
|
add_library(
|
||||||
|
UI
|
||||||
|
STATIC
|
||||||
|
jamcswindow.cpp
|
||||||
|
viewfinder.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(
|
||||||
|
UI
|
||||||
|
PUBLIC
|
||||||
|
CommonUI
|
||||||
|
)
|
||||||
20
src/ui/common/CMakeLists.txt
Normal file
20
src/ui/common/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
add_library(
|
||||||
|
CommonUI
|
||||||
|
STATIC
|
||||||
|
closebutton.cpp
|
||||||
|
)
|
||||||
|
target_include_directories(
|
||||||
|
CommonUI
|
||||||
|
PUBLIC
|
||||||
|
${GTK_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
target_link_directories(
|
||||||
|
CommonUI
|
||||||
|
PUBLIC
|
||||||
|
${GTK_LIBRARY_DIRS}
|
||||||
|
)
|
||||||
|
target_link_libraries(
|
||||||
|
CommonUI
|
||||||
|
PUBLIC
|
||||||
|
${GTK_LIBRARIES}
|
||||||
|
)
|
||||||
15
src/ui/common/closebutton.cpp
Normal file
15
src/ui/common/closebutton.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include "closebutton.h"
|
||||||
|
|
||||||
|
#include <gtkmm.h>
|
||||||
|
|
||||||
|
CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> appPtr) : app(appPtr)
|
||||||
|
{
|
||||||
|
set_label(label);
|
||||||
|
|
||||||
|
signal_clicked().connect(sigc::mem_fun(*this, &CloseButton::on_button_clicked));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseButton::on_button_clicked()
|
||||||
|
{
|
||||||
|
this->app.get()->quit();
|
||||||
|
}
|
||||||
15
src/ui/common/closebutton.h
Normal file
15
src/ui/common/closebutton.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef _CLOSEBUTTON_H
|
||||||
|
#define _CLOSEBUTTON_H
|
||||||
|
|
||||||
|
#include <gtkmm.h>
|
||||||
|
|
||||||
|
class CloseButton : public Gtk::Button
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
void on_button_clicked();
|
||||||
|
Glib::RefPtr<Gtk::Application> app;
|
||||||
|
public:
|
||||||
|
CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> appPtr);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _CLOSEBUTTON_H
|
||||||
6
src/ui/common/common.h
Normal file
6
src/ui/common/common.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef _COMMON_H
|
||||||
|
#define _COMMON_H
|
||||||
|
|
||||||
|
#include "closebutton.h"
|
||||||
|
|
||||||
|
#endif // _COMMON_H
|
||||||
18
src/ui/jamcswindow.cpp
Normal file
18
src/ui/jamcswindow.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include "jamcswindow.h"
|
||||||
|
|
||||||
|
#include <gtkmm.h>
|
||||||
|
|
||||||
|
#include "viewfinder.h"
|
||||||
|
|
||||||
|
JamcsWindow::JamcsWindow(Glib::RefPtr<Gtk::Application> appPtr, const Glib::ustring &title, int width, int height) : app(appPtr)
|
||||||
|
{
|
||||||
|
set_title(title);
|
||||||
|
set_default_size(width, height);
|
||||||
|
|
||||||
|
this->viewfinder = std::unique_ptr<Viewfinder>(new Viewfinder(app));
|
||||||
|
this->stack.add(*this->viewfinder, "viewfinder");
|
||||||
|
|
||||||
|
this->stack.set_visible_child("viewfinder");
|
||||||
|
|
||||||
|
this->add(this->stack);
|
||||||
|
}
|
||||||
19
src/ui/jamcswindow.h
Normal file
19
src/ui/jamcswindow.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef _WINDOW_H
|
||||||
|
#define _WINDOW_H
|
||||||
|
|
||||||
|
#include <gtkmm.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
#include "viewfinder.h"
|
||||||
|
|
||||||
|
class JamcsWindow : public Gtk::Window
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Glib::RefPtr<Gtk::Application> app;
|
||||||
|
Gtk::Stack stack;
|
||||||
|
std::unique_ptr<Viewfinder> viewfinder = nullptr;
|
||||||
|
public:
|
||||||
|
JamcsWindow(Glib::RefPtr<Gtk::Application> appPtr, const Glib::ustring &title, int width, int height);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _WINDOW_H
|
||||||
11
src/ui/viewfinder.cpp
Normal file
11
src/ui/viewfinder.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "viewfinder.h"
|
||||||
|
|
||||||
|
#include "common/common.h"
|
||||||
|
|
||||||
|
Viewfinder::Viewfinder(Glib::RefPtr<Gtk::Application> appPtr) : app(appPtr)
|
||||||
|
{
|
||||||
|
this->close_button = std::unique_ptr<CloseButton>(new CloseButton("X", app));
|
||||||
|
this->add(*this->close_button);
|
||||||
|
|
||||||
|
this->show_all();
|
||||||
|
}
|
||||||
17
src/ui/viewfinder.h
Normal file
17
src/ui/viewfinder.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef _VIEWFINDER_H
|
||||||
|
#define _VIEWFINDER_H
|
||||||
|
|
||||||
|
#include <gtkmm.h>
|
||||||
|
|
||||||
|
#include "common/common.h"
|
||||||
|
|
||||||
|
class Viewfinder : public Gtk::Box
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Glib::RefPtr<Gtk::Application> app;
|
||||||
|
std::unique_ptr<CloseButton> close_button = nullptr;
|
||||||
|
public:
|
||||||
|
Viewfinder(Glib::RefPtr<Gtk::Application> appPtr);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _VIEWFINDER_H
|
||||||
Reference in New Issue
Block a user