source: synfigstudio/trunk/fuentes/src/gui/dialogs/dialog_spritesheetparam.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 5.2 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file dialog_spritesheetparam.cpp
3**      \brief Implementation for the SpriteSheetParam Dialog
4**
5**      $Id$
6**
7**      \legal
8**      Copyright (c) 2015 Denis Zdorovtsov
9**
10**      This package is free software; you can redistribute it and/or
11**      modify it under the terms of the GNU General Public License as
12**      published by the Free Software Foundation; either version 2 of
13**      the License, or (at your option) any later version.
14**
15**      This package is distributed in the hope that it will be useful,
16**      but WITHOUT ANY WARRANTY; without even the implied warranty of
17**      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18**      General Public License for more details.
19**      \endlegal
20*/
21/* ========================================================================= */
22
23/* === H E A D E R S ======================================================= */
24#include <math.h>
25
26#include <gtkmm/grid.h>
27
28#include "dialogs/dialog_spritesheetparam.h"
29#include "general.h"
30
31namespace studio
32{
33
34Dialog_SpriteSheetParam::Dialog_SpriteSheetParam(Gtk::Window &parent):
35        Dialog_TargetParam(parent, _("Sprite sheet parameters")), 
36        frame_count(0)
37{       
38        //Checkbox
39        check_button = Gtk::manage(new Gtk::CheckButton(_("Add into an existing file."),true));
40
41        //Offset X
42        Gtk::Label* offset_x_label(manage(new Gtk::Label(_("Offset X:"))));
43        offset_x_label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
44        offset_x_box = Gtk::manage(new Gtk::SpinButton(Gtk::Adjustment::create(0.0, 0.0,10000.0)));
45
46        //Offset Y
47        Gtk::Label* offset_y_label(manage(new Gtk::Label(_("Offset Y:"))));
48        offset_y_label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
49        offset_y_box = Gtk::manage(new Gtk::SpinButton(Gtk::Adjustment::create(0.0, 0.0,10000.0)));
50
51        //Dirrection
52        Gtk::Label* direction_label(manage(new Gtk::Label(_("Direction:"))));
53        direction_label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
54        direction_box = Gtk::manage(new Gtk::ComboBoxText());
55        direction_box->append("horizontal");
56        direction_box->append("vertical");
57        direction_box->set_active(0);
58        direction_box->signal_changed().connect(sigc::mem_fun(*this, &Dialog_SpriteSheetParam::on_dir_change));
59       
60        //Row count
61        Gtk::Label* rows_label(manage(new Gtk::Label(_("Rows:"))));
62        rows_label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
63        rows_box = Gtk::manage(new Gtk::SpinButton(Gtk::Adjustment::create(0.0, 1.0,1000.0)));
64        rows_box->signal_value_changed().connect(sigc::mem_fun(*this, &Dialog_SpriteSheetParam::on_rows_change));
65
66        //Column count
67        Gtk::Label* columns_label(manage(new Gtk::Label(_("Columns:"))));
68        columns_label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
69        columns_box = Gtk::manage(new Gtk::SpinButton(Gtk::Adjustment::create(0.0, 1.0,1000.0)));
70        columns_box->signal_value_changed().connect(sigc::mem_fun(*this, &Dialog_SpriteSheetParam::on_cols_change));
71
72        //Grid
73        Gtk::Grid* grid = Gtk::manage(new Gtk::Grid());
74        grid->attach(*check_button,0,0,2,1);
75        grid->attach(*offset_x_label,0,1,1,1);
76        grid->attach(*offset_x_box,1,1,1,1);
77        grid->attach(*offset_y_label,2,1,1,1);
78        grid->attach(*offset_y_box,3,1,1,1);
79        grid->attach(*direction_label,0,2,2,1);
80        grid->attach(*direction_box,1,2,3,1);
81        grid->attach(*rows_label,0,3,1,1);
82        grid->attach(*rows_box,1,3,1,1);
83        grid->attach(*columns_label,2,3,1,1);
84        grid->attach(*columns_box,3,3,1,1);
85        grid->set_row_spacing (4);
86        grid->set_column_spacing (2);
87        grid->set_border_width(8);
88        grid->show_all();
89
90        get_content_area()->pack_start(*grid, true, true, 3);
91        get_content_area()->show_all();
92}
93
94Dialog_SpriteSheetParam::~Dialog_SpriteSheetParam()
95{
96}
97
98void
99Dialog_SpriteSheetParam::init()
100{
101        frame_count = get_desc().get_frame_end() - get_desc().get_frame_start() + 1;
102       
103        offset_x_box->set_value(get_tparam().offset_x);
104        offset_y_box->set_value(get_tparam().offset_y);
105        rows_box->set_value(get_tparam().rows);
106        columns_box->set_value(get_tparam().columns);
107        direction_box->set_active(get_tparam().dir);
108        check_button->set_active(get_tparam().append);
109        on_dir_change(); //Update boxes
110}
111
112void
113Dialog_SpriteSheetParam::on_dir_change()
114{
115        rows_box->set_sensitive(direction_box->get_active_row_number() == 1);
116        rows_box->set_value(direction_box->get_active_row_number() == 1 ? frame_count : 1);
117        columns_box->set_sensitive(direction_box->get_active_row_number() == 0);
118        columns_box->set_value(direction_box->get_active_row_number() == 0 ? frame_count : 1);
119}
120
121void
122Dialog_SpriteSheetParam::on_rows_change()
123{
124        static bool flag = false;
125        if (direction_box->get_active_row_number() == 0)
126                return;
127        if ((flag = !flag))
128                columns_box->set_value(ceil((double)frame_count / rows_box->get_value()));
129}
130
131void
132Dialog_SpriteSheetParam::on_cols_change()
133{
134        static bool flag = false;
135        if (direction_box->get_active_row_number() == 1)
136                return;
137        if ((flag = !flag))
138                rows_box->set_value(ceil((double)frame_count / columns_box->get_value()));
139}
140
141void
142Dialog_SpriteSheetParam::write_tparam(synfig::TargetParam & tparam_)
143{
144        tparam_.offset_x = offset_x_box->get_value();
145        tparam_.offset_y = offset_y_box->get_value();
146        tparam_.rows = rows_box->get_value();
147        tparam_.columns = columns_box->get_value();
148        tparam_.dir = (synfig::TargetParam::Direction)direction_box->get_active_row_number ();
149        tparam_.append = check_button->get_active();
150}
151
152}
Note: See TracBrowser for help on using the repository browser.