- if (pattern.led_map == "r") {
- ctx.set_source_rgb (1, 0, 0);
- } else if (pattern.led_map == "g") {
- ctx.set_source_rgb (0, 1, 0);
- } else if (pattern.led_map == "b") {
- ctx.set_source_rgb (0, 0, 1);
- } else if (pattern.led_map == "rg") {
- ctx.set_source_rgb (1, 1, 0);
- } else if (pattern.led_map == "rb") {
- ctx.set_source_rgb (1, 0, 1);
- } else if (pattern.led_map == "gb") {
- ctx.set_source_rgb (0, 1, 1);
- } else if (pattern.led_map == "rgb") {
- ctx.set_source_rgb (1, 1, 1);
- } else {
- ctx.set_source_rgb (0.75, 0.75, 0.75);
+ private void draw_pattern (Cairo.Context ctx, int width, int height, LedColor color,
+ List<LedCommandRX51> engine) {
+ double pps = width / duration; // pixel per second
+
+ ctx.new_path ();
+
+ ctx.set_operator (Cairo.Operator.ADD);
+
+ ctx.set_source_rgb ((LedColor.R in color) ? 1.0 : 0.0,
+ (LedColor.G in color) ? 1.0 : 0.0,
+ (LedColor.B in color) ? 1.0 : 0.0);
+ ctx.set_line_width (3.0);
+
+ double x = 0, y = 0;
+ foreach (LedCommand command in engine) {
+ x = command.time * pps/1000.0;
+ y = (255 - command.level) * (height - 1)/255.0;
+ switch (command.type) {
+ case CommandType.RAMP_WAIT:
+ case CommandType.TRIGGER:
+ x += command.duration * pps/1000.0;
+ y -= command.steps * (height - 1)/255.0;
+ if (y < 0)
+ y = 0;
+ if (y > (height - 1))
+ y = height - 1;
+ ctx.line_to (x, y);
+ break;
+ default:
+ ctx.line_to (x, y);
+ break;