[gtk/wip/otte/listview-colors: 6/8] gtk-demo: Add a permutation to compute colors from the position
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview-colors: 6/8] gtk-demo: Add a permutation to compute colors from the position
- Date: Sun, 21 Jun 2020 03:28:49 +0000 (UTC)
commit f0bc85d756069b9b693a6dc749d221c6cbfcbeba
Author: Benjamin Otte <otte redhat com>
Date: Sun Jun 21 04:11:24 2020 +0200
gtk-demo: Add a permutation to compute colors from the position
This way, the colors are furthest apart at the start and fill up the
remaining spots towards the end.
demos/gtk-demo/listview_colors.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
---
diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c
index 9ec5dc3328..a50a180d96 100644
--- a/demos/gtk-demo/listview_colors.c
+++ b/demos/gtk-demo/listview_colors.c
@@ -330,6 +330,32 @@ gtk_color_list_get_n_items (GListModel *list)
return N_COLORS;
}
+static guint
+position_to_color (guint position)
+{
+ static guint map[] = {
+ 0xFF0000, 0x00FF00, 0x0000FF,
+ 0x7F0000, 0x007F00, 0x00007F,
+ 0x3F0000, 0x003F00, 0x00003F,
+ 0x1F0000, 0x001F00, 0x00001F,
+ 0x0F0000, 0x000F00, 0x00000F,
+ 0x070000, 0x000700, 0x000007,
+ 0x030000, 0x000300, 0x000003,
+ 0x010000, 0x000100, 0x000001
+ };
+ guint result, i;
+
+ result = 0;
+
+ for (i = 0; i < G_N_ELEMENTS (map); i++)
+ {
+ if (position & (1 << i))
+ result ^= map[i];
+ }
+
+ return result;
+}
+
static gpointer
gtk_color_list_get_item (GListModel *list,
guint position)
@@ -339,6 +365,8 @@ gtk_color_list_get_item (GListModel *list,
if (position >= N_COLORS)
return NULL;
+ position = position_to_color (position);
+
if (self->colors[position] == NULL)
{
guint red, green, blue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]