2
* Copyright (C) 2011 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by Neil Jagdish Patel <njpatel@gmail.com>
19
public class StreamEntry : Gtk.Alignment
21
private Gtk.VBox _vbox;
22
private Gtk.Alignment _align;
23
public GwibberGtk.InputTextView text_view;
24
private Gtk.Label _spacing;
25
public Gtk.Image private;
27
private Gwibber.Service _service;
29
private uint _anim_id = 0;
30
private float _anim_offset = 0.0f;
31
private int64 _anim_start = 0;
33
public GwibberGtk.AccountTargetBar target_bar;
35
private bool _showing = false;
47
target_bar.selected = null;
61
set_reallocate_redraws (true);
63
_vbox = new Gtk.VBox (false, 0);
66
_align = new Gtk.Alignment (0.0f, 0.0f, 1.0f, 1.0f);
67
_align.set_padding (18, 18, 18, 18);
68
_vbox.pack_start (_align, false, false, 0);
70
var box = new Gtk.VBox (false, 4);
72
_service = new Gwibber.Service ();
74
var group = new Gtk.SizeGroup (Gtk.SizeGroupMode.VERTICAL);
76
_spacing = new Gtk.Label (" ");
77
box.pack_start (_spacing, false, true, 0);
78
_spacing.set_no_show_all (true);
80
group.add_widget (_spacing);
82
text_view = new GwibberGtk.InputTextView (_service);
83
text_view.set_wrap_mode (Gtk.WrapMode.WORD_CHAR);
84
text_view.set_border_window_size (Gtk.TextWindowType.LEFT, 0);
85
text_view.set_border_window_size (Gtk.TextWindowType.RIGHT, 0);
86
text_view.set_border_window_size (Gtk.TextWindowType.TOP, 0);
87
text_view.set_border_window_size (Gtk.TextWindowType.BOTTOM, 0);
88
text_view.set_no_show_all (true);
89
group.add_widget (text_view);
90
box.pack_start (text_view, false, true, 0);
91
text_view.key_press_event.connect ((t, e)=>
93
if (e.keyval == 65307) // Escape
102
color.red = 34/255.0f;
103
color.green = 34/255.0f;
104
color.blue = 34/255.0f;
106
text_view.override_background_color (Gtk.StateFlags.NORMAL, color);
111
text_view.override_color (Gtk.StateFlags.NORMAL, color);
112
text_view.fg_color = { 0, 65535, 65535, 65535 };
115
text_view.override_background_color (Gtk.StateFlags.SELECTED, color);
121
text_view.override_color (Gtk.StateFlags.SELECTED, color);
123
var hbox = new Gtk.HBox (false, 12);
124
box.pack_start (hbox, false, false, 0);
126
private = new Gtk.Image.from_icon_name ("status_lock", Gtk.IconSize.MENU);
127
private.set_no_show_all (true);
129
hbox.pack_end (private, false, false, 0);
131
target_bar = new GwibberGtk.AccountTargetBar ();
132
hbox.pack_start (target_bar, true, true, 0);
137
target_bar.override_color (Gtk.StateFlags.NORMAL, color);
138
target_bar.count.override_color (Gtk.StateFlags.NORMAL, color);
140
target_bar.send.clicked.connect (()=>
145
text_view.submit.connect (() =>
150
_align.size_allocate.connect_after (()=> { queue_draw (); });
151
text_view.size_allocate.connect_after (()=> { queue_draw (); });
152
box.size_allocate.connect_after (()=> { queue_draw (); });
154
text_view.get_buffer ().changed.connect (() =>
156
target_bar.set_counter(text_view.get_buffer ().get_char_count ());
159
var eb = new Gtk.EventBox ();
160
eb.set_visible_window (false);
161
eb.set_above_child (false);
162
_vbox.pack_end (eb, true, true, 0);
163
eb.button_press_event.connect (()=> { showing = false; });
165
notify["showing"].connect (()=>
168
Source.remove (_anim_id);
170
_anim_start = G.get_monotonic_time ();
172
_anim_id = Timeout.add (15, ()=>
174
float LENGTH = 120000.0f;
175
int64 diff = G.get_monotonic_time () - _anim_start;
176
float progress = diff/LENGTH;
182
_anim_offset = (_anim_offset + (1.0f-_anim_offset) * progress);
186
_anim_offset = _anim_offset - (_anim_offset * progress);
192
_anim_offset = _showing ? 1.0f : 0.0f;
193
text_view.visible = _showing;
194
_spacing.visible = !_showing;
195
set_visible (_showing);
204
public override bool draw (Cairo.Context cr)
211
_align.get_allocation (out a);
213
cr.translate (0, (-1 * a.height) + (a.height * _anim_offset));
217
var r = 4.0f; //radius
218
cr.rectangle (a.x, a.y, a.width, a.height);
220
var pat = new Cairo.Pattern.linear (0, 0, 0, _align.get_allocated_height ());
221
pat.add_color_stop_rgba (0, 69/255.0, 69/255.0, 69/255.0, 0.85);
222
pat.add_color_stop_rgba (1.0, 20/255.0, 20/255.0, 20/255.0, 0.85);
226
cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.3f);
227
cr.rectangle (a.x, a.y, a.width, 1);
230
cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.2f);
231
cr.rectangle (a.x, a.y + 1, a.width, 1);
234
cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.2f);
235
cr.rectangle (a.x, a.y + a.height-2, a.width, 1);
238
cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.3f);
239
cr.rectangle (a.x, a.y + a.height-1, a.width, 1);
242
// Shadow (we'll make it nicer later)
243
pat = new Cairo.Pattern.linear (a.x, a.y + a.height, a.x, a.y + a.height + 12);
244
pat.add_color_stop_rgba (0.0f, 0.0f, 0.0f, 0.0f, 0.4f);
245
pat.add_color_stop_rgba (1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
246
cr.rectangle (a.x, a.y + a.height, a.width, 12);
251
if (text_view.visible)
252
text_view.get_allocation (out a);
254
_spacing.get_allocation (out a);
256
pat = new Cairo.Pattern.linear (a.x, a.y, a.x, a.y + a.height);
257
pat.add_color_stop_rgba (0.99, 24/255.0f, 24/255.0f, 24/255.0f, 1.0);
258
pat.add_color_stop_rgba (1.0, 90/255.0f, 90/255.0f, 90/255.0f, 0.9);
261
cr.rectangle (a.x - 1,
268
cr.move_to (a.x -1, a.y-1);
269
cr.line_to (a.x -1 + a.width + 2, a.y-1);
270
cr.set_source_rgba (10/255.0f, 10/255.0f, 10/255.0f, 1.0f);
273
propagate_draw (_vbox, cr);
277
cr.pop_group_to_source ();
278
cr.paint_with_alpha (_anim_offset);