mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-19 01:40:10 +00:00
treeview: Draw column reordering arrows with Cairo
This commit is contained in:
parent
09080e3c76
commit
7ee63c07ee
@ -3400,6 +3400,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
|
|||||||
gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
|
gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
|
||||||
GdkWindowAttr attributes;
|
GdkWindowAttr attributes;
|
||||||
guint attributes_mask;
|
guint attributes_mask;
|
||||||
|
cairo_t *cr;
|
||||||
|
|
||||||
if (!reorder ||
|
if (!reorder ||
|
||||||
reorder->left_column == tree_view->priv->drag_column ||
|
reorder->left_column == tree_view->priv->drag_column ||
|
||||||
@ -3425,9 +3426,6 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
|
|||||||
/* We want to draw the rectangle over the initial location. */
|
/* We want to draw the rectangle over the initial location. */
|
||||||
if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
|
if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
|
||||||
{
|
{
|
||||||
GdkGC *gc;
|
|
||||||
GdkColor col;
|
|
||||||
|
|
||||||
if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
|
if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
|
||||||
{
|
{
|
||||||
if (tree_view->priv->drag_highlight_window)
|
if (tree_view->priv->drag_highlight_window)
|
||||||
@ -3451,14 +3449,14 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
|
|||||||
gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
|
gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
|
||||||
|
|
||||||
mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
|
mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
|
||||||
gc = gdk_gc_new (mask);
|
cr = gdk_cairo_create (mask);
|
||||||
col.pixel = 1;
|
|
||||||
gdk_gc_set_foreground (gc, &col);
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
||||||
gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
|
cairo_paint (cr);
|
||||||
col.pixel = 0;
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||||
gdk_gc_set_foreground(gc, &col);
|
cairo_rectangle (cr, 1, 1, width - 2, height - 2);
|
||||||
gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
|
cairo_stroke (cr);
|
||||||
g_object_unref (gc);
|
cairo_destroy (cr);
|
||||||
|
|
||||||
gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
|
gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
|
||||||
mask, 0, 0);
|
mask, 0, 0);
|
||||||
@ -3468,10 +3466,6 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
|
|||||||
}
|
}
|
||||||
else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
|
else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
|
||||||
{
|
{
|
||||||
gint i, j = 1;
|
|
||||||
GdkGC *gc;
|
|
||||||
GdkColor col;
|
|
||||||
|
|
||||||
width = tree_view->priv->expander_size;
|
width = tree_view->priv->expander_size;
|
||||||
|
|
||||||
/* Get x, y, width, height of arrow */
|
/* Get x, y, width, height of arrow */
|
||||||
@ -3514,25 +3508,20 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
|
|||||||
gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
|
gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
|
||||||
|
|
||||||
mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
|
mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
|
||||||
gc = gdk_gc_new (mask);
|
cr = gdk_cairo_create (mask);
|
||||||
col.pixel = 1;
|
|
||||||
gdk_gc_set_foreground (gc, &col);
|
|
||||||
gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
|
|
||||||
|
|
||||||
/* Draw the 2 arrows as per above */
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
||||||
col.pixel = 0;
|
cairo_paint (cr);
|
||||||
gdk_gc_set_foreground (gc, &col);
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||||
for (i = 0; i < width; i ++)
|
cairo_move_to (cr, 0, 0);
|
||||||
{
|
cairo_line_to (cr, width, 0);
|
||||||
if (i == (width/2 - 1))
|
cairo_line_to (cr, width / 2., width / 2);
|
||||||
continue;
|
cairo_move_to (cr, 0, height);
|
||||||
gdk_draw_line (mask, gc, i, j, i, height - j);
|
cairo_line_to (cr, width, height);
|
||||||
if (i < (width/2 - 1))
|
cairo_line_to (cr, width / 2., height - width / 2.);
|
||||||
j++;
|
cairo_fill (cr);
|
||||||
else
|
|
||||||
j--;
|
cairo_destroy (cr);
|
||||||
}
|
|
||||||
g_object_unref (gc);
|
|
||||||
gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
|
gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
|
||||||
mask, 0, 0);
|
mask, 0, 0);
|
||||||
if (mask) g_object_unref (mask);
|
if (mask) g_object_unref (mask);
|
||||||
@ -3544,10 +3533,6 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
|
|||||||
else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
|
else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
|
||||||
arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
|
arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
|
||||||
{
|
{
|
||||||
gint i, j = 1;
|
|
||||||
GdkGC *gc;
|
|
||||||
GdkColor col;
|
|
||||||
|
|
||||||
width = tree_view->priv->expander_size;
|
width = tree_view->priv->expander_size;
|
||||||
|
|
||||||
/* Get x, y, width, height of arrow */
|
/* Get x, y, width, height of arrow */
|
||||||
@ -3589,28 +3574,26 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
|
|||||||
gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
|
gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
|
||||||
|
|
||||||
mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
|
mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
|
||||||
gc = gdk_gc_new (mask);
|
cr = gdk_cairo_create (mask);
|
||||||
col.pixel = 1;
|
|
||||||
gdk_gc_set_foreground (gc, &col);
|
|
||||||
gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
|
|
||||||
|
|
||||||
/* Draw the 2 arrows as per above */
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
||||||
col.pixel = 0;
|
cairo_paint (cr);
|
||||||
gdk_gc_set_foreground (gc, &col);
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||||
j = tree_view->priv->expander_size;
|
/* mirror if we're on the left */
|
||||||
for (i = 0; i < width; i ++)
|
if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
|
||||||
{
|
{
|
||||||
gint k;
|
cairo_translate (cr, width, 0);
|
||||||
if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
|
cairo_scale (cr, -1, 1);
|
||||||
k = width - i - 1;
|
}
|
||||||
else
|
cairo_move_to (cr, 0, 0);
|
||||||
k = i;
|
cairo_line_to (cr, width, width);
|
||||||
gdk_draw_line (mask, gc, k, j, k, height - j);
|
cairo_line_to (cr, 0, tree_view->priv->expander_size);
|
||||||
gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
|
cairo_move_to (cr, 0, height);
|
||||||
gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
|
cairo_line_to (cr, width, height - width);
|
||||||
j--;
|
cairo_line_to (cr, 0, height - tree_view->priv->expander_size);
|
||||||
}
|
cairo_fill (cr);
|
||||||
g_object_unref (gc);
|
|
||||||
|
cairo_destroy (cr);
|
||||||
gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
|
gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
|
||||||
mask, 0, 0);
|
mask, 0, 0);
|
||||||
if (mask) g_object_unref (mask);
|
if (mask) g_object_unref (mask);
|
||||||
|
Loading…
Reference in New Issue
Block a user