[gnome-chess/mcatanzaro/gtk4] progress
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/mcatanzaro/gtk4] progress
- Date: Wed, 23 Dec 2020 23:23:39 +0000 (UTC)
commit 0d5b6e65c0b3dab739dd63e85aca281ae12ec60c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Wed Dec 23 16:57:51 2020 -0600
progress
data/gnome-chess.ui | 8 -----
src/gnome-chess.vala | 97 ++++++++++++++--------------------------------------
2 files changed, 26 insertions(+), 79 deletions(-)
---
diff --git a/data/gnome-chess.ui b/data/gnome-chess.ui
index 2e07d0f..6493318 100644
--- a/data/gnome-chess.ui
+++ b/data/gnome-chess.ui
@@ -153,7 +153,6 @@
</style>
<child>
<object class="GtkButton" id="first_move_button">
- <property name="hexpand">1</property>
<property name="sensitive">0</property>
<property name="tooltip-text" translatable="yes" comments="Tooltip on the show first
move (i.e. game start) navigation button">Rewind to the game start</property>
<!-- <accelerator key="Left" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_MOD1_MASK"/> -->
@@ -172,7 +171,6 @@
</child>
<child>
<object class="GtkButton" id="prev_move_button">
- <property name="hexpand">1</property>
<property name="sensitive">0</property>
<property name="tooltip-text" translatable="yes" comments="Tooltip on the show
previous move navigation button">Show the previous move</property>
<!-- <accelerator key="Left" signal="activate" modifiers="GDK_MOD1_MASK"/> -->
@@ -191,7 +189,6 @@
</child>
<child>
<object class="GtkButton" id="next_move_button">
- <property name="hexpand">1</property>
<property name="sensitive">0</property>
<property name="tooltip-text" translatable="yes" comments="Tooltip on the show next
move navigation button">Show the next move</property>
<!-- <accelerator key="Right" signal="activate" modifiers="GDK_MOD1_MASK"/> -->
@@ -210,7 +207,6 @@
</child>
<child>
<object class="GtkButton" id="last_move_button">
- <property name="hexpand">1</property>
<property name="sensitive">0</property>
<property name="tooltip-text" translatable="yes" comments="Tooltip on the show
current move navigation button">Show the current move</property>
<!-- <accelerator key="Right" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_MOD1_MASK"/> -->
@@ -254,16 +250,12 @@
<property name="homogeneous">1</property>
<child>
<object class="GtkDrawingArea" id="white_time_label">
- <property name="hexpand">1</property>
<property name="can-focus">0</property>
-<!-- <signal name="draw" handler="white_time_draw_cb" swapped="no"/> -->
</object>
</child>
<child>
<object class="GtkDrawingArea" id="black_time_label">
- <property name="hexpand">1</property>
<property name="can-focus">0</property>
-<!-- <signal name="draw" handler="black_time_draw_cb" swapped="no"/> -->
</object>
</child>
</object>
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 1a73dc8..1eacd5d 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -30,15 +30,15 @@ public class ChessApplication : Gtk.Application
private ChessView view;
private Button pause_resume_button;
private Box navigation_box;
- private Widget first_move_button;
- private Widget prev_move_button;
- private Widget next_move_button;
- private Widget last_move_button;
+ private Button first_move_button;
+ private Button prev_move_button;
+ private Button next_move_button;
+ private Button last_move_button;
private ComboBox history_combo;
private Box clock_box;
- private Widget white_time_label;
- private Widget black_time_label;
- private Widget timer_increment_label;
+ private DrawingArea white_time_label;
+ private DrawingArea black_time_label;
+ private Label timer_increment_label;
private HeaderBar headerbar;
private Dialog? preferences_dialog = null;
@@ -166,14 +166,14 @@ Copyright © 2015–2016 Sahil Sareen""";
info_bar_label = (Label) builder.get_object ("info_bar_label");
pause_resume_button = (Button) builder.get_object ("pause_button");
navigation_box = (Box) builder.get_object ("navigation_box");
- first_move_button = (Widget) builder.get_object ("first_move_button");
- prev_move_button = (Widget) builder.get_object ("prev_move_button");
- next_move_button = (Widget) builder.get_object ("next_move_button");
- last_move_button = (Widget) builder.get_object ("last_move_button");
+ first_move_button = (Button) builder.get_object ("first_move_button");
+ prev_move_button = (Button) builder.get_object ("prev_move_button");
+ next_move_button = (Button) builder.get_object ("next_move_button");
+ last_move_button = (Button) builder.get_object ("last_move_button");
history_combo = (ComboBox) builder.get_object ("history_combo");
clock_box = (Box) builder.get_object ("clock_box");
- white_time_label = (Widget) builder.get_object ("white_time_label");
- black_time_label = (Widget) builder.get_object ("black_time_label");
+ white_time_label = (DrawingArea) builder.get_object ("white_time_label");
+ black_time_label = (DrawingArea) builder.get_object ("black_time_label");
headerbar = (HeaderBar) builder.get_object ("headerbar");
update_pause_resume_button ();
@@ -209,6 +209,11 @@ Copyright © 2015–2016 Sahil Sareen""";
main_box.insert_child_after (view, info_bar);
view.show ();
+ white_time_label.content_width = 80;
+ black_time_label.content_width = 80;
+ white_time_label.set_draw_func (draw_white_time_label);
+ black_time_label.set_draw_func (draw_black_time_label);
+
var system_engine_cfg = Path.build_filename (SYSCONFDIR, "gnome-chess", "engines.conf", null);
var user_engine_cfg = Path.build_filename (Environment.get_user_config_dir (), "gnome-chess",
"engines.conf", null);
if (FileUtils.test (user_engine_cfg, FileTest.EXISTS))
@@ -1693,24 +1698,14 @@ Copyright © 2015–2016 Sahil Sareen""";
quit_game ();
}
- [CCode (cname = "white_time_draw_cb", instance_pos = -1)]
- public bool white_time_draw_cb (Widget widget, Cairo.Context c)
+ private void draw_white_time_label (DrawingArea drawing_area, Cairo.Context c, int width, int height)
{
- double fg[3] = { 0.0, 0.0, 0.0 };
- double bg[3] = { 1.0, 1.0, 1.0 };
-
- draw_time (widget, c, make_clock_text (game.clock, Color.WHITE), fg, bg);
- return false;
+ draw_time (drawing_area, c, width, height, make_clock_text (game.clock, Color.WHITE), { 0.0, 0.0,
0.0 }, { 1.0, 1.0, 1.0 });
}
- [CCode (cname = "black_time_draw_cb", instance_pos = -1)]
- public bool black_time_draw_cb (Widget widget, Cairo.Context c)
+ private void draw_black_time_label (DrawingArea drawing_area, Cairo.Context c, int width, int height)
{
- double fg[3] = { 1.0, 1.0, 1.0 };
- double bg[3] = { 0.0, 0.0, 0.0 };
-
- draw_time (widget, c, make_clock_text (game.clock, Color.BLACK), fg, bg);
- return false;
+ draw_time (drawing_area, c, width, height, make_clock_text (game.clock, Color.BLACK), { 1.0, 1.0,
1.0 }, { 0.0, 0.0, 0.0 });
}
private string make_clock_text (ChessClock? clock, Color color)
@@ -1728,46 +1723,11 @@ Copyright © 2015–2016 Sahil Sareen""";
return "∶\xE2\x80\x8E%02d".printf (time);
}
- /*
- * Compute the largest possible size the timer label might ever want to take.
- * The size of the characters may vary by font, but one digit will always
- * be the largest.
- */
- private int compute_time_label_width_request (Cairo.Context c)
- ensures (result > 0)
- {
- Cairo.TextExtents extents;
- double max = 0;
-
- c.text_extents ("000∶00", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("111∶11", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("222∶22", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("333∶33", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("444∶44", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("555∶55", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("666∶66", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("777∶77", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("888∶88", out extents);
- max = (max > extents.width ? max : extents.width);
- c.text_extents ("999∶99", out extents);
- max = (max > extents.width ? max : extents.width);
-
- /* Leave a little bit of room to the sides. */
- return (int) Math.ceil (max) + 6;
- }
-
- private void draw_time (Widget widget, Cairo.Context c, string text, double[] fg, double[] bg)
+ private void draw_time (Widget widget, Cairo.Context c, int width, int height, string text, double[] fg,
double[] bg)
{
- double alpha = 1.0;
+ c.scale (width, height);
+ double alpha = 1.0;
if ((widget.get_state_flags () & StateFlags.INSENSITIVE) != 0)
alpha = 0.5;
c.set_source_rgba (bg[0], bg[1], bg[2], alpha);
@@ -1781,11 +1741,6 @@ Copyright © 2015–2016 Sahil Sareen""";
c.move_to ((widget.get_allocated_width () - extents.width) / 2 - extents.x_bearing,
(widget.get_allocated_height () - extents.height) / 2 - extents.y_bearing);
c.show_text (text);
-
- int width;
- widget.get_size_request (out width, null);
- if (width == -1)
- widget.set_size_request (compute_time_label_width_request (c), -1);
}
[CCode (cname = "history_combo_changed_cb", instance_pos = -1)]
@@ -1903,7 +1858,7 @@ Copyright © 2015–2016 Sahil Sareen""";
timer_increment_box = (Box) preferences_builder.get_object ("timer_increment_box");
custom_duration_units_combo = (ComboBox) preferences_builder.get_object
("custom_duration_units_combo");
set_duration (settings.get_int ("duration"));
- timer_increment_label = (Widget) preferences_builder.get_object ("timer_increment_label");
+ timer_increment_label = (Label) preferences_builder.get_object ("timer_increment_label");
timer_increment_units_combo = (ComboBox) preferences_builder.get_object
("timer_increment_units_combo");
if (pgn_game.clock_type != null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]