Skip to content

Commit

Permalink
feat(about): add about window
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniMay committed Mar 25, 2022
1 parent a9f3ae7 commit df41635
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 25 deletions.
Binary file added assets/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions casim.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ HEADERS += \
src/gui/logger.hpp \
src/gui/viewer_config.hpp \
src/gui/pattern_config.hpp \
src/gui/help_widget.hpp \
third_party/lua/lapi.h \
third_party/lua/lauxlib.h \
third_party/lua/lcode.h \
Expand Down Expand Up @@ -64,6 +65,7 @@ SOURCES += \
src/gui/main_window.cpp \
src/gui/viewer_config.cpp \
src/gui/pattern_config.cpp \
src/gui/help_widget.cpp \
third_party/lua/lapi.c \
third_party/lua/lauxlib.c \
third_party/lua/lbaselib.c \
Expand Down
6 changes: 6 additions & 0 deletions casim.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
<file>assets/random.png</file>
<file>assets/icon.png</file>
<file>assets/icon.ico</file>
<file>assets/help.png</file>
<file>third_party/lua/LICENSE</file>
<file>third_party/xtensor/LICENSE</file>
<file>third_party/xtl/LICENSE</file>
<file>third_party/freeglut/COPYING</file>
<file>LICENSE</file>
</qresource>
</RCC>
50 changes: 32 additions & 18 deletions src/core/automaton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Automaton::Automaton(const xt::xarray<size_t>& shape,
fetch_all();
}

