Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/browser_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,22 @@ Browser::Browser() : Gtk::Box(Gtk::Orientation::VERTICAL) {
throw ex;
}

// Get the GtkBuilder-instantiated nav and header:
header = Gtk::manage(ref_builder->get_widget<Gtk::Box>("header_bar"));

// Get the GtkBuilder-instantiated browser_scroller, and connect WebKitWebView with home site loaded
web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
auto web_view_widget {Glib::wrap(GTK_WIDGET(web_view))};
g_object_ref_sink(web_view_widget->gobj());
web_view_widget->set_name("browser_webview");
web_view_widget->set_vexpand(true);

// Get the GtkBuilder-instantiated buttons, and connect a signal handler
back_button = ref_builder->get_widget<Gtk::Button>("back_button");
// Get the GtkBuilder-instantiated widgets
header = Gtk::manage(ref_builder->get_widget<Gtk::Box>("header_bar"));
back_button = ref_builder->get_widget<Gtk::Button>("back_button");
forward_button = ref_builder->get_widget<Gtk::Button>("forward_button");
home_button = ref_builder->get_widget<Gtk::Button>("home_button");
reload_button = ref_builder->get_widget<Gtk::Button>("reload_button");
uri_entry = ref_builder->get_widget<Gtk::Entry>("header_entry");
enter_button = ref_builder->get_widget<Gtk::Button>("enter_button");
menu_button = ref_builder->get_widget<Gtk::MenuButton>("header_menu");
home_button = ref_builder->get_widget<Gtk::Button>("home_button");
reload_button = ref_builder->get_widget<Gtk::Button>("reload_button");
uri_entry = ref_builder->get_widget<Gtk::Entry>("header_entry");
enter_button = ref_builder->get_widget<Gtk::Button>("enter_button");
menu_button = ref_builder->get_widget<Gtk::MenuButton>("header_menu");

// Add Callbacks
if(back_button) [[likely]]
Expand Down
39 changes: 22 additions & 17 deletions src/chat_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
#include <thread>


