Difference between revisions of "Dev:Adding a Panel - Part I"

From Synfig Studio :: Documentation
Jump to: navigation, search
m (Text replace - '[[' to '{{l|')
m
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{l|Category:Code]]
+
{{Title|Adding a Panel - Part I}}
 +
{{Category|Code}}
 +
 
 +
  '''These are highly out of date''' please note that the directory "gtkmm" has been renamed to "gui",
 +
  Panel is now know has Dock. Also, some files were moved into subfolders, take a look
 +
  inside the "gui/docks" folder is a good start to understand how Docks and Dockable Class work.
 +
 
 
Here's an example of how to build a module and add a basic panel option to the file menu in Synfig Studio.  For this example I will make a empty panel option and have subsequent parts adding to it.
 
Here's an example of how to build a module and add a basic panel option to the file menu in Synfig Studio.  For this example I will make a empty panel option and have subsequent parts adding to it.
  
Line 286: Line 292:
 
== The Location ==
 
== The Location ==
  
{{l|Image:adding_a_panel_I_1.jpg|300px]]
+
{{l|Image:adding_a_panel_I_1.jpg|300px}}
  
 
After you install the newly compiled Synfigstudio, run the binary. From the main Synfigstudio interface choose the "File" option and select "panels".
 
After you install the newly compiled Synfigstudio, run the binary. From the main Synfigstudio interface choose the "File" option and select "panels".
  
{{l|Image:adding_a_panel_I_2.jpg|150px]]
+
{{l|Image:adding_a_panel_I_2.jpg|150px}}
  
 
From here your new panel should be located in this list of items. Select it. An empty tab window, based on the default synfigstudio layout should show up with the default exec icon. The only thing you can do at this time is drag and drop it into another one of the panels. To try this choose one or more and drag it onto the boring panel. They should become one. This gives you a basic dock widget to work with.
 
From here your new panel should be located in this list of items. Select it. An empty tab window, based on the default synfigstudio layout should show up with the default exec icon. The only thing you can do at this time is drag and drop it into another one of the panels. To try this choose one or more and drag it onto the boring panel. They should become one. This gives you a basic dock widget to work with.
  
{{l|Image:adding_a_panel_I_3.jpg|150px]]
+
{{l|Image:adding_a_panel_I_3.jpg|150px}}
  
  
Line 301: Line 307:
 
This will be described in the next part of adding a panel.
 
This will be described in the next part of adding a panel.
  
  {{l|Adding a Panel-Part II]]
+
  {{l|Dev:Adding a Panel - Part II | Adding a Panel Part II}}

Latest revision as of 18:09, 16 March 2017

  These are highly out of date please note that the directory "gtkmm" has been renamed to "gui", 
  Panel is now know has Dock. Also, some files were moved into subfolders, take a look 
  inside the "gui/docks" folder is a good start to understand how Docks and Dockable Class work.

Here's an example of how to build a module and add a basic panel option to the file menu in Synfig Studio. For this example I will make a empty panel option and have subsequent parts adding to it.

Section 1, "The Code" will present the entire source, uninterrupted

The Code

We need to create four new files (two header (.h) files. One for the module and one for the dock, and two implementations (.cpp) files. Also one for the module and one for the dock), and edit one existing files (outside of the newly created module directory app.cpp, and the Makefile.am), all in the synfigstudio/src/gtkmm/ folder:

<gtkmm dir>/mod_boring/mod_boring.h

/* === S Y N F I G ========================================================= */
/*!	\file mod_boring.h
**	\brief Template Header
**
**	$Id$
**
**	\legal
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
**	This package is free software; you can redistribute it and/or
**	modify it under the terms of the GNU General Public License as
**	published by the Free Software Foundation; either version 2 of
**	the License, or (at your option) any later version.
**
**	This package is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**	General Public License for more details.
**	\endlegal
*/
/* ========================================================================= */
/* === S T A R T =========================================================== */
#ifndef __SYNFIG_MOD_BORING_H
#define __SYNFIG_MOD_BORING_H
/* === H E A D E R S ======================================================= */
#include <ETL/handle>
#include "../module.h"
/* === C L A S S E S & S T R U C T S ======================================= */
namespace studio {
class Dock_BoringEdit;
class ModBoring : public Module
{
	friend class Dock_BoringEdit;
	Dock_BoringEdit*	dock_boring_edit;

protected:
	virtual bool start_vfunc();
	virtual bool stop_vfunc();

public:
       virtual ~ModBoring() { stop(); }
};

}; // END of namespace studio
/* === E N D =============================================================== */
#endif

