[gtk/wip/otte/listview-colors: 5/9] gtk-demo: Make colors demo contain all 16, 777, 216 colors
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview-colors: 5/9] gtk-demo: Make colors demo contain all 16, 777, 216 colors
- Date: Sun, 21 Jun 2020 04:23:09 +0000 (UTC)
commit 47f61f7f21e5301fd03fd72a6a71174150e20379
Author: Benjamin Otte <otte redhat com>
Date: Fri Jun 19 03:59:59 2020 +0200
gtk-demo: Make colors demo contain all 16,777,216 colors
This makes it slightly slow, so not sure it should stay like this.
demos/gtk-demo/listview_colors.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c
index 1f0320ba31..b7b5263158 100644
--- a/demos/gtk-demo/listview_colors.c
+++ b/demos/gtk-demo/listview_colors.c
@@ -313,11 +313,14 @@ create_colors_model (void)
GBytes *data;
char **lines;
guint i;
+ GHashTable *names;
result = g_list_store_new (GTK_TYPE_COLOR);
data = g_resources_lookup_data ("/listview_colors/color.names.txt", 0, NULL);
lines = g_strsplit (g_bytes_get_data (data, NULL), "\n", 0);
+ names = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
+
for (i = 0; lines[i]; i++)
{
const char *name;
@@ -333,14 +336,30 @@ create_colors_model (void)
green = atoi (fields[4]);
blue = atoi (fields[5]);
- color = gtk_color_new (name, red / 255., green / 255., blue / 255.);
- g_list_store_append (result, color);
- g_object_unref (color);
+ g_hash_table_insert (names, GUINT_TO_POINTER (((red & 0xFF) << 16) | ((green & 0xFF) << 8) | blue),
g_strdup (name));
g_strfreev (fields);
}
g_strfreev (lines);
+ for (i = 0; i < 0x1000000; i++)
+ {
+ guint red, green, blue;
+ const char *name;
+
+ red = (i >> 16) & 0xFF;
+ green = (i >> 8) & 0xFF;
+ blue = i & 0xFF;
+ name = g_hash_table_lookup (names, GUINT_TO_POINTER (i));
+ if (name == NULL)
+ name = "";
+
+ color = gtk_color_new (name, red / 255., green / 255., blue / 255.);
+ g_list_store_append (result, color);
+ g_object_unref (color);
+ }
+
+ g_hash_table_unref (names);
g_bytes_unref (data);
return G_LIST_MODEL (result);
@@ -591,7 +610,9 @@ do_listview_colors (GtkWidget *do_widget)
gtk_drop_down_set_model (GTK_DROP_DOWN (dropdown), G_LIST_MODEL (sorters));
g_object_unref (sorters);
+#if 0
g_object_bind_property (dropdown, "selected-item", model, "sorter", G_BINDING_SYNC_CREATE);
+#endif
factories = g_list_store_new (GTK_TYPE_LIST_ITEM_FACTORY);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]