cheese r1198 - branches/cheese-vala/src



Author: jhaitsma
Date: Fri Feb 27 19:01:11 2009
New Revision: 1198
URL: http://svn.gnome.org/viewvc/cheese?rev=1198&view=rev

Log:
Forgot to add this file. Trying to have it compile under vala 0.5.6. Not completed yet


Added:
   branches/cheese-vala/src/cheese-effect-chooser.vala

Added: branches/cheese-vala/src/cheese-effect-chooser.vala
==============================================================================
--- (empty file)
+++ branches/cheese-vala/src/cheese-effect-chooser.vala	Fri Feb 27 19:01:11 2009
@@ -0,0 +1,222 @@
+/* cheese-effect-chooser.vala
+ *
+ * Copyright (C) 2007,2008 daniel g. siegel <dgsiegel gmail com>
+ * Copyright (C) 2007,2008 Jaap Haitsma <jaap haitsma org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk, Cairo, Gdk, Cheese;
+
+
+public struct EffectData {
+	public Effect effect;
+	public string name;
+	public string filename;
+	public bool is_black;
+} 
+
+const EffectData[] EFFECT_DATA = {
+	{Effect.NO_EFFECT, N_("No Effect"),
+	 Config.PACKAGE_DATADIR + "/effects/identity.png", false},
+	{Effect.MAUVE, N_("Mauve"), 
+	 Config.PACKAGE_DATADIR + "/effects/Mauve.png", false},
+	{Effect.NOIR_BLANC, N_("Noir/Blanc"), 
+	 Config.PACKAGE_DATADIR + "/effects/NoirBlanc.png", false},
+	{Effect.SATURATION, N_("Saturation"),
+	 Config.PACKAGE_DATADIR + "/effects/Saturation.png", false},
+	{Effect.HULK, N_("Hulk"),
+	 Config.PACKAGE_DATADIR + "/effects/Hulk.png", false},
+	{Effect.VERTICAL_FLIP, N_("Vertical Flip"),
+	 Config.PACKAGE_DATADIR + "/effects/videoflip_v.png", false},
+	{Effect.HORIZONTAL_FLIP, N_("Horizontal Flip"), 
+	 Config.PACKAGE_DATADIR + "/effects/videoflip_h.png", false},
+	{Effect.SHAGADELIC, N_("Shagadelic"),
+	 Config.PACKAGE_DATADIR + "/effects/shagadelictv.png", false},
+	{Effect.VERTIGO, N_("Vertigo"),
+	 Config.PACKAGE_DATADIR + "/effects/vertigotv.png", false},
+	{Effect.EDGE, N_("Edge"),
+	 Config.PACKAGE_DATADIR + "/effects/edgetv.png", true},
+	{Effect.DICE, N_("Dice"),
+	 Config.PACKAGE_DATADIR + "/effects/dicetv.png", false},
+	{Effect.WARP, N_("Warp"), 
+	 Config.PACKAGE_DATADIR + "/effects/warptv.png", false}		
+}; 
+
+
+
+public class Cheese.CairoContext : Cairo.Context {
+	void shrink (double x) {
+		translate ((1 - x) / 2.0, (1 - x) / 2.0);
+		scale (x, x);
+	} 
+
+	void rounded_rectangle (double x0, double y0, double width, double height, double radius) {
+		double x1, y1;
+		x1 = x0 + width;
+		y1 = y0 + height;
+
+		if (width <= 0.0 || height <= 0.0)
+			return;
+		if (width / 2 < radius) {
+			if (height / 2 < radius) {
+				move_to (x0, (y0 + y1) / 2);
+				curve_to (x0, y0, x0, y0, (x0 + x1) / 2, y0);
+				curve_to (x1, y0, x1, y0, x1, (y0 + y1) / 2);
+				curve_to (x1, y1, x1, y1, (x1 + x0) / 2, y1);
+				curve_to (x0, y1, x0, y1, x0, (y0 + y1) / 2);
+			} else {
+				move_to (x0, y0 + radius);
+				curve_to (x0, y0, x0, y0, (x0 + x1) / 2, y0);
+				curve_to (x1, y0, x1, y0, x1, y0 + radius);
+				line_to (x1, y1 - radius);
+				curve_to (x1, y1, x1, y1, (x1 + x0) / 2, y1);
+				curve_to (x0, y1, x0, y1, x0, y1 - radius);
+			}
+		} else {
+			if (height / 2 < radius) {
+				move_to (x0, (y0 + y1) / 2);
+				curve_to (x0, y0, x0, y0, x0 + radius, y0);
+				line_to (x1 - radius, y0);
+				curve_to (x1, y0, x1, y0, x1, (y0 + y1) / 2);
+				curve_to (x1, y1, x1, y1, x1 - radius, y1);
+				line_to (x0 + radius, y1);
+				curve_to (x0, y1, x0, y1, x0, (y0 + y1) / 2);
+			} else {
+				move_to (x0, y0 + radius);
+				curve_to (x0, y0, x0, y0, x0 + radius, y0);
+				line_to (x1 - radius, y0);
+				curve_to (x1, y0, x1, y0, x1, y0 + radius);
+				line_to (x1, y1 - radius);
+				curve_to (x1, y1, x1, y1, x1 - radius, y1);
+				line_to (x0 + radius, y1);
+				curve_to (x0, y1, x0, y1, x0, y1 - radius);
+			}
+		}
+		close_path ();
+	}
+
+	public void draw_card (EffectData effect_data, bool highlight) {
+		save ();
+		shrink (0.9);
+
+		rounded_rectangle (0, 0, 1.0, 1.0, 0.1);
+		set_source_rgb (0, 0, 0);
+
+		save ();
+
+		rounded_rectangle (0, 0, 1.0, 1.0, 0.1);
+		clip ();
+		new_path ();
+
+		var image = new ImageSurface.from_png (effect_data.filename);
+		scale (1.0 / image.get_width (), 1.0 / image.get_height ());
+
+		set_source_surface (image, 0, 0);
+		paint ();
+
+		restore ();
+
+		if (effect_data.is_black)
+			set_source_rgb ( 1, 1, 1);
+
+		select_font_face ("Sans", FontSlant.NORMAL, FontWeight.NORMAL);
+
+		set_font_size (0.09);
+		TextExtents extents;
+		text_extents (effect_data.name, ref extents);
+		int x = (int)(0.5 - (extents.width / 2 + extents.x_bearing));
+		int y = (int)(0.92 - (extents.height / 2 + extents.y_bearing));
+
+		move_to (x, y);
+		show_text (effect_data.name);
+
+		if (highlight) {
+			rounded_rectangle (0, 0, 1.0, 1.0, 0.1);
+			set_source_rgba (0, 0, 1, 0.25);
+			fill ();
+		}
+		restore ();
+	}
+
+}
+
+
+public class Cheese.EffectChooser : DrawingArea {
+	public const int NUM_EFFECTS = 12;
+	bool[] selected = new bool[NUM_EFFECTS];
+	const int BOARD_COLS = 4;
+	const int BOARD_ROWS = 3;
+	
+	public Effect effect {get; set;}
+		
+	construct {
+		add_event (EventMask.BUTTON_PRESS_MASK);
+		button_press_event += on_button_press;
+		expose_event += on_expose;
+		selected[0] = false;
+		for (int i = 1;  i < NUM_EFFECTS; i++) {
+			selected[i] = effect & (1 << (i - 1)) != 0;
+		}
+	}
+
+	public EffectChooser (Effect effect) {
+		this.effect = effect;
+	}
+	public Effect get_selection () {		
+		effect = Effect.NO_EFFECT;
+		
+		for (int i = 0;  i < NUM_EFFECTS; i++) {
+			if (selected[i]) {
+				effect |= EFFECT_DATA[i].effect;
+			}
+		}
+		return effect;
+	}
+	
+	bool on_expose (Widget sender, EventExpose event) {		
+		CairoContext cr;
+		cr = (CairoContext)cairo_create (sender.window);
+		cr.save ();
+		cr.scale (sender.allocation.width, sender.allocation.height);
+
+		for (int i = 0; i < NUM_EFFECTS; i++) {
+			cr.save ();
+			cr.translate (1.0 / BOARD_COLS * (i % BOARD_COLS), 1.0 / BOARD_ROWS * (i / BOARD_COLS));
+			cr.scale (1.0 / BOARD_COLS, 1.0 / BOARD_ROWS);
+			cr.draw_card (EFFECT_DATA[i], selected[i]);
+			cr.restore ();
+		}
+		cr.restore ();		
+		return true;
+	}
+	
+	bool on_button_press (Gdk.EventButton event) {
+		int col = (int) (event.x / allocation.width * BOARD_COLS);
+		int row = (int) (event.y / allocation.height * BOARD_ROWS);
+		int slot = (row * BOARD_COLS + col);
+
+		selected [slot] = !selected [slot];
+
+		if (selected[0] == true) { // NO_EFFECT is pressed
+			for (int i = 0; i < NUM_EFFECTS; i++)
+				selected[i] = false;
+		}
+		queue_draw ();
+	}
+}
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]