Commit 6bdf3a6a authored by Colomban Wendling's avatar Colomban Wendling

OVCCGtk: port the board widget to GTK3

parent 2edf7aaa
......@@ -101,12 +101,16 @@ static void ovccgtk_board_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void ovccgtk_board_realize (GtkWidget *self);
static void ovccgtk_board_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void ovccgtk_board_get_preferred_width (GtkWidget *widget,
gint *minimum_width,
gint *natural_width);
static void ovccgtk_board_get_preferred_height (GtkWidget *widget,
gint *minimum_height,
gint *natural_height);
static void ovccgtk_board_size_allocate (GtkWidget *widget,
GtkAllocation *requisition);
static gboolean ovccgtk_board_expose (GtkWidget *self,
GdkEventExpose *event);
static gboolean ovccgtk_board_draw (GtkWidget *self,
cairo_t *cr);
static gboolean ovccgtk_board_button_release_event (GtkWidget *widget,
GdkEventButton *event);
static gboolean ovccgtk_board_button_press_event (GtkWidget *widget,
......@@ -115,9 +119,6 @@ static gboolean ovccgtk_board_scroll (GtkWidget *widget,
GdkEventScroll *event);
static gboolean ovccgtk_board_key_press (GtkWidget *widget,
GdkEventKey *event);
static void ovccgtk_board_set_scroll_adjustments (OVCCGtkBoard *board,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
G_DEFINE_TYPE (OVCCGtkBoard, ovccgtk_board, GTK_TYPE_DRAWING_AREA)
......@@ -131,15 +132,15 @@ static void ovccgtk_board_class_init (OVCCGtkBoardClass *klass)
object_class->set_property = ovccgtk_board_set_property;
object_class->get_property = ovccgtk_board_get_property;
widget_class->realize = ovccgtk_board_realize;
widget_class->size_request = ovccgtk_board_size_request;
widget_class->get_preferred_width = ovccgtk_board_get_preferred_width;
widget_class->get_preferred_height = ovccgtk_board_get_preferred_height;
widget_class->size_allocate = ovccgtk_board_size_allocate;
widget_class->expose_event = ovccgtk_board_expose;
widget_class->draw = ovccgtk_board_draw;
widget_class->button_release_event = ovccgtk_board_button_release_event;
widget_class->button_press_event = ovccgtk_board_button_press_event;
widget_class->scroll_event = ovccgtk_board_scroll;
widget_class->key_press_event = ovccgtk_board_key_press;
klass->add_tile = NULL;
klass->set_scroll_adjustments = ovccgtk_board_set_scroll_adjustments;
g_object_class_install_property (
object_class, PROP_BOARD,
......@@ -240,16 +241,6 @@ static void ovccgtk_board_class_init (OVCCGtkBoardClass *klass)
OVCC_TYPE_POSITION,
OVCC_TYPE_TILE_OBJECT,
OVCC_TYPE_PAWN_KIND);
/*widget_class->set_scroll_adjustments_signal =
g_signal_new ("set-scroll-adjustments",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (OVCCGtkBoardClass, set_scroll_adjustments),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_OBJECT,
G_TYPE_NONE, 2,
GTK_TYPE_ADJUSTMENT,
GTK_TYPE_ADJUSTMENT);*/
g_type_class_add_private ((gpointer)klass, sizeof(OVCCGtkBoardPrivate));
}
......@@ -283,14 +274,6 @@ ovccgtk_board_finalize (GObject *object)
G_OBJECT_CLASS (ovccgtk_board_parent_class)->finalize (object);
}
static void
ovccgtk_board_set_scroll_adjustments (OVCCGtkBoard *board,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
{
}
static void
ovccgtk_board_set_property (GObject *object,
guint prop_id,
......@@ -355,8 +338,6 @@ ovccgtk_board_realize (GtkWidget *widget)
GdkWindowAttr attributes;
GtkAllocation allocation;
GdkWindow *window;
GtkStyle *style;
guint attributes_mask;
gtk_widget_get_allocation (widget, &allocation);
attributes.window_type = GDK_WINDOW_CHILD;
......@@ -370,16 +351,13 @@ ovccgtk_board_realize (GtkWidget *widget)
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y;
window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
&attributes, GDK_WA_X | GDK_WA_Y);
gdk_window_set_user_data (window, widget);
gtk_widget_set_window (widget, window);
style = gtk_style_attach (gtk_widget_get_style (widget), window);
gtk_widget_set_style (widget, style);
gtk_style_set_background (style, window, GTK_STATE_NORMAL);
gtk_style_context_set_background (gtk_widget_get_style_context (widget),
window);
gtk_widget_set_realized (widget, TRUE);
gtk_widget_set_can_focus (widget, TRUE);
......@@ -429,10 +407,12 @@ auto_update_zoom (OVCCGtkBoard *self,
}
static void
ovccgtk_board_size_request (GtkWidget *widget,
GtkRequisition *requisition)
ovccgtk_board_preferred_size (OVCCGtkBoard *self,
gint *minimum_width,
gint *natural_width,
gint *minimum_height,
gint *natural_height)
{
OVCCGtkBoard *self = OVCCGTK_BOARD (widget);
GtkAllocation allocation;
gint width, height;
gint tile_size;
......@@ -440,14 +420,39 @@ ovccgtk_board_size_request (GtkWidget *widget,
ovcc_board_get_bounds (self->priv->board, NULL, NULL, NULL, NULL,
&width, &height);
g_debug ("req (board size): [%u,%u]", width, height);
gtk_widget_get_allocation (widget, &allocation);
gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
auto_update_zoom (self, &allocation);
tile_size = (IS_USER_ZOOM (self))
? (gint)(TILE_SIZE * self->priv->zoom)
: TILE_SIZE_MIN;
requisition->width = (width * (tile_size + 1)) + (2 * self->priv->margin);
requisition->height = (height * (tile_size + 1)) + (2 * self->priv->margin);
g_debug ("req: [%u,%u]", requisition->width, requisition->height);
if (minimum_width)
*minimum_width = (width * (tile_size + 1)) + (2 * self->priv->margin);
if (natural_width)
*natural_width = (width * (TILE_SIZE + 1)) + (2 * self->priv->margin);
if (minimum_height)
*minimum_height = (height * (tile_size + 1)) + (2 * self->priv->margin);
if (natural_height)
*natural_height = (height * (TILE_SIZE + 1)) + (2 * self->priv->margin);
}
static void
ovccgtk_board_get_preferred_width (GtkWidget *widget,
gint *minimum_width,
gint *natural_width)
{
ovccgtk_board_preferred_size (OVCCGTK_BOARD (widget),
minimum_width, natural_width,
NULL, NULL);
}
static void
ovccgtk_board_get_preferred_height (GtkWidget *widget,
gint *minimum_height,
gint *natural_height)
{
ovccgtk_board_preferred_size (OVCCGTK_BOARD (widget),
NULL, NULL,
minimum_height, natural_height);
}
static void
......@@ -782,14 +787,14 @@ draw_tile_cb (OVCCBoard *board,
static void
ovccgtk_cairo_pattern_add_color_stop_color_a (cairo_pattern_t *pattern,
gdouble offset,
const GdkColor *color,
const GdkRGBA *color,
gdouble alpha)
{
cairo_pattern_add_color_stop_rgba (pattern,
offset,
color->red / 65535.0,
color->green / 65535.0,
color->blue / 65535.0,
color->red,
color->green,
color->blue,
alpha);
}
......@@ -798,10 +803,14 @@ paint_cursor (OVCCGtkBoard *self)
{
gint dest_x, dest_y;
gint size = (gint)(TILE_SIZE * self->priv->zoom);
GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (self));
GdkColor *color = &style->bg[GTK_STATE_SELECTED];
GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (self));
GdkRGBA color;
cairo_pattern_t *pattern;
gtk_style_context_get_background_color (context,
GTK_STATE_FLAG_SELECTED,
&color);
ovccgtk_board_board_to_widget_coords (self, self->priv->cursor_pos.x,
self->priv->cursor_pos.y,
&dest_x, &dest_y);
......@@ -812,36 +821,31 @@ paint_cursor (OVCCGtkBoard *self)
dest_x + size / 2,
dest_y + size / 2,
0.0);
ovccgtk_cairo_pattern_add_color_stop_color_a (pattern, 0.0, color, 0.25);
ovccgtk_cairo_pattern_add_color_stop_color_a (pattern, 1.0, color, 0.0);
ovccgtk_cairo_pattern_add_color_stop_color_a (pattern, 0.0, &color, 0.25);
ovccgtk_cairo_pattern_add_color_stop_color_a (pattern, 1.0, &color, 0.0);
cairo_set_source (self->priv->cr, pattern);
cairo_pattern_destroy (pattern);
cairo_rectangle (self->priv->cr,
dest_x - 0.5, dest_y - 0.5,
size + 1, size + 1);
cairo_fill_preserve (self->priv->cr);
gdk_cairo_set_source_color (self->priv->cr, color);
gdk_cairo_set_source_rgba (self->priv->cr, &color);
cairo_stroke (self->priv->cr);
}
static gboolean
ovccgtk_board_expose (GtkWidget *widget,
GdkEventExpose *event)
ovccgtk_board_draw (GtkWidget *widget,
cairo_t *cr)
{
if (gtk_widget_is_drawable (widget)) {
OVCCGtkBoard *self = (OVCCGtkBoard *) widget;
self->priv->cr = gdk_cairo_create (GDK_DRAWABLE (event->window));
self->priv->cr = cr;
cairo_set_line_width (self->priv->cr, 1.0);
gdk_cairo_rectangle (self->priv->cr, &event->area);
cairo_clip (self->priv->cr);
ovcc_board_foreach (self->priv->board, draw_tile_cb, self);
paint_cursor (self);
cairo_destroy (self->priv->cr);
self->priv->cr = NULL;
}
return TRUE;
}
......
......@@ -63,9 +63,6 @@ struct _OVCCGtkBoardClass
const OVCCPosition *pos,
OVCCTileObject *obj,
OVCCPawnKind kind);
void (*set_scroll_adjustments) (OVCCGtkBoard *board,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment