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.

Data Structures

struct  keyanim
 

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 (int index)
 
void anim_remove (int index)
 
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 randomBright = 0
 
long ffade = 30
 
double pressestofull = 10.f
 
keyanimanims = NULL
 

Data Structure Documentation

struct keyanim

Definition at line 56 of file main.c.

+ Collaboration diagram for keyanim:
Data Fields
int pressed
double timing
unsigned int usages
int x
int y

Function Documentation

void anim_add ( int  index)

Definition at line 81 of file main.c.

References ffade, keyanim::pressed, keyanim::timing, and keyanim::usages.

Referenced by ckb_keypress(), and ckb_start().

81  {
82  anims[index].usages += ffade;
83  anims[index].pressed = 1;
84  anims[index].timing = 0.f;
85 }
double timing
Definition: main.c:59
keyanim * anims
Definition: main.c:64
int pressed
Definition: main.c:58
long ffade
Definition: main.c:53
unsigned int usages
Definition: main.c:57

+ Here is the caller graph for this function:

void anim_remove ( int  index)

Definition at line 87 of file main.c.

References keyanim::pressed.

Referenced by ckb_keypress(), and ckb_start().

87  {
88  anims[index].pressed = 0;
89 }
keyanim * anims
Definition: main.c:64
int pressed
Definition: main.c:58

+ Here is the caller graph for this function:

int ckb_frame ( ckb_runctx context)

Definition at line 117 of file main.c.

References ckb_alpha_blend(), ckb_grad_color(), CKB_KEYCLEAR, ffade, ckb_runctx::keycount, ckb_runctx::keys, pressestofull, and randomBright.

117  {
118  CKB_KEYCLEAR(context);
119  // Draw spots
120  unsigned count = context->keycount;
121  ckb_key* keys = context->keys;
122  unsigned int full = pressestofull*ffade;
123  for(int i =0; i < count; i++){
124  if(!anims[i].usages)
125  continue;
126  float a, r, g, b;
127  if(randomBright)
128  ckb_grad_color(&a, &r, &g, &b, &animcolor, ((float)(rand() % 1024))/10.f);
129  else
130  ckb_grad_color(&a, &r, &g, &b, &animcolor, (float)fmin(anims[i].usages,full)*100.f/full);
131  ckb_alpha_blend(keys+i, a, r, g, b);
132  }
133  return 0;
134 }
ckb_gradient animcolor
Definition: main.c:52
int randomBright
Definition: main.c:52
keyanim * anims
Definition: main.c:64
unsigned keycount
Definition: ckb-anim.h:141
double pressestofull
Definition: main.c:54
#define CKB_KEYCLEAR(context)
Definition: ckb-anim.h:148
long ffade
Definition: main.c:53
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
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 20 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_BOOL, CKB_PARAM_DOUBLE, CKB_PARAM_LONG, CKB_PRESET_END, CKB_PRESET_PARAM, CKB_PRESET_START, CKB_REPEAT, CKB_TIME_ABSOLUTE, CKB_TIMEMODE, CKB_VERSION, FALSE, and TRUE.

20  {
21  // Plugin info
22  CKB_NAME("Heat Map");
23  CKB_VERSION("0.2");
24  CKB_COPYRIGHT("2017", "RULER501");
25  CKB_LICENSE("GPLv2");
26  CKB_GUID("{097D69F0-70B2-48B8-AFE2-25A1CDB0D92C}");
27  CKB_DESCRIPTION("A spot effect on pressed keys that shows usage");
28 
29  // Effect parameters
30  CKB_PARAM_AGRADIENT("color", "Fade color:", "", "ffffffff");
31  CKB_PARAM_BOOL("random", "Random Brightness", 0);
32  CKB_PARAM_LONG("ffade", "Frames to fade", "frames", 30, 10, 1000);
33  CKB_PARAM_DOUBLE("pressestofull", "Presses to full", "keypresses", 10.f, 1.f, 100.f);
34 
35  // Timing/input parameters
40 
41  // Presets
42  CKB_PRESET_START("Single Spot");
43  CKB_PRESET_PARAM("random", "0");
44  CKB_PRESET_PARAM("ffade", "30");
45  CKB_PRESET_PARAM("pressestofull", "10");
46  CKB_PRESET_PARAM("trigger", "0");
47  CKB_PRESET_PARAM("kptrigger", "1");
49 }
#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_PARAM_LONG(name, prefix, postfix, default, min, max)
Definition: ckb-anim.h:74
#define CKB_TIME_ABSOLUTE
Definition: ckb-anim.h:96
#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_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_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 66 of file main.c.

