rendered paste bodyIndex: VolumeButton.cs
===================================================================
RCS file: /cvs/gnome/muine/src/VolumeButton.cs,v
retrieving revision 1.16
diff -u -B -u -p -r1.16 VolumeButton.cs
--- VolumeButton.cs 9 Sep 2006 00:35:36 -0000 1.16
+++ VolumeButton.cs 20 Nov 2006 03:16:25 -0000
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2004 Ross Girshick <ross.girshick@gmail.com>
+ * Copyright (C) 2006 Luis Medinas <metalgod@gentoo.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -36,9 +37,12 @@ namespace Muine
// Widgets
private Image icon;
private Window popup;
+ private VScale scale;
// Variables
private int volume;
+ private bool button_pressed;
+ private uint timeoutId = 0;
// Variables :: revert_volume
// Volume to restore to if the user rejects the slider changes.
@@ -92,6 +96,8 @@ namespace Muine
private void ShowScale ()
{
revert_volume = this.Volume;
+ Label label;
+ Button button;
// Popup
popup = new Window (WindowType.Popup);
@@ -110,19 +116,12 @@ namespace Muine
box.Show();
frame.Add (box);
- // +
- Gtk.Label plus_label = new Gtk.Label ("+");
- plus_label.Show ();
- box.PackStart (plus_label, false, true, 0);
-
// Adjustment
Adjustment adj = new Adjustment (volume, 0, 100, 5, 10, 0);
// Scale
- VScale scale = new VScale (adj);
-
- scale.ValueChanged += OnScaleValueChanged;
- scale.KeyPressEvent += OnScaleKeyPressEvent;
+ scale = new VScale (adj);
+ scale.ValueChanged += new EventHandler (OnScaleValueChanged);
scale.Adjustment.Upper = 100.0;
scale.Adjustment.Lower = 0.0;
@@ -132,13 +131,31 @@ namespace Muine
scale.Show ();
- box.PackStart (scale, true, true, 0);
+ // +
+ label = new Label();
+ label.Markup = "+";
+ button = new Button(label);
+ button.Relief = ReliefStyle.None;
+ button.Pressed += new EventHandler (OnPlusButtonPressed);
+ button.Released += new EventHandler (OnButtonReleased);
+ button.ScrollEvent += new ScrollEventHandler (OnScrollEvent);
+ button.KeyPressEvent += new KeyPressEventHandler (delegate (object o, KeyPressEventArgs args) { OnKeyPress (o, args, 1)});;
+ button.ShowAll();
+ box.PackStart (button, false, true, 0);
// -
- Gtk.Label minus_label = new Gtk.Label ("-");
- minus_label.Show ();
- box.PackEnd (minus_label, false, true, 0);
-
+ label = new Label();
+ label.Markup = "-";
+ button = new Button(label);
+ button.Relief = ReliefStyle.None;
+ button.Pressed += new EventHandler (OnMinusButtonPressed);
+ button.Released += new EventHandler (OnButtonReleased);
+ button.ScrollEvent += new ScrollEventHandler (OnScrollEvent);
+ button.KeyPressEvent += new KeyPressEventHandler (delegate (object o, KeyPressEventArgs args) { OnKeyPress (o, args, -1)});
+ button.ShowAll();
+ box.PackEnd (button, false, true, 0);
+
+ box.PackStart (scale, true, true, 0);
Requisition req = SizeRequest ();
@@ -151,7 +168,7 @@ namespace Muine
popup.Move (x + Allocation.X, y + Allocation.Y + req.Height);
popup.Show ();
- popup.GrabFocus ();
+ scale.GrabFocus ();
Grab.Add (popup);
@@ -260,6 +277,39 @@ namespace Muine
break;
}
}
+ private void OnKeyPressEvent (object obj, KeyPressEventArgs args, int adjust)
+ {
+ switch (args.Event.Key) {
+ case Gdk.Key.Escape:
+ HideScale ();
+
+ break;
+ case Gdk.Key.Return:
+ AdjustVolume (direction);
+
+ break;
+ default:
+ break;
+ }
+ }
+
// Handlers :: OnPopupButtonPressEvent
private void OnPopupButtonPressEvent
@@ -269,6 +319,64 @@ namespace Muine
return;
HideScale ();
+ }
+
+ private void OnPlusButtonPressed (object obj, EventArgs args)
+ {
+ button_pressed = true;
+ OnPlusButtonPressedTimeout();
+ }
+
+ private void OnMinusButtonPressed (object obj, EventArgs args)
+ {
+ button_pressed = true;
+ OnMinusButtonPressedTimeout();
+ }
+
+ private bool OnPlusButtonPressedTimeout () {
+ if (button_pressed) {
+ AdjustVolume (1);
+
+ if (timeoutId == 0) {
+ timeoutId = GLib.Timeout.Add(250, OnPlusButtonPressedTimeout);
+ }
+ }
+ return button_pressed;
+ }
+
+ private bool OnMinusButtonPressedTimeout () {
+ if (button_pressed) {
+ AdjustVolume (-1);
+
+ if (timeoutId == 0) {
+ timeoutId = GLib.Timeout.Add(250, OnMinusButtonPressedTimeout);
+ }
+ }
+ return button_pressed;
+ }
+
+ private void OnButtonReleased (object obj, EventArgs args) {
+ button_pressed = false;
+ if (timeoutId > 0) {
+ GLib.Source.Remove(timeoutId);
+ timeoutId = 0;
+ }
+ }
+
+ private void AdjustVolume (int direction) {
+ int vol = Volume + direction * 10;
+
+ // A CLAMP equiv doesn't seem to exist ... doing that manually
+ vol = Math.Min (100, vol);
+ vol = Math.Max (0, vol);
+
+ Volume = vol;
+
+ if (scale != null) {
+ scale.Value = vol;
+ } else {
+ VolumeChanged (Volume);
+ }
}
}
}