Commit 9ca9425
Move birdui to its own repository
Changed files (10)
deletedbirdui/BoxLayout.valadeletedbirdui/Component.valadeletedbirdui/GtkWidget.valadeletedbirdui/GtkWindow.valadeletedbirdui/HBox.valadeletedbirdui/Overflow.valadeletedbirdui/Style.valadeletedbirdui/SvgComponent.valadeletedbirdui/VBox.valamodifieddodo.py
Diff
deleted file mode 100644@@ -1,215 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using Gee;-using SvgBird;-using B;-using Cairo;--namespace Bird {--public enum BoxOrientation {- HORIZONTAL,- VERTICAL-}--class BoxLayout : Component {-- public BoxOrientation orientation { get; private set; }- - public BoxLayout (XmlElement layout_tag, BoxOrientation orientation, Defs defs) {- base (layout_tag, defs);- this.orientation = orientation;- }-- public override void draw (Context cairo) {- cairo.save ();- cairo.translate (x, y);- clip (cairo);- - foreach (Component component in components) {- component.draw (cairo);- }-- cairo.restore ();- }- - bool is_width_remainder (Component component) {- return component.style.property_equals ("width", "remainder");- }-- bool is_height_remainder (Component component) {- return component.style.property_equals ("height", "remainder");- }-- /** The smallest size this layout can be. */- public override void get_min_size (out double min_width, out double min_height) {- min_width = 0;- min_height = 0;- - if (orientation == BoxOrientation.HORIZONTAL) {- foreach (Component component in components) {- double w, h;- - component.get_min_size (out w, out h);- min_width += w;- - if (h > min_height) {- min_height = h;- }- } - } else {- foreach (Component component in components) {- double w, h;- - component.get_min_size (out w, out h); - min_height += h;- - if (w > min_width) {- min_width = w;- }- }- }- - min_width += get_padding_left ();- min_width += get_padding_right ();- min_height += get_padding_top ();- min_height += get_padding_bottom ();- - limit_size (ref min_width, ref min_height);- }-- public override void layout (double parent_width, double parent_height) {- double w, h;- - get_min_size (out w, out h);- int remainders = count_remainders ();- - if (!is_width_remainder (this)) {- width = w;- }- - if (!is_height_remainder (this)) {- height = h;- }- - if (remainders > 0) {- double remainder_size;- - if (orientation == BoxOrientation.HORIZONTAL) {- remainder_size = (parent_width - w) / remainders;- layout_variable_size (remainder_size, parent_height);- } else {- remainder_size = (parent_height - h) / remainders;- layout_variable_size (remainder_size, parent_width);- }- }- - if (orientation == BoxOrientation.HORIZONTAL) {- foreach (Component component in components) {- component.layout (parent_width, h);- }- } else {- foreach (Component component in components) {- component.layout (w, parent_height);- }- }- - layout_positions ();- }- - int count_remainders () {- int remainders = 0;- - if (orientation == BoxOrientation.HORIZONTAL) {- foreach (Component component in components) {- if (is_width_remainder (component)) {- remainders++;- }- }- } else {- foreach (Component component in components) {- if (is_height_remainder (component)) {- remainders++;- }- }- }- - return remainders;- }- - void layout_variable_size (double remainder_size, double fixed_size) {- double w, h;- - w = 0;- h = 0;- foreach (Component component in components) {- bool width_remainder = is_width_remainder (component);- bool height_remainder = is_height_remainder (component);- - if (width_remainder && orientation == BoxOrientation.HORIZONTAL) {- w = remainder_size;- w -= component.get_padding_left ();- w -= component.get_padding_right ();- h = fixed_size;- }- - if (height_remainder && orientation == BoxOrientation.VERTICAL) {- w = fixed_size;- h = remainder_size;- h -= component.get_padding_top ();- h -= component.get_padding_bottom ();- }- - if (width_remainder || height_remainder) {- double min_width, min_height;- component.get_min_size (out min_width, out min_height);- - if (w < min_width) {- w = min_width;- }- - if (h < min_height) {- h = min_height;- }- - component.limit_size (ref w, ref h);- component.width = w;- component.height = h;- }- }- }-- void layout_positions () {- double child_x = 0;- double child_y = 0;-- foreach (Component component in components) {- component.x = child_x + component.get_padding_left ();- component.y = child_y + component.get_padding_top ();-- if (orientation == BoxOrientation.HORIZONTAL) {- child_x = component.x + component.padded_width + get_padding_right ();- } else {- child_y = component.y + component.padded_height + get_padding_bottom ();- }- }- }-- public override string to_string () {- return "BoxLayout";- }-}--}deleted file mode 100644@@ -1,414 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using B;-using SvgBird;-using Gee;-using Cairo;--namespace Bird {--public abstract class Component : GLib.Object {- public double width { get; protected set; }- public double height { get; protected set; }- - public double padded_width {- get {- return width + get_padding_left () + get_padding_right ();- }- }- - public double padded_height { - get {- return height + get_padding_top () + get_padding_bottom ();- }- }-- public double padded_x {- get {- return x + get_padding_left ();- }- }- - public double padded_y { - get {- return y + get_padding_top ();- }- }- - /** Vertical placement for this component relative to the parent container. */- public double x { get; protected set; }- - /** Horizontal placement for this component relative to the parent container. */- public double y { get; protected set; }-- /** The parts this component is made of. */- protected ArrayList<Component> components = new ArrayList<Component> ();-- XmlElement component_tag;- - /** Style sheet and other SVG definitions. */- Defs defs = new Defs ();- protected SvgStyle style = new SvgStyle ();-- public string? css_class = null;- public string? id = null;-- Overflow overflow = Overflow.VISIBLE;-- public Component.empty (double width, double height) {- this.width = width;- this.height = height;- }-- public Component.load (string file_name, double width, double height) {- this.width = width;- this.height = height;- load_file (file_name, null);- layout (width, height);- }-- /** Parse component ui file but don't do layout. */- internal Component.load_component (string file_name, Component parent) {- load_file (file_name, parent);- }- - public Component (XmlElement component_tag, Defs defs) {- this.defs = defs;- this.component_tag = component_tag;- set_identification ();- parse (component_tag);- }-- public Component.embedded (XmlElement component_tag, Defs defs) {- this.defs = defs;- this.component_tag = component_tag;- set_identification ();- }-- void set_identification () {- foreach (Attribute attribute in component_tag.get_attributes ()) {- string attribute_name = attribute.get_name ();- - if (attribute_name == "id") {- id = attribute.get_content ();- } else if (attribute_name == "class") {- css_class = attribute.get_content ();- }- }- }-- private void inherit_styles_sheet (Defs defs) {- this.defs = defs;- }-- protected void parse_style (XmlElement style_tag) {- defs = defs.shallow_copy ();- StyleSheet style_sheet = StyleSheet.parse (defs, style_tag);- defs.style_sheet.merge (style_sheet);- }- - protected void parse_svg (XmlElement svg_tag) {- foreach (Attribute attribute in svg_tag.get_attributes ()) {- string attribute_name = attribute.get_name ();- - if (attribute_name == "file") {- string file_name = attribute.get_content ();- SvgComponent svg = new SvgComponent (svg_tag, defs, file_name);- add_component (svg); - }- }- }-- protected void add_component (Component component) {- components.add (component);- component.set_style_properties (this);- }-- protected void set_style_properties (Component parent) {- inherit_styles_sheet (parent.defs);- style = SvgStyle.parse (parent.defs, parent.style, component_tag); - set_overflow_property_from_css ();- set_identification ();- }- - protected void set_overflow_property_from_css () {- string? css_overflow = style.get_css_property ("overflow");- - if (css_overflow != null) {- string overflow_property = (!) css_overflow;- - if (overflow_property == "hidden") {- overflow = Overflow.HIDDEN;- } else if (overflow_property == "visible") {- overflow = Overflow.VISIBLE;- }- }- }-- protected void parse_layout (XmlElement layout_tag) {- string type = "";- - foreach (Attribute attribute in layout_tag.get_attributes ()) {- string attribute_name = attribute.get_name ();- - if (attribute_name == "type") {- type = attribute.get_content (); - }- }- - if (type == "hbox") {- HBox hbox = new HBox (layout_tag, defs);- add_component (hbox);- } else if (type == "vbox") {- VBox vbox = new VBox (layout_tag, defs);- add_component (vbox);- } else {- warning (type + " layout of type is supported in this verison.");- }- }- - protected void parse_component (XmlElement component_tag) {- foreach (Attribute attribute in component_tag.get_attributes ()) {- string attribute_name = attribute.get_name ();- - if (attribute_name == "file") {- string file_name = attribute.get_content ();- UI ui = new UI.load_component (file_name, this);- - foreach (Component component in ui.components) {- add_component (component);- - SvgStyle copied_style;- copied_style = SvgStyle.parse (defs, style, component_tag); - copied_style.apply (component.style);- component.style = copied_style;- }- }- }- }- - protected void parse (XmlElement component_tag) {- foreach (XmlElement tag in component_tag) {- string tag_name = tag.get_name ();- - if (tag_name == "ui") {- parse (tag);- } else if (tag_name == "layout") {- parse_layout (tag);- } else if (tag_name == "component") {- parse_component (tag);- } else if (tag_name == "svg") {- parse_svg (tag);- } else if (tag_name == "style") {- parse_style (tag);- } else {- unused_tag (tag_name);- }- }- }-- internal void unused_attribute (string attribute) {- warning ("The attribute " + attribute + " is not known in this version.");- }- - internal void unused_tag (string tag_name) {- warning ("The tag " + tag_name + " is not known in this version.");- }-- public void load_file (string file_name, Component? parent) {- if (file_name.has_suffix (".ui")) {- load_layout (file_name, parent);- } else if (file_name.has_suffix (".svg")) {- SvgComponent svg = new SvgComponent.for_file (file_name);- add_component (svg); - } else {- warning (file_name + " is not a ui file or svg file.");- }- }-- public void load_layout (string file_name, Component? parent) {- string? path = find_file (file_name);- - if (path == null) {- warning (file_name + " not found.");- return;- }- - string xml_data;- File layout_file = File.new_for_path ((!) path); - - try {- FileUtils.get_contents((!) layout_file.get_path (), out xml_data);- } catch (GLib.Error error) {- warning (error.message);- return;- }-- XmlTree xml_parser = new XmlTree (xml_data); - XmlElement tag = xml_parser.get_root ();- - if (parent == null) {- component_tag = tag;- defs = new Defs ();- } else {- Component p = (!) parent;- component_tag = p.component_tag;- defs = p.defs;- }- - parse (tag);- }- - public static string find_file (string file_name) {- File file = File.new_for_path ("birdui/" + file_name);- - if (file.query_exists ()) {- return (!) file.get_path ();- }- - return file_name;- }- - public virtual void get_min_size (out double min_width, out double min_height) {- min_width = width;- min_height = height;- - if (unlikely (components.size > 1)) {- warning ("A component has several parts but no layout has been set.");- }- - foreach (Component component in components) {- component.get_min_size (out min_width, out min_height);- }-- min_width += get_padding_left ();- min_width += get_padding_right ();- min_height += get_padding_top ();- min_height += get_padding_bottom ();- }- - public virtual void layout (double parent_width, double parent_height) {- warning ("A component without a layout was added to the view.");-- double w, h;- get_min_size (out w, out h);-- width = w;- height = h;- - foreach (Component component in components) {- component.layout (parent_width, parent_height);- }- }- - public void clip (Context cairo) {- if (overflow == Overflow.HIDDEN) {- cairo.rectangle (0, 0, width, height);- cairo.clip ();- }- }- - public abstract void draw (Context cairo);- - public virtual void motion_notify_event (double x, double y) { - }- - public virtual void button_press_event (uint button, double x, double y) { - }- - public virtual string to_string () {- return @"$(component_tag.get_name ())";- }- - public void print_tree () {- print_tree_level (0);- }-- protected void print_tree_level (int indent) {- for (int i = 0; i < indent; i++) {- print ("\t");- }- - print (@"$(to_string ()) width: $padded_width, height: $padded_height x $x y $y $(style)\n");- - foreach (Component component in components) {- component.print_tree_level (indent + 1);- }- }- - protected double get_padding_bottom () {- return SvgFile.parse_number (style.get_css_property ("padding-bottom"));- }-- protected double get_padding_top () {- return SvgFile.parse_number (style.get_css_property ("padding-top"));- }-- protected double get_padding_left () {- return SvgFile.parse_number (style.get_css_property ("padding-left"));- }-- protected double get_padding_right () {- return SvgFile.parse_number (style.get_css_property ("padding-right"));- }-- protected void limit_size (ref double width, ref double height) {- string? min_width = style.get_css_property ("min-width");- if (min_width != null) {- double w = SvgFile.parse_number (min_width);- if (width < w) {- width = w;- }- }-- string? min_height = style.get_css_property ("min-height");- if (min_height != null) {- double h = SvgFile.parse_number (min_height);- - if (height < h) {- height = h;- }- }- - string? max_width = style.get_css_property ("max-width");- if (max_width != null) {- double w = SvgFile.parse_number (max_width);- - if (width > w) {- width = w;- }- }-- string? max_height = style.get_css_property ("max-height");- if (max_height != null) {- double h = SvgFile.parse_number (max_height);- - if (height > h) {- height = h;- }- }- - if (width < 0) {- width = 0;- }-- if (height < 0) {- height = 0;- }- }-}--}-deleted file mode 100644@@ -1,59 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using Gtk;-using Gdk;-using Cairo;-using Math;--namespace Bird {--public class Widget : DrawingArea {- - UI component;- - public Widget (UI main_component) { - component = main_component;-- add_events (EventMask.BUTTON_PRESS_MASK - | EventMask.POINTER_MOTION_MASK- | EventMask.LEAVE_NOTIFY_MASK);- - motion_notify_event.connect ((event)=> {- component.motion_notify_event (event.x, event.y);- return true;- }); - - button_press_event.connect ((event)=> {- component.button_press_event (event.button, event.x, event.y);- return true;- });-- draw.connect ((event) => {- Context cairo_context = cairo_create (get_window ());- component.draw (cairo_context);- return true;- });- - int width = (int) rint (component.padded_width);- int height = (int) rint (component.padded_height);- set_size_request (width, height);-- size_allocate.connect((allocation) => {- component.resize (allocation.width, allocation.height);- });- }-}--}deleted file mode 100644@@ -1,39 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using Bird;-using Gtk;--int main (string[] args) {- Gtk.init (ref args);- - Window window = new Window ();- window.set_title ("UI Bird");- window.destroy.connect (Gtk.main_quit);- - UI layout = new UI.for_file ("test.ui", 700, 200);- - layout.print_tree ();- - Bird.Widget primary_layout = new Bird.Widget (layout);-- Box vbox = new Box (Orientation.VERTICAL, 0);- vbox.pack_start(primary_layout, true, true, 0);- window.add (vbox);- - window.show_all ();- - Gtk.main ();- return 0;-}deleted file mode 100644@@ -1,31 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using Gee;-using B;-using SvgBird;--namespace Bird {--class HBox : BoxLayout {- public HBox (XmlElement layout, Defs defs) {- base (layout, BoxOrientation.HORIZONTAL, defs);- }- - public override string to_string () {- return "HBox";- }-}--}deleted file mode 100644@@ -1,22 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--namespace Bird {--public enum Overflow {- HIDDEN,- VISIBLE-}--}deleted file mode 100644@@ -1,34 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using B;-using SvgBird;-using Gee;-using Cairo;--namespace Bird {--public class Style : GLib.Object {- public SvgStyle svg_style;- - public Style () {- svg_style = new SvgStyle ();- }- - public Style.for_svg (SvgStyle svg_style) {- this.svg_style = svg_style;- }-}--}deleted file mode 100644@@ -1,102 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using B;-using SvgBird;-using Gee;-using Cairo;--namespace Bird {--class SvgComponent : Component {- string? path = null;- string file_name = "";- SvgDrawing? drawing = null;- - public SvgComponent (XmlElement svg_component_tag, Defs defs, string svg_file) {- base.embedded (svg_component_tag, defs);- load_svg (svg_file);- }-- public SvgComponent.for_file (string svg_file) {- base.embedded (new XmlElement.empty (), new Defs ());- load_svg (svg_file);- }-- public override void get_min_size (out double min_width, out double min_height) {- min_width = 0;- min_height = 0;- - if (drawing != null) {- SvgDrawing svg = (!) drawing;- min_width = svg.width + get_padding_left () + get_padding_right ();- min_height = svg.height + get_padding_bottom () + get_padding_top ();- }- }- - public override void layout (double parent_width, double parent_height) {- if (unlikely (components.size > 0)) {- warning ("SVG files can not have subviews.");- }- - if (drawing != null) {- SvgDrawing svg = (!) drawing;- width = svg.width;- height = svg.height;- }- }- - public override string to_string () {- return "Svg: " + file_name;- }-- private void load_svg (string file_name) {- this.file_name = file_name;- path = find_file (file_name);- - if (path == null) {- warning (file_name + " not found.");- return;- }- - string xml_data;- File svg_file = File.new_for_path ((!) path); - try {- FileUtils.get_contents((!) svg_file.get_path (), out xml_data);- } catch (GLib.Error error) {- warning (error.message);- return;- }- - SvgFile svg_parser = new SvgFile ();- drawing = svg_parser.parse_svg_data (xml_data);- }-- public override void draw (Context cairo) {- cairo.save ();- cairo.translate (padded_x, padded_y);- clip (cairo);- - if (drawing != null) {- SvgDrawing svg = (!) drawing;- svg.draw (cairo);- }- - cairo.restore ();- }--}--}-deleted file mode 100644@@ -1,32 +0,0 @@-/*- Copyright (C) 2016 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library 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 - Lesser General Public License for more details.-*/--using Gee;-using B;-using SvgBird;--namespace Bird {- -class VBox : BoxLayout {- public VBox (XmlElement layout, Defs defs) {- base (layout, BoxOrientation.VERTICAL, defs);- }- - public override string to_string () {- return "VBox";- }--}--}@@ -559,55 +559,3 @@ def make_birdfont_test(target_binary, deps): def task_birdfont_test(): yield make_birdfont_test('birdfont-test', ['libbirdgems.so', 'libbirdfont.so']) -def make_birdui(target_binary, deps):- valac_command = config.VALAC + """\- -C \- --pkg posix \- --pkg """ + config.GEE + """ \- --pkg gtk+-3.0 \- --pkg libsvgbird \- --pkg xmlbird \- --vapidir=./ \- --basedir=build/birdui/ \- """ + config.NON_NULL + """ \- --enable-experimental \- birdui/*.vala \- """-- cc_command = config.CC + """ \- -fPIC \- $(pkg-config --cflags gtk+-3.0) \- $(pkg-config --cflags glib-2.0) \- $(pkg-config --cflags xmlbird) \- $(pkg-config --cflags """ + config.GEE + """) \- -g \- -I ./build/libsvgbird \- -c C_SOURCE \- -o OBJECT_FILE \- """-- linker_command = config.CC + """ \- """ + soname(target_binary) + """ \- -fPIC \- -g \- build/birdui/*.o \- $(pkg-config --libs gtk+-3.0) \- $(pkg-config --libs glib-2.0) \- $(pkg-config --libs gobject-2.0) \- $(pkg-config --libs xmlbird) \- $(pkg-config --libs """ + config.GEE + """) \- -L./build -L./build/bin -l m -l svgbird \- -o build/bin/""" + target_binary-- libbirdgems = Builder('birdui',- valac_command, - cc_command,- linker_command,- target_binary,- None,- deps)- - yield libbirdgems.build()--def task_birdui():- yield make_birdui('birdui', [])