References ckb_runctx::keycount, ckb_runctx::keys, keyanim::x, ckb_key::x, keyanim::y, and ckb_key::y.

66  {
67  anims = calloc(context->keycount, sizeof(keyanim));
68  for(int i=0; i < context->keycount; i++){
69  anims[i].x = context->keys[i].x;
70  anims[i].y = context->keys[i].y;
71  }
72 }
int x
Definition: ckb-anim.h:133
Definition: main.c:56
keyanim * anims
Definition: main.c:64
unsigned keycount
Definition: ckb-anim.h:141
int y
Definition: ckb-anim.h:133
int x
Definition: main.c:60
ckb_key * keys
Definition: ckb-anim.h:140
int y
Definition: main.c:61
void ckb_keypress ( ckb_runctx context,
ckb_key key,
int  x,
int  y,
int  state 
)

Definition at line 91 of file main.c.

References anim_add(), anim_remove(), and ckb_runctx::keys.

91  {
92  // Add or remove a spot on this key
93  if(state)
94  anim_add(key - context->keys);
95  else
96  anim_remove(key - context->keys);
97 }
void anim_remove(int index)
Definition: main.c:87
void anim_add(int index)
Definition: main.c:81
ckb_key * keys
Definition: ckb-anim.h:140

+ Here is the call graph for this function:

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

Definition at line 74 of file main.c.

References CKB_PARSE_AGRADIENT, CKB_PARSE_BOOL, CKB_PARSE_DOUBLE, CKB_PARSE_LONG, ffade, pressestofull, and randomBright.

74  {
75  CKB_PARSE_AGRADIENT("color", &animcolor){}
76  CKB_PARSE_BOOL("random", &randomBright){}
77  CKB_PARSE_LONG("ffade", &ffade){}
78  CKB_PARSE_DOUBLE("pressestofull", &pressestofull){}
79 }
ckb_gradient animcolor
Definition: main.c:52
#define CKB_PARSE_AGRADIENT(param_name, gradient_ptr)
Definition: ckb-anim.h:121
int randomBright
Definition: main.c:52
double pressestofull
Definition: main.c:54
#define CKB_PARSE_LONG(param_name, value_ptr)
Definition: ckb-anim.h:115
#define CKB_PARSE_BOOL(param_name, value_ptr)
Definition: ckb-anim.h:117
long ffade
Definition: main.c:53
#define CKB_PARSE_DOUBLE(param_name, value_ptr)
Definition: ckb-anim.h:116
void ckb_start ( ckb_runctx context,
int  state 
)

Definition at line 99 of file main.c.

99  {
100  return;
101 }
void ckb_time ( ckb_runctx context,
double  delta 
)

Definition at line 103 of file main.c.

References ckb_runctx::keycount, keyanim::timing, and keyanim::usages.

103  {
104  unsigned int count = context->keycount;
105  for(unsigned int i=0; i < count; i++){
106  if(anims[i].usages && !anims[i].pressed){
107  anims[i].timing -= delta;
108  while(anims[i].timing < 0){
109  anims[i].timing += 1.f/30.f;
110  if(anims[i].usages > 0)
111  anims[i].usages--;
112  }
113  }
114  }
115 }
double timing
Definition: main.c:59
keyanim * anims
Definition: main.c:64
unsigned keycount
Definition: ckb-anim.h:141
unsigned int usages
Definition: main.c:57

Variable Documentation

ckb_gradient animcolor = { 0 }

Definition at line 51 of file main.c.

keyanim* anims = NULL

Definition at line 64 of file main.c.

long ffade = 30

Definition at line 53 of file main.c.

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

double pressestofull = 10.f

Definition at line 54 of file main.c.

Referenced by ckb_frame(), and ckb_parameter().

int randomBright = 0

Definition at line 52 of file main.c.

Referenced by ckb_frame(), and ckb_parameter().