<gtkmm dir>/mod_boring/mod_boring.cpp

/* === S Y N F I G ========================================================= */
/*!	\file mod_boring.cpp
**	\brief Template File
**
**	$Id$
**
**	\legal
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
**	This package is free software; you can redistribute it and/or
**	modify it under the terms of the GNU General Public License as
**	published by the Free Software Foundation; either version 2 of
**	the License, or (at your option) any later version.
**
**	This package is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**	General Public License for more details.
**	\endlegal
*/
/* ========================================================================= */
/* === H E A D E R S ======================================================= */
#ifdef USING_PCH
#	include "pch.h"
#else
#ifdef HAVE_CONFIG_H
#	include <config.h>
#endif
#include "mod_boring.h"
#include "dock_boringedit.h"
#include "../app.h"
#include "../dockmanager.h"
#include "../general.h"
#endif
/* === U S I N G =========================================================== */
using namespace std;
using namespace etl;
using namespace synfig;
using namespace studio;
/* === M E T H O D S ======================================================= */
bool
studio::ModBoring::start_vfunc()
{
	dock_boring_edit=new Dock_BoringEdit();
	App::get_dock_manager()->register_dockable(*dock_boring_edit);
	return true;
}
bool
studio::ModBoring::stop_vfunc()
{
       App::get_dock_manager()->unregister_dockable(*dock_boring_edit);
	delete dock_boring_edit;
	return true;
}
 

<gtkmm dir>/mod_boring/dock_boring.h

/* === S Y N F I G ========================================================= */
/*!	\file dock_boringedit.h
**	\brief Template Header
**
**	$Id$
**
**	\legal
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
**	This package is free software; you can redistribute it and/or
**	modify it under the terms of the GNU General Public License as
**	published by the Free Software Foundation; either version 2 of
**	the License, or (at your option) any later version.
**
**	This package is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**	General Public License for more details.
**	\endlegal
*/
/* ========================================================================= */
/* === S T A R T =========================================================== */
#ifndef __SYNFIG_STUDIO_DOCK_BORING_EDIT_H
#define __SYNFIG_STUDIO_DOCK_BORING_EDIT_H
/* === H E A D E R S ======================================================= */
#include <gtk/gtk.h>
#include <gtkmm/adjustment.h>
#include <gtkmm/table.h>
#include <gtkmm/dialog.h>
#include <synfig/time.h>
#include <synfigapp/value_desc.h>
#include <synfig/time.h>
#include "../dockable.h"
#include <vector>
#include <gtkmm/actiongroup.h>
/* === C L A S S E S & S T R U C T S ======================================= */
namespace synfigapp {
class CanvasInterface;
};
namespace studio {

class Dock_BoringEdit : public Dockable
{ 	
	Glib::RefPtr<Gtk::ActionGroup> action_group;
	Gtk::Table table;
	sigc::signal<void> signal_changed_;
public:
       Dock_BoringEdit();
       ~Dock_BoringEdit();
}; // END of Dock_BoringEdit
}; // END of namespace studio
/* === E N D =============================================================== */
#endif
  

<gtkmm dir>/mod_boring/dock_boring.cpp

