This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository evisum.

View the commit online.

commit dce74a8eae24b83965dc5cfbbf512d1699d2b9d6
Author: Alastair Poole <m...@alastairpoole.com>
AuthorDate: Sat Mar 22 12:11:24 2025 +0000

    colors: Let's not repeat ourselves here.
    
    This is necessary if we're going to add another element that
    does this.
---
 src/bin/ui/evisum_ui.c        |  2 ++
 src/bin/ui/evisum_ui_colors.c | 56 +++++++++++++++++++++++++++++
 src/bin/ui/evisum_ui_colors.h | 52 +++++++++++++++++++++++++++
 src/bin/ui/meson.build        |  2 ++
 src/bin/ui/ui_cpu.c           | 84 -------------------------------------------
 src/bin/ui/ui_cpu.h           | 16 +--------
 src/bin/ui/ui_process_view.c  | 75 +++-----------------------------------
 7 files changed, 117 insertions(+), 170 deletions(-)

diff --git a/src/bin/ui/evisum_ui.c b/src/bin/ui/evisum_ui.c
index e231a4f..91180b1 100644
--- a/src/bin/ui/evisum_ui.c
+++ b/src/bin/ui/evisum_ui.c
@@ -6,6 +6,7 @@
 #include "system/filesystems.h"
 
 #include "evisum_ui.h"
+#include "ui/evisum_ui_colors.h"
 #include "ui/ui_cpu.h"
 #include "ui/ui_memory.h"
 #include "ui/ui_disk.h"
@@ -815,6 +816,7 @@ evisum_ui_init(void)
    EVISUM_EVENT_CONFIG_CHANGED = ecore_event_type_new();
 
    config_init();
+   evisum_ui_colors_init();
    evisum_ui_config_load(ui);
 
    _ui_init_system_probe(ui);
