Skip to content

Commit

Permalink
Re-arrange code
Browse files Browse the repository at this point in the history
declare `get_color_from_theme()` to be available in common.h
prepare to consolidate color and interpolation methods
  • Loading branch information
x42 committed Aug 28, 2019
1 parent 36e3664 commit c33ae02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gtk2/common_cgtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void get_color_from_gtk (GdkColor *c, int which) {
static float robtk_colorcache[3][4];
static bool robtk_colorcached[3] = { false, false, false };

void get_color_from_theme (int which, float *col) {
static void get_color_from_theme (int which, float *col) {
GdkColor color;
assert(which >= 0 && which <= 2);

Expand Down
9 changes: 1 addition & 8 deletions robtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,7 @@ static void rect_combine(const cairo_rectangle_t *r1, const cairo_rectangle_t *r
dest->y = dest_y;
}

static float rtk_hue2rgb(const float p, const float q, float t) {
if(t < 0.f) t += 1.f;
if(t > 1.f) t -= 1.f;
if(t < 1.f/6.f) return p + (q - p) * 6.f * t;
if(t < 1.f/2.f) return q;
if(t < 2.f/3.f) return p + (q - p) * (2.f/3.f - t) * 6.f;
return p;
}
static void get_color_from_theme (int which, float *col);

#include "rtk/style.h"
#include "rtk/common.h"
Expand Down
9 changes: 9 additions & 0 deletions rtk/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
#include <string.h>
#include <math.h>

static float rtk_hue2rgb(const float p, const float q, float t) {
if(t < 0.f) t += 1.f;
if(t > 1.f) t -= 1.f;
if(t < 1.f/6.f) return p + (q - p) * 6.f * t;
if(t < 1.f/2.f) return q;
if(t < 2.f/3.f) return p + (q - p) * (2.f/3.f - t) * 6.f;
return p;
}

static void get_interpolate_color (float* c, const float* c1, const float* c2, float f) {
assert (f >= 0.f && f <= 1.f);
c[0] = c1[0] + f * (c2[0] - c1[0]);
Expand Down

0 comments on commit c33ae02

Please sign in to comment.