1 /* === S Y N F I G ========================================================= */
2 /*! \file state_text.cpp
3 ** \brief Template File
4 **
5 ** $Id$
6 **
7 ** \legal
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
10 ** Copyright (c) 2010 Carlos López
11 **
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
16 **
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
21 ** \endlegal
22 */
23 /* ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #ifdef USING_PCH
28 # include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 # include <config.h>
32 #endif
33
34 #include <synfig/general.h>
35
36 #include "state_text.h"
37 #include "state_normal.h"
38 #include "canvasview.h"
39 #include "workarea.h"
40 #include "app.h"
41
42 #include <synfigapp/action.h>
43 #include "event_mouse.h"
44 #include "event_layerclick.h"
45 #include "docks/dock_toolbox.h"
46 #include "docks/dialog_tooloptions.h"
47 #include "duck.h"
48 #include "widgets/widget_enum.h"
49 #include <synfigapp/main.h>
50
51 #include <gui/localization.h>
52
53 #endif
54
55 /* === U S I N G =========================================================== */
56
57 using namespace std;
58 using namespace etl;
59 using namespace synfig;
60 using namespace studio;
61
62 /* === M A C R O S ========================================================= */
63
64 #ifndef LAYER_CREATION
65 #define LAYER_CREATION(button, stockid, tooltip) \
66 { \
67 Gtk::Image *icon = manage(new Gtk::Image(Gtk::StockID(stockid), \
68 Gtk::ICON_SIZE_SMALL_TOOLBAR)); \
69 button.add(*icon); \
70 } \
71 button.set_relief(Gtk::RELIEF_NONE); \
72 button.set_tooltip_text(tooltip); \
73 button.signal_toggled().connect(sigc::mem_fun(*this, \
74 &studio::StateText_Context::toggle_layer_creation))
75 #endif
76
77 // indentation for options layout
78 #ifndef SPACING
79 #define SPACING(name, px) \
80 Gtk::Alignment *name = Gtk::manage(new Gtk::Alignment()); \
81 name->set_size_request(px)
82 #endif
83
84 #define GAP (3)
85 #define INDENTATION (6)
86
87 /* === G L O B A L S ======================================================= */
88
89 StateText studio::state_text;
90
91 /* === C L A S S E S & S T R U C T S ======================================= */
92
93 class studio::StateText_Context
94 {
95 etl::handle<CanvasView> canvas_view;
96 CanvasView::IsWorking is_working;
97
98 Duckmatic::Push duckmatic_push;
99
100 void refresh_ducks();
101
102 bool prev_workarea_layer_status_;
103
104 //Toolbox settings
105 synfigapp::Settings& settings;
106
107 // holder of options
108 Gtk::Table options_table;
109
110 // title
111 Gtk::Label title_label;
112
113 // layer name:
114 Gtk::Label id_label;
115 Gtk::HBox id_box;
116 Gtk::Entry id_entry;
117
118 // layer types to create:
119 Gtk::Label layer_types_label;
120 Gtk::ToggleButton layer_text_togglebutton;
121 Gtk::HBox layer_types_box;
122
123 // blend method
124 Gtk::Label blend_label;
125 Gtk::HBox blend_box;
126 Widget_Enum blend_enum;
127
128 // opacity
129 Gtk::Label opacity_label;
130 Gtk::HScale opacity_hscl;
131
132 // paragraph
133 Gtk::Label paragraph_label;
134 Gtk::CheckButton paragraph_checkbutton;
135 Gtk::HBox paragraph_box;
136
137 // size
138 Gtk::Label size_label;
139 Widget_Vector size_widget;
140
141 // orientation
142 Gtk::Label orientation_label;
143 Widget_Vector orientation_widget;
144
145 // font family
146 Gtk::Label family_label;
147 Gtk::Entry family_entry;
148
149
150 public:
151
get_id() const152 synfig::String get_id()const { return id_entry.get_text(); }
set_id(const synfig::String & x)153 void set_id(const synfig::String& x) { return id_entry.set_text(x); }
154
get_layer_text_flag() const155 bool get_layer_text_flag()const { return layer_text_togglebutton.get_active(); }
set_layer_text_flag(bool x)156 void set_layer_text_flag(bool x) { return layer_text_togglebutton.set_active(x); }
157
get_blend() const158 int get_blend()const { return blend_enum.get_value(); }
set_blend(int x)159 void set_blend(int x) { return blend_enum.set_value(x); }
160
get_opacity() const161 Real get_opacity()const { return opacity_hscl.get_value(); }
set_opacity(Real x)162 void set_opacity(Real x) { opacity_hscl.set_value(x); }
163
get_paragraph_flag() const164 bool get_paragraph_flag()const { return paragraph_checkbutton.get_active(); }
set_paragraph_flag(bool x)165 void set_paragraph_flag(bool x) { return paragraph_checkbutton.set_active(x); }
166
get_size()167 Vector get_size() { return size_widget.get_value(); }
set_size(Vector s)168 void set_size(Vector s) { return size_widget.set_value(s); }
169
get_orientation()170 Vector get_orientation() { return orientation_widget.get_value(); }
set_orientation(Vector s)171 void set_orientation(Vector s) { return orientation_widget.set_value(s); }
172
get_family() const173 String get_family()const { return family_entry.get_text(); }
set_family(String s)174 void set_family(String s) { return family_entry.set_text(s); }
175
176 bool layer_text_flag;
177
178 void refresh_tool_options(); //to refresh the toolbox
179
180 //events
181 Smach::event_result event_stop_handler(const Smach::event& x);
182 Smach::event_result event_refresh_handler(const Smach::event& x);
183 Smach::event_result event_mouse_click_handler(const Smach::event& x);
184 Smach::event_result event_refresh_tool_options(const Smach::event& x);
185 Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
186
187 //constructor destructor
188 StateText_Context(CanvasView *canvas_view);
189 ~StateText_Context();
190
get_canvas_view() const191 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view;}
get_canvas_interface() const192 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view->canvas_interface();}
get_work_area() const193 WorkArea * get_work_area()const{return canvas_view->get_work_area();}
194
195 //Modifying settings etc.
196 void load_settings();
197 void save_settings();
198 void reset();
199 void increment_id();
200 bool egress_on_selection_change;
event_layer_selection_changed_handler(const Smach::event &)201 Smach::event_result event_layer_selection_changed_handler(const Smach::event& /*x*/)
202 {
203 if(egress_on_selection_change)
204 throw &state_normal; //throw Smach::egress_exception();
205 return Smach::RESULT_OK;
206 }
207
208 void make_text(const Point& point);
209 void toggle_layer_creation();
210
211 }; // END of class StateText_Context
212
213 /* === P R O C E D U R E S ================================================= */
214
215 /* === M E T H O D S ======================================================= */
216
StateText()217 StateText::StateText():
218 Smach::state<StateText_Context>("text")
219 {
220 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateText_Context::event_layer_selection_changed_handler));
221 insert(event_def(EVENT_STOP,&StateText_Context::event_stop_handler));
222 insert(event_def(EVENT_REFRESH,&StateText_Context::event_refresh_handler));
223 insert(event_def(EVENT_REFRESH_DUCKS,&StateText_Context::event_refresh_handler));
224 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateText_Context::event_workarea_mouse_button_down_handler));
225 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateText_Context::event_refresh_tool_options));
226 }
227
~StateText()228 StateText::~StateText()
229 {
230 }
231
232 void
load_settings()233 StateText_Context::load_settings()
234 {
235 try
236 {
237 synfig::ChangeLocale change_locale(LC_NUMERIC, "C");
238 String value;
239 Vector v;
240
241 //parse the arguments yargh!
242 if(settings.get_value("text.id",value))
243 set_id(value);
244 else
245 set_id("Text");
246
247 if(settings.get_value("text.blend",value) && value != "")
248 set_blend(atoi(value.c_str()));
249 else
250 set_blend(0);//(int)Color::BLEND_COMPOSITE); //0 should be blend composites value
251
252 if(settings.get_value("text.opacity",value))
253 set_opacity(atof(value.c_str()));
254 else
255 set_opacity(1);
256
257 if(settings.get_value("text.paragraph",value) && value=="1")
258 set_paragraph_flag(true);
259 else
260 set_paragraph_flag(false);
261
262 if(settings.get_value("text.size_x",value))
263 v[0] = atof(value.c_str());
264 else
265 v[0] = 0.25;
266 if(settings.get_value("text.size_y",value))
267 v[1] = atof(value.c_str());
268 else
269 v[1] = 0.25;
270 set_size(v);
271
272 if(settings.get_value("text.orient_x",value))
273 v[0] = atof(value.c_str());
274 else
275 v[0] = 0.5;
276 if(settings.get_value("text.orient_y",value))
277 v[1] = atof(value.c_str());
278 else
279 v[1] = 0.5;
280 set_orientation(v);
281
282 if(settings.get_value("text.family",value))
283 set_family(value);
284 else
285 set_family("Sans Serif");
286
287 // since we have only text layer creation button, always turn it on.
288 if(settings.get_value("text.layer_text",value) && value=="0")
289 set_layer_text_flag(true);
290 else
291 set_layer_text_flag(true);
292
293 // determine layer flags
294 layer_text_flag = get_layer_text_flag();
295 }
296 catch(...)
297 {
298 synfig::warning("State Text: Caught exception when attempting to load settings.");
299 }
300 }
301
302 void
save_settings()303 StateText_Context::save_settings()
304 {
305 try
306 {
307 synfig::ChangeLocale change_locale(LC_NUMERIC, "C");
308 settings.set_value("text.id",get_id());
309 settings.set_value("text.layer_polygon",get_layer_text_flag()?"1":"0");
310 settings.set_value("text.blend",strprintf("%d",get_blend()));
311 settings.set_value("text.opacity",strprintf("%f",(float)get_opacity()));
312 settings.set_value("text.paragraph",get_paragraph_flag()?"1":"0");
313 settings.set_value("text.size_x",strprintf("%f",(float)get_size()[0]));
314 settings.set_value("text.size_y",strprintf("%f",(float)get_size()[1]));
315 settings.set_value("text.orient_x",strprintf("%f",(float)get_orientation()[0]));
316 settings.set_value("text.orient_y",strprintf("%f",(float)get_orientation()[1]));
317 settings.set_value("text.family",get_family());
318 }
319 catch(...)
320 {
321 synfig::warning("State Text: Caught exception when attempting to save settings.");
322 }
323 }
324
325 void
reset()326 StateText_Context::reset()
327 {
328 refresh_ducks();
329 }
330
331 void
increment_id()332 StateText_Context::increment_id()
333 {
334 String id(get_id());
335 int number=1;
336 int digits=0;
337
338 if(id.empty())
339 id="Text";
340
341 // If there is a number
342 // already at the end of the
343 // id, then remove it.
344 if(id[id.size()-1]<='9' && id[id.size()-1]>='0')
345 {
346 // figure out how many digits it is
347 for (digits = 0;
348 (int)id.size()-1 >= digits && id[id.size()-1-digits] <= '9' && id[id.size()-1-digits] >= '0';
349 digits++)
350 ;
351
352 String str_number;
353 str_number=String(id,id.size()-digits,id.size());
354 id=String(id,0,id.size()-digits);
355
356 number=atoi(str_number.c_str());
357 }
358 else
359 {
360 number=1;
361 digits=3;
362 }
363
364 number++;
365
366 // Add the number back onto the id
367 {
368 const String format(strprintf("%%0%dd",digits));
369 id+=strprintf(format.c_str(),number);
370 }
371
372 // Set the ID
373 set_id(id);
374 }
375
StateText_Context(CanvasView * canvasView)376 StateText_Context::StateText_Context(CanvasView *canvasView):
377 canvas_view(canvasView),
378 is_working(*canvasView),
379 duckmatic_push(get_work_area()),
380 prev_workarea_layer_status_(get_work_area()->get_allow_layer_clicks()),
381 settings(synfigapp::Main::get_selected_input_device()->settings()),
382 opacity_hscl(0.0f, 1.0125f, 0.0125f)
383 {
384 egress_on_selection_change=true;
385
386
387 /* Set up the tool options dialog */
388
389 // 0, title
390 title_label.set_label(_("Text Creation"));
391 Pango::AttrList list;
392 Pango::AttrInt attr = Pango::Attribute::create_attr_weight(Pango::WEIGHT_BOLD);
393 list.insert(attr);
394 title_label.set_attributes(list);
395 title_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
396
397 // 1, layer name label and entry
398 id_label.set_label(_("Name:"));
399 id_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
400 SPACING(id_gap, GAP);
401 id_box.pack_start(id_label, Gtk::PACK_SHRINK);
402 id_box.pack_start(*id_gap, Gtk::PACK_SHRINK);
403
404 id_box.pack_start(id_entry);
405
406 // 2, layer types creation
407 layer_types_label.set_label(_("Layer Type:"));
408 layer_types_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
409
410 LAYER_CREATION(layer_text_togglebutton,
411 ("synfig-layer_other_text"), _("Create a text layer"));
412
413 SPACING(layer_types_indent, INDENTATION);
414
415 layer_types_box.pack_start(*layer_types_indent, Gtk::PACK_SHRINK);
416 layer_types_box.pack_start(layer_text_togglebutton, Gtk::PACK_SHRINK);
417
418 // 3, blend method label and dropdown list
419 blend_label.set_label(_("Blend Method:"));
420 blend_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
421 SPACING(blend_gap, GAP);
422 blend_box.pack_start(blend_label, Gtk::PACK_SHRINK);
423 blend_box.pack_start(*blend_gap, Gtk::PACK_SHRINK);
424
425 blend_enum.set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method")
426 .set_local_name(_("Blend Method"))
427 .set_description(_("Defines the blend method to be used for texts")));
428
429 // 4, opacity label and slider
430 opacity_label.set_label(_("Opacity:"));
431 opacity_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
432
433 opacity_hscl.set_digits(2);
434 opacity_hscl.set_value_pos(Gtk::POS_LEFT);
435 opacity_hscl.set_tooltip_text(_("Opacity"));
436
437 // 5, paragraph
438 paragraph_label.set_label(_("Multiline Text"));
439 paragraph_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
440 paragraph_box.pack_start(paragraph_label, Gtk::PACK_SHRINK);
441 paragraph_box.pack_end(paragraph_checkbutton, Gtk::PACK_SHRINK);
442
443 // 6, size
444 size_label.set_label(_("Size:"));
445 size_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
446
447 size_widget.set_digits(2);
448 size_widget.set_canvas(canvas_view->get_canvas());
449
450 // 7, orientation
451 orientation_label.set_label(_("Orientation:"));
452 orientation_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
453
454 orientation_widget.set_digits(2);
455
456 // 8, family
457 family_label.set_label(_("Family:"));
458 family_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
459
460 // pack all options to the options_table
461
462 // 0, title
463 options_table.attach(title_label,
464 0, 2, 0, 1, Gtk::FILL, Gtk::FILL, 0, 0
465 );
466 // 1, name
467 options_table.attach(id_box,
468 0, 2, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0
469 );
470 // 2, layer types creation
471 options_table.attach(layer_types_label,
472 0, 2, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0
473 );
474 options_table.attach(layer_types_box,
475 0, 2, 3, 4, Gtk::FILL, Gtk::FILL, 0, 0
476 );
477 // 3, blend method
478 options_table.attach(blend_box,
479 0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
480 );
481 options_table.attach(blend_enum,
482 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
483 );
484 // 4, opacity
485 options_table.attach(opacity_label,
486 0, 1, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
487 );
488 options_table.attach(opacity_hscl,
489 1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
490 );
491 // 5, paragraph
492 options_table.attach(paragraph_box,
493 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
494 );
495 // 6, size
496 options_table.attach(size_label,
497 0, 1, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
498 );
499 options_table.attach(size_widget,
500 1, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
501 );
502 // 7, orientation
503 options_table.attach(orientation_label,
504 0, 1, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
505 );
506 options_table.attach(orientation_widget,
507 1, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0
508 );
509 // 8, family
510 options_table.attach(family_label,
511 0, 1, 9, 10, Gtk::FILL, Gtk::FILL, 0, 0
512 );
513 options_table.attach(family_entry,
514 1, 2, 9, 10, Gtk::FILL, Gtk::FILL, 0, 0
515 );
516 // fine-tune options layout
517 options_table.set_border_width(GAP*2); // border width
518 options_table.set_row_spacings(GAP); // row gap
519 options_table.set_row_spacing(0, GAP*2); // the gap between first and second row.
520 options_table.set_row_spacing(2, 1); // row gap between label and icon of layer type
521 //options_table.set_row_spacing(9, 0); // the final row using border width of table
522 options_table.set_margin_bottom(0);
523
524 options_table.show_all();
525
526 load_settings();
527
528 refresh_tool_options();
529 App::dialog_tool_options->present();
530
531 // Turn off layer clicking
532 get_work_area()->set_allow_layer_clicks(false);
533
534 // clear out the ducks
535 get_work_area()->clear_ducks();
536
537 // Refresh the work area
538 get_work_area()->queue_draw();
539
540 // Hide the tables if they are showing
541 //prev_table_status=get_canvas_view()->tables_are_visible();
542 //if(prev_table_status)get_canvas_view()->hide_tables();
543
544 // Disable the time bar
545 //get_canvas_view()->set_sensitive_timebar(false);
546
547 // Connect a signal
548 //get_work_area()->signal_user_click().connect(sigc::mem_fun(*this,&studio::StateText_Context::on_user_click));
549 get_work_area()->set_cursor(Gdk::XTERM);
550
551 App::dock_toolbox->refresh();
552 }
553
554 void
refresh_tool_options()555 StateText_Context::refresh_tool_options()
556 {
557 App::dialog_tool_options->clear();
558 App::dialog_tool_options->set_widget(options_table);
559 App::dialog_tool_options->set_local_name(_("Text Tool"));
560 App::dialog_tool_options->set_name("text");
561 }
562
563 Smach::event_result
event_refresh_tool_options(const Smach::event &)564 StateText_Context::event_refresh_tool_options(const Smach::event& /*x*/)
565 {
566 refresh_tool_options();
567 return Smach::RESULT_ACCEPT;
568 }
569
~StateText_Context()570 StateText_Context::~StateText_Context()
571 {
572 save_settings();
573
574 // Restore layer clicking
575 get_work_area()->set_allow_layer_clicks(prev_workarea_layer_status_);
576 get_work_area()->reset_cursor();
577
578 App::dialog_tool_options->clear();
579
580 get_work_area()->queue_draw();
581
582 get_canvas_view()->queue_rebuild_ducks();
583
584 App::dock_toolbox->refresh();
585 }
586
587 Smach::event_result
event_stop_handler(const Smach::event &)588 StateText_Context::event_stop_handler(const Smach::event& /*x*/)
589 {
590 //throw Smach::egress_exception();
591 throw &state_normal;
592 return Smach::RESULT_OK;
593 }
594
595 Smach::event_result
event_refresh_handler(const Smach::event &)596 StateText_Context::event_refresh_handler(const Smach::event& /*x*/)
597 {
598 refresh_ducks();
599 return Smach::RESULT_ACCEPT;
600 }
601
602 void
make_text(const Point & _point)603 StateText_Context::make_text(const Point& _point)
604 {
605 if (get_layer_text_flag())
606 {
607
608 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("New Text"));
609 synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL);
610
611 Layer::Handle layer;
612
613 Canvas::Handle canvas(get_canvas_view()->get_canvas());
614 int depth(0);
615
616 // we are temporarily using the layer to hold something
617 layer=get_canvas_view()->get_selection_manager()->get_selected_layer();
618 if(layer)
619 {
620 depth=layer->get_depth();
621 canvas=layer->get_canvas();
622 }
623
624 synfigapp::SelectionManager::LayerList layer_selection;
625 if (!getenv("SYNFIG_TOOLS_CLEAR_SELECTION"))
626 layer_selection = get_canvas_view()->get_selection_manager()->get_selected_layers();
627
628 const synfig::TransformStack& transform(get_work_area()->get_curr_transform_stack());
629 const Point point(transform.unperform(_point));
630
631 String text;
632 if (get_paragraph_flag())
633 App::dialog_paragraph(_("Text Paragraph"), _("Enter text here:"), text);
634 else
635 App::dialog_entry(_("Input text"),
636 _("Text: "),
637 text,
638 _("Cancel"),
639 _("Ok"));
640
641 egress_on_selection_change=false;
642 layer=get_canvas_interface()->add_layer_to("text",canvas,depth);
643 egress_on_selection_change=true;
644 if (!layer)
645 {
646 get_canvas_view()->get_ui_interface()->error(_("Unable to create layer"));
647 group.cancel();
648 return;
649 }
650 layer_selection.push_back(layer);
651
652 layer->set_param("blend_method", get_blend());
653 get_canvas_interface()->signal_layer_param_changed()(layer,"blend_method");
654
655 layer->set_param("amount", get_opacity());
656 get_canvas_interface()->signal_layer_param_changed()(layer, "amount");
657
658 layer->set_param("origin",point);
659 get_canvas_interface()->signal_layer_param_changed()(layer,"origin");
660
661 layer->set_param("text",text);
662 get_canvas_interface()->signal_layer_param_changed()(layer,"text");
663
664 layer->set_param("size",get_size());
665 get_canvas_interface()->signal_layer_param_changed()(layer,"size");
666
667 layer->set_param("orient",get_orientation());
668 get_canvas_interface()->signal_layer_param_changed()(layer,"orient");
669
670 layer->set_param("family",get_family());
671 get_canvas_interface()->signal_layer_param_changed()(layer,"family");
672
673 layer->set_description(get_id());
674 get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description());
675
676 egress_on_selection_change=false;
677 get_canvas_interface()->get_selection_manager()->clear_selected_layers();
678 get_canvas_interface()->get_selection_manager()->set_selected_layers(layer_selection);
679 egress_on_selection_change=true;
680
681 reset();
682 increment_id();
683 }
684 }
685
686 Smach::event_result
event_workarea_mouse_button_down_handler(const Smach::event & x)687 StateText_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
688 {
689 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
690 if(event.button==BUTTON_LEFT)
691 {
692 make_text(get_work_area()->snap_point_to_grid(event.pos));
693
694 get_work_area()->clear_ducks();
695 return Smach::RESULT_ACCEPT;
696 }
697 return Smach::RESULT_OK;
698 }
699
700 void
refresh_ducks()701 StateText_Context::refresh_ducks()
702 {
703 get_work_area()->clear_ducks();
704 get_work_area()->queue_draw();
705 }
706
707 void
toggle_layer_creation()708 StateText_Context::toggle_layer_creation()
709 {
710 // don't allow none layer creation
711 if (get_layer_text_flag() == 0)
712 {
713 if(layer_text_flag) set_layer_text_flag(true);
714 }
715
716 // update layer flags
717 layer_text_flag = get_layer_text_flag();
718 }
719