1 /* 2 * Copyright (C) 2007-2011 Jordi Mas i Hernàndez <jmas@softcatala.org> 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as 6 * published by the Free Software Foundation; either version 2 of the 7 * License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public 15 * License along with this program; if not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 using System; 19 using Gtk; 20 using Mono.Unix; 21 22 namespace gbrainy.Clients.Classical.Widgets 23 { 24 // Build and manages gbrainy's client Toolbar 25 public class Toolbar : Gtk.Toolbar 26 { 27 Gtk.Box main_hbox; 28 Gtk.Box framework_vbox; 29 30 public ToolButton AllButton {get; private set; } 31 public ToolButton CalculationButton {get; private set; } 32 public ToolButton FinishButton {get; private set; } 33 public ToolButton LogicButton {get; private set; } 34 public ToolButton MemoryButton {get; private set; } 35 public ToolButton PauseButton {get; private set; } 36 public ToolButton VerbalButton {get; private set; } 37 public bool InitCompleted {get; private set; } 38 Toolbar(Gtk.Box main_hbox, Gtk.Box framework_vbox)39 public Toolbar (Gtk.Box main_hbox, Gtk.Box framework_vbox) 40 { 41 this.main_hbox = main_hbox; 42 this.framework_vbox = framework_vbox; 43 ToolbarStyle = ToolbarStyle.Both; 44 BuildToolBar (); 45 } 46 Attach(Gtk.Orientation orientation_new)47 public void Attach (Gtk.Orientation orientation_new) 48 { 49 Gtk.Box.BoxChild child = null; 50 Box box; 51 52 switch (Orientation) { 53 case Gtk.Orientation.Vertical: 54 box = main_hbox; 55 break; 56 case Gtk.Orientation.Horizontal: 57 { 58 box = framework_vbox; 59 break; 60 } 61 default: 62 throw new InvalidOperationException (); 63 } 64 65 bool contained = false; 66 foreach (var ch in box.AllChildren) 67 { 68 if (ch == this) 69 { 70 contained = true; 71 break; 72 } 73 } 74 if (contained == true) 75 box.Remove (this); 76 77 Orientation = (Gtk.Orientation) orientation_new; 78 79 switch (Orientation) { 80 case Gtk.Orientation.Vertical: 81 main_hbox.Add (this); 82 main_hbox.ReorderChild (this, 0); 83 child = ((Gtk.Box.BoxChild)(main_hbox[this])); 84 break; 85 case Gtk.Orientation.Horizontal: 86 framework_vbox.Add (this); 87 framework_vbox.ReorderChild (this, 1); 88 child = ((Gtk.Box.BoxChild)(framework_vbox[this])); 89 break; 90 default: 91 throw new InvalidOperationException (); 92 } 93 94 child.Expand = false; 95 child.Fill = false; 96 ShowAll (); 97 InitCompleted = true; 98 } 99 BuildToolBar()100 void BuildToolBar () 101 { 102 IconFactory icon_factory = new IconFactory (); 103 AddIcon (icon_factory, "logic-games", "logic-games-32.png"); 104 AddIcon (icon_factory, "math-games", "math-games-32.png"); 105 AddIcon (icon_factory, "memory-games", "memory-games-32.png"); 106 AddIcon (icon_factory, "verbal-games", "verbal-games-32.png"); 107 AddIcon (icon_factory, "pause", "pause-32.png"); 108 AddIcon (icon_factory, "resume", "resume-32.png"); 109 AddIcon (icon_factory, "endgame", "endgame-32.png"); 110 AddIcon (icon_factory, "allgames", "allgames-32.png"); 111 icon_factory.AddDefault (); 112 113 IconSize = Gtk.IconSize.Dnd; 114 115 AllButton = new ToolButton ("allgames"); 116 AllButton.TooltipText = Catalog.GetString ("Play all the games"); 117 AllButton.Label = Catalog.GetString ("All"); 118 Insert (AllButton, -1); 119 120 LogicButton = new ToolButton ("logic-games"); 121 LogicButton.TooltipText = Catalog.GetString ("Play games that challenge your reasoning and thinking"); 122 LogicButton.Label = Catalog.GetString ("Logic"); 123 Insert (LogicButton, -1); 124 125 CalculationButton = new ToolButton ("math-games"); 126 CalculationButton.Label = Catalog.GetString ("Calculation"); 127 CalculationButton.TooltipText = Catalog.GetString ("Play games that challenge your mental calculation skills"); 128 Insert (CalculationButton, -1); 129 130 MemoryButton = new ToolButton ("memory-games"); 131 MemoryButton.Label = Catalog.GetString ("Memory"); 132 MemoryButton.TooltipText = Catalog.GetString ("Play games that challenge your short term memory"); 133 Insert (MemoryButton, -1); 134 135 VerbalButton = new ToolButton ("verbal-games"); 136 VerbalButton.Label = Catalog.GetString ("Verbal"); 137 VerbalButton.TooltipText = Catalog.GetString ("Play games that challenge your verbal aptitude"); 138 Insert (VerbalButton, -1); 139 140 PauseButton = new ToolButton ("pause"); 141 PauseButton.Label = Catalog.GetString ("Pause"); 142 PauseButton.TooltipText = Catalog.GetString ("Pause or resume the game"); 143 Insert (PauseButton, -1); 144 145 FinishButton = new ToolButton ("endgame"); 146 FinishButton.TooltipText = Catalog.GetString ("End the game and show score"); 147 FinishButton.Label = Catalog.GetString ("End"); 148 Insert (FinishButton, -1); 149 } 150 AddIcon(IconFactory stock, string stockid, string resource)151 static void AddIcon (IconFactory stock, string stockid, string resource) 152 { 153 Gtk.IconSet iconset = stock.Lookup (stockid); 154 155 if (iconset != null) 156 return; 157 158 iconset = new Gtk.IconSet (); 159 Gdk.Pixbuf img = Gdk.Pixbuf.LoadFromResource (resource); 160 IconSource source = new IconSource (); 161 source.Pixbuf = img; 162 iconset.AddSource (source); 163 stock.Add (stockid, iconset); 164 } 165 } 166 } 167