Skip to content

Commit 675cadd

Browse files
committed
Added svg import support
1 parent e88b6fe commit 675cadd

17 files changed

+452
-44
lines changed

images/pomelo_logo.png

41.7 KB
Loading

images/pomelo_logo.svg

+61-7
Loading

meson.build

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
project('gtkmm_example','cpp','c')
1+
project('pomelo','cpp','c')
2+
subproject('nanosvg')
23

34
gnome = import('gnome')
45

56
name='pomelo'
67
name_cap = 'Pomelo'
7-
version = '0.0.2'
8+
version = '0.0.3'
89

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

2324
cpp_args = ['-DCOMMIT_ID="'+sha1+'"',
24-
'-DCOMMIT_TIME="'+commit_time+'"'
25+
'-DCOMMIT_TIME="'+commit_time+'"',
26+
'-DVERSION="'+version+'"',
2527
]
2628

2729
subdir('src')
@@ -43,7 +45,7 @@ if host_machine.system() == 'windows'
4345
'-DICON_NAME='+name + '_logo',
4446
'-DARCH='+arch,
4547
'-DHOST='+host,
46-
'-DVERSION='+'v'+ version + 'a',
48+
'-DVERSION='+'v'+ version,
4749
'-DLIBGCCDLL=libgcc_s_seh-1.dll',
4850
'@INPUT@',
4951
]

src/main-input.cc

+38-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ MainInput::MainInput()
4646

