Skip to content

Commit

Permalink
Add GSVGtk support
Browse files Browse the repository at this point in the history
  • Loading branch information
esodan authored and Philip-Scott committed Feb 18, 2018
1 parent 1c178e1 commit 3da2ded
Show file tree
Hide file tree
Showing 22 changed files with 427 additions and 79 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ deconf.set('API_VERSION', API_VERSION)
deconf.set('prefix', get_option('prefix'))
deconf.set('libdir', '${exec_prefix}/'+get_option('libdir'))

configure_file(input : 'gtkcanvas.pc.in',
output : 'gtkcanvas-@[email protected]'.format(API_VERSION),
configure_file(input : 'gcav.pc.in',
output : 'gcav-@[email protected]'.format(API_VERSION),
configuration : deconf,
install : true,
install_dir : join_paths(get_option('libdir'), 'pkgconfig')
Expand Down
9 changes: 6 additions & 3 deletions demo/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ int main (string argv[]) {
GtkClutter.init (ref argv);

var window = new Gtk.Window ();
window.title = "GtkCanvas Demo";
window.title = "GtkCanvas (Gcav) Demo";

window.resize (1000, 800);

var canvas = new GtkCanvas.Canvas (600, 400);
var canvas = new Gcav.Canvas (600, 400);
canvas.add_shape ("rectangle", "blue", 45.0);
canvas.add_shape ("rectangle", "red", 30.0);
canvas.add_shape ("circle", "green", 0.0);
#if GSVGTK
canvas.add_shape ("svg", "blue", 0.0);
#endif

canvas.clicked.connect ((modifier) => {
canvas.resizer.visible = false;
Expand Down Expand Up @@ -94,4 +97,4 @@ int main (string argv[]) {
window.show_all ();
Gtk.main ();
return 0;
}
}
10 changes: 7 additions & 3 deletions demo/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ files_demo=([
'Window.vala'
])

args = ['--vapidir='+ldir]

if svgdep.found()
args+= ['--define=GSVGTK']
endif

executable ('gtkcanvas-demo',
files_demo,
vala_args: [
'--vapidir='+ldir
],
vala_args: args,
dependencies : [ deps, inc_libh_dep ],
link_with: lib,
install: false)
15 changes: 11 additions & 4 deletions docs/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
pkgs = [
'--pkg=gtk+-3.0',
'--pkg=granite',
'--pkg=clutter-1.0',
'--pkg=clutter-gtk-1.0'
]
if svgdep.found ()
pkgs += ['--pkg=gsvgtk-0.6']
endif

valadoc = find_program ('valadoc', required: false)
if valadoc.found()
outdir = CAMEL_CASE_NAME+'-'+API_VERSION
Expand All @@ -17,10 +27,7 @@ if valadoc.found()
'--force',
pkgname,
pkgversion,
'--pkg=gtk+-3.0',
'--pkg=granite',
'--pkg=clutter-1.0',
'--pkg=clutter-gtk-1.0',
pkgs,
'--directory=@OUTDIR@',
valasources],
install : true,
Expand Down
6 changes: 4 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
project('gtkcanvas', [ 'vala', 'c'], version : '0.1.0')

PROJECT_NAME = meson.project_name()
PROJECT_NAME = 'gcav'
API_VERSION = '0.4'
PROJECT_VERSION = meson.project_version()
VERSIONED_PROJECT_NAME = PROJECT_NAME+'-'+API_VERSION
CAMEL_CASE_NAME = 'GtkCanvas'
CAMEL_CASE_NAME = 'Gcav'
VERSIONED_CAMEL_CASE_NAME = CAMEL_CASE_NAME +'-'+ API_VERSION

cc = meson.get_compiler('c')
Expand All @@ -17,6 +17,8 @@ deps = ([dependency('gtk+-3.0', version:'>=3.18'),
m_dep
])

svgdep = dependency('gsvgtk-0.6', version:'>=0.5.0', required: false)


inc_rooth = include_directories ('.')
inc_rooth_dep = declare_dependency (include_directories : inc_rooth)
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ It is meant to contain the basic elements such as a basic container class, move,
- clutter-gtk-1.0
- granite

#### For SVG support

- gsvgtk-0.6
- librsvg-2.0
- gsvg-0.4
- gxml-0.16

### To compile & run the demo

#### Meson Build
Expand Down
12 changes: 6 additions & 6 deletions src/Utils/HoverAction.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Authored by: Alessandro Castellani <[email protected]>
*/

internal class GtkCanvas.HoverAction : Object {
internal class Gcav.HoverAction : Object {
/**
* Toggle the visibility of the HoverEffect()
*/
Expand All @@ -42,9 +42,9 @@ internal class GtkCanvas.HoverAction : Object {
bool visible = false;

/**
* Parent CanvasItem passed on mouse enter
* Parent Item passed on mouse enter
*/
private unowned CanvasItem item;
private unowned Item item;

/**
* HoverEffect (int border_width )
Expand All @@ -53,9 +53,9 @@ internal class GtkCanvas.HoverAction : Object {

/**
* Initialize Class
* @param CanvasItem item [hovered item from canvas]
* @param Item item [hovered item from canvas]
*/
public HoverAction (CanvasItem item) {
public HoverAction (Item item) {
this.item = item;
}

Expand All @@ -67,4 +67,4 @@ internal class GtkCanvas.HoverAction : Object {
public void toggle (bool toggle) {
toggled = toggle;
}
}
}
2 changes: 1 addition & 1 deletion src/Utils/HoverEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Authored by: Felipe Escoto <[email protected]>
*/

internal class HoverEffect : Clutter.Effect {
internal class Gcav.HoverEffect : Clutter.Effect {
public int border_size { get; construct; }
public float scale_factor { get; set; default = 1; }

Expand Down
8 changes: 4 additions & 4 deletions src/Utils/MoveAction.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
*/

/**
* Manages and controls a CanvasItem's movement.
* Manages and controls a Item's movement.
*/
internal class GtkCanvas.MoveAction : Clutter.DragAction {
internal class Gcav.MoveAction : Clutter.DragAction {
private int x_offset_press = 0;
private int y_offset_press = 0;

private unowned CanvasItem item;
private unowned Item item;

public MoveAction (CanvasItem item) {
public MoveAction (Item item) {
this.item = item;

drag_begin.connect (on_move_begin);
Expand Down
39 changes: 22 additions & 17 deletions src/Widgets/Canvas.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@
*/

/**
* This is a widget that holds and renders {@link GtkCanvas.CanvasItem} and their subclasses
* This is a widget that holds and renders {@link Gcav.Item} and their subclasses
*
* This class should take care of zoom-in/out, and maintaing the aspect ratio of this and it's CanvasItems when the canvas is resized.
* This class should take care of zoom-in/out, and maintaing the aspect ratio of this and it's Items when the canvas is resized.
*/
public class GtkCanvas.Canvas : Gtk.AspectFrame {
public class Gcav.Canvas : Gtk.AspectFrame {
/**
* Signal triggered when a {@link GtkCanvas.CanvasItem} on this canvas is selected by the user.
* Signal triggered when a {@link Gcav.Item} on this canvas is selected by the user.
*
* @param item The canvas item which triggered the event.
* @param modifiers A mask that contains all the modifiers for the event such as if Shift/Ctrl were pressed, or which button on the mouse was clicked.
*/
public signal void item_selected (CanvasItem item, Clutter.ModifierType modifiers);
public signal void item_selected (Item item, Clutter.ModifierType modifiers);

/**
* Signal triggered when the canvas is clicked, but not any of the items in this
*/
public signal void clicked (Clutter.ModifierType modifiers);

private List<CanvasItem> items;
private List<Item> items;

private int current_allocated_width;
private float current_ratio = 1.0f;

private GtkClutter.Embed stage;

/**
* The resizer the {@link GtkCanvas.CanvasItem}s in this canvas will use.
* The resizer the {@link Gcav.Item}s in this canvas will use.
*
* Can be overwritten to make the items use a different style of resizer.
*/
Expand Down Expand Up @@ -107,7 +107,7 @@ public class GtkCanvas.Canvas : Gtk.AspectFrame {
private int _height = 100;

/**
* Creates a new {@link GtkCanvas.Canvas}.
* Creates a new {@link Gcav.Canvas}.
*
* @param width the width in px the canvas will represent
* @param height the height in px the canvas will represent
Expand All @@ -124,7 +124,7 @@ public class GtkCanvas.Canvas : Gtk.AspectFrame {

var actor = stage.get_stage ();

items = new List<CanvasItem>();
items = new List<Item>();
resizer = new ItemResizer (actor);

var drag_action = new Clutter.DragAction ();
Expand Down Expand Up @@ -156,8 +156,8 @@ public class GtkCanvas.Canvas : Gtk.AspectFrame {
* @param color the color the test-shape will be, in CSS format
* @param rotation the amount of degrees the item will be rotated
*/
public CanvasItem add_shape (string type, string color, double rotation) {
CanvasItem item;
public Item add_shape (string type, string color, double rotation) {
Item item;

switch (type) {
case "rectangle":
Expand All @@ -166,6 +166,11 @@ public class GtkCanvas.Canvas : Gtk.AspectFrame {
case "circle":
item = new ShapeCircle (color, rotation);
break;
#if GSVGTK
case "svg":
item = new GSvgtkShapeImage ();
break;
#endif
default:
item = new ShapeRectangle (color, rotation);
break;
Expand All @@ -176,11 +181,11 @@ public class GtkCanvas.Canvas : Gtk.AspectFrame {
}

/**
* Adds a {@link CanvasItem} to this
* Adds a {@link Item} to this
*
* @param item the canvas item to be added
*/
public void add_item (CanvasItem item) {
public void add_item (Item item) {
items.prepend (item);
stage.get_stage ().add_child (item);
item.apply_ratio (current_ratio);
Expand All @@ -192,19 +197,19 @@ public class GtkCanvas.Canvas : Gtk.AspectFrame {
}

/**
* Removes a {@link CanvasItem} from this
* Removes a {@link Item} from this
*
* @param item the canvas item to be removed
*/
public void remove_item (CanvasItem item) {
public void remove_item (Item item) {
items.remove (item);
stage.get_stage ().remove_child (item);
}

/**
* Returns a read-only list of all the {@link GtkCanvas.CanvasItem}s on this canvas
* Returns a read-only list of all the {@link Gcav.Item}s on this canvas
*/
public List<weak CanvasItem> get_items () {
public List<weak Item> get_items () {
return items.copy ();
}

Expand Down
20 changes: 2 additions & 18 deletions src/Widgets/CanvasItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,7 @@
* This class should take care of the basics such as dragging, clicks and rotation,
* and leave more specific implementations to child classes.
*/
public class GtkCanvas.CanvasItem : Clutter.Actor {
/**
* Signal triggered when this is selected by the user.
*
* @param modifiers this is a mask that contains all the modifiers for the event such as if Shift/Ctrl were pressed, or which button on the mouse was clicked
*/
public signal void selected (Clutter.ModifierType modifiers);

/**
* Signal triggered when the rectangle of this changes
*/
public signal void updated ();

/**
* Triggered after a move operation, when the mouse button is lifted
*/
public signal void on_move_end ();
public class Gcav.CanvasItem : Clutter.Actor, Gcav.Item {

private MoveAction move_action;
private HoverAction hover_action;
Expand Down Expand Up @@ -151,7 +135,7 @@ public class GtkCanvas.CanvasItem : Clutter.Actor {
/**
* Ratio relative to the container to properly scale all the elements
*/
internal float ratio = 1.0f;
public float ratio { get; set; default = 1.0f; }

public CanvasItem.with_values (float x, float y, float w, float h, string color) {
Object (background_color: Clutter.Color.from_string (color));
Expand Down
Loading

0 comments on commit 3da2ded

Please sign in to comment.