Permalink
Browse files

Sample gauge is working now.

  • Loading branch information...
1 parent 1a47a61 commit 71a3d4995383c631cfb57fd2d03065a242337a9f @tadeboro committed Dec 17, 2009
Showing with 173 additions and 30 deletions.
  1. +2 −0 .gitignore
  2. +21 −21 po/sl.po
  3. +36 −2 src/sampala-app.vala
  4. +108 −3 src/sampala-gauge.vala
  5. +3 −1 src/sampala.vala
  6. +3 −3 vapi/config.vapi
View
@@ -1,3 +1,5 @@
+*.swp
+*.pot
Makefile
Makefile.in
aclocal.m4
View
@@ -1,35 +1,35 @@
-# Slovenian translations for Imagination package
-# Slovenski prevodi paketa Imagination.
-# Copyright (C) 2009 THE Imagination'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the Imagination package.
+# Slovenian translations for Sampala package
+# Slovenski prevodi paketa Sampala.
+# Copyright (C) 2009 THE Sampala'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the Sampala package.
# <tadeboro@gmail.com>, 2009.
#
msgid ""
msgstr ""
-"Project-Id-Version: Imagination 3.0\n"
-"Report-Msgid-Bugs-To: <tadeboro@gmail.com>\n"
-"POT-Creation-Date: 2009-12-14 13:46+0100\n"
-"PO-Revision-Date: 2009-12-14 13:54+0100\n"
-"Last-Translator: <tadeboro@gmail.com>\n"
+"Project-Id-Version: Sampala 3.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2009-12-15 18:09+0100\n"
+"PO-Revision-Date: 2009-12-15 18:09+0100\n"
+"Last-Translator: Tadej Borovšak <tadeboro@gmail.com>\n"
"Language-Team: Slovenian\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n"
"%100==4 ? 2 : 3);\n"
-#: ../data/imagination.desktop.in.in.h:1
-msgid "A DVD slideshow maker"
-msgstr "Izdelovalec DVD predstavitev"
+#: ../data/sampala.desktop.in.in.h:1
+msgid "Sampala"
+msgstr "Sampala"
-#: ../data/imagination.desktop.in.in.h:2
-msgid "A lightweight DVD slideshow maker using GTK+2"
-msgstr "Lahkokategorni izdelovalec DVD predstavitev"
+#: ../data/sampala.desktop.in.in.h:2
+msgid "Sample Vala application"
+msgstr "Vzorčni Vala program"
-#: ../data/imagination.desktop.in.in.h:3 ../src/imagination.vala:9
-msgid "Imagination"
-msgstr "Domišljija"
+#: ../data/sampala.desktop.in.in.h:3
+msgid "Vala application that can serve as a learnign example"
+msgstr "Vala program, ki lahko služi kot vzorec za učenje"
-#: ../src/imagination.vala:13
-msgid "Sample app"
-msgstr "Vzorčna applikacija"
+#: ../src/sampala-gauge.vala:25
+msgid "Sample gauge"
+msgstr "Vzorčni merilnik"
View
@@ -17,20 +17,54 @@
*/
using Gtk;
-using Sample;
+using Cairo;
public class Sample.App : Window
{
private Gauge gauge;
+ private bool direction;
public App()
{
+ ImageSurface back,
+ needle;
+ string path;
+
set_title( Config.PACKAGE_STRING );
set_default_size( 300, 200 );
this.destroy.connect( Gtk.main_quit );
- gauge = new Gauge();
+ path = GLib.Path.build_filename( Config.PKGDATADIR, "images",
+ "gauge.png", null );
+ back = new ImageSurface.from_png( path );
+
+ path = GLib.Path.build_filename( Config.PKGDATADIR, "images",
+ "needle.png", null );
+ needle = new ImageSurface.from_png( path );
+
+ gauge = new Gauge( back, needle, 0, 100, 70, 231,
+ - 44, 7, 0, - Math.PI_2 );
gauge.show();
add( gauge );
+
+ /* Install timeout to move gauge a bit */
+ direction = true;
+ Timeout.add( 50, move_gauge );
+ }
+
+ /* Helper functions */
+ private bool move_gauge()
+ {
+ double tmp;
+
+ tmp = gauge.current_value;
+ if( ( tmp + 1 ) > 100 )
+ direction = false;
+ else if( ( tmp - 1 ) < 0 )
+ direction = true;
+
+ gauge.current_value = tmp + ( direction ? 1 : - 1 );
+
+ return( true );
}
}
View
@@ -17,11 +17,116 @@
*/
using Gtk;
+using Cairo;
-public class Sample.Gauge : Label
+public class Sample.Gauge : DrawingArea
{
- public Gauge()
+ /* Private fields */
+ private int width;
+ private int height;
+ private double angle;
+
+ /* Property backing fileds */
+ private double _current_value;
+
+ /* Properties */
+ [Property(nick = "Background image", blurb = "Background image")]
+ public ImageSurface background{ get; construct; }
+
+ [Property(nick = "Needle", blurb = "Gauge needle image")]
+ public ImageSurface needle{ get; construct; }
+
+ [Property(nick = "Needle x offset", blurb = "Needle x offset")]
+ public double needle_x_offset{ get; construct; default = 0; }
+
+ [Property(nick = "Needle y offset", blurb = "Needle y offset")]
+ public double needle_y_offset{ get; construct; default = 0; }
+
+ [Property(nick = "Needle center x", blurb = "Needle center y")]
+ public double needle_center_x{ get; construct; default = 0; }
+
+ [Property(nick = "Neelde center y", blurb = "Needle center y")]
+ public double needle_center_y{ get; construct; default = 0; }
+
+ [Property(nick = "Minimal value", blurb = "Minimal value")]
+ public double min_value{ get; construct; default = 0; }
+
+ [Property(nick = "Maximal value", blurb = "Maximal value")]
+ public double max_value{ get; construct; default = 90; }
+
+ [Property(nick = "Current value", blurb = "Current value being displayed")]
+ public double current_value
+ {
+ get{ return( _current_value ); }
+ set{ update_current_value( value ); }
+ }
+
+ [Property(nick = "Minimal position", blurb = "Angle of minimal position")]
+ public double min_angle{ get; construct; }
+
+ [Property(nick = "Maximal position", blurb = "Angle at maximal value")]
+ public double max_angle{ get; construct; default = GLib.Math.PI_2; }
+
+ /* Constructor */
+ public Gauge( ImageSurface background,
+ ImageSurface needle,
+ double min_value = 0,
+ double max_value = 90,
+ double center_x = 0,
+ double center_y = 0,
+ double offset_x = 0,
+ double offset_y = 0,
+ double min_angle = 0,
+ double max_angle = GLib.Math.PI_2 )
+ {
+ /* Instantiate new object using construction values */
+ GLib.Object( background: background,
+ needle: needle,
+ min_value: min_value,
+ max_value: max_value,
+ needle_center_x: center_x,
+ needle_center_y: center_y,
+ needle_x_offset: offset_x,
+ needle_y_offset: offset_y,
+ min_angle: min_angle,
+ max_angle: max_angle );
+
+ /* Get background image dimensions and set size request to match */
+ width = background.get_width();
+ height = background.get_height();
+ set_size_request( width, height );
+
+ /* Update current value and calculate proper angle for it */
+ current_value = min_value;
+ update_current_value( min_value );
+ }
+
+ /* Expose handler */
+ public override bool expose_event( Gdk.EventExpose event )
+ {
+ var cr = Gdk.cairo_create( event.window );
+
+ cr.set_source_surface( background, 0, 0 );
+ cr.paint();
+
+ cr.translate( needle_center_x, needle_center_y );
+ cr.rotate( angle );
+ cr.set_source_surface( needle, - needle_x_offset, - needle_y_offset );
+ cr.paint();
+
+ return( true );
+ }
+
+ /* Private methods */
+ private void update_current_value( double val )
{
- set_label( _("Sample gauge") );
+ double fraction;
+
+ _current_value = val;
+ fraction = val / ( max_value - min_value );
+ angle = min_angle + ( max_angle - min_angle ) * fraction;
+
+ /* Force redraw of gauge */
+ queue_draw();
}
}
View
@@ -16,6 +16,8 @@
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+using Sample;
+
int
main( string[] args )
{
@@ -25,7 +27,7 @@ main( string[] args )
Gtk.init( ref args );
- var test = new Sample.App();
+ var test = new App();
test.show();
Gtk.main();
View
@@ -11,7 +11,7 @@ namespace Config
/* Configured paths - these variables are not present in config.h, they are
* passed to underlying C code as cmd line macros. */
- public const string LOCALEDIR; /* /usr/local/share/locale */
- public const string PKGDATADIR; /* /usr/local/share/imagination */
- public const string PKGLIBDIR; /* /usr/local/lib/imagination */
+ public const string LOCALEDIR; /* /usr/local/share/locale */
+ public const string PKGDATADIR; /* /usr/local/share/sampala */
+ public const string PKGLIBDIR; /* /usr/local/lib/sampala */
}

0 comments on commit 71a3d49

Please sign in to comment.