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
Go to the documentation of this file.
1 #include "../ckb/ckb-anim.h"
2 
3 void ckb_info(){
4  // Plugin info
5  CKB_NAME("Pinwheel");
6  CKB_VERSION("0.9");
7  CKB_COPYRIGHT("2014-2016", "MSC");
8  CKB_LICENSE("GPLv2");
9  CKB_GUID("{07551A90-D97A-4DD0-A770-E9E280A90891}");
10  CKB_DESCRIPTION("A spinning pinwheel effect.");
11 
12  // Effect parameters
13  CKB_PARAM_AGRADIENT("color", "Wheel color:", "", "ffffffff");
14  CKB_PARAM_DOUBLE("length", "Wheel size:", "%", 100, 1., 100.);
15  CKB_PARAM_DOUBLE("x_offset", "X offset:", "%", 0, -100, 100);
16  CKB_PARAM_DOUBLE("y_offset", "Y offset:", "%", 0, -100, 100);
17  CKB_PARAM_BOOL("counter_clock", "Counter Clockwise", 0);
18  CKB_PARAM_BOOL("symmetric", "Symmetric", 0);
19 
20  // Timing/input parameters
25 
26  // Presets
27  CKB_PRESET_START("Search light");
28  CKB_PRESET_PARAM("duration", "2.0");
29  CKB_PRESET_PARAM("length", "50.0");
30  CKB_PRESET_PARAM("symmetric", "1");
32 
33  CKB_PRESET_START("Rainbow");
34  CKB_PRESET_PARAM("color", "0:ffff0000 17:ffffff00 33:ff00ff00 50:ff00ffff 67:ff0000ff 83:ffff00ff 100:ffff0000");
35  CKB_PRESET_PARAM("duration", "2.0");
37 }
38 
40 double animlength = 0.;
41 int symmetric = 0;
42 int counter_clock = 0;
43 double x_offset = 0, y_offset = 0;
44 
45 void ckb_parameter(ckb_runctx* context, const char* name, const char* value){
46  CKB_PARSE_AGRADIENT("color", &animcolor){}
47  double len;
48  CKB_PARSE_DOUBLE("length", &len){
49  animlength = len / 100. * M_PI * 2.;
50  }
51  CKB_PARSE_BOOL("symmetric", &symmetric){}
52  CKB_PARSE_BOOL("counter_clock", &counter_clock){}
53  CKB_PARSE_DOUBLE("x_offset", &x_offset) {}
54  CKB_PARSE_DOUBLE("y_offset", &y_offset) {}
55 }
56 
57 void ckb_init(ckb_runctx* context){
58  // Unused
59 }
60 
61 void ckb_keypress(ckb_runctx* context, ckb_key* key, int x, int y, int state){
62  // Unused
63 }
64 
65 double frame = -1.;
66 float x, y;
67 
68 #define ANGLE(theta) fmod((theta) + M_PI * 2., M_PI * 2.)
69 
70 void ckb_start(ckb_runctx* context, int state){
71  // Begin or end animation
72  frame = state ? 0. : -1.;
73  x = (context->width + (context->width * x_offset * 0.01)) / 2.f;
74  y = (context->height - (context->height * y_offset * 0.01)) / 2.f;
75 }
76 
77 void ckb_time(ckb_runctx* context, double delta){
78  if(frame < 0.)
79  return;
80  // Spin the wheel
81  frame += delta;
82  if(frame > 1.)
83  frame -= 1.;
84 }
85 
86 int ckb_frame(ckb_runctx* context){
87  CKB_KEYCLEAR(context);
88  if(frame < 0.)
89  return 0;
90  // Color each key according to its angle from the center
91  float position;
92  if(counter_clock)
93  position = ANGLE(frame * M_PI * 2.);
94  else
95  position = ANGLE(-frame * M_PI * 2.);
96  unsigned count = context->keycount;
97  ckb_key* keys = context->keys;
98  for(ckb_key* key = keys; key < keys + count; key++){
99  float theta;
100  if(key->x == x && key->y == y)
101  // Dead center = 0°
102  theta = 0.f;
103  else
104  theta = ANGLE(ANGLE(atan2(x - key->x, y - key->y)) - position);
105  // If the animation is symmetric, mirror the second half
106  if(symmetric && theta > M_PI)
107  theta = M_PI * 2. - theta;
108  // Draw the gradient position that corresponds to this angle
109  if(theta < animlength){
110  float distance = theta / animlength;
111  float a, r, g, b;
112  ckb_grad_color(&a, &r, &g, &b, &animcolor, distance * 100.);
113  ckb_alpha_blend(key, a, r, g, b);
114  }
115  }
116  return 0;
117 }
#define CKB_PRESET_END
Definition: ckb-anim.h:87
#define FALSE
Definition: ckb-anim.h:49
void ckb_keypress(ckb_runctx *context, ckb_key *key, int x, int y, int state)
Definition: main.c:75
void ckb_parameter(ckb_runctx *context, const char *name, const char *value)
Definition: main.c:68
#define CKB_PARAM_DOUBLE(name, prefix, postfix, default, min, max)
Definition: ckb-anim.h:75
double frame
Definition: main.c:65
#define CKB_VERSION(version)
Definition: ckb-anim.h:64
#define M_PI
Definition: ckb-anim.h:42
#define CKB_TIMEMODE(mode)
Definition: ckb-anim.h:97
float y
Definition: main.c:66
#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_KP_NONE
Definition: ckb-anim.h:90
float x
Definition: main.c:66
ckb_gradient animcolor
Definition: main.c:52
#define CKB_PARSE_AGRADIENT(param_name, gradient_ptr)
Definition: ckb-anim.h:121
#define CKB_LICENSE(license)
Definition: ckb-anim.h:68
#define CKB_COPYRIGHT(year, author)
Definition: ckb-anim.h:66
Definition: keymap.h:49
unsigned height
Definition: ckb-anim.h:143
#define CKB_DESCRIPTION(description)
Definition: ckb-anim.h:70
int ckb_frame(ckb_runctx *context)
Definition: main.c:137
unsigned keycount
Definition: ckb-anim.h:141
#define CKB_PRESET_START(name)
Definition: ckb-anim.h:85
void ckb_time(ckb_runctx *context, double delta)
Definition: main.c:126
#define CKB_KPMODE(mode)
Definition: ckb-anim.h:93
int symmetric
Definition: main.c:41
#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
void ckb_info()
Definition: main.c:5
#define CKB_PARSE_BOOL(param_name, value_ptr)
Definition: ckb-anim.h:117
void ckb_init(ckb_runctx *context)
Definition: main.c:57
#define CKB_REPEAT(enable)
Definition: ckb-anim.h:99
#define ANGLE(theta)
Definition: main.c:68
double x_offset
Definition: main.c:43
#define CKB_KEYCLEAR(context)
Definition: ckb-anim.h:148
double y_offset
Definition: main.c:43
void ckb_start(ckb_runctx *context, int state)
Definition: main.c:114
#define CKB_PRESET_PARAM(name, value)
Definition: ckb-anim.h:86
ckb_key * keys
Definition: ckb-anim.h:140
#define CKB_PARSE_DOUBLE(param_name, value_ptr)
Definition: ckb-anim.h:116
#define CKB_PARAM_BOOL(name, text, default)
Definition: ckb-anim.h:76
void ckb_alpha_blend(ckb_key *key, float a, float r, float g, float b)
Definition: ckb-anim.h:283
unsigned width
Definition: ckb-anim.h:143
int counter_clock
Definition: main.c:42
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