[gnome-mines/wip/cssstyling: 1/4] Move the minefield to an aspectframe. https://bugzilla.gnome.org/show_bug.cgi?id=728483
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mines/wip/cssstyling: 1/4] Move the minefield to an aspectframe. https://bugzilla.gnome.org/show_bug.cgi?id=728483
- Date: Sun, 20 Apr 2014 12:29:55 +0000 (UTC)
commit 56a368bb5fe1d87af0d2dfe46ea62a7c9586091e
Author: Robert Roth <robert roth off gmail com>
Date: Fri Apr 18 11:13:17 2014 +0300
Move the minefield to an aspectframe. https://bugzilla.gnome.org/show_bug.cgi?id=728483
Moved the minefield to an aspectframe correctly maintaining the
aspect and centering of the minefield, and removed the hard-coded
calculations from the minefield class.
src/gnome-mines.vala | 18 +++++++++++++-----
src/minefield-view.vala | 42 +++++++++++++-----------------------------
2 files changed, 26 insertions(+), 34 deletions(-)
---
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index 8422816..8a6762c 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -31,7 +31,8 @@ public class Mines : Gtk.Application
private Gtk.Button replay_button;
private Gtk.Button high_scores_button;
private Gtk.Button new_game_button;
-
+ private Gtk.AspectFrame minefield_aspect;
+
private Gtk.Label clock_label;
private Menu app_main_menu;
@@ -159,8 +160,14 @@ public class Mines : Gtk.Application
main_vbox.pack_start (view_box, true, true, 0);
minefield_view = new MinefieldView (settings);
+ minefield_view.show ();
minefield_view.button_press_event.connect (view_button_press_event);
- view_box.pack_start (minefield_view, true, true, 0);
+
+ minefield_aspect = new Gtk.AspectFrame (null, 0.5f, 0.5f, 1.0f , false);
+ minefield_aspect.set_shadow_type (Gtk.ShadowType.NONE);
+ minefield_aspect.add (minefield_view);
+
+ view_box.pack_start (minefield_aspect, true, true, 0);
/* Initialize New Game Screen */
startup_new_game_screen ();
@@ -455,7 +462,7 @@ public class Mines : Gtk.Application
{
is_new_game_screen = false;
custom_game_screen.show ();
- minefield_view.hide ();
+ minefield_aspect.hide ();
new_game_screen.hide ();
}
@@ -497,7 +504,7 @@ public class Mines : Gtk.Application
is_new_game_screen = true;
custom_game_screen.hide ();
- minefield_view.hide ();
+ minefield_aspect.hide ();
new_game_screen.show ();
window.resize (window_width, window_height);
@@ -514,7 +521,7 @@ public class Mines : Gtk.Application
is_new_game_screen = false;
custom_game_screen.hide ();
window_skip_configure = true;
- minefield_view.show ();
+ minefield_aspect.show ();
minefield_view.has_focus = true;
new_game_screen.hide ();
play_pause_button.hide ();
@@ -561,6 +568,7 @@ public class Mines : Gtk.Application
minefield.paused_changed.connect (paused_changed_cb);
minefield.clock_started.connect (clock_started_cb);
+ minefield_aspect.ratio = (float)x / y;
minefield_view.minefield = minefield;
update_flag_label ();
diff --git a/src/minefield-view.vala b/src/minefield-view.vala
index 555ae38..5e54976 100644
--- a/src/minefield-view.vala
+++ b/src/minefield-view.vala
@@ -142,22 +142,6 @@ public class MinefieldView : Gtk.DrawingArea
}
}
- private uint x_offset
- {
- get
- {
- return (get_allocated_width () - minefield.width * mine_size) / 2;
- }
- }
-
- private uint y_offset
- {
- get
- {
- return (get_allocated_height () - minefield.height * mine_size) / 2;
- }
- }
-
private uint minimum_size
{
get
@@ -338,7 +322,7 @@ public class MinefieldView : Gtk.DrawingArea
private void redraw_sector_cb (uint x, uint y)
{
- queue_draw_area ((int) (x_offset + x * mine_size), (int) (y_offset + y * mine_size), (int)
mine_size, (int) mine_size);
+ queue_draw_area ((int) (x * mine_size), (int) (y * mine_size), (int) mine_size, (int) mine_size);
}
private void draw_square (Cairo.Context cr, uint x, uint y)
@@ -480,7 +464,7 @@ public class MinefieldView : Gtk.DrawingArea
}
double dimensions[2] = {minefield.width * mine_size, minefield.height * mine_size};
- double centre[2] = { x_offset + 0.5 * dimensions[0], y_offset + 0.5 * dimensions[1] };
+ double centre[2] = { 0.5 * dimensions[0], 0.5 * dimensions[1] };
double radius = Math.fmax (dimensions[0], dimensions[1]);
/* Draw Background */
@@ -488,7 +472,7 @@ public class MinefieldView : Gtk.DrawingArea
pattern.add_color_stop_rgba (0.0, 0.0, 0.0, 0.0, 0.1);
pattern.add_color_stop_rgba (1.0, 0.0, 0.0, 0.0, 0.4);
- cr.rectangle (x_offset - 0.5, y_offset - 0.5, dimensions[0] + 0.5, dimensions[1] + 0.5);
+ cr.rectangle (- 0.5, - 0.5, dimensions[0] + 0.5, dimensions[1] + 0.5);
cr.save ();
cr.set_source (pattern);
cr.fill_preserve ();
@@ -506,15 +490,15 @@ public class MinefieldView : Gtk.DrawingArea
for (var x = 1; x < minefield.width; x++)
{
- cr.move_to (x_offset + x * mine_size, y_offset);
- cr.line_to (x_offset + x * mine_size, y_offset + dimensions[1]);
+ cr.move_to (x * mine_size, 0);
+ cr.line_to (x * mine_size, dimensions[1]);
cr.stroke ();
}
for (var y = 1; y < minefield.height; y++)
{
- cr.move_to (x_offset, y_offset + y * mine_size);
- cr.line_to (x_offset + dimensions[0], y_offset + y * mine_size);
+ cr.move_to (0, y * mine_size);
+ cr.line_to (dimensions[0], y * mine_size);
cr.stroke ();
}
@@ -526,7 +510,7 @@ public class MinefieldView : Gtk.DrawingArea
for (var y = 0; y < minefield.height; y++)
{
cr.save ();
- cr.translate (x_offset + x * mine_size, y_offset + y * mine_size);
+ cr.translate (x * mine_size, y * mine_size);
draw_square (cr, x, y);
cr.restore ();
}
@@ -535,7 +519,7 @@ public class MinefieldView : Gtk.DrawingArea
/* Draw keyboard cursor */
if (keyboard_cursor.is_set)
{
- double key_centre[2] = { x_offset + (keyboard_cursor.x+0.5) * mine_size, y_offset +
(keyboard_cursor.y+0.5) * mine_size };
+ double key_centre[2] = { (keyboard_cursor.x+0.5) * mine_size, (keyboard_cursor.y+0.5) *
mine_size };
var key_cursor = new Cairo.Pattern.radial (key_centre[0], key_centre[1], 0.0, key_centre[0],
key_centre[1], 0.25 * mine_size);
key_cursor.add_color_stop_rgba (0.0, 1.0, 1.0, 1.0, 1.0);
key_cursor.add_color_stop_rgba (0.8, 1.0, 1.0, 1.0, 0.1);
@@ -676,8 +660,8 @@ public class MinefieldView : Gtk.DrawingArea
/* Hide any lingering previously selected and get new location */
selected.is_set = false;
- selected.x = (int) Math.floor ((event.x - x_offset) / mine_size);
- selected.y = (int) Math.floor ((event.y - y_offset) / mine_size);
+ selected.x = (int) Math.floor ((event.x) / mine_size);
+ selected.y = (int) Math.floor ((event.y) / mine_size);
/* Is the current position a minefield square? */
if (!selected.is_valid)
@@ -712,8 +696,8 @@ public class MinefieldView : Gtk.DrawingArea
if (!selected.is_set || keyboard_cursor.is_set)
return false;
- var x = (int) Math.floor ((event.x - x_offset) / mine_size);
- var y = (int) Math.floor ((event.y - y_offset) / mine_size);
+ var x = (int) Math.floor ((event.x) / mine_size);
+ var y = (int) Math.floor ((event.y) / mine_size);
selected.position = {x, y};
return false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]