View difference between Paste ID: UtMJ3Enx and r1rGSJAi
SHOW: | | - or go back to the newest paste.
1-
public class FancyWindow : Gtk.Window
1+
/*  Title: Elementary Sequal
2-
{
2+
 *  
3-
	Gtk.Box container;
3+
 *
4-
	Gtk.Toolbar toolbar;
4+
 *  Based Upon the code-example by Tom Beckmann:            https://plus.google.com/111734729718206650167/posts/jGGQrQrqxdg
5-
	Gtk.ToolItem label;
5+
 *  Toms' Code is Based upon the design by Harvey Cabaguio: https://plus.google.com/110079731285191638950/posts/F8LZJuHxojD
6
 *
7-
	const int HEIGHT = 48;
7+
 */
8-
	const int ICON_SIZE = Gtk.IconSize.LARGE_TOOLBAR;
8+
9-
	const string CSS = """
9+
10-
		.title {
10+
11-
			color: #666;
11+
using Gtk;
12-
			text-shadow: 0px 1px 0px white;
12+
using Granite;
13-
		}
13+
14-
		.toolbar {
14+
namespace eSQL {
15-
			padding: 0px;
15+
16-
			box-shadow: inset 0px 1px 0px rgba(255,255,255,0.3);
16+
    class MainWindow : Gtk.Window {
17-
		}
17+
18-
	""";
18+
        /* APPLICATION INFORMATION */
19-
	Gtk.CssProvider css;
19+
        const string program_name = "";
20
        const string exec_name = "";
21-
	Gtk.Label _title;
21+
22-
	public new string title {
22+
        const string app_years = "";
23-
		get {
23+
        const string app_version = "";
24-
			return _title.label;
24+
        const string application_id = "";
25-
		}
25+
        const string app_icon = "";
26-
		set {
26+
        const string app_launcher = ".desktop";
27-
			_title.label = value;
27+
        const string app_website = "";
28-
		}
28+
        const string app_website_lbl = "";
29-
	}
29+
        
30
        const string[] app_authors = {""};
31-
	public FancyWindow ()
31+
        const string[] app_documenters = {""};
