~ubuntu-branches/ubuntu/lucid/synfigstudio/lucid

« back to all changes in this revision

Viewing changes to src/synfigapp/canvasinterface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2010-01-26 11:20:50 UTC
  • mfrom: (1.1.5 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100126112050-e43u17c5zpc5hse4
Tags: 0.62.00-1
* QA upload
* Properly orphan the package (set Maintainer to QA, empty Uploaders)
* New upstream release
* Bump build-dep on (lib)synfig to most recent version
* Bump standards-version to 3.8.3, no changes needed
* Change section of the "-dbg" package to debug, thanks lintian

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*!     \file canvasinterface.cpp
3
3
**      \brief Template File
4
4
**
5
 
**      $Id: canvasinterface.cpp 1923 2008-03-26 20:04:43Z dooglus $
 
5
**      $Id$
6
6
**
7
7
**      \legal
8
8
**      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9
9
**      Copyright (c) 2007, 2008 Chris Moore
 
10
**      Copyright (c) 2009 Carlos A. Sosa Navarro
10
11
**
11
12
**      This package is free software; you can redistribute it and/or
12
13
**      modify it under the terms of the GNU General Public License as
52
53
#include "instance.h"
53
54
 
54
55
#include "actions/layeradd.h"
 
56
#include "actions/layerremove.h"
55
57
#include "actions/valuedescconvert.h"
56
58
#include "actions/valuenodeadd.h"
57
59
#include "actions/editmodeset.h"
214
216
        layer->set_canvas(canvas);
215
217
 
216
218
        // Apply some defaults
217
 
        if(layer->set_param("fg",synfigapp::Main::get_foreground_color()))
218
 
                layer->set_param("bg",synfigapp::Main::get_background_color());
 
219
        if(layer->set_param("fg",synfigapp::Main::get_outline_color()))
 
220
                layer->set_param("bg",synfigapp::Main::get_fill_color());
 
221
        else if (name == "outline")
 
222
                layer->set_param("color",synfigapp::Main::get_outline_color());
219
223
        else
220
 
                layer->set_param("color",synfigapp::Main::get_foreground_color());
 
224
                layer->set_param("color",synfigapp::Main::get_fill_color());
221
225
 
222
226
        layer->set_param("width",synfigapp::Main::get_bline_width().units(get_canvas()->rend_desc()));
223
227
        layer->set_param("gradient",synfigapp::Main::get_gradient());
300
304
        // Action to move the layer (if necessary)
301
305
        if(depth>0)
302
306
        {
303
 
                Action::Handle  action(Action::create("layer_move"));
 
307
                Action::Handle  action(Action::create("LayerMove"));
304
308
 
305
309
                assert(action);
306
310
                if(!action)
463
467
void
464
468
CanvasInterface::set_rend_desc(const synfig::RendDesc &rend_desc)
465
469
{
466
 
        Action::Handle  action(Action::create("canvas_rend_desc_set"));
 
470
        Action::Handle  action(Action::create("CanvasRendDescSet"));
467
471
 
468
472
        assert(action);
469
473
        if(!action)
480
484
void
481
485
CanvasInterface::set_name(const synfig::String &x)
482
486
{
483
 
        Action::Handle  action(Action::create("canvas_name_set"));
 
487
        Action::Handle  action(Action::create("CanvasNameSet"));
484
488
 
485
489
        assert(action);
486
490
        if(!action)
499
503
void
500
504
CanvasInterface::set_description(const synfig::String &x)
501
505
{
502
 
        Action::Handle  action(Action::create("canvas_description_set"));
 
506
        Action::Handle  action(Action::create("CanvasDescriptionSet"));
503
507
 
504
508
        assert(action);
505
509
        if(!action)
516
520
void
517
521
CanvasInterface::set_id(const synfig::String &x)
518
522
{
519
 
        Action::Handle  action(Action::create("canvas_id_set"));
 
523
        Action::Handle  action(Action::create("CanvasIdSet"));
520
524
 
521
525
        assert(action);
522
526
        if(!action)
560
564
}
561
565
 
562
566
bool
563
 
CanvasInterface::import(const synfig::String &filename, bool /*copy*/)
 
567
CanvasInterface::import(const synfig::String &filename, synfig::String &errors, synfig::String &warnings, bool resize_image)
564
568
{
565
569
        Action::PassiveGrouper group(get_instance().get(),_("Import Image"));
566
570
 
576
580
        if (ext.size()) ext = ext.substr(1); // skip initial '.'
577
581
        std::transform(ext.begin(),ext.end(),ext.begin(),&::tolower);
578
582
 
 
583
        if(ext=="svg"){//I don't like it, but worse is nothing
 
584
                Layer::Handle _new_layer(add_layer_to("PasteCanvas",get_canvas()));
 
585
                Layer::Handle _aux_layer(add_layer_to("svg_layer",get_canvas()));
 
586
                if(_aux_layer){
 
587
                        _aux_layer->set_param("filename",ValueBase(filename));
 
588
                        _new_layer->set_param("canvas",ValueBase(_aux_layer->get_param("canvas")));
 
589
                        //remove aux layer
 
590
                        Action::Handle  action(Action::LayerRemove::create());
 
591
                        assert(action);
 
592
                        if(!action)
 
593
                                return 0;
 
594
                        action->set_param("canvas",get_canvas());
 
595
                        action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
 
596
                        action->set_param("layer",_aux_layer);
 
597
                        if(!action->is_ready()){
 
598
                                get_ui_interface()->error(_("Action Not Ready"));
 
599
                                return 0;
 
600
                        }
 
601
                        if(!get_instance()->perform_action(action)){
 
602
                                get_ui_interface()->error(_("Action Failed."));
 
603
                                return 0;
 
604
                        }
 
605
                }
 
606
                signal_layer_new_description()(_new_layer,filename);
 
607
                return true;
 
608
        }
 
609
 
579
610
        // If this is a SIF file, then we need to do things slightly differently
580
611
        if(ext=="sif" || ext=="sifz")try
581
612
        {
582
 
 
583
 
                Canvas::Handle outside_canvas(synfig::open_canvas(filename));
 
613
                Canvas::Handle outside_canvas(synfig::open_canvas(filename, errors, warnings));
584
614
                if(!outside_canvas)
585
 
                        throw String(_("Unable to open this composition"));
 
615
                        throw String(_("Unable to open this composition")) + ":\n\n" + errors;
586
616
 
587
617
                Layer::Handle layer(add_layer_to("PasteCanvas",get_canvas()));
588
618
                if(!layer)
589
619
                        throw String(_("Unable to create \"Paste Canvas\" layer"));
590
620
                if(!layer->set_param("canvas",ValueBase(outside_canvas)))
591
621
                        throw int();
 
622
                get_canvas()->register_external_canvas(filename, outside_canvas);
592
623
 
593
624
                //layer->set_description(basename(filename));
594
625
                signal_layer_new_description()(layer,filename);
596
627
        }
597
628
        catch(String x)
598
629
        {
599
 
                get_ui_interface()->error(x+" -- "+filename);
 
630
                get_ui_interface()->error(filename + ": " + x);
600
631
                return false;
601
632
        }
602
633
        catch(...)
623
654
                h=layer->get_param("_height").get(int());
624
655
                if(w&&h)
625
656
                {
626
 
                        Vector size=ValueBase(get_canvas()->rend_desc().get_br()-get_canvas()->rend_desc().get_tl());
627
 
                        Vector x;
628
 
                        if(size[0]<size[1])
 
657
                        Vector x, size=ValueBase(get_canvas()->rend_desc().get_br()-get_canvas()->rend_desc().get_tl());
 
658
 
 
659
                        // vector from top left of canvas to bottom right
 
660
                        if (resize_image)
629
661
                        {
630
 
                                x[0]=size[0];
631
 
                                x[1]=size[0]/w*h;
632
 
                                if((size[0]<0) ^ (size[1]<0))
633
 
                                        x[1]=-x[1];
 
662
                                if(abs(size[0])<abs(size[1]))   // if canvas is tall and thin
 
663
                                {
 
664
                                        x[0]=size[0];   // use full width
 
665
                                        x[1]=size[0]/w*h; // and scale for height
 
666
                                        if((size[0]<0) ^ (size[1]<0))
 
667
                                                x[1]=-x[1];
 
668
                                }
 
669
                                else                            // else canvas is short and fat (or maybe square)
 
670
                                {
 
671
                                        x[1]=size[1];   // use full height
 
672
                                        x[0]=size[1]/h*w; // and scale for width
 
673
                                        if((size[0]<0) ^ (size[1]<0))
 
674
                                                x[0]=-x[0];
 
675
                                }
634
676
                        }
635
677
                        else
636
678
                        {
637
 
                                x[1]=size[1];
638
 
                                x[0]=size[1]/h*w;
639
 
                                if((size[0]<0) ^ (size[1]<0))
640
 
                                        x[0]=-x[0];
 
679
                                x[0] = w/60.0;
 
680
                                x[1] = h/60.0;
 
681
                                if((size[0]<0)) x[0]=-x[0];
 
682
                                if((size[1]<0)) x[1]=-x[1];
641
683
                        }
 
684
 
642
685
                        if(!layer->set_param("tl",ValueBase(-x/2)))
643
686
                                throw int();
644
687
                        if(!layer->set_param("br",ValueBase(x/2)))
676
719
void
677
720
CanvasInterface::waypoint_duplicate(ValueNode::Handle value_node,synfig::Waypoint waypoint)
678
721
{
679
 
        Action::Handle  action(Action::create("waypoint_set_smart"));
 
722
        Action::Handle  action(Action::create("WaypointSetSmart"));
680
723
 
681
724
        assert(action);
682
725
        if(!action)
705
748
void
706
749
CanvasInterface::waypoint_remove(ValueNode::Handle value_node,synfig::Waypoint waypoint)
707
750
{
708
 
        Action::Handle  action(Action::create("waypoint_remove"));
 
751
        Action::Handle  action(Action::create("WaypointRemove"));
709
752
 
710
753
        assert(action);
711
754
        if(!action)
729
772
        if(value_node->is_exported())
730
773
                return;
731
774
 
732
 
        Action::Handle  action(Action::create("value_node_add"));
 
775
        Action::Handle  action(Action::create("ValueNodeAdd"));
733
776
 
734
777
        assert(action);
735
778
        if(!action)
756
799
        if(value_desc.is_exported())
757
800
                return;
758
801
 
759
 
        Action::Handle  action(Action::create("value_desc_export"));
 
802
        Action::Handle  action(Action::create("ValueDescExport"));
760
803
 
761
804
        assert(action);
762
805
        if(!action)
803
846
        { synfig::warning("Can't get canvas from value desc...?"); }
804
847
#endif
805
848
 
806
 
        synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_set"));
 
849
        synfigapp::Action::Handle action(synfigapp::Action::create("ValueDescSet"));
807
850
        if(!action)
808
851
        {
809
852
                return false;