Automaton::Automaton(const xt::xarray<size_t>& shape, const std::string& script,
Automaton::Automaton(const xt::xarray<size_t>& shape,
const std::string& script,
const size_t& neighbor_radius) {
shape_ = shape;
script_ = script;
Expand Down Expand Up @@ -84,13 +85,21 @@ const xt::xarray<uint32_t>& Automaton::get_curr_generation() {
}
}

const xt::xarray<size_t>& Automaton::get_shape() { return shape_; }
const xt::xarray<size_t>& Automaton::get_shape() {
return shape_;
}

const std::string& Automaton::get_script() { return script_; }
const std::string& Automaton::get_script() {
return script_;
}

const size_t& Automaton::get_neighbor_radius() { return neighbor_radius_; }
const size_t& Automaton::get_neighbor_radius() {
return neighbor_radius_;
}

const std::string& Automaton::get_name() { return name_; }
const std::string& Automaton::get_name() {
return name_;
}

const std::string& Automaton::get_default_color() {
return state_color_list_[0];
Expand All @@ -100,9 +109,13 @@ const std::vector<std::string>& Automaton::get_state_color_list() {
return state_color_list_;
}

const size_t& Automaton::get_state_cnt() { return state_cnt_; }
const size_t& Automaton::get_state_cnt() {
return state_cnt_;
}

const size_t& Automaton::get_dim() { return dim_; }
const size_t& Automaton::get_dim() {
return dim_;
}

void Automaton::reset() {
flip_ = 0;
Expand Down Expand Up @@ -269,27 +282,26 @@ bool Automaton::fetch_neighbor_radius() {
return true;
}

bool Automaton::fetch_all() {
void Automaton::fetch_all() {
if (!fetch_name()) {
// return false;
name_ = "";
}
if (!fetch_state_cnt()) {
return false;
state_cnt_ = 0;
}
if (!fetch_state_color_list()) {
return false;
//
}
if (!fetch_dim()) {
return false;
dim_ = 0;
}
if (!fetch_min_size()) {
return false;
//
}
if (!fetch_neighbor_radius()) {
return false;
neighbor_radius_ = 0;
}
reset();
return true;
}

bool Automaton::load_pattern_from_file(const std::string& path) {
Expand Down Expand Up @@ -324,7 +336,8 @@ void Automaton::random(const std::vector<double>& w) {
// native recursive
// TODO: use stack
void Automaton::fecth_local_states_helper(const xt::xarray<size_t>& coordinate,
xt::xarray<size_t>& c, size_t axis) {
xt::xarray<size_t>& c,
size_t axis) {
if (axis == dim_) {
for (size_t i = 0; i < axis; ++i) {
if (c[i] == (size_t)-1) {
Expand Down Expand Up @@ -367,8 +380,9 @@ void Automaton::fecth_local_states_helper(const xt::xarray<size_t>& coordinate,
// native recursive
// TODO: use stack
// TODO: multithreading?
bool Automaton::evolve_helper(lua_State*& L, xt::xarray<size_t>& c,
size_t axis) {
bool Automaton::evolve_helper(lua_State*& L,
xt::xarray<size_t>& c,
size_t axis) {
if (axis == dim_) {
lua_getglobal(L, "local_evolve");
if (!lua_isfunction(L, -1)) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/automaton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Automaton {
// evolve single step to next generation
bool evolve();
// fetch all config from lua script
bool fetch_all();
void fetch_all();
// load `*.npy` file from `path`
// after loading the shape of the generation buffer is set to the shape in
// `*.npy` file
Expand Down
1 change: 1 addition & 0 deletions src/gui/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QtGui/QOpenGLExtraFunctions>
#include <QtGui/QPainter>
#include <QtGui/QSyntaxHighlighter>
#include <QtGui/QWindow>
#include <QtOpenGL/QOpenGLBuffer>
#include <QtOpenGL/QOpenGLShaderProgram>
#include <QtOpenGL/QOpenGLVertexArrayObject>
Expand Down
5 changes: 0 additions & 5 deletions src/gui/config_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ ConfigEditor::ConfigEditor(QWidget* parent) : QTabWidget(parent) {
pattern_config_scroll_area_->setWidgetResizable(true);
this->addTab(pattern_config_scroll_area_, tr("Pattern"));

dummy1_ = new QWidget(this);
dummy2_ = new QWidget(this);
this->addTab(dummy1_, "Rule");
this->addTab(dummy2_, "Color");

// The ConfigEditor is basicly a intermeidate for signals
// Qt's signals and slots are reallu annoying.
// If anyone knows a better solution please let me know.
Expand Down
1 change: 0 additions & 1 deletion src/gui/config_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ConfigEditor : public QTabWidget {
void viewer_view_mode_changed_from_config(const ViewMode& view_mode);

private:
QPointer<QWidget> dummy1_, dummy2_; //
QPointer<QScrollArea> viewer_config_scroll_area_;
QPointer<QScrollArea> pattern_config_scroll_area_;
QPointer<PatternConfig> pattern_config_;
Expand Down
66 changes: 66 additions & 0 deletions src/gui/help_widget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "gui/help_widget.hpp"

HelpWidget::HelpWidget(QWidget* parent) : QWidget(parent) {
this->setWindowTitle(tr("Help"));
layout_ = new QVBoxLayout(this);
xtensor_button_ = new QPushButton(tr("About xtensor"), this);
xtl_button_ = new QPushButton(tr("About xtl"), this);
lua_button_ = new QPushButton(tr("About Lua"), this);
casim_button_ = new QPushButton(tr("About Casim"), this);
qt_button_ = new QPushButton(tr("About Qt"), this);
freeglut_button_ = new QPushButton(tr("About FreeGLUT"), this);

this->setMinimumSize(200, 150);

layout_->addWidget(casim_button_);
layout_->addWidget(freeglut_button_);
layout_->addWidget(lua_button_);
layout_->addWidget(qt_button_);
layout_->addWidget(xtl_button_);
layout_->addWidget(xtensor_button_);
layout_->addStretch();

connect(casim_button_, &QPushButton::clicked, this,
&HelpWidget::casim_handler);
connect(xtensor_button_, &QPushButton::clicked, this,
&HelpWidget::xtensor_handler);
connect(xtl_button_, &QPushButton::clicked, this, &HelpWidget::xtl_handler);
connect(lua_button_, &QPushButton::clicked, this, &HelpWidget::lua_handler);
connect(qt_button_, &QPushButton::clicked, this, &HelpWidget::qt_handler);
connect(freeglut_button_, &QPushButton::clicked, this,
&HelpWidget::freeglut_handler);
}

void HelpWidget::xtensor_handler() {
QFile license(":/third_party/xtensor/LICENSE");
license.open(QIODevice::ReadOnly);
QMessageBox::about(this, "About xtensor", license.readAll());
}

void HelpWidget::xtl_handler() {
QFile license(":/third_party/xtl/LICENSE");
license.open(QIODevice::ReadOnly);
QMessageBox::about(this, "About xtl", license.readAll());
}

void HelpWidget::casim_handler() {
QFile license(":/LICENSE");
license.open(QIODevice::ReadOnly);
QMessageBox::about(this, "About Casim", license.readAll());
}

void HelpWidget::lua_handler() {
QFile license(":/third_party/lua/LICENSE");
license.open(QIODevice::ReadOnly);
QMessageBox::about(this, "About Lua", license.readAll());
}

void HelpWidget::qt_handler() {
QMessageBox::aboutQt(this, tr("About Qt"));
}

void HelpWidget::freeglut_handler() {
QFile license(":/third_party/freeglut/COPYING");
license.open(QIODevice::ReadOnly);
QMessageBox::about(this, "About FreeGLUT", license.readAll());
}
30 changes: 30 additions & 0 deletions src/gui/help_widget.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef CASIM_GUI_HELP_WINDOW_HPP_
#define CASIM_GUI_HELP_WINDOW_HPP_

#include "gui/common.hpp"

class HelpWidget : public QWidget {
Q_OBJECT
public:
HelpWidget(QWidget* parent = nullptr);

public slots:

void xtensor_handler();
void xtl_handler();
void casim_handler();
void lua_handler();
void qt_handler();
void freeglut_handler();

private:
QPointer<QVBoxLayout> layout_;
QPointer<QPushButton> xtensor_button_;
QPointer<QPushButton> xtl_button_;
QPointer<QPushButton> lua_button_;
QPointer<QPushButton> casim_button_;
QPointer<QPushButton> qt_button_;
QPointer<QPushButton> freeglut_button_;
};

#endif // CASIM_GUI_HELP_WINDOW_HPP_
4 changes: 4 additions & 0 deletions src/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ void MainWindow::reset_pattern() {
void MainWindow::random_pattern() {
logger_->log("Randomizing pattern...");
size_t state_cnt = automaton_->get_state_cnt();
if (state_cnt == 0) {
logger_->log("Randomizing failed: No states specified.");
return;
}
logger_->log("Done.");
std::vector<double> w;
for (size_t i = 0; i < state_cnt; ++i) {
Expand Down
7 changes: 7 additions & 0 deletions src/gui/tool_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent) {
stop_action_ = this->addAction(QIcon(":/assets/stop.png"), tr("Stop"));
reset_action_ = this->addAction(QIcon(":/assets/reset.png"), tr("Reset"));
random_action_ = this->addAction(QIcon(":/assets/random.png"), tr("Random"));
help_action_ = this->addAction(QIcon(":/assets/help.png"), tr("Help"));

connect(evolve_action_, &QAction::triggered, this, &ToolBar::evolve_handler);
connect(evolve_step_action_, &QAction::triggered, this,
Expand All @@ -19,6 +20,7 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent) {
&ToolBar::open_folder_handler);
connect(stop_action_, &QAction::triggered, this, &ToolBar::stop_handler);
connect(random_action_, &QAction::triggered, this, &ToolBar::random_signal);
connect(help_action_, &QAction::triggered, this, &ToolBar::help_handler);
}

void ToolBar::evolve_handler() {
Expand All @@ -44,3 +46,8 @@ void ToolBar::open_folder_handler() {
void ToolBar::random_handler() {
emit random_signal();
}

void ToolBar::help_handler() {
QPointer<HelpWidget> help_widget_ = new HelpWidget();
help_widget_->show();
}
5 changes: 5 additions & 0 deletions src/gui/tool_bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "gui/common.hpp"

#include "help_widget.hpp"

class ToolBar : public QToolBar {
Q_OBJECT
public:
Expand All @@ -24,13 +26,16 @@ class ToolBar : public QToolBar {
void open_folder_handler();
void random_handler();

void help_handler();

private:
QPointer<QAction> evolve_action_;
QPointer<QAction> evolve_step_action_;
QPointer<QAction> stop_action_;
QPointer<QAction> open_folder_action_;
QPointer<QAction> reset_action_;
QPointer<QAction> random_action_;
QPointer<QAction> help_action_;
};

#endif // CASIM_GUI_TOOL_BAR_HPP_
27 changes: 27 additions & 0 deletions third_party/freeglut/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Freeglut Copyright
------------------

Freeglut code without an explicit copyright is covered by the following
copyright:

Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies or substantial portions of the Software.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of Pawel W. Olszta shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Pawel W. Olszta.

0 comments on commit df41635

Please sign in to comment.