231 {
232 struct DrawPoints {
233 int n_black0;
234 int n_fade0;
235 int n_fill;
236 int n_fade1;
237 int n_black1;
238 float fade_factor;
239
240 float SumBrightness() const {
241 float out = 0;
242 out += n_fill;
243 out += (fade_factor * n_fade0);
244 out += (fade_factor * n_fade1);
245 return out;
246 }
247 };
248
249
250
251
252 struct F {
253 static DrawPoints Generate(int n_led, float factor) {
254 DrawPoints out;
255 memset(&out, 0, sizeof(out));
256 if (n_led == 0 || factor == 0.0f) {
257 out.n_black0 = n_led;
258 return out;
259 }
260 const int is_odd = (n_led % 2);
261 const int n_half_lights = n_led / 2 + is_odd;
262 const float f_half_fill = n_half_lights * factor;
263 const int n_half_fill = static_cast<int>(f_half_fill);
264
265 float fade_pix_perc = f_half_fill - static_cast<float>(n_half_fill);
266 int n_fade_pix = fade_pix_perc < 1.0f;
267 if (n_half_fill == 0) {
268 n_fade_pix = 1;
269 }
270 int n_half_black = n_half_lights - n_half_fill - n_fade_pix;
271
272 int n_fill_pix = 0;
273 if (n_half_fill > 0) {
274 n_fill_pix = n_half_fill * 2 + (is_odd ? -1 : 0);
275 }
276
277 out.n_black0 = n_half_black;
278 out.n_fade0 = n_fade_pix;
279 out.n_fill = n_fill_pix;
280 out.n_fade1 = n_fade_pix;
281 if (!n_fill_pix && is_odd) {
282 out.n_fade1 = 0;
283 }
284 out.n_black1 = n_half_black;
285 out.fade_factor = fade_pix_perc;
286 return out;
287 }
288 };
289
290
292
293 for (int i = 0; i < led_column_table_length; ++i) {
294 const Key& key = keyboard.
keys_[i];
295
297
298
299
300
301
302 const int n_led = led_column_table[i];
303
304 if (active_lights_factor > 0.0f) {
305 DrawPoints dp = F::Generate(n_led, active_lights_factor);
306
309 Color3i color = hsv.
ToRGB();
310
311 Color3i fade_col;
313 c.
v_ = dp.fade_factor;
314 fade_col = c.
ToRGB();
315
316
322
323#ifdef DEBUG_PAINTER
324 if (active_lights_factor > 0.0) {
325 int total_lights_on = dp.SumBrightness();
326
327
328
329
330 #define P(X) dprint(", "#X ": "); dprint(X);
331
332
333
334
336 P(active_lights_factor);
337
339 }
340#endif
341 } else {
343 }
344
345
346
347 }
348
349
351}
virtual void RawCommitDraw()=0
virtual void RawBeginDraw()=0
virtual void RawDrawPixels(const Color3i &c, int n)=0
#define P(x)
Reads a single byte from the p array.
float IntensityFactor() const