32-
	{
32+
        const string[] app_translators = {"Chris Timberlake <game64@gmail.com>"};
33-
		css = new Gtk.CssProvider ();
33+
        const string[] app_artists = {""};
34-
		try {
34+
35-
			css.load_from_data (CSS, -1);
35+
        const string app_license_name = "Unknown License";
36-
		} catch (Error e) { warning (e.message); }
36+
        const Gtk.License app_license = License.Unknown;
37
        
38-
		toolbar = new Gtk.Toolbar ();
38+
        const string app_comments = "";
39-
		toolbar.icon_size = ICON_SIZE;
39+
40-
		toolbar.get_style_context ().add_class ("primary-toolbar");
40+
    
41-
		toolbar.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
41+
        //Define variables.
42-
		container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
42+
        Gtk.Box         			main_container;
43-
		container.margin = 1;
43+
        Gtk.Toolbar     			main_toolbar;   
44-
		container.pack_start (toolbar, false);
44+
        Gtk.ToolItem    			main_title;
45
46-
		var close = new Gtk.ToolButton (new Gtk.Image.from_file ("/usr/share/themes/elementary/metacity-1/close.svg"), "Close");
46+
47-
		close.height_request = HEIGHT;
47+
        const int icon_size    = Gtk.IconSize.LARGE_TOOLBAR; 
48-
		close.width_request = HEIGHT;
48+
        const int icon_height  = 48;
49-
		close.clicked.connect (() => destroy ());
49+
50
        const string main_toolbar_css      = """
51-
		var maximize = new Gtk.ToolButton (new Gtk.Image.from_file ("/usr/share/themes/elementary/metacity-1/maximize.svg"), "Close");
51+
                                    .title {
52-
		maximize.height_request = HEIGHT;
52+
                                            color: #666;
53-
		maximize.width_request = HEIGHT;
53+
                                            text-shadow: 0px 1px 0px white;
54-
		maximize.clicked.connect (() => this.maximize ());
54+
                                    }
55
                                    .toolbar {
56-
		_title = new Gtk.Label ("");
56+
                                            padding: 0px;
57-
		_title.override_font (Pango.FontDescription.from_string ("bold"));
57+
                                            box-shadow: inset 0px 1px 0px rgba(255,255,255,0.3);
58-
		label = new Gtk.ToolItem ();
58+
                                    }
59-
		label.add (_title);
59+
                                  """;
60-
		label.set_expand (true);
60+
        Gtk.CssProvider css; 
61-
		label.get_style_context ().add_class ("title");
61+
62-
		label.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
62+
        /* CUSTOM WIDGETS */
63
        
64-
		toolbar.insert (close, -1);
64+
        // It's just good coding practice in any language to define everything before it's used.
65-
		toolbar.insert (create_separator (), -1);
65+
        // Even if that specific language doesn't care.
66-
		toolbar.insert (label, -1);
66+
        public Gtk.ToolItem toolbar_seperator() {
67-
		toolbar.insert (create_separator (), -1);
67+
    
68-
		toolbar.insert (maximize, -1);
68+
            //Create the Seperator Referance
69
            var sep = new Gtk.ToolItem ();
70-
		draw.connect_after ((cr) => {
70+
            //Set Height/Width
71-
			Granite.Drawing.Utilities.cairo_rounded_rectangle (cr, 0, 0, get_allocated_width (), get_allocated_height (), 8);
71+
            sep.height_request = icon_height;
72-
			cr.set_source_rgba (0, 0, 0, 0.7);
72+
            sep.width_request = 1;
73-
			cr.set_line_width (1);
73+
            
74-
			cr.stroke ();
74+
            //Design the look!
75-
			return false;
75+
            sep.draw.connect ((cr) => {
76-
		});
76+
                   cr.move_to (0, 0);
77
                   cr.line_to (0, 60);
78-
		base.add (container);
78+
                   cr.set_line_width (1);
79-
	}
79+
                   var grad = new Cairo.Pattern.linear (0, 0, 0, icon_height);
80
                   grad.add_color_stop_rgba (0, 0.3, 0.3, 0.3, 0.4);
81-
	public override bool configure_event (Gdk.EventConfigure event)
81+
                   grad.add_color_stop_rgba (0.8, 0, 0, 0, 0);
82-
	{
82+
                   cr.set_source (grad);
83-
		if (get_window () != null)
83+
                   cr.stroke ();
84-
			get_window ().shape_combine_region (get_window_shape (event.width, event.height, 8), 0, 0);
84+
                   return true;
85
            });
86-
		return false;
86+
            //Add CSS Class Contexts
87-
	}
87+
            sep.get_style_context ().add_class ("sep");
88
            sep.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
89-
	public Gtk.ToolItem create_separator ()
89+
 
90-
	{
90+
            return sep;
91-
		var sep = new Gtk.ToolItem ();
91+
        }        
92-
		sep.height_request = HEIGHT;
92+
93-
		sep.width_request = 1;
93+
        //Main window's title
94-
		sep.draw.connect ((cr) => {
94+
        Gtk.Label mw_title;
95-
			cr.move_to (0, 0);
95+
        public new string title {
96-
			cr.line_to (0, 60);
96+
            get {
97-
			cr.set_line_width (1);
97+
                return mw_title.label;
98-
			var grad = new Cairo.Pattern.linear (0, 0, 0, HEIGHT);
98+
            }
99-
			grad.add_color_stop_rgba (0, 0.3, 0.3, 0.3, 0.4);
99+
            set {
100-
			grad.add_color_stop_rgba (0.8, 0, 0, 0, 0);
100+
                mw_title.label = value;
101-
			cr.set_source (grad);
101+
            }
102-
			cr.stroke ();
102+
        }
103-
			return true;
103+
104-
		});
104+
        public MainWindow(){
105-
		sep.get_style_context ().add_class ("sep");
105+
            
106-
		sep.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
106+
            /* CREATE THE BASE! */            
107
            
108-
		return sep;
108+
            //Build Main Toolbar
109-
	}
109+
            main_toolbar = new Gtk.Toolbar();
110
            //Setup the Toolbar's Look
111-
	public override void add (Gtk.Widget widget)
111+
            main_toolbar.icon_size = icon_size;
112-
	{
112+
            //The CSS
113-
		container.pack_start (widget);
113+
            main_toolbar.get_style_context().add_class ("primary-toolbar");
114-
	}
114+
            main_toolbar.get_style_context().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
115
116-
	public override void remove (Gtk.Widget widget)
116+
            //Build the Box Container!
117-
	{
117+
            main_container = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
118-
		container.remove (widget);
118+
            main_container.pack_start (main_toolbar, false);
119-
	}
119+
            //main_container.window-state-event.connect (() => { this.toggle_maximize();  });
120
121-
	public override void show ()
121+
            /* TOOLBAR ITEMS! */
122-
	{
122+
            // Close Button
123-
		base.show ();
123+
            var tb_close = new Gtk.ToolButton (new Gtk.Image.from_file("/usr/share/themes/elementary/metacity-1/close.svg"), "Close");
124-
		get_window ().set_decorations (Gdk.WMDecoration.BORDER);
124+
            // Clicked Action
125-
	}
125+
            tb_close.clicked.connect (() => destroy ());
126
            // Set the proper dimension so it doesn't look ugly!
127-
	public void append_toolitem (Gtk.ToolItem item, bool after_title = false)
127+
            tb_close.height_request = icon_height;
128-
	{
128+
            tb_close.width_request  = icon_height;
129-
		toolbar.insert (item, after_title ? toolbar.get_n_items () - 2 : toolbar.get_item_index (label));
129+
130-
	}
130+
            // Maximize Button
131
            var tb_maximize = new Gtk.ToolButton (new Gtk.Image.from_file("/usr/share/themes/elementary/metacity-1/maximize.svg"), "Close");
132-
	public static Cairo.Region get_window_shape (int width, int height, int radius) {
132+
            // Clicked Action => TOGGLE MAXIMIZE!
133-
		var rectangles = new Cairo.RectangleInt[0];
133+
            tb_maximize.clicked.connect (() => { this.toggle_maximize();  });
134
            // Set the proper dimension so it doesn't look ugly!
135-
		for (int vertical_pixel = 1; vertical_pixel <= radius; vertical_pixel++) {
135+
            tb_maximize.height_request = icon_height;
136-
			int horizontal_offset = (int) Math.round (Math.sqrt (radius*radius - vertical_pixel*vertical_pixel) ) - radius;
136+
            tb_maximize.width_request  = icon_height;
137-
			Cairo.RectangleInt rect = {horizontal_offset, vertical_pixel, width - horizontal_offset, 1};
137+
            
138-
			rectangles += rect;
138+
            // Prepare the Main Window Title.
139-
		}
139+
            mw_title = new Gtk.Label("Elementary Studio (Sequal)");
140
            // Make it look right.
141-
		var res = new Cairo.Region.rectangles (rectangles);
141+
            mw_title.override_font(Pango.FontDescription.from_string("bold"));
142-
		return res;
142+
            //  Create the ToolBar Item
143-
	}
143+
            main_title = new Gtk.ToolItem();
144
            // Add the Main Window Title.
145
            main_title.add(mw_title);
146-
int main (string [] args)
146+
            // Expand it!
147-
{
147+
            main_title.set_expand(true);
148-
	Gtk.init (ref args);
148+
149
            // Settings Menu!
150-
	var w = new FancyWindow ();
150+
            var settings_menu = new Gtk.Menu();
151-
	w.set_default_size (720, 600);
151+
            //Make a spot for an about dlg
152-
	w.destroy.connect (Gtk.main_quit);
152+
            Gtk.MenuItem item_about = new Gtk.MenuItem.with_label ("About");
153-
	var lbl = new Gtk.Label ("Hello");
153+
            Gtk.MenuItem item_tf = new Gtk.MenuItem.with_label ("tf");
154-
	lbl.margin = 100;
154+
            item_about.activate.connect (() => {
155
156-
	var measure = new Gtk.ToolItem ();
156+
                            Granite.Widgets.show_about_dialog (base, 
157-
	var m = new Gtk.ComboBoxText ();
157+
                                               "program_name", program_name,
158-
	m.append ("px", "px");
158+
                                            //   "version", build_version,
159-
	m.append ("cm", "cm");
159+
                                               "logo_icon_name", app_icon,
160-
	m.append ("in", "in");
160+
161-
	m.active = 0;
161+
                                               "comments", app_comments,
162-
	measure.add (m);
162+
                                               "copyright", "%s %s Developers".printf (app_years, program_name),
163
                                               "website", app_website,
164-
	w.add (lbl);
164+
                                               "website_label", "Website",
165-
	w.append_toolitem (new Gtk.ToolButton.from_stock (Gtk.Stock.NEW));
165+
166-
	w.append_toolitem (new Gtk.ToolButton.from_stock (Gtk.Stock.OPEN));
166+
                                               "authors", app_authors,
167-
	w.append_toolitem (new Gtk.ToolButton.from_stock (Gtk.Stock.SAVE));
167+
                                               "documenters", app_documenters,
168-
	w.append_toolitem (new Gtk.ToolButton.from_stock (Gtk.Stock.PRINT));
168+
                                               "artists", app_artists,
169-
	w.append_toolitem (w.create_separator ());
169+
                                               "translator_credits", app_translators,
170-
	w.append_toolitem (new Gtk.ToolButton (new Gtk.Image.from_icon_name ("document-import", Gtk.IconSize.LARGE_TOOLBAR), ""));
170+
                                               "license", app_license_name,
171-
	w.append_toolitem (new Gtk.ToolButton (new Gtk.Image.from_icon_name ("document-export", Gtk.IconSize.LARGE_TOOLBAR), ""));
171+
                                               "license_type", app_license,
172-
	w.append_toolitem (measure, true);
172+
173-
	w.append_toolitem (w.create_separator (), true);
173+
                                               "help", app_website,
174-
	w.append_toolitem (new Gtk.ToolButton.from_stock (Gtk.Stock.PRINT), true);
174+
                                               "translate", app_website,
175-
	w.append_toolitem (new Gtk.ToolButton.from_stock (Gtk.Stock.SAVE_AS), true);
175+
                                               "bug", app_website);
176-
	w.append_toolitem (w.create_separator (), true);
176+
            });
177-
	w.append_toolitem (new Granite.Widgets.ToolButtonWithMenu (new Gtk.Image.from_icon_name ("application-menu", Gtk.IconSize.LARGE_TOOLBAR), "", new Gtk.Menu ()), true);
177+
178-
	w.show_all ();
178+
179
            // Compile the menu!
180
            settings_menu.add(item_about);
181-
	Gtk.main ();
181+
            settings_menu.add(item_tf);
182
183-
	return 0;
183+
            // Settings Button!
184
            //new Granite.Widgets.ToolButtonWithMenu (new Gtk.Image.from_icon_name ("application-menu", Gtk.IconSize.LARGE_TOOLBAR), "", new Gtk.Menu ()), true
185
            var tb_menu = new Granite.Widgets.ToolButtonWithMenu(new Gtk.Image.from_icon_name ("application-menu", Gtk.IconSize.LARGE_TOOLBAR), "", settings_menu);
186
187
            // Insert the toolbar items in order!
188
            main_toolbar.insert (tb_close, -1);
189
            main_toolbar.insert (toolbar_seperator (), -1);
190
            main_toolbar.insert (main_title, -1);
191
            main_toolbar.insert (toolbar_seperator (), -1);
192
            main_toolbar.insert (tb_menu, -1);
193
            main_toolbar.insert (toolbar_seperator (), -1);
194
            main_toolbar.insert (tb_maximize, -1);
195
            
196
            
197
            /*CONTENT */
198
199
	    //main_container.pack_start(/*CONTENT WIDGET HERE*/, true, true, 0);
200
	    
201
	    
202
	    
203
            //Add the Container to the Base GTK
204
            base.add(main_container);
205
            //set the default size
206
            base.set_default_size(800, 600);
207
            //Push it to the center!
208
            base.window_position = WindowPosition.CENTER;
209
        }
210
        
211
        // This is to check and see if it's maximized. If so, Minimize.
212
        void toggle_maximize(){
213
            get_window ().maximize ();
214
        }
215
216
        // We need to hijack the show function of the GTK Window.
217
        public override void show(){
218
            //Show the GTK Window
219
            base.show();
220
            //Change the window style. Border-Only.
221
            get_window ().set_decorations (Gdk.WMDecoration.BORDER);
222
        }
223
224
225
        public override void add (Gtk.Widget widget){
226
            main_container.pack_start(widget, true, true, 0);
227
            main_container.show_all();
228
        }
229
        
230
231
        public override void remove (Gtk.Widget widget){
232
            main_container.remove(widget);
233
        }
234
    }
235
}
236
237
238
//Main Loop!
239
public static int main (string[] args){
240
241
    //Init GTK!
242
    Gtk.init(ref args);
243
244
    //Assign window
245
    var main_window = new eSQL.MainWindow();
246
    // When our app is closed, Cancel the process.
247
    main_window.destroy.connect (Gtk.main_quit);
248
249
    //Show the main window.
250
    main_window.show_all();
251
252
    //GTK Main Loop.
253
    Gtk.main();
254
    return 0;
255
}