ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.c File Reference
#include "../ckb/ckb-anim.h"
#include <math.h>
+ Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define ANIM_MAX   (144 * 2)
 

Functions

void ckb_info ()
 
void ckb_init (ckb_runctx *context)
 
void ckb_parameter (ckb_runctx *context, const char *name, const char *value)
 
void anim_add (float x, float y)
 
void anim_remove (float x, float y)
 
void ckb_keypress (ckb_runctx *context, ckb_key *key, int x, int y, int state)
 
void ckb_start (ckb_runctx *context, int state)
 
void ckb_time (ckb_runctx *context, double delta)
 
int ckb_frame (ckb_runctx *context)
 

Variables

ckb_gradient animcolor = { 0 }
 
int symmetric = 0
 
int kprelease = 0
 
double angle = 0.
 
double left = 0.
 
double top = 0.
 
double animlength = 0.
 
double width = 0.
 
struct {
int active
 
float x
 
float y
 
float curx
 
anim [(144 *2)] = { }
 

Macro Definition Documentation

#define ANIM_MAX   (144 * 2)

Definition at line 98 of file main.c.

Referenced by anim_add(), anim_remove(), ckb_frame(), and ckb_time().

Function Documentation

void anim_add ( float  x,
float  y 
)

Definition at line 105 of file main.c.

References anim, ANIM_MAX, animlength, symmetric, width, x, and y.

105  {
106  for(int i = 0; i < ANIM_MAX; i++){
107  if(anim[i].active)
108  continue;
109  anim[i].active = 1;
110  anim[i].x = x;
111  anim[i].y = y;
112  anim[i].curx = symmetric ? -animlength * width : 0.f;
113  return;
114  }
115 }
#define ANIM_MAX
Definition: main.c:98
float y
Definition: main.c:66
float x
Definition: main.c:66
double width
Definition: main.c:52
int symmetric
Definition: main.c:41
double animlength
Definition: main.c:40
struct keyAnim * anim
Definition: main.c:55
void anim_remove ( float  x,
float  y 
)

Definition at line 117 of file main.c.

References anim, and ANIM_MAX.

117  {
118  for(int i = 0; i < ANIM_MAX; i++){
119  if(anim[i].active && anim[i].x == x && anim[i].y == y)
120  anim[i].active = 0;
121  }
122 }
#define ANIM_MAX
Definition: main.c:98
float y
Definition: main.c:66
float x
Definition: main.c:66
struct keyAnim * anim
Definition: main.c:55
int ckb_frame ( ckb_runctx context)

Definition at line 152 of file main.c.

References angle, anim, ANIM_MAX, animlength, ckb_alpha_blend(), ckb_grad_color(), CKB_KEYCLEAR, ckb_runctx::keycount, ckb_runctx::keys, symmetric, width, x, and y.

Referenced by main().

152  {
153  CKB_KEYCLEAR(context);
154  // Draw keys
155  double length = animlength * width;
156  unsigned count = context->keycount;
157  ckb_key* keys = context->keys;
158  for(unsigned i = 0; i < ANIM_MAX; i++){
159  if(anim[i].active){
160  for(ckb_key* key = keys; key < keys + count; key++){
161  // Translate and rotate the key position into the animation's coordinate system
162  float x = key->x - anim[i].x, y = key->y - anim[i].y;
163  // Distance is the current X minus the key's X
164  float distance = anim[i].curx - (x * cos(angle) - y * sin(angle));
165  distance /= length;
166  // If symmetric, use absolute distance
167  if(symmetric)
168  distance = fabs(distance);
169  else if(distance >= -0.005f && distance < 0.f)
170  // If not symmetric, round values close to 0
171  distance = 0.f;
172  if(distance > 1.f && distance <= 1.005f)
173  // Round values close to 1
174  distance = 1.f;
175  // Pick gradient position based on distance
176  if(distance <= 1.f && distance >= 0.){
177  float a, r, g, b;
178  ckb_grad_color(&a, &r, &g, &b, &animcolor, distance * 100.);
179  ckb_alpha_blend(key, a, r, g, b);
180  }
181  }
182  }
183  }
184  return 0;
185 }
#define ANIM_MAX
Definition: main.c:98
float y
Definition: main.c:66
float x
Definition: main.c:66
ckb_gradient animcolor
Definition: main.c:52
double width
Definition: main.c:52
Definition: keymap.h:49
unsigned keycount
Definition: ckb-anim.h:141
double angle
Definition: main.c:50
int symmetric
Definition: main.c:41
#define CKB_KEYCLEAR(context)
Definition: ckb-anim.h:148
ckb_key * keys
Definition: ckb-anim.h:140
void ckb_alpha_blend(ckb_key *key, float a, float r, float g, float b)
Definition: ckb-anim.h:283
double animlength
Definition: main.c:40
void ckb_grad_color(float *a, float *r, float *g, float *b, const ckb_gradient *grad, float pos)
Definition: ckb-anim.h:254
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ckb_info ( )

Definition at line 4 of file main.c.

References CKB_COPYRIGHT, CKB_DESCRIPTION, CKB_GUID, CKB_KP_POSITION, CKB_KPMODE, CKB_LICENSE, CKB_LIVEPARAMS, CKB_NAME, CKB_PARAM_AGRADIENT, CKB_PARAM_ANGLE, CKB_PARAM_BOOL, CKB_PARAM_DOUBLE, CKB_PREEMPT, CKB_PRESET_END, CKB_PRESET_PARAM, CKB_PRESET_START, CKB_TIME_DURATION, CKB_TIMEMODE, CKB_VERSION, and TRUE.

Referenced by main().

4  {
5  // Plugin info
6  CKB_NAME("Wave");
7  CKB_VERSION("0.10");
8  CKB_COPYRIGHT("2014-2016", "MSC");
9  CKB_LICENSE("GPLv2");
10  CKB_GUID("{E0BBA19E-C328-4C0E-8E3C-A06D5722B4FC}");
11  CKB_DESCRIPTION("A moving wave effect.");
12 
13  // Effect parameters
14  CKB_PARAM_ANGLE("angle", "Angle:", "", 90);
15  CKB_PARAM_AGRADIENT("color", "Wave color:", "", "ffffffff");
16  CKB_PARAM_DOUBLE("length", "Wave length:", "%", 100, 1., 100.);
17  CKB_PARAM_BOOL("symmetric", "Symmetric", 0);
18 
19  // Timing/input parameters
24 
25  // Presets
26  CKB_PRESET_START("Shimmer");
27  CKB_PRESET_PARAM("duration", "2.0");
28  CKB_PRESET_PARAM("length", "50.0");
29  CKB_PRESET_PARAM("symmetric", "1");
31 
32  CKB_PRESET_START("Rainbow");
33  CKB_PRESET_PARAM("color", "0:ffff0000 17:ffffff00 33:ff00ff00 50:ff00ffff 67:ff0000ff 83:ffff00ff 100:ffff0000");
34  CKB_PRESET_PARAM("duration", "2.0");
36 
37  CKB_PRESET_START("Vertical rainbow");
38  CKB_PRESET_PARAM("color", "0:ffff0000 17:ffffff00 33:ff00ff00 50:ff00ffff 67:ff0000ff 83:ffff00ff 100:ffff0000");
39  CKB_PRESET_PARAM("duration", "2.0");
40  CKB_PRESET_PARAM("angle", "180");
42 }
#define CKB_PRESET_END
Definition: ckb-anim.h:87
#define CKB_PARAM_DOUBLE(name, prefix, postfix, default, min, max)
Definition: ckb-anim.h:75
#define CKB_VERSION(version)
Definition: ckb-anim.h:64
#define CKB_TIMEMODE(mode)
Definition: ckb-anim.h:97
#define TRUE
Definition: ckb-anim.h:46
#define CKB_GUID(guid)
Definition: ckb-anim.h:60
#define CKB_NAME(name)
Definition: ckb-anim.h:62
#define CKB_PARAM_ANGLE(name, prefix, postfix, default)
Definition: ckb-anim.h:81
#define CKB_LICENSE(license)
Definition: ckb-anim.h:68
#define CKB_KP_POSITION
Definition: ckb-anim.h:92
#define CKB_COPYRIGHT(year, author)
Definition: ckb-anim.h:66
#define CKB_DESCRIPTION(description)
Definition: ckb-anim.h:70
#define CKB_PRESET_START(name)
Definition: ckb-anim.h:85
#define CKB_PREEMPT(enable)
Definition: ckb-anim.h:102
#define CKB_KPMODE(mode)
Definition: ckb-anim.h:93
#define CKB_PARAM_AGRADIENT(name, prefix, postfix, default)
Definition: ckb-anim.h:80
#define CKB_LIVEPARAMS(enable)
Definition: ckb-anim.h:104
#define CKB_TIME_DURATION
Definition: ckb-anim.h:95
#define CKB_PRESET_PARAM(name, value)
Definition: ckb-anim.h:86
#define CKB_PARAM_BOOL(name, text, default)
Definition: ckb-anim.h:76

+ Here is the caller graph for this function:

void ckb_init ( ckb_runctx context)

Definition at line 44 of file main.c.

Referenced by main().

44  {
45  // Nothing to do
46 }

+ Here is the caller graph for this function:

void ckb_keypress ( ckb_runctx context,
ckb_key key,
int  x,
int  y,
int  state 
)

Definition at line 124 of file main.c.

References anim_add(), and anim_remove().

Referenced by main().

124  {
125  // Start or stop animation on a key
126  if(state)
127  anim_add(x, y);
128  else
129  anim_remove(x, y);
130 }
float y
Definition: main.c:66
float x
Definition: main.c:66
void anim_remove(int index)
Definition: main.c:87
void anim_add(int index)
Definition: main.c:81

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ckb_parameter ( ckb_runctx context,
const char *  name,
const char *  value 
)

Definition at line 54 of file main.c.

References angle, animlength, CKB_PARSE_AGRADIENT, CKB_PARSE_ANGLE, CKB_PARSE_BOOL, CKB_PARSE_DOUBLE, CKB_REAL_ANGLE, ckb_runctx::height, kprelease, left, symmetric, top, width, ckb_runctx::width, x, and y.

Referenced by ckb_read_params().

54  {
55  CKB_PARSE_AGRADIENT("color", &animcolor){}
56  double len;
57  CKB_PARSE_DOUBLE("length", &len){
58  animlength = len / 100.;
59  }
60  CKB_PARSE_BOOL("symmetric", &symmetric){}
61  CKB_PARSE_BOOL("kprelease", &kprelease){}
62  long _angle;
63  CKB_PARSE_ANGLE("angle", &_angle){
64  angle = CKB_REAL_ANGLE(_angle);
65  // Get each of the four corners of the keyboard, relative to the center
66  double wOver2 = context->width / 2., hOver2 = context->height / 2.;
67  double x[4] = {
68  -wOver2, wOver2,
69  -wOver2, wOver2
70  };
71  double y[4] = {
72  -hOver2, -hOver2,
73  hOver2, hOver2
74  };
75  // Rotate them in the direction that the animation will travel
76  for(int i = 0; i < 4; i++){
77  double x2 = x[i] * cos(angle) - y[i] * sin(angle);
78  y[i] = x[i] * sin(angle) + y[i] * cos(angle);
79  x[i] = x2;
80  }
81  // Determine the leftmost and rightmost points
82  double min_x = INFINITY, max_x = -INFINITY;
83  for(int i = 0; i < 4; i++){
84  if(x[i] < min_x)
85  min_x = x[i];
86  if(x[i] > max_x)
87  max_x = x[i];
88  }
89  // The leftmost point is where the animation will begin when started with the mode,
90  // and the difference between the two is the animation width.
91  // Animations always travel left to right in their own coordinate system.
92  left = min_x * cos(-angle) + wOver2;
93  top = min_x * sin(-angle) + hOver2;
94  width = max_x - min_x;
95  }
96 }
float y
Definition: main.c:66
float x
Definition: main.c:66
ckb_gradient animcolor
Definition: main.c:52
double width
Definition: main.c:52
#define CKB_PARSE_AGRADIENT(param_name, gradient_ptr)
Definition: ckb-anim.h:121
unsigned height
Definition: ckb-anim.h:143
double top
Definition: main.c:51
double angle
Definition: main.c:50
int symmetric
Definition: main.c:41
double left
Definition: main.c:51
#define CKB_PARSE_BOOL(param_name, value_ptr)
Definition: ckb-anim.h:117
#define CKB_PARSE_ANGLE(param_name, value_ptr)
Definition: ckb-anim.h:122
int kprelease
Definition: main.c:53
#define CKB_PARSE_DOUBLE(param_name, value_ptr)
Definition: ckb-anim.h:116
unsigned width
Definition: ckb-anim.h:143
double animlength
Definition: main.c:40
#define CKB_REAL_ANGLE(angle)
Definition: ckb-anim.h:127

+ Here is the caller graph for this function:

void ckb_start ( ckb_runctx context,
int  state 
)

Definition at line 132 of file main.c.

References anim_add(), anim_remove(), kprelease, left, and top.

Referenced by main().

132  {
133  // Start or stop animation on the edge of the keyboard
134  if(state)
135  anim_add(left, top);
136  else if(kprelease)
137  anim_remove(left, top);
138 }
double top
Definition: main.c:51
double left
Definition: main.c:51
void anim_remove(int index)
Definition: main.c:87
void anim_add(int index)
Definition: main.c:81
int kprelease
Definition: main.c:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ckb_time ( ckb_runctx context,
double  delta 
)

Definition at line 140 of file main.c.

References anim, ANIM_MAX, animlength, and width.

Referenced by main().

140  {
141  // Advance all waves, remove them if they pass the edge
142  double length = animlength * width;
143  for(unsigned i = 0; i < ANIM_MAX; i++){
144  if(anim[i].active){
145  anim[i].curx += width * delta;
146  if(anim[i].curx > width + length)
147  anim[i].active = 0;
148  }
149  }
150 }
#define ANIM_MAX
Definition: main.c:98
double width
Definition: main.c:52
double animlength
Definition: main.c:40
struct keyAnim * anim
Definition: main.c:55

+ Here is the caller graph for this function:

Variable Documentation

double angle = 0.

Definition at line 50 of file main.c.

Referenced by angleFlip(), ckb_frame(), and ckb_parameter().

struct { ... } anim[ (144 * 2) ]
ckb_gradient animcolor = { 0 }

Definition at line 48 of file main.c.

double animlength = 0.

Definition at line 52 of file main.c.

int kprelease = 0

Definition at line 49 of file main.c.

double left = 0.
int symmetric = 0

Definition at line 49 of file main.c.

double top = 0.

Definition at line 51 of file main.c.

Referenced by ckb_parameter(), ckb_start(), and GradientDialogWidget::mouseMoveEvent().