4747
// Configure the widgets
4848
m_text.set_hexpand(true);
49+
m_text.set_focus_on_click(true);
50+
m_text.signal_focus_in_event().connect( sigc::mem_fun(*this, &MainInput::on_text_focus_in));
4951
m_text_buffer = m_text.get_buffer();
5052
m_text_buffer->set_text("Pomelo");
5153
m_text_buffer->signal_changed().connect( sigc::mem_fun(*this,
@@ -117,12 +119,12 @@ MainInput::MainInput()
117119
// Button box
118120
auto w_hbox = mmHBox;
119121
w_vbox->pack_start(*w_hbox, Gtk::PACK_SHRINK);
120-
auto w_button = mm<Gtk::Button>("Build");
121-
w_hbox->pack_start(*w_button, false,false);
122+
m_skeleton_button.set_label("Build");
123+
w_hbox->pack_start(m_skeleton_button, false,false);
122124
m_skeleton_status_label.set_markup("Status: <span foreground=\"red\">❌</span>");
123125
w_hbox->pack_end(m_skeleton_status_label, false,false);
124126

125-
w_button->signal_clicked().connect( sigc::mem_fun(*this,
127+
m_skeleton_button.signal_clicked().connect( sigc::mem_fun(*this,
126128
&MainInput::on_button_skeleton_clicked) );
127129

128130
// Lower frame
@@ -161,6 +163,11 @@ MainInput::MainInput()
161163

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

166+
// Create tags or the text buffer
167+
Glib::RefPtr<Gtk::TextBuffer::Tag> refTag;
168+
169+
refTag = m_text_buffer->create_tag("info");
170+
refTag->property_foreground() = "#808080";
164171
}
165172

166173
void MainInput::on_button_skeleton_clicked()
@@ -217,6 +224,18 @@ void MainInput::on_profile_input_changed()
217224
set_profile_ready_state(false);
218225
}
219226

227+
//void MainInput::on_text_insert_at_cursor(const Glib::ustring& str)
228+
bool MainInput::on_text_focus_in(GdkEventFocus*)
229+
{
230+
if (m_clean_on_edit)
231+
{
232+
m_clean_on_edit = false;
233+
m_text_buffer->set_text("");
234+
m_signal_text_edited();
235+
}
236+
return true;
237+
}
238+
220239
MainInput::type_signal_build_skeleton MainInput::signal_build_skeleton()
221240
{
222241
return m_signal_build_skeleton;
@@ -226,3 +245,19 @@ MainInput::type_signal_build_profile MainInput::signal_build_profile()
226245
{
227246
return m_signal_build_profile;
228247
}
248+
249+
MainInput::type_signal_text_edited MainInput::signal_text_edited()
250+
{
251+
return m_signal_text_edited;
252+
}
253+
254+
void MainInput::set_text_edit_info_string(const Glib::ustring& info_string)
255+
{
256+
m_skeleton_button.grab_focus();
257+
m_text_buffer->set_text("");
258+
auto iter = m_text_buffer->begin();
259+
m_text_buffer->insert_with_tag(iter,info_string,"info");
260+
m_clean_on_edit = true;
261+
262+
}
263+

src/main-input.h

+16
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ class MainInput : public Gtk::Box
3030
)>;
3131
type_signal_build_profile signal_build_profile();
3232

33+
// When the text is edited, the following signal is sent
34+
using type_signal_text_edited = sigc::signal<void()>;
35+
type_signal_text_edited signal_text_edited();
36+
3337
// Setup UI for readiness
3438
void set_skeleton_ready_state(bool is_ready);
3539
void set_profile_ready_state(bool is_ready);
3640

41+
// Change the text to a placeholder
42+
void set_text_edit_info_string(const Glib::ustring& info_string);
43+
3744
private:
3845
Gtk::TextView m_text;
3946
Glib::RefPtr<Gtk::TextBuffer> m_text_buffer;
@@ -45,16 +52,25 @@ class MainInput : public Gtk::Box
4552
Gtk::SpinButton m_linear_limit;
4653
Gtk::Label m_skeleton_status_label;
4754
Gtk::Label m_profile_status_label;
55+
Gtk::Button m_skeleton_button;
4856
Gtk::Button m_profile_button;
4957

58+
// If the text was set externally then this flag tells the
59+
// widget that on the next edit, we should clean and send a signal
60+
// about it.
61+
bool m_clean_on_edit = false;
62+
5063
// Signals
5164
type_signal_build_skeleton m_signal_build_skeleton;
5265
type_signal_build_profile m_signal_build_profile;
66+
type_signal_text_edited m_signal_text_edited;
5367

5468
void on_button_skeleton_clicked();
5569
void on_button_profile_clicked();
5670
void on_skeleton_input_changed();
5771
void on_profile_input_changed();
72+
// void on_text_insert_at_cursor(const Glib::ustring& str);
73+
bool on_text_focus_in(GdkEventFocus*);
5874

5975
};
6076

src/mesh-viewer.cc

-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ bool MeshViewer::on_scroll_event(GdkEventScroll *scroll_event)
511511

512512
bool MeshViewer::on_enter_notify_event (GdkEventCrossing *event)
513513
{
514-
print("Enter notify\n");
515514
if (!this->has_focus())
516515
this->grab_focus();
517516
return true;

src/meson.build

+28-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sources = ['pomelo-main.cc',
88
'worker-skeleton.cc',
99
'progress-dialog.cc',
1010
'skeleton-viewer.cc',
11+
'svgpath-to-cairo.cc',
1112
]
1213

1314
if host_machine.system() == 'windows'
@@ -21,22 +22,26 @@ endif
2122
cc = meson.get_compiler('c')
2223
m_dep = cc.find_library('m', required : false)
2324
pthread_dep = cc.find_library('pthread', required : false)
24-
gtkmmdep = dependency('gtkmm-3.0')
25-
pangoftdep = dependency('pangoft2')
26-
epoxydep = dependency('epoxy')
27-
fmtdep = dependency('fmt')
28-
glmdep = dependency('glm')
29-
gmpdep = dependency('gmp')
30-
mpfrdep = dependency('mpfr')
31-
deps = [gtkmmdep,
32-
pangoftdep,
33-
epoxydep,
34-
fmtdep,
35-
glmdep,
36-
gmpdep,
37-
mpfrdep,
25+
gtkmm_dep = dependency('gtkmm-3.0')
26+
pangoft_dep = dependency('pangoft2')
27+
cairo_dep = dependency('cairo')
28+
epoxy_dep = dependency('epoxy')
29+
fmt_dep = dependency('fmt')
30+
glm_dep = dependency('glm')
31+
gmp_dep = dependency('gmp')
32+
mpfr_dep = dependency('mpfr')
33+
nanosvg_dep = dependency('nanosvg')
34+
35+
deps = [gtkmm_dep,
36+
pangoft_dep,
37+
epoxy_dep,
38+
fmt_dep,
39+
glm_dep,
40+
gmp_dep,
41+
mpfr_dep,
3842
m_dep,
39-
pthread_dep]
43+
pthread_dep,
44+
nanosvg_dep]
4045

4146

4247
subdir('giv-widget')
@@ -49,6 +54,7 @@ resources = gnome.compile_resources(
4954
'..',
5055
'../images',]
5156
)
57+
5258
incdir = ['giv-widget']
5359
exe = executable(name_cap,
5460
sources,
@@ -58,8 +64,14 @@ exe = executable(name_cap,
5864
cpp_args : cpp_args,
5965
include_directories : incdir,
6066
link_with : [libgivwidget,
61-
libgtkimageviewer],
67+
libgtkimageviewer,
68+
],
6269
install :true
6370
)
6471

6572

73+
# An example for converting an svg path to cairo
74+
executable('test-svgpath-to-cairo',
75+
['test-svgpath-to-cairo.cc',
76+
'svgpath-to-cairo.cc'],
77+
dependencies : deps)

src/pangocairo-to-contour.cc

+18-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@
99
#include <vector>
1010
#include <list>
1111
#include "pangocairo-to-contour.h"
12+
#include "svgpath-to-cairo.h"
1213

1314
using namespace std;
1415
using namespace Glib;
1516
using namespace fmt;
1617

18+
// Create a pango context from a svg filename
19+
Cairo::RefPtr<Cairo::Context> TeXtrusion::svg_filename_to_context(const string& filename)
20+
{
21+
auto surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 500, 500);
22+
auto cr = Cairo::Context::create(surface);
23+
24+
svgpaths_to_cairo(cr->cobj(), filename.c_str(), true);
25+
26+
return cr;
27+
}
28+
1729
// Take a pango markup and turn it into a cairo context that is returned
18-
Cairo::RefPtr<Cairo::Context> TeXtrusion::markup_to_context()
30+
Cairo::RefPtr<Cairo::Context> TeXtrusion::markup_to_context(const string& markup)
1931
{
2032
PangoFontMap *fm;
2133
fm = pango_ft2_font_map_new();
@@ -296,7 +308,6 @@ vector<PHoleInfo> TeXtrusion::skeletonize(const std::vector<Polygon_with_holes>&
296308
for (int ph_idx=0; ph_idx < (int)phole_infos.size(); ph_idx++) {
297309
auto& phi = phole_infos[ph_idx];
298310
for (auto &r : phi.regions) {
299-
double depth = r.get_depth();
300311
string path = "skeleton";
301312
string color = "blue";
302313

@@ -353,12 +364,14 @@ Mesh TeXtrusion::skeleton_to_mesh(const vector<PHoleInfo>& phole_infos,
353364
// triangulation for both.
354365
double offset_thickness = 0.5;
355366
for (int ph_idx=0; ph_idx < (int)phole_infos.size(); ph_idx++) {
367+
if (updater->info("profile", 1.0*ph_idx/phole_infos.size()))
368+
throw EAborted("Aborted!");
369+
356370
auto& phi = phole_infos[ph_idx];
357371
int r_idx = -1;
358372
for (auto &r : phi.regions) {
359373
r_idx++;
360374
double depth = r.get_depth();
361-
int num_offsets = int(ceil(depth/offset_thickness));
362375
string color = "blue";
363376
string path_modifier;
364377

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

489504
return mesh;
490505
}

0 commit comments

Comments
 (0)