Session::Session(const std::string &host, unsigned port)
: host(host), port(port), send_timer(std::make_unique<asio::steady_timer>(ioc)), socket(ioc) {
Session::Session(const std::string &host, unsigned port) :
host (host),
port (port),
send_timer (std::make_unique<asio::steady_timer>(ioc)),
socket (ioc) {
if ( port > 65535 ) {
std::cerr << "Port out of bounds (0-65535)" << std::endl;
throw std::out_of_range("Port out of bounds (0-65535)");
Expand Down Expand Up @@ -120,12 +123,14 @@ void Session::set_poster(std::function<void(void)> message_poster)
void Session::set_disconnecter(std::function<void(void)> new_disconnecter)
{ disconnecter = std::move(new_disconnecter); }

Server::Client::Client(asio::io_context& ioc, unsigned id)
: socket(ioc), timer(ioc), nickname("User" + std::to_string(id))
Server::Client::Client(asio::io_context& ioc, unsigned id) :
socket (ioc),
timer (ioc),
nickname ("User" + std::to_string(id))
{ timer.expires_at(asio::steady_timer::time_point::min()); }

Server::Server(unsigned port)
: acceptor(ioc, tcp::endpoint(tcp::v4(), static_cast<asio::ip::port_type>(port))) {
Server::Server(unsigned port) :
acceptor(ioc, tcp::endpoint(tcp::v4(), static_cast<asio::ip::port_type>(port))) {
asio::co_spawn(ioc, accept_loop(), asio::detached);
ioc_thread = std::thread([this](){ ioc.run(); });
std::cout << "[server] listening on port " << port << "\n";
Expand All @@ -145,7 +150,7 @@ Server::~Server() noexcept {
std::cout << "[server] stopped\n";
}

void Server::broadcast(const std::string& line, Client* origin = nullptr) {
void Server::broadcast(const std::string& line, Client* origin) {
for (auto& client : clients) {
if (client.get() == origin) continue;
client->buf += line;
Expand Down Expand Up @@ -250,17 +255,17 @@ Chat::Chat() : Gtk::Box(Gtk::Orientation::VERTICAL) {
// Get the GtkBuilder-instantiated objects:
auto header {Gtk::manage(ref_builder->get_widget<Gtk::Box>("header_box"))};

home_button = ref_builder->get_widget<Gtk::Button>("home_button");
connect_button = ref_builder->get_widget<Gtk::Button>("connect_button");
message_button = ref_builder->get_widget<Gtk::Button>("message_button");
home_button = ref_builder->get_widget<Gtk::Button>("home_button");
connect_button = ref_builder->get_widget<Gtk::Button>("connect_button");
message_button = ref_builder->get_widget<Gtk::Button>("message_button");

ip_entry = ref_builder->get_widget<Gtk::Entry>("ip_entry");
port_entry = ref_builder->get_widget<Gtk::Entry>("port_entry");
message_entry = ref_builder->get_widget<Gtk::Entry>("message_entry");
ip_entry = ref_builder->get_widget<Gtk::Entry>("ip_entry");
port_entry = ref_builder->get_widget<Gtk::Entry>("port_entry");
message_entry = ref_builder->get_widget<Gtk::Entry>("message_entry");

chat_scrolled = Gtk::manage(ref_builder->get_widget<Gtk::ScrolledWindow>("chat_scrolled"));
chat_box = Gtk::manage(ref_builder->get_widget<Gtk::Box>("chat_box"));
footer_box = Gtk::manage(ref_builder->get_widget<Gtk::Box>("footer_box"));
chat_scrolled = Gtk::manage(ref_builder->get_widget<Gtk::ScrolledWindow>("chat_scrolled"));
chat_box = Gtk::manage(ref_builder->get_widget<Gtk::Box>("chat_box"));
footer_box = Gtk::manage(ref_builder->get_widget<Gtk::Box>("footer_box"));

// Add Callbacks
if(home_button) [[likely]]
Expand Down Expand Up @@ -306,7 +311,7 @@ inline void Chat::session_connection() {
// Disconnect if connected
if (!connect_button->get_label().compare("Disconnect")) {
session = nullptr;
server = nullptr;
server = nullptr;
std::cout << "\n[disconnected from server due to user request]\n";

connect_button->set_label("Connect");
Expand Down
55 changes: 37 additions & 18 deletions src/fractal_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,26 @@ int julia(double cr, double ci, int max_iter, const std::vector<std::any> consts
return max_iter;
}

void FractalArea::set_selection(const std::string new_selection) { selection = new_selection; queue_draw(); }
void FractalArea::set_max_iter(int iter) { max_iter = iter; queue_draw(); }
void FractalArea::set_consts(double cr, double ci) { const_r = cr; const_i = ci; queue_draw(); }
void FractalArea::set_selection(const std::string new_selection)
{ selection = new_selection; queue_draw(); }

void FractalArea::set_r(double min, double max) { r_lower_level = min/100; r_upper_level = max/100; queue_draw(); }
void FractalArea::set_g(double min, double max) { g_lower_level = min/100; g_upper_level = max/100; queue_draw(); }
void FractalArea::set_b(double min, double max) { b_lower_level = min/100; b_upper_level = max/100; queue_draw(); }
void FractalArea::set_max_iter(int iter)
{ max_iter = iter; queue_draw(); }

void FractalArea::reset() { cx = -0.5; cy = 0.0; range = 3.5; queue_draw(); }
void FractalArea::set_consts(double cr, double ci)
{ const_r = cr; const_i = ci; queue_draw(); }

void FractalArea::set_r(double min, double max)
{ r_lower_level = min/100; r_upper_level = max/100; queue_draw(); }

void FractalArea::set_g(double min, double max)
{ g_lower_level = min/100; g_upper_level = max/100; queue_draw(); }

void FractalArea::set_b(double min, double max)
{ b_lower_level = min/100; b_upper_level = max/100; queue_draw(); }

void FractalArea::reset()
{ cx = -0.5; cy = 0.0; range = 3.5; queue_draw(); }

void FractalArea::iter_to_rgb(int iter, int max_iter, uint8_t &r, uint8_t &g, uint8_t &b) {
if (iter == max_iter) { r = g = b = 0; return; }
Expand All @@ -55,12 +66,16 @@ void FractalArea::iter_to_rgb(int iter, int max_iter, uint8_t &r, uint8_t &g, ui
}


FractalArea::FractalArea(const std::string selection) : Gtk::DrawingArea(),
cx{-0.5}, cy{0}, range{3.5},
drag_start_cx{}, drag_start_cy{},
surface{}, selection{selection},
fractal_map{ { "Julia", julia }, { "Mandelbrot", mandelbrot }
} {
FractalArea::FractalArea(const std::string selection) :
Gtk::DrawingArea(),
selection (selection),
cx (-0.5),
cy (0.0),
range (3.5),
drag_start_cx (),
drag_start_cy (),
surface (),
fractal_map ({ { "Julia", julia }, { "Mandelbrot", mandelbrot } }) {
set_expand(true);
set_draw_func(sigc::mem_fun(*this, &FractalArea::on_draw));

Expand Down Expand Up @@ -157,15 +172,15 @@ FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
}

// Get the GtkBuilder-instantiated nav and header:
menu = Gtk::manage(ref_builder->get_widget<Gtk::Box>("menu_bar"));
menu = Gtk::manage(ref_builder->get_widget<Gtk::Box>("menu_bar"));

// Get the GtkBuilder-instantiated buttons, and connect a signal handler
reset_button = ref_builder->get_widget<Gtk::Button>("reset_button");
save_button = ref_builder->get_widget<Gtk::Button>("save_button");
reset_button = ref_builder->get_widget<Gtk::Button>("reset_button");
save_button = ref_builder->get_widget<Gtk::Button>("save_button");
fractal_dropdown = ref_builder->get_widget<Gtk::DropDown>("fractal_dropdown");
consts_box = ref_builder->get_widget<Gtk::Box>("consts_box");
consts_box = ref_builder->get_widget<Gtk::Box>("consts_box");

fractal_area = Gtk::manage(new FractalArea());
fractal_area = Gtk::manage(new FractalArea());

// Add Callbacks
if(reset_button) [[likely]]
Expand Down Expand Up @@ -203,6 +218,7 @@ FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
});
fractal_area->set_max_iter(static_cast<int>(iter_scale->get_value()));
}

r_min_scale = ref_builder->get_widget<Gtk::Scale>("r_scale_min");
r_max_scale = ref_builder->get_widget<Gtk::Scale>("r_scale_max");
if(r_min_scale && r_max_scale) [[likely]] {
Expand All @@ -213,6 +229,7 @@ FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
r_max_scale->signal_value_changed().connect(r_change);
fractal_area->set_r(r_min_scale->get_value(), r_max_scale->get_value());
}

g_min_scale = ref_builder->get_widget<Gtk::Scale>("g_scale_min");
g_max_scale = ref_builder->get_widget<Gtk::Scale>("g_scale_max");
if(g_min_scale && g_max_scale) [[likely]] {
Expand All @@ -223,6 +240,7 @@ FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
g_max_scale->signal_value_changed().connect(g_change);
fractal_area->set_g(g_min_scale->get_value(), g_max_scale->get_value());
}

b_min_scale = ref_builder->get_widget<Gtk::Scale>("b_scale_min");
b_max_scale = ref_builder->get_widget<Gtk::Scale>("b_scale_max");
if(b_min_scale && b_max_scale) [[likely]] {
Expand All @@ -233,6 +251,7 @@ FractalBox::FractalBox() : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
b_max_scale->signal_value_changed().connect(b_change);
fractal_area->set_b(b_min_scale->get_value(), b_max_scale->get_value());
}

const_r_scale = ref_builder->get_widget<Gtk::Scale>("const_r_scale");
const_i_scale = ref_builder->get_widget<Gtk::Scale>("const_i_scale");
if(const_r_scale && const_i_scale) [[likely]] {
Expand Down
18 changes: 10 additions & 8 deletions src/include/browser_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ class Browser : public Gtk::Box {
friend class BrowserTest;
friend class BrowserTest_BrowserFunctionalTest_Test;

WebKitWebView *web_view{};
Gtk::Box *header{};
Gtk::Button *back_button{}, *forward_button{},
*home_button{}, *reload_button{},
*enter_button{};
Gtk::Entry *uri_entry{};
Gtk::MenuButton *menu_button{};
Gtk::Label *status_label{};

Gtk::Label *status_label{};
WebKitWebView *web_view{};
Gtk::Box *header{};
Gtk::Button *back_button{};
Gtk::Button *forward_button{};
Gtk::Button *home_button{};
Gtk::Button *reload_button{};
Gtk::Button *enter_button{};
Gtk::Entry *uri_entry{};
Gtk::MenuButton *menu_button{};

/**
* @brief Removes initial http(s)?:// and www. substrings from uri.
Expand Down
4 changes: 2 additions & 2 deletions src/include/chat_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ class Server {

asio::io_context ioc;
tcp::acceptor acceptor;
std::thread ioc_thread;
std::thread ioc_thread{};
unsigned current_id{};

std::list<std::shared_ptr<Client>> clients{};

/* Queue line for every client except origin, then wake their sender. */
void broadcast(const std::string&, Client*);
void broadcast(const std::string&, Client* = nullptr);

/**
* @brief Sender function to run so the session sends data.
Expand Down
68 changes: 48 additions & 20 deletions src/include/fractal_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
* @return Number of iterations until the value diverges.
*/
int mandelbrot(double cr, double ci, int max_iter, const std::vector<std::any> = {});

int mandelbrot(double, double, int, const std::vector<std::any> = {});
/**
* @brief Julia Fractal algorithm
*
Expand All @@ -45,17 +46,24 @@ class FractalArea : public Gtk::DrawingArea {
friend class FractalTest;
friend class FractalTest_FractalFunctionalTest_Test;

double cx{}, cy{}, range{},
drag_start_cx{}, drag_start_cy{},
const_r{}, const_i{},
r_lower_level{}, r_upper_level{},
g_lower_level{}, g_upper_level{},
b_lower_level{}, b_upper_level{};
int max_iter{};
std::string selection;
double cx{};
double cy{};
double range{};
double drag_start_cx{};
double drag_start_cy{};
double const_r{};
double const_i{};
double r_lower_level{};
double r_upper_level{};
double g_lower_level{};
double g_upper_level{};
double b_lower_level{};
double b_upper_level{};
int max_iter{};

Cairo::RefPtr<Cairo::ImageSurface> surface;

std::string selection;
std::unordered_map<std::string, std::function<int(double, double, int, std::vector<std::any>)>> fractal_map;

/**
Expand All @@ -80,6 +88,16 @@ class FractalArea : public Gtk::DrawingArea {
*/
FractalArea(const std::string selection = "Julia");

/**
* @brief Draws the fractal needed into the Cairo Context.
*
* Whenever the drawing area needs to redraw, this slot will be called.
* It will draw the fractal using the current settings into the provided Cairo Context with threading support.
*
* @param[in] cr: Cairo Context to draw to.
* @param[in] w: Width of the drawing area.
* @param[in] h: Height of the drawing area.
*/
void on_draw(const Cairo::RefPtr<Cairo::Context>&, int, int);

/**
Expand All @@ -90,33 +108,38 @@ class FractalArea : public Gtk::DrawingArea {
* @param[in] new_selection: New fractal algorithm selection to use next.
*/
void set_selection(const std::string new_selection);

/**
* @brief Sets the max_iter variable for fractal rsolution.
*
* @param[in] iter: New max_iter to use in the fractal algorithms.
*/
void set_max_iter(int iter);

/**
* @brief Sets ranges for the blue channel in the iter_to_rgb function.
*
* @param[in] min: New lower limit on the R spectrum to use.
* @param[in] max: New upper limit on the R spectrum to use.
*/
void set_r(double min, double max);

/**
* @brief Sets ranges for the blue channel in the iter_to_rgb function.
*
* @param[in] min: New lower limit on the G spectrum to use.
* @param[in] max: New upper limit on the G spectrum to use.
*/
void set_g(double min, double max);

/**
* @brief Sets ranges for the blue channel in the iter_to_rgb function.
*
* @param[in] min: New lower limit on the B spectrum to use.
* @param[in] max: New upper limit on the B spectrum to use.
*/
void set_b(double min, double max);

/**
* @brief Sets the Julia algorithm constants.
*
Expand Down Expand Up @@ -145,18 +168,23 @@ class FractalBox : public Gtk::Box {
friend class FractalTest;
friend class FractalTest_FractalFunctionalTest_Test;

Gtk::Box *menu{}, *consts_box{};
Gtk::Button *reset_button{}, *save_button{};
std::string selection{};
Gtk::Box *menu{};
Gtk::Box *consts_box{};
Gtk::Button *reset_button{};
Gtk::Button *save_button{};
Gtk::DropDown *fractal_dropdown{};
FractalArea *fractal_area{};
Gtk::Label *status_label{};
Gtk::Scale *iter_scale{},
*const_r_scale{}, *const_i_scale{},
*r_min_scale{}, *r_max_scale{},
*g_min_scale{}, *g_max_scale{},
*b_min_scale{}, *b_max_scale{};

std::string selection{};
FractalArea *fractal_area{};
Gtk::Label *status_label{};
Gtk::Scale *iter_scale{};
Gtk::Scale *const_r_scale{};
Gtk::Scale *const_i_scale{};
Gtk::Scale *r_min_scale{};
Gtk::Scale *r_max_scale{};
Gtk::Scale *g_min_scale{};
Gtk::Scale *g_max_scale{};
Gtk::Scale *b_min_scale{};
Gtk::Scale *b_max_scale{};

/**
* @brief Get Main Application status label.
Expand Down
Loading