The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

MenuAction.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

Revisions

View the latest version of libbirdfont/MenuAction.vala.
Fix memory leak
1 /* 2 Copyright (C) 2012 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 17 namespace BirdFont { 18 19 public class MenuAction : GLib.Object { 20 public string label; 21 public DropMenu.Selected action; 22 public DropMenu? parent = null; 23 public int index = -1; 24 public bool has_delete_button = true; 25 public double width = 100; 26 public Text text; 27 28 bool selected = false; 29 30 public MenuAction (string label) { 31 this.label = label; 32 } 33 34 public void set_selected (bool s) { 35 selected = s; 36 } 37 38 public virtual void draw (double x, double y, Context cr) { 39 if (selected) { 40 cr.save (); 41 Theme.color (cr, "Highlighted 1"); 42 cr.rectangle (x - 2, y - 12, width, 15); 43 cr.fill_preserve (); 44 cr.stroke (); 45 cr.restore (); 46 } 47 48 if (has_delete_button) { 49 cr.save (); 50 Theme.color (cr, "Foreground 1"); 51 cr.move_to (x + width - 10, y - 2); 52 cr.line_to (x + width - 10 - 5, y - 2 - 5); 53 cr.move_to (x + width - 10 - 5, y - 2); 54 cr.line_to (x + width - 10, y - 2 - 5); 55 cr.set_line_width (1); 56 cr.stroke (); 57 cr.restore (); 58 } 59 60 text = new Text (label); 61 Theme.text_color (text, "Foreground 1"); 62 text.draw_at_baseline (cr, x, y); 63 } 64 } 65 66 } 67