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 dependency graph for main.c:

Go to the source code of this file.

Macros

#define ANGLE(theta)   fmod((theta) + M_PI * 2., M_PI * 2.)
 

Functions

void ckb_info ()
 
void ckb_parameter (ckb_runctx *context, const char *name, const char *value)
 
void ckb_init (ckb_runctx *context)
 
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 }
 
double animlength = 0.
 
int symmetric = 0
 
int counter_clock = 0
 
double x_offset = 0
 
double y_offset = 0
 
double frame = -1.
 
float x
 
float y
 

Macro Definition Documentation

#define ANGLE (   theta)    fmod((theta) + M_PI * 2., M_PI * 2.)

Definition at line 68 of file main.c.

Referenced by ckb_frame().

Function Documentation

int ckb_frame ( ckb_runctx context)

Definition at line 86 of file main.c.

References ANGLE, animlength, ckb_alpha_blend(), ckb_grad_color(), CKB_KEYCLEAR, counter_clock, frame, ckb_runctx::keycount, ckb_runctx::keys, M_PI, symmetric, x, and y.

86  {
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 }
double frame
Definition: main.c:65
#define M_PI
Definition: ckb-anim.h:42
float y
Definition: main.c:66
float x
Definition: main.c:66
ckb_gradient animcolor
Definition: main.c:52
Definition: keymap.h:49
unsigned keycount
Definition: ckb-anim.h:141
int symmetric
Definition: main.c:41
#define ANGLE(theta)
Definition: main.c:68
#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
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

+ Here is the call graph for this function:

void ckb_info ( )

Definition at line 3 of file main.c.

References CKB_COPYRIGHT, CKB_DESCRIPTION, CKB_GUID, CKB_KP_NONE, CKB_KPMODE, CKB_LICENSE, CKB_LIVEPARAMS, CKB_NAME, CKB_PARAM_AGRADIENT, CKB_PARAM_BOOL, CKB_PARAM_DOUBLE, CKB_PRESET_END, CKB_PRESET_PARAM, CKB_PRESET_START, CKB_REPEAT, CKB_TIME_DURATION, CKB_TIMEMODE, CKB_VERSION, FALSE, and TRUE.

3  {
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 }
#define CKB_PRESET_END
Definition: ckb-anim.h:87
#define FALSE
Definition: ckb-anim.h:49
#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_KP_NONE
Definition: ckb-anim.h:90
#define CKB_LICENSE(license)
Definition: ckb-anim.h:68
#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_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_REPEAT(enable)
Definition: ckb-anim.h:99
#define CKB_PRESET_PARAM(name, value)
Definition: ckb-anim.h:86
#define CKB_PARAM_BOOL(name, text, default)
Definition: ckb-anim.h:76
void ckb_init ( ckb_runctx context)

Definition at line 57 of file main.c.

57  {
58  // Unused
59 }
void ckb_keypress ( ckb_runctx context,
ckb_key key,
int  x,
int  y,
int  state 
)

Definition at line 61 of file main.c.

61  {
62  // Unused
63 }
void ckb_parameter ( ckb_runctx context,
const char *  name,
const char *  value 
)

Definition at line 45 of file main.c.

References animlength, CKB_PARSE_AGRADIENT, CKB_PARSE_BOOL, CKB_PARSE_DOUBLE, counter_clock, M_PI, symmetric, x_offset, and y_offset.

45  {
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 }
#define M_PI
Definition: ckb-anim.h:42
ckb_gradient animcolor
Definition: main.c:52
#define CKB_PARSE_AGRADIENT(param_name, gradient_ptr)
Definition: ckb-anim.h:121
int symmetric
Definition: main.c:41
#define CKB_PARSE_BOOL(param_name, value_ptr)
Definition: ckb-anim.h:117
double x_offset
Definition: main.c:43
double y_offset
Definition: main.c:43
#define CKB_PARSE_DOUBLE(param_name, value_ptr)
Definition: ckb-anim.h:116
int counter_clock
Definition: main.c:42
double animlength
Definition: main.c:40
void ckb_start ( ckb_runctx context,
int  state 
)

Definition at line 70 of file main.c.

References frame, ckb_runctx::height, ckb_runctx::width, x, x_offset, y, and y_offset.

70  {
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 }
double frame
Definition: main.c:65
float y
Definition: main.c:66
float x
Definition: main.c:66
unsigned height
Definition: ckb-anim.h:143
double x_offset
Definition: main.c:43
double y_offset
Definition: main.c:43
unsigned width
Definition: ckb-anim.h:143
void ckb_time ( ckb_runctx context,
double  delta 
)

Definition at line 77 of file main.c.

References frame.

77  {
78  if(frame < 0.)
79  return;
80  // Spin the wheel
81  frame += delta;
82  if(frame > 1.)
83  frame -= 1.;
84 }
double frame
Definition: main.c:65

Variable Documentation

ckb_gradient animcolor = { 0 }

Definition at line 39 of file main.c.

double animlength = 0.

Definition at line 40 of file main.c.

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

int counter_clock = 0

Definition at line 42 of file main.c.

Referenced by ckb_frame(), and ckb_parameter().

double frame = -1.

Definition at line 65 of file main.c.

Referenced by ckb_frame(), ckb_start(), ckb_time(), and AnimSettingDialog::hLine().

int symmetric = 0

Definition at line 41 of file main.c.

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

double x_offset = 0

Definition at line 43 of file main.c.

Referenced by ckb_parameter(), and ckb_start().

double y_offset = 0

Definition at line 43 of file main.c.

Referenced by ckb_parameter(), and ckb_start().