The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Widget.vala in /libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
1 /* 2 Copyright (C) 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Cairo; 16 using Math; 17 18 namespace BirdFont { 19 20 public abstract class Widget : GLib.Object { 21 22 public double margin_bottom = 0; 23 public double widget_x = 0; 24 public double widget_y = 0; 25 26 public abstract double get_height (); 27 public abstract double get_width (); 28 public abstract void draw (Context cr); 29 30 public WidgetAllocation allocation = new WidgetAllocation (); 31 32 public static void draw_rounded_rectangle (Context cr, double x, double y, double w, double h, double radius) { 33 // fixme radius is padding not margin 34 cr.move_to (x, y + radius); 35 cr.arc (x + radius, y + radius, radius, 2 * (PI / 2), 3 * (PI / 2)); 36 cr.line_to (x + w - radius, y); 37 cr.arc (x + w - radius, y + radius, radius, 3 * (PI / 2), 4 * (PI / 2)); 38 cr.line_to (x + w, y + h); 39 cr.arc (x + w - radius, y + h, radius, 4 * (PI / 2), 5 * (PI / 2)); 40 cr.line_to (x + radius, y + h + radius); 41 cr.arc (x + radius, y + h, radius, 5 * (PI / 2), 6 * (PI / 2)); 42 cr.line_to (x, y + radius); 43 cr.close_path (); 44 } 45 46 public virtual void layout () { 47 } 48 49 public bool is_over (double x, double y) { 50 return widget_x <= x <= widget_x + get_width () 51 && widget_y <= y <= widget_y + get_height (); 52 } 53 54 public bool is_on_screen () { 55 return (widget_y <= 0 <= widget_y + get_height ()) 56 || (widget_y <= allocation.height <= widget_y + get_height ()) 57 || (0 <= widget_y <= allocation.height); 58 } 59 60 public virtual void key_press (uint keyval) { 61 } 62 63 public virtual void focus (bool enter) { 64 } 65 66 public virtual void button_press (uint button, double x, double y) { 67 } 68 69 public virtual void button_release (uint button, double x, double y) { 70 } 71 72 public virtual bool motion (double x, double y) { 73 return false; 74 } 75 } 76 77 } 78