/* === S Y N F I G ========================================================= */
/*!	\file dock_boringedit.cpp
**	\brief Template File
**
**     Takes two lists of ducks coords and matches one to another blines ducks coords
**     creating a shapeshift not a tween of the two blines instead of working with one
**     bline.
**
**	$Id$
**
**	\legal
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**	Copyright (c) 2007 Chris Moore
**
**	This package is free software; you can redistribute it and/or
**	modify it under the terms of the GNU General Public License as
**	published by the Free Software Foundation; either version 2 of
**	the License, or (at your option) any later version.
**
**	This package is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**	General Public License for more details.
**	\endlegal
*/
/* ========================================================================= */
/* === H E A D E R S ======================================================= */
#ifdef USING_PCH
#	include "pch.h"
#else
#ifdef HAVE_CONFIG_H
#	include <config.h>
#endif
#include "dock_boringedit.h"
#include <gtkmm/frame.h>
#include <gtkmm/table.h>
#include <gtkmm/label.h>
#include <synfig/general.h>
#include <synfigapp/canvasinterface.h>
#include <synfigapp/value_desc.h>
#include <synfigapp/main.h>
#include "../app.h"
#include "../general.h"
#endif
/* === U S I N G =========================================================== */
using namespace std;
using namespace etl;
using namespace synfig;
using namespace studio;
/* === M E T H O D S ======================================================= */
Dock_BoringEdit::Dock_BoringEdit():
	Dockable("boring_edit",_("Boring"), Gtk::StockID("gtk-execute")),
	table(2,2,false)
{
Glib::ustring ui_info =
       "<ui>"
       "	<toolbar action='toolbar-boring'>"	
       "	</toolbar>"
       "</ui>"	;
       App::ui_manager()->add_ui_from_string(ui_info);
set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-boring")));
       add(table);
       table.set_homogeneous(true);
       show_all_children();
}
Dock_BoringEdit::~Dock_BoringEdit()
{
}

<gtkmm dir/app.cpp

Now we edit <gtkmm dir>mod_boring/app.cpp. Add this with the other #include lines:

#include "mod_boring/mod_boring.h"

We add this with the others in the G L O B A L section lines:

etl::handle< studio::ModBoring > mod_boring_;

(edited by Mesco64) I just couldn't see the new entry under the Panels menu. In order to make it work I had to add these couple of lines to <gtkmm dir>mod_boring/app.cpp (line 1272 aprox.):

       studio_init_cb.task(_("Init ModBoring..."));
       module_list_.push_back(new ModBoring()); module_list_.back()->start();

After this change not only the newly created panel is available under Panels menu, but this way you'll find it already open on startup (the second line creates an instance of the panel) Moreover, Synfig remembers about open panels and where they're placed... very nice (end addition)

<gtkmm dir>/Makefile.am

Then I need to edit <gtkmm dir>Makefile.am and add these two files to the list of source files (maintain alphabetical order please):

This will be added above the PALETTE_HH section.

BORING_HH = \
	mod_boring/dock_boringedit.h  mod_boring/mod_boring.h
BORING_CC = \
	 mod_boring/dock_boringedit.cpp mod_boring/mod_boring.cpp

This will be added to the list of items in the "synfigstudio_SOURCES =" line.

$(BORING_CC) $(BORING_HH)

Compiling

Note: This directory structures is based on the *NIX environment.

First you will need to follow the http://www.synfig.org/Build_Instructions. Then you will need to create a directory in synfigstudio/src/gtkmm/ called mod_boring. Next you will copy the above four files into that directory. After That you will need to modify the two files app.cpp and Makefile.am as stated above. You will have to run "autoreconf --install --force" and "./configure" once again to sync the makefiles up with your changes. This is only done if you modify the Makefile.am

The Location

Adding a panel I 1.jpg

After you install the newly compiled Synfigstudio, run the binary. From the main Synfigstudio interface choose the "File" option and select "panels".

Adding a panel I 2.jpg

From here your new panel should be located in this list of items. Select it. An empty tab window, based on the default synfigstudio layout should show up with the default exec icon. The only thing you can do at this time is drag and drop it into another one of the panels. To try this choose one or more and drag it onto the boring panel. They should become one. This gives you a basic dock widget to work with.

Adding a panel I 3.jpg


Adding Widgets

This will be described in the next part of adding a panel.

Adding a Panel Part II