diff --git a/src/bin/ui/evisum_ui_colors.c b/src/bin/ui/evisum_ui_colors.c
new file mode 100644
index 0000000..28d692d
--- /dev/null
+++ b/src/bin/ui/evisum_ui_colors.c
@@ -0,0 +1,56 @@
+#include "evisum_ui_colors.h"
+#include "config.h"
+
+unsigned int cpu_colormap[256];
+unsigned int freq_colormap[256];
+unsigned int temp_colormap[256];
+
+static void
+_evisum_ui_colors_init(const Color_Point *col_in, unsigned int n, unsigned int *col)
+{
+   unsigned int pos, interp, val, dist, d;
+   unsigned int a, r, g, b;
+   unsigned int a1, r1, g1, b1, v1;
+   unsigned int a2, r2, g2, b2, v2;
+
+   // wal colormap_in until colormap table is full
+   for (pos = 0, val = 0; pos < n; pos++)
+     {
+        // get first color and value position
+        v1 = col_in[pos].val;
+        a1 = AVAL(col_in[pos].color);
+        r1 = RVAL(col_in[pos].color);
+        g1 = GVAL(col_in[pos].color);
+        b1 = BVAL(col_in[pos].color);
+        // get second color and valuje position
+        v2 = col_in[pos + 1].val;
+        a2 = AVAL(col_in[pos + 1].color);
+        r2 = RVAL(col_in[pos + 1].color);
+        g2 = GVAL(col_in[pos + 1].color);
+        b2 = BVAL(col_in[pos + 1].color);
+        // get distance between values (how many entires to fill)
+        dist = v2 - v1;
+        // walk over the span of colors from point a to point b
+        for (interp = v1; interp < v2; interp++)
+          {
+             // distance from starting point
+             d = interp - v1;
+             // calculate linear interpolation between start and given d
+             a = ((d * a2) + ((dist - d) * a1)) / dist;
+             r = ((d * r2) + ((dist - d) * r1)) / dist;
+             g = ((d * g2) + ((dist - d) * g1)) / dist;
+             b = ((d * b2) + ((dist - d) * b1)) / dist;
+             // write out resulting color value
+             col[val] = ARGB(a, r, g, b);
+             val++;
+          }
+     }
+}
+
+void evisum_ui_colors_init(void)
+{
+    _evisum_ui_colors_init(cpu_colormap_in, COLOR_CPU_NUM, cpu_colormap);
+    _evisum_ui_colors_init(freq_colormap_in, COLOR_FREQ_NUM, freq_colormap);
+    _evisum_ui_colors_init(temp_colormap_in, COLOR_TEMP_NUM, temp_colormap);
+}
+
diff --git a/src/bin/ui/evisum_ui_colors.h b/src/bin/ui/evisum_ui_colors.h
new file mode 100644
index 0000000..33ff5f7
--- /dev/null
+++ b/src/bin/ui/evisum_ui_colors.h
@@ -0,0 +1,52 @@
+#ifndef __EVISUM_UI_COLORS_H__
+#define __EVISUM_UI_COLORS_H__
+
+#include "evisum_ui.h"
+#include "../system/machine.h"
+
+typedef struct _Color_Point {
+   unsigned int val;
+   unsigned int color;
+} Color_Point;
+
+extern unsigned int cpu_colormap[256];
+extern unsigned int freq_colormap[256];
+extern unsigned int temp_colormap[256];
+
+#define AVAL(x) (((x) >> 24) & 0xff)
+#define RVAL(x) (((x) >> 16) & 0xff)
+#define GVAL(x) (((x) >>  8) & 0xff)
+#define BVAL(x) (((x)      ) & 0xff)
+#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
+
+#define COLOR_CPU_NUM 5
+static const Color_Point cpu_colormap_in[] = {
+   {   0, 0xff202020 },
+   {  25, 0xff2030a0 },
+   {  50, 0xffa040a0 },
+   {  75, 0xffff9040 },
+   { 100, 0xffffffff },
+   { 256, 0xffffffff }
+};
+#define COLOR_FREQ_NUM 4
+static const Color_Point freq_colormap_in[] = {
+   {   0, 0xff202020 },
+   {  33, 0xff285020 },
+   {  67, 0xff30a060 },
+   { 100, 0xffa0ff80 },
+   { 256, 0xffa0ff80 }
+};
+
+#define COLOR_TEMP_NUM 5
+static const Color_Point temp_colormap_in[] = {
+   {  0,  0xff57bb8a },
+   {  25, 0xffa4c073 },
+   {  50, 0xfff5ce62 },
+   {  75, 0xffe9a268 },
+   { 100, 0xffdd776e },
+   { 256, 0xffdd776e }
+};
+
+void evisum_ui_colors_init();
+
+#endif
diff --git a/src/bin/ui/meson.build b/src/bin/ui/meson.build
index 21eb116..7fcaada 100644
--- a/src/bin/ui/meson.build
+++ b/src/bin/ui/meson.build
@@ -2,6 +2,8 @@ src += files([
    'gettext.h',
    'evisum_ui.h',
    'evisum_ui.c',
+   'evisum_ui_colors.c',
+   'evisum_ui_colors.h',
    'ui_util.h',
    'ui_util.c',
    'ui_cache.c',
diff --git a/src/bin/ui/ui_cpu.c b/src/bin/ui/ui_cpu.c
index cdc234b..747434e 100644
--- a/src/bin/ui/ui_cpu.c
+++ b/src/bin/ui/ui_cpu.c
@@ -5,38 +5,6 @@
 #include "visuals/visuals.x"
 
 // config for colors/sizing
-#define COLOR_CPU_NUM 5
-static const Color_Point cpu_colormap_in[] = {
-   {   0, 0xff202020 },
-   {  25, 0xff2030a0 },
-   {  50, 0xffa040a0 },
-   {  75, 0xffff9040 },
-   { 100, 0xffffffff },
-   { 256, 0xffffffff }
-};
-#define COLOR_FREQ_NUM 4
-static const Color_Point freq_colormap_in[] = {
-   {   0, 0xff202020 },
-   {  33, 0xff285020 },
-   {  67, 0xff30a060 },
-   { 100, 0xffa0ff80 },
-   { 256, 0xffa0ff80 }
-};
-
-#define COLOR_TEMP_NUM 5
-static const Color_Point temp_colormap_in[] = {
-   {  0,  0xff57bb8a },
-   {  25, 0xffa4c073 },
-   {  50, 0xfff5ce62 },
-   {  75, 0xffe9a268 },
-   { 100, 0xffdd776e },
-   { 256, 0xffdd776e }
-};
-
-unsigned int cpu_colormap[256];
-unsigned int freq_colormap[256];
-unsigned int temp_colormap[256];
-
 static void
 _win_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
 {
@@ -130,48 +98,6 @@ _win_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void
    ui->cpu.win = NULL;
 }
 
-static void
-_color_init(const Color_Point *col_in, unsigned int n, unsigned int *col)
-{
-   unsigned int pos, interp, val, dist, d;
-   unsigned int a, r, g, b;
-   unsigned int a1, r1, g1, b1, v1;
-   unsigned int a2, r2, g2, b2, v2;
-
-   // wal colormap_in until colormap table is full
-   for (pos = 0, val = 0; pos < n; pos++)
-     {
-        // get first color and value position
-        v1 = col_in[pos].val;
-        a1 = AVAL(col_in[pos].color);
-        r1 = RVAL(col_in[pos].color);
-        g1 = GVAL(col_in[pos].color);
-        b1 = BVAL(col_in[pos].color);
-        // get second color and valuje position
-        v2 = col_in[pos + 1].val;
-        a2 = AVAL(col_in[pos + 1].color);
-        r2 = RVAL(col_in[pos + 1].color);
-        g2 = GVAL(col_in[pos + 1].color);
-        b2 = BVAL(col_in[pos + 1].color);
-        // get distance between values (how many entires to fill)
-        dist = v2 - v1;
-        // walk over the span of colors from point a to point b
-        for (interp = v1; interp < v2; interp++)
-          {
-             // distance from starting point
-             d = interp - v1;
-             // calculate linear interpolation between start and given d
-             a = ((d * a2) + ((dist - d) * a1)) / dist;
-             r = ((d * r2) + ((dist - d) * r1)) / dist;
-             g = ((d * g2) + ((dist - d) * g1)) / dist;
-             b = ((d * b2) + ((dist - d) * b1)) / dist;
-             // write out resulting color value
-             col[val] = ARGB(a, r, g, b);
-             val++;
-          }
-     }
-}
-
 Eina_List *
 ui_cpu_visuals_get(void)
 {
@@ -213,7 +139,6 @@ ui_cpu_win_add(Evisum_Ui *ui)
    Evas_Object *tb;
    Elm_Layout *lay;
    Cpu_Visual *vis;
-   static Eina_Bool init = 0;
 
    if (ui->cpu.win)
      {
@@ -221,15 +146,6 @@ ui_cpu_win_add(Evisum_Ui *ui)
         return;
      }
 
-   if (!init)
-     {
-        // init colormaps from a small # of points
-        _color_init(cpu_colormap_in, COLOR_CPU_NUM, cpu_colormap);
-        _color_init(freq_colormap_in, COLOR_FREQ_NUM, freq_colormap);
-        _color_init(temp_colormap_in, COLOR_TEMP_NUM, temp_colormap);
-        init = 1;
-     }
-
    ui->cpu.win = win = elm_win_util_standard_add("evisum",
                    _("CPU Activity"));
    elm_win_autodel_set(win, 1);
diff --git a/src/bin/ui/ui_cpu.h b/src/bin/ui/ui_cpu.h
index 346c537..9bbaf9b 100644
--- a/src/bin/ui/ui_cpu.h
+++ b/src/bin/ui/ui_cpu.h
@@ -2,23 +2,9 @@
 #define __UI_CPU_H__
 
 #include "evisum_ui.h"
+#include "evisum_ui_colors.h"
 #include "../system/machine.h"
 
-typedef struct _Color_Point {
-   unsigned int val;
-   unsigned int color;
-} Color_Point;
-
-extern unsigned int cpu_colormap[256];
-extern unsigned int freq_colormap[256];
-extern unsigned int temp_colormap[256];
-
-#define AVAL(x) (((x) >> 24) & 0xff)
-#define RVAL(x) (((x) >> 16) & 0xff)
-#define GVAL(x) (((x) >>  8) & 0xff)
-#define BVAL(x) (((x)      ) & 0xff)
-#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
-
 typedef struct {
    short id;
    short percent;
diff --git a/src/bin/ui/ui_process_view.c b/src/bin/ui/ui_process_view.c
index 3f0304d..37f78d6 100644
--- a/src/bin/ui/ui_process_view.c
+++ b/src/bin/ui/ui_process_view.c
@@ -1,4 +1,5 @@
 #include "ui_process_view.h"
+#include "evisum_ui_colors.h"
 #include "../system/process.h"
 #include "util.c"
 #define __STDC_FORMAT_MACROS
@@ -70,7 +71,6 @@ typedef struct
       struct
       {
          int           cpu_count;
-         unsigned int  cpu_colormap[256];
          unsigned int  cores[256];
          Evas_Object   *obj;
          Evas_Object   *lb;
@@ -97,71 +97,6 @@ typedef struct
 
 } Win_Data;
 
-typedef struct _Color_Point {
-   unsigned int val;
-   unsigned int color;
-} Color_Point;
-
-#define COLOR_CPU_NUM 5
-static const Color_Point cpu_colormap_in[] = {
-   {   0, 0xff202020 },
-   {  25, 0xff2030a0 },
-   {  50, 0xffa040a0 },
-   {  75, 0xffff9040 },
-   { 100, 0xffffffff },
-   { 256, 0xffffffff }
-};
-
-#define AVAL(x) (((x) >> 24) & 0xff)
-#define RVAL(x) (((x) >> 16) & 0xff)
-#define GVAL(x) (((x) >>  8) & 0xff)
-#define BVAL(x) (((x)      ) & 0xff)
-#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
-
-#define BAR_HEIGHT 2
-
-static void
-_color_init(const Color_Point *col_in, unsigned int n, unsigned int *col)
-{
-   unsigned int pos, interp, val, dist, d;
-   unsigned int a, r, g, b;
-   unsigned int a1, r1, g1, b1, v1;
-   unsigned int a2, r2, g2, b2, v2;
-
-   // walk colormap_in until colormap table is full
-   for (pos = 0, val = 0; pos < n; pos++)
-     {
-        // get first color and value position
-        v1 = col_in[pos].val;
-        a1 = AVAL(col_in[pos].color);
-        r1 = RVAL(col_in[pos].color);
-        g1 = GVAL(col_in[pos].color);
-        b1 = BVAL(col_in[pos].color);
-        // get second color and valuje position
-        v2 = col_in[pos + 1].val;
-        a2 = AVAL(col_in[pos + 1].color);
-        r2 = RVAL(col_in[pos + 1].color);
-        g2 = GVAL(col_in[pos + 1].color);
-        b2 = BVAL(col_in[pos + 1].color);
-        // get distance between values (how many entires to fill)
-        dist = v2 - v1;
-        // walk over the span of colors from point a to point b
-        for (interp = v1; interp < v2; interp++)
-          {
-             // distance from starting point
-             d = interp - v1;
-             // calculate linear interpolation between start and given d
-             a = ((d * a2) + ((dist - d) * a1)) / dist;
-             r = ((d * r2) + ((dist - d) * r1)) / dist;
-             g = ((d * g2) + ((dist - d) * g1)) / dist;
-             b = ((d * b2) + ((dist - d) * b1)) / dist;
-             // write out resulting color value
-             col[val] = ARGB(a, r, g, b);
-             val++;
-          }
-     }
-}
-
 typedef struct
 {
    long cpu_time;
@@ -743,7 +678,7 @@ _graph_update(Win_Data *wd, Proc_Info *proc)
           {
              pix = &(pixels[y * (stride / 4)]);
              for (x = 0; x < (w - 1); x++)
-               pix[x] = wd->threads.graph.cpu_colormap[0];
+               pix[x] = cpu_colormap[0];
           }
         else
           {
@@ -751,7 +686,7 @@ _graph_update(Win_Data *wd, Proc_Info *proc)
              for (x = 0; x < (w - 1); x++) pix[x] = pix[x + 1];
           }
         unsigned int c1;
-        c1 = wd->threads.graph.cpu_colormap[wd->threads.graph.cores[y] & 0xff];
+        c1 = cpu_colormap[wd->threads.graph.cores[y] & 0xff];
         pix = &(pixels[y * (stride / 4)]);
         pix[x] = c1;
      }
@@ -787,12 +722,10 @@ _graph(Evas_Object *parent, Win_Data *wd)
    evas_object_show(obj);
 
    evas_object_size_hint_min_set(obj, 100,
-                                 (BAR_HEIGHT * wd->threads.graph.cpu_count)
+                                 (2 * wd->threads.graph.cpu_count)
                                   * elm_config_scale_get());
    elm_object_content_set(scr, obj);
 
-   _color_init(cpu_colormap_in, COLOR_CPU_NUM, wd->threads.graph.cpu_colormap);
-
    // Overlay
    fr = elm_frame_add(parent);
    elm_object_style_set(fr, "pad_small");

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to