Skip to content

Commit

Permalink
Develop (#53)
Browse files Browse the repository at this point in the history
* adding ruler tool and line drawing tool. closes: #50 ; closes: #49 
* shift-click to draw straight lines with brush tool. closes: #51 
* better keyboard handling (all dialogs can be confirmed/canceled using Return/Esc)
* toolbar can now be resized to have two columns
  • Loading branch information
wkjarosz authored Jun 20, 2021
1 parent ff90a39 commit 951c805
Show file tree
Hide file tree
Showing 20 changed files with 1,792 additions and 666 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ add_executable(HDRView
src/commandhistory.h
src/common.cpp
src/common.h
src/dialog.cpp
src/dialog.h
src/dithermatrix256.h
src/drawline.cpp
src/drawline.h
Expand Down
2 changes: 1 addition & 1 deletion src/colorwheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ColorWheel2 : public Widget
/// Handles mouse drag events for the ColorWheel.
virtual bool mouse_drag_event(const Vector2i &p, const Vector2i &rel, int button, int modifiers) override;

/// Handle a mouse motion event (default implementation: propagate to children)
/// Handle a mouse motion event
virtual bool mouse_motion_event(const Vector2i &p, const Vector2i &rel, int button, int modifiers) override;

private:
Expand Down
83 changes: 83 additions & 0 deletions src/dialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

#include "dialog.h"
#include <nanogui/button.h>
#include <nanogui/formhelper.h>
#include <nanogui/label.h>
#include <nanogui/layout.h>

NAMESPACE_BEGIN(nanogui)

Dialog::Dialog(Widget *parent, const std::string &title, bool form) : Window(parent, title)
{
set_modal(true);

request_focus();
if (form)
make_form();
}

void Dialog::make_form()
{
// copied from FormHelper
auto layout = new AdvancedGridLayout({10, 0, 10, 0}, {});
layout->set_margin(10);
layout->set_col_stretch(2, 1);
set_layout(layout);
}

Widget *Dialog::add_buttons(const std::string &button_text, const std::string &alt_button_text, bool alt_button)
{
Widget *button_panel = new Widget(this);
button_panel->set_layout(new GridLayout(Orientation::Horizontal, 2, Alignment::Fill, 0, 5));

if (alt_button)
{
Button *button = new Button(button_panel, alt_button_text, m_theme->m_message_alt_button_icon);
button->set_callback(
[this]
{
if (m_callback)
m_callback(1);
dispose();
});
}
Button *button = new Button(button_panel, button_text, m_theme->m_message_primary_button_icon);
button->set_callback(
[this]
{
if (m_callback)
m_callback(0);
dispose();
});

return button_panel;
}

SimpleDialog::SimpleDialog(Widget *parent, Type type, const std::string &title, const std::string &message,
const std::string &button_text, const std::string &alt_button_text, bool alt_button) :
Dialog(parent, title, false)
{
set_layout(new BoxLayout(Orientation::Vertical, Alignment::Middle, 10, 10));

Widget *message_panel = new Widget(this);
message_panel->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 10, 15));
int icon = 0;
switch (type)
{
case Type::Empty: icon = 0; break;
case Type::Information: icon = m_theme->m_message_information_icon; break;
case Type::Question: icon = m_theme->m_message_question_icon; break;
case Type::Warning: icon = m_theme->m_message_warning_icon; break;
}
Label *icon_label = new Label(message_panel, std::string(utf8(icon).data()), "icons");
icon_label->set_font_size(50);
m_message_label = new Label(message_panel, message);
m_message_label->set_fixed_width(icon ? 200 : 0);

add_buttons(button_text, alt_button_text, alt_button);

center();
request_focus();
}

NAMESPACE_END(nanogui)
50 changes: 50 additions & 0 deletions src/dialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#pragma once

#include <nanogui/messagedialog.h>
#include <nanogui/nanogui.h>

NAMESPACE_BEGIN(nanogui)

/// Similar to MessageDialog but extensible and can be used with FormHelper class
class Dialog : public Window
{
public:
Dialog(Widget *parent, const std::string &title = "Untitled", bool form = true);

void make_form();
Widget *add_buttons(const std::string &button_text = "OK", const std::string &alt_button_text = "Cancel",
bool alt_button = true);

std::function<void(int)> callback() const { return m_callback; }
void set_callback(const std::function<void(int)> &callback) { m_callback = callback; }

protected:
std::function<void(int)> m_callback;
};

/// Identical to MessageDialog but derived from the above Dialog class.
class SimpleDialog : public Dialog
{
public:
/// Classification of the type of message this SimpleDialog represents.
enum class Type
{
Empty,
Information,
Question,
Warning
};

SimpleDialog(Widget *parent, Type type, const std::string &title = "Untitled",
const std::string &message = "Message", const std::string &button_text = "OK",
const std::string &alt_button_text = "Cancel", bool alt_button = false);

Label * message_label() { return m_message_label; }
const Label *message_label() const { return m_message_label; }

protected:
Label *m_message_label;
};

NAMESPACE_END(nanogui)
Loading

0 comments on commit 951c805

Please sign in to comment.