Skip to content

Commit

Permalink
Added svg import support
Browse files Browse the repository at this point in the history
  • Loading branch information
dov committed Jan 31, 2021
1 parent e88b6fe commit 675cadd
Show file tree
Hide file tree
Showing 17 changed files with 452 additions and 44 deletions.
Binary file modified images/pomelo_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 61 additions & 7 deletions images/pomelo_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
project('gtkmm_example','cpp','c')
project('pomelo','cpp','c')
subproject('nanosvg')

gnome = import('gnome')

name='pomelo'
name_cap = 'Pomelo'
version = '0.0.2'
version = '0.0.3'

r = run_command('git', 'rev-parse', 'HEAD')
if r.returncode() != 0
Expand All @@ -21,7 +22,8 @@ endif
commit_time=r.stdout().strip()

cpp_args = ['-DCOMMIT_ID="'+sha1+'"',
'-DCOMMIT_TIME="'+commit_time+'"'
'-DCOMMIT_TIME="'+commit_time+'"',
'-DVERSION="'+version+'"',
]

subdir('src')
Expand All @@ -43,7 +45,7 @@ if host_machine.system() == 'windows'
'-DICON_NAME='+name + '_logo',
'-DARCH='+arch,
'-DHOST='+host,
'-DVERSION='+'v'+ version + 'a',
'-DVERSION='+'v'+ version,
'-DLIBGCCDLL=libgcc_s_seh-1.dll',
'@INPUT@',
]
Expand Down
41 changes: 38 additions & 3 deletions src/main-input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ MainInput::MainInput()

// Configure the widgets
m_text.set_hexpand(true);
m_text.set_focus_on_click(true);
m_text.signal_focus_in_event().connect( sigc::mem_fun(*this, &MainInput::on_text_focus_in));
m_text_buffer = m_text.get_buffer();
m_text_buffer->set_text("Pomelo");
m_text_buffer->signal_changed().connect( sigc::mem_fun(*this,
Expand Down Expand Up @@ -117,12 +119,12 @@ MainInput::MainInput()
// Button box
auto w_hbox = mmHBox;
w_vbox->pack_start(*w_hbox, Gtk::PACK_SHRINK);
auto w_button = mm<Gtk::Button>("Build");
w_hbox->pack_start(*w_button, false,false);
m_skeleton_button.set_label("Build");
w_hbox->pack_start(m_skeleton_button, false,false);
m_skeleton_status_label.set_markup("Status: <span foreground=\"red\">❌</span>");
w_hbox->pack_end(m_skeleton_status_label, false,false);

w_button->signal_clicked().connect( sigc::mem_fun(*this,
m_skeleton_button.signal_clicked().connect( sigc::mem_fun(*this,
&MainInput::on_button_skeleton_clicked) );

// Lower frame
Expand Down Expand Up @@ -161,6 +163,11 @@ MainInput::MainInput()

w_hbox->pack_end(m_profile_status_label, false,false);

// Create tags or the text buffer
Glib::RefPtr<Gtk::TextBuffer::Tag> refTag;

refTag = m_text_buffer->create_tag("info");
refTag->property_foreground() = "#808080";
}

void MainInput::on_button_skeleton_clicked()
Expand Down Expand Up @@ -217,6 +224,18 @@ void MainInput::on_profile_input_changed()
set_profile_ready_state(false);
}

//void MainInput::on_text_insert_at_cursor(const Glib::ustring& str)
bool MainInput::on_text_focus_in(GdkEventFocus*)
{
if (m_clean_on_edit)
{
m_clean_on_edit = false;
m_text_buffer->set_text("");
m_signal_text_edited();
}
return true;
}

MainInput::type_signal_build_skeleton MainInput::signal_build_skeleton()
{
return m_signal_build_skeleton;
Expand All @@ -226,3 +245,19 @@ MainInput::type_signal_build_profile MainInput::signal_build_profile()
{
return m_signal_build_profile;
}

MainInput::type_signal_text_edited MainInput::signal_text_edited()
{
return m_signal_text_edited;
}

void MainInput::set_text_edit_info_string(const Glib::ustring& info_string)
{
m_skeleton_button.grab_focus();
m_text_buffer->set_text("");
auto iter = m_text_buffer->begin();
m_text_buffer->insert_with_tag(iter,info_string,"info");
m_clean_on_edit = true;

}

16 changes: 16 additions & 0 deletions src/main-input.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ class MainInput : public Gtk::Box
)>;
type_signal_build_profile signal_build_profile();

// When the text is edited, the following signal is sent
using type_signal_text_edited = sigc::signal<void()>;
type_signal_text_edited signal_text_edited();

// Setup UI for readiness
void set_skeleton_ready_state(bool is_ready);
void set_profile_ready_state(bool is_ready);

// Change the text to a placeholder
void set_text_edit_info_string(const Glib::ustring& info_string);

private:
Gtk::TextView m_text;
Glib::RefPtr<Gtk::TextBuffer> m_text_buffer;
Expand All @@ -45,16 +52,25 @@ class MainInput : public Gtk::Box
Gtk::SpinButton m_linear_limit;
Gtk::Label m_skeleton_status_label;
Gtk::Label m_profile_status_label;
Gtk::Button m_skeleton_button;
Gtk::Button m_profile_button;

// If the text was set externally then this flag tells the
// widget that on the next edit, we should clean and send a signal
// about it.
bool m_clean_on_edit = false;

// Signals
type_signal_build_skeleton m_signal_build_skeleton;
type_signal_build_profile m_signal_build_profile;
type_signal_text_edited m_signal_text_edited;

void on_button_skeleton_clicked();
void on_button_profile_clicked();
void on_skeleton_input_changed();
void on_profile_input_changed();
// void on_text_insert_at_cursor(const Glib::ustring& str);
bool on_text_focus_in(GdkEventFocus*);

};

Expand Down
1 change: 0 additions & 1 deletion src/mesh-viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ bool MeshViewer::on_scroll_event(GdkEventScroll *scroll_event)

bool MeshViewer::on_enter_notify_event (GdkEventCrossing *event)
{
print("Enter notify\n");
if (!this->has_focus())
this->grab_focus();
return true;
Expand Down
44 changes: 28 additions & 16 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sources = ['pomelo-main.cc',
'worker-skeleton.cc',
'progress-dialog.cc',
'skeleton-viewer.cc',
'svgpath-to-cairo.cc',
]

if host_machine.system() == 'windows'
Expand All @@ -21,22 +22,26 @@ endif
cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false)
pthread_dep = cc.find_library('pthread', required : false)
gtkmmdep = dependency('gtkmm-3.0')
pangoftdep = dependency('pangoft2')
epoxydep = dependency('epoxy')
fmtdep = dependency('fmt')
glmdep = dependency('glm')
gmpdep = dependency('gmp')
mpfrdep = dependency('mpfr')
deps = [gtkmmdep,
pangoftdep,
epoxydep,
fmtdep,
glmdep,
gmpdep,
mpfrdep,
gtkmm_dep = dependency('gtkmm-3.0')
pangoft_dep = dependency('pangoft2')
cairo_dep = dependency('cairo')
epoxy_dep = dependency('epoxy')
fmt_dep = dependency('fmt')
glm_dep = dependency('glm')
gmp_dep = dependency('gmp')
mpfr_dep = dependency('mpfr')
nanosvg_dep = dependency('nanosvg')

deps = [gtkmm_dep,
pangoft_dep,
epoxy_dep,
fmt_dep,
glm_dep,
gmp_dep,
mpfr_dep,
m_dep,
pthread_dep]
pthread_dep,
nanosvg_dep]


subdir('giv-widget')
Expand All @@ -49,6 +54,7 @@ resources = gnome.compile_resources(
'..',
'../images',]
)

incdir = ['giv-widget']
exe = executable(name_cap,
sources,
Expand All @@ -58,8 +64,14 @@ exe = executable(name_cap,
cpp_args : cpp_args,
include_directories : incdir,
link_with : [libgivwidget,
libgtkimageviewer],
libgtkimageviewer,
],
install :true
)


# An example for converting an svg path to cairo
executable('test-svgpath-to-cairo',
['test-svgpath-to-cairo.cc',
'svgpath-to-cairo.cc'],
dependencies : deps)
21 changes: 18 additions & 3 deletions src/pangocairo-to-contour.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@
#include <vector>
#include <list>
#include "pangocairo-to-contour.h"
#include "svgpath-to-cairo.h"

using namespace std;
using namespace Glib;
using namespace fmt;

// Create a pango context from a svg filename
Cairo::RefPtr<Cairo::Context> TeXtrusion::svg_filename_to_context(const string& filename)
{
auto surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 500, 500);
auto cr = Cairo::Context::create(surface);

svgpaths_to_cairo(cr->cobj(), filename.c_str(), true);

return cr;
}

// Take a pango markup and turn it into a cairo context that is returned
Cairo::RefPtr<Cairo::Context> TeXtrusion::markup_to_context()
Cairo::RefPtr<Cairo::Context> TeXtrusion::markup_to_context(const string& markup)
{
PangoFontMap *fm;
fm = pango_ft2_font_map_new();
Expand Down Expand Up @@ -296,7 +308,6 @@ vector<PHoleInfo> TeXtrusion::skeletonize(const std::vector<Polygon_with_holes>&
for (int ph_idx=0; ph_idx < (int)phole_infos.size(); ph_idx++) {
auto& phi = phole_infos[ph_idx];
for (auto &r : phi.regions) {
double depth = r.get_depth();
string path = "skeleton";
string color = "blue";

Expand Down Expand Up @@ -353,12 +364,14 @@ Mesh TeXtrusion::skeleton_to_mesh(const vector<PHoleInfo>& phole_infos,
// triangulation for both.
double offset_thickness = 0.5;
for (int ph_idx=0; ph_idx < (int)phole_infos.size(); ph_idx++) {
if (updater->info("profile", 1.0*ph_idx/phole_infos.size()))
throw EAborted("Aborted!");

auto& phi = phole_infos[ph_idx];
int r_idx = -1;
for (auto &r : phi.regions) {
r_idx++;
double depth = r.get_depth();
int num_offsets = int(ceil(depth/offset_thickness));
string color = "blue";
string path_modifier;

Expand Down Expand Up @@ -485,6 +498,8 @@ Mesh TeXtrusion::skeleton_to_mesh(const vector<PHoleInfo>& phole_infos,
of << giv_string;
of.close();
#endif
if (updater->info("profile", 1.0))
throw EAborted("Aborted!");

return mesh;
}
Expand Down
Loading

0 comments on commit 675cadd

Please sign in to comment.