1 /*
2 * ColorPaletteCircle.c
3 *
4 * Copyright (C) 2002 Christian Hanisch
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file "COPYING" for details); if
18 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 * Cambridge, MA 02139, USA.
20 */
21
22 #ifdef WIN32
23 #include <windows.h>
24 #endif
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <math.h>
29 #ifndef FLT_MAX
30 # include <float.h>
31 #endif
32 #include "swt.h"
33 extern "C" {
34 #include "../../mysnprintf.h"
35 }
36
37 #define REDWINKEL 0.0
38 #define YELLOWWINKEL 60.0
39 #define GREENWINKEL 120.0
40 #define CYANWINKEL 180.0
41 #define BLUEWINKEL 240.0
42 #define MAGENTAWINKEL 300.0
43 #define MAXWINKEL 360.0
44
45 #define MAXFARBANTEIL 255
46 #define AUFLOESUNG 100
47
48 #define X_ScrollBar 30
49 #define Y_ScrollBar_TextEdit 160
50 #define Y_ABSTAND 20
51 #define ScrollBarVisit 10
52
53 #define VALUEBARWIDTH 20
54
55 #define X_TEXTEDIT 240
56
57 #define X_WINDOWSIZE 300
58 #define Y_WINDOWSIZE 240
59
60 #define X0_POINT -20
61 #define Y0_POINT 200
62
63 SWND canvas, RedScrollBar, GreenScrollBar, BlueScrollBar, CloseButton,
64 OkeyButton, RedTextEdit, GreenTextEdit, BlueTextEdit;
65 int drawing = 0;
66
67 /**
68 * SetGetColorPoint -- Setzen oder Rueckgabe der gemerkten Farbe
69 *
70 * Color zu setzende Farbe
71 *
72 * Set wenn gesetzt soll die Farbe sie gesetzt werden. Wenn nicht gesetzt soll nur
73 * die Farbe uebergeben werden.
74 *
75 * RETURN Rueckgabe der aktuellen Farbe
76 */
SetGetColorPoint(int Color,bool Set)77 int SetGetColorPoint(int Color, bool Set)
78 {
79 static int ColorAll=0;
80
81 if(Set)
82 ColorAll = Color;
83 return ColorAll;
84 }
85
OldColor(float * Red,float * Green,float * Blue,bool oldcolor)86 void OldColor(float *Red, float *Green, float *Blue, bool oldcolor)
87 {
88 static float RedValue, GreenValue, BlueValue;
89
90 if(oldcolor)
91 {
92 RedValue = *Red;
93 GreenValue = *Green;
94 BlueValue = *Blue;
95 }else
96 {
97 *Red = RedValue;
98 *Green = GreenValue;
99 *Blue = BlueValue;
100 }
101 }
102
103 /**
104 * ScrollBar -- Stuktur fuer die ScrollBars zum setzten der Position und der Groesse fuer
105 * der Funktion risizeCallBack gedacht
106 *
107 * x X - Position des jeweiligen ScrollBar
108 *
109 * y Y - Position des jeweiligen ScrollBar
110 *
111 * width Breite des jeweiligen ScrollBar
112 *
113 * height Hoehe des jeweiligen ScrollBar
114 */
115 struct ScrollBar
116 {
117 int x, y;
118 int width, height;
119 };
120
121
122 /**
123 * TextEdit -- Stuktur fuer die TextEdits zum setzten der Position und der Groesse fuer
124 * der Funktion risizeCallBack gedacht
125 *
126 * x X - Position des jeweiligen TextEdit
127 *
128 * y Y - Position des jeweiligen TextEdit
129 *
130 * width Breite des jeweiligen TextEdit
131 *
132 * height Hoehe des jeweiligen TextEdit
133 */struct TextEdit
134 {
135 int x, y;
136 int width, height;
137 };
138
139
140
141 /**
142 * Button -- Stuktur fuer die Buttons zum setzten der Position und der Groesse fuer
143 * der Funktion risizeCallBack gedacht
144 *
145 * x X - Position des jeweiligen Button
146 *
147 * y Y - Position des jeweiligen Button
148 *
149 * width Breite des jeweiligen Button
150 *
151 * height Hoehe des jeweiligen Button
152 */
153 struct Button
154 {
155 int x, y;
156 int width, height;
157 };
158
159 /**
160 * ScrollBars -- Struktur fuer die ScrollBars der jeweiligen Farbanteile Rot, Gruen und
161 * Blau
162 *
163 * red ScrollBar von dem Rotanteil der Positionen und Groessen
164 *
165 * green ScrollBar von dem Gruenanteil der Positionen und Groessen
166 *
167 * blue ScrollBar von dem Blauanteil der Positionen und Groessen
168 */
169 struct ScrollBars
170 {
171 struct ScrollBar red;
172 struct ScrollBar green;
173 struct ScrollBar blue;
174 };
175
176 /**
177 * TextEdits -- Struktur fuer die TextEdits der jeweiligen Farbanteile Rot, Gruen und Blau
178 *
179 * red ScrollBar von dem Rotanteil der Positionen und Groessen
180 *
181 * green ScrollBar von dem Gruenanteil der Positionen und Groessen
182 *
183 * blue ScrollBar von dem Blauanteil der Positionen und Groessen
184 */
185 struct TextEdits
186 {
187 struct TextEdit red;
188 struct TextEdit green;
189 struct TextEdit blue;
190 };
191
192
193 /**
194 * Buttons -- Struktur fuer die Buttons der jeweiligem Button
195 *
196 * okey Button fuer das Okay zum Bestaetigen der ausgewaehlten Farbe der Positionen und Groessen
197 *
198 * close Button fuer das Close zum Abbrechen der Farbauswahl der Positionen und Groessen
199 */
200 struct Buttons
201 {
202 struct Button okay;
203 struct Button close;
204 };
205
206 /**
207 * SetScrollBar -- Setzen der Position und Groesse aller ScrollBars, TextEdit und Buttons
208 * bei einem resizeCallBack
209 *
210 * scroll alle Werte fuer die Postion und Groesse der ScrollBars
211 *
212 * TextEdit alle Werte fuer die Postion und Groesse der TextEdits
213 *
214 * buton alle Werte fuer die Postion und Groesse der buttons
215 */
SetScrollBar(struct ScrollBars scroll,struct TextEdits textedit,struct Buttons button)216 void SetScrollBar(struct ScrollBars scroll, struct TextEdits textedit, struct Buttons button)
217 {
218
219 // Hier kann die ScrollBar Groesse und die Button Groesse mit dem Befehl
220 // extern void swSetSize(SWND wnd, int width, int height); gesetzt werden.
221
222 swSetPosition(RedScrollBar, scroll.red.x, scroll.red.y);
223 swSetPosition(GreenScrollBar, scroll.green.x, scroll.green.y);
224 swSetPosition(BlueScrollBar, scroll.blue.x, scroll.blue.y);
225
226 swSetPosition(RedTextEdit, textedit.red.x, textedit.red.y);
227 swSetPosition(GreenTextEdit, textedit.green.x, textedit.green.y);
228 swSetPosition(BlueTextEdit, textedit.blue.x, textedit.blue.y);
229
230 swSetPosition(OkeyButton, button.okay.x, button.okay.y);
231 swSetPosition(CloseButton, button.close.x, button.close.y);
232
233 }
234
235 /**
236 * window_size -- Struktur fuer den Mittelpunkt des Farbkreises und der Groesse des
237 * Arbeitsfensters und des Radius des Farbkreises
238 *
239 * x0 Position vom Mittelpunkt des Farbkreises in der X-Achse
240 *
241 * y0 Position vom Mittelpunkt des Farbkreises in der Y-Achse
242 *
243 * x_window Fenstergoesse in der X-Achse
244 *
245 * y_window Fenstergoesse in der Y-Achse
246 *
247 * Radius Radius des Farbkreises
248 */
249 struct window_size
250 {
251 int x0, y0;
252 int x_window, y_window;
253 float Radius;
254 };
255
256 /**
257 * GetPositions -- Errechnen der Stellen oder auch Postionen fuer alle Objekte
258 *
259 * windowback Inhalt aller wichtigen Information fuer die Stellungen der Objekte
260 *
261 * resize Pruefen ob es sich um ein resizeCallBack handelt oder nicht, um sich die
262 * neue Fenstergroesse zumerken und sie dann auch setzen, ruft dabei die Funktion
263 * SetScrollBar auf um die Objekte zusetzen
264 */
GetPositions(struct window_size * windowback,bool resize)265 void GetPositions(struct window_size* windowback, bool resize)
266 {
267 static struct window_size window = {X0_POINT, Y0_POINT, X_WINDOWSIZE, Y_WINDOWSIZE, 0};
268 struct ScrollBars scrollbar;
269 struct TextEdits textedit;
270 struct Buttons button;
271 static int x_SetPalette, y_SetPalette;
272
273 if(resize)
274 {
275 window.x_window = windowback->x_window;
276 window.y_window = windowback->y_window;
277 button.okay.x = (window.x_window / 4) - 60;
278 button.okay.y = window.y_window - 40;
279 button.close.x = (window.x_window / 2) + 30;
280 button.close.y = window.y_window - 40;
281 scrollbar.red.x = (window.x_window / 4) - 40;
282 scrollbar.red.y = window.y_window - 60 - 2*Y_ABSTAND;
283 scrollbar.green.x = (window.x_window / 4) - 40;
284 scrollbar.green.y = window.y_window - 60 - Y_ABSTAND;
285 scrollbar.blue.x = (window.x_window / 4) - 40;
286 scrollbar.blue.y = window.y_window - 60;
287 textedit.red.x = (window.x_window / 2) + 90;
288 textedit.red.y = window.y_window - 100;
289 textedit.green.x = (window.x_window / 2) + 90;
290 textedit.green.y = window.y_window - 100 + Y_ABSTAND;
291 textedit.blue.x = (window.x_window / 2) + 90;
292 textedit.blue.y = window.y_window - 100 + 2*Y_ABSTAND;
293 SetScrollBar(scrollbar, textedit, button);
294
295 }
296
297 window.x0 = (window.x_window / 2) - 30;
298
299 if(window.x_window>window.y_window*0.4)
300 {
301 windowback->Radius = ((window.x_window - window.x0-60)/ 2);
302 }else
303 {
304 windowback->Radius = ((window.y_window * 0.4) / 2);
305 }
306
307
308 windowback->y0 = (int) windowback->Radius + 10;
309 windowback->x0 = (window.x_window / 2) + (int) windowback->Radius - 60;
310
311 windowback->x_window = window.x_window;
312 windowback->y_window = window.y_window;
313
314 }
315
316
317 /**
318 * Round_float_to_int -- Runden einer Floatzahl
319 *
320 * number zu rundende Zahl
321 *
322 * RETURN gerundeter Integer
323 */
Round_float_to_int(float number)324 int Round_float_to_int(float number)
325 {
326 float rest;
327
328 rest = number - floor(number);
329 number -= rest;
330 if(rest>=0.5)
331 number++;
332
333 return (int) number;
334
335 }
336
337 /**
338 * GetColorFloatToInt -- Errechnet die zusammengesetze Farbe von Scrollbar(0-100) float werten in
339 * Farbwerte(0-255) und setzt diese dann zusammen in rin Integer Wert
340 * um diesen gibt er dann als Rueckgabewert zurueck
341 *
342 * red Rotanteil der ganzen Farbe
343 *
344 * green Gruenanteil der ganzen Farbe
345 *
346 * blue Blauanteil der ganzen Farbe
347 *
348 * RETURN Rueckgabe der vollstaendigen Farbe als ein Integerwert
349 */
GetColorFloatToInt(float red,float green,float blue)350 int GetColorFloatToInt(float red, float green, float blue)
351 {
352 int Color;
353 int red_int, green_int, blue_int;
354
355
356 red_int = Round_float_to_int(red * MAXFARBANTEIL);
357 green_int = Round_float_to_int(green * MAXFARBANTEIL);
358 blue_int = Round_float_to_int(blue * MAXFARBANTEIL);
359
360 Color = 0;
361 Color += (red_int & 0xff);
362 Color += (green_int & 0xff) << 8;
363 Color += (blue_int & 0xff) << 16;
364 return Color;
365 }
366
367
368 /**
369 * GetBarValue -- Holen einer Farbe vom Farbbalken
370 *
371 * x X-Achse des Farbbalken von der die Farbe ermittlet werden soll
372 *
373 * y Y-Achse des Farbbalken von der die Farbe ermittlet werden soll
374 *
375 * RETURN Rueckgabe der jeweiligen Farbe als Integer, wenn die y Koordinate nicht im Farbbalken ist
376 * dann gibt die Funktion die Fehlermeldung -1 zurueck
377 *
378 * ACHTUNG Die Funtkion berechnet selbststaendig alle Positionen aus
379 */
GetBarValue(int y)380 int GetBarValue(int y)
381 {
382 struct window_size window;
383 int Color, Red, Green, Blue;
384 float RedColor=0, GreenColor=0, BlueColor=0;
385 float DifRedValue, DifGreenValue, DifBlueValue;
386 int y0, y_again, y1;
387
388 GetPositions(&window, false);
389
390 Color = SetGetColorPoint(0, false);
391 Red = (Color & 0xff);
392 Green = (Color & 0xff00) >> 8;
393 Blue = (Color & 0xff0000) >> 16;
394
395 y0 = window.y0 - (int) window.Radius;
396 y1 = y - y0;
397 y_again = 2 * (int) window.Radius;
398
399 if(y1!=0)
400 {
401 RedColor = (1 / ((window.Radius * 2) / y1) * (float) Red);
402 GreenColor = (1 / ((window.Radius * 2) / y1) * (float) Green);
403 BlueColor = (1 / ((window.Radius * 2) / y1) * (float) Blue);
404 }
405 if(Color==0)
406 {
407 RedColor = (1 / ((window.Radius * 2) / y1) * MAXFARBANTEIL);
408 GreenColor = (1 / ((window.Radius * 2) / y1) * MAXFARBANTEIL);
409 BlueColor = (1 / ((window.Radius * 2) / y1) * MAXFARBANTEIL);
410 }
411
412 if((y<=y_again+y0)&&(y>=y0))
413 {
414 Red = (int) RedColor;
415 Green = (int) GreenColor;
416 Blue = (int) BlueColor;
417 if(Red>=MAXFARBANTEIL+1)
418 Red = MAXFARBANTEIL;
419 if(Green>=MAXFARBANTEIL+1)
420 Green = MAXFARBANTEIL;
421 if(Blue>=MAXFARBANTEIL+1)
422 Blue = MAXFARBANTEIL;
423 Color = (Red & 0xff);
424 Color += (Green & 0xff) << 8;
425 Color += (Blue & 0xff) << 16;
426
427 return Color;
428 }else
429 {
430 return -1;
431 }
432 }
433
434 /**
435 * SetBarValue -- Setzen des Farbbalkens in die canvas(Leinwand) auf dem Bildschirm
436 *
437 * ACHTUNG Die Funtkion berechnet selbststaendig alle Positionen aus
438 */
SetBarValue()439 void SetBarValue()
440 {
441 SDC dc = swCreateDC(canvas);
442 struct window_size window;
443 int x0, y0, x_again, y_again, i, k, Color;
444
445 GetPositions(&window, false);
446 x0 = window.x0 + (int) window.Radius + 30;
447 y0 = window.y0 - (int) window.Radius;
448 x_again = VALUEBARWIDTH;
449 y_again = 2 * (int) window.Radius;
450
451 for(i=y0;i<=y_again+y0;i++)
452 {
453 Color = GetBarValue(i);
454 for(k=x0;k<=x_again+x0;k++)
455 {
456 if(Color!=-1)
457 {
458 swSetFGColor(dc, Color);
459 swDrawPoint(dc, k , i);
460 }
461 }
462 }
463 swDestroyDC(dc);
464 }
465
466
467
468 /**
469 * Colors -- Struktur fuer die Farbanteile um nur die Farbanteile von der GetColorCircle
470 * zu uebergeben. Benoetigen einige Funktionen
471 *
472 * red Rotanteil als float
473 *
474 * green Gruenanteil als float
475 *
476 * blue Blauanteil als float
477 */
478 struct Colors
479 {
480 float red;
481 float green;
482 float blue;
483 };
484
485 /**
486 * GetColorCircle -- Holen der Farbe fuer den Farbkreis
487 *
488 * x X-Position des holende Farbe fuer dem Farbkeis
489 *
490 * y Y-Position des holende Farbe fuer dem Farbkeis
491 *
492 * colors Farbenuebergabe in float(0-1.00) brauchen einige Funktionen
493 *
494 * ACHTUNG Die Funtkion berechnet selbststaendig alle Positionen aus
495 */
GetColorCircle(int x,int y,struct Colors * colors)496 int GetColorCircle(int x, int y, struct Colors* colors)
497 {
498 float red, green, blue;
499 int Color;
500 float alpha;
501 float r, r2, R;
502 struct window_size window;
503
504 GetPositions(&window, false);
505
506 x = x - window.x0;
507 y = y - window.y0;
508 R = window.Radius;
509
510 alpha = (atan2((float)y, (float)x) * 180.0 / M_PI) + 180; // Winkel berechnen
511
512
513 r2 = (x * x) + (y * y);
514 r = sqrt(r2); // r-achse berechnen (Groesse des Kreises)
515
516
517 if(r<=R) // Pruefen ob die Koordinate im Kreis ist
518 {
519 float temp = 1 - (r / R);
520 if(alpha>BLUEWINKEL)
521 {
522 if (alpha>MAGENTAWINKEL)
523 {
524 blue = 1 - alpha / (MAXWINKEL - MAGENTAWINKEL)
525 + MAGENTAWINKEL / (MAXWINKEL - MAGENTAWINKEL);
526 red = 1;
527 }
528 else
529 {
530 blue = 1;
531 red = alpha / (MAGENTAWINKEL - BLUEWINKEL)
532 - BLUEWINKEL / (MAGENTAWINKEL - BLUEWINKEL);
533 }
534 green = temp;
535 blue=blue - temp * blue + temp;
536 red=red - temp * red + temp;
537 }else if(alpha>GREENWINKEL) // Winkelbereich
538 {
539 if (alpha>CYANWINKEL)
540 {
541 green = 1 - alpha / (BLUEWINKEL - CYANWINKEL)
542 + CYANWINKEL / (BLUEWINKEL - CYANWINKEL);
543 blue = 1;
544 }
545 else
546 {
547 green = 1;
548 blue = alpha / (CYANWINKEL - GREENWINKEL)
549 - GREENWINKEL / (CYANWINKEL - GREENWINKEL);
550 }
551 red = temp;
552 blue=blue - temp * blue + temp;
553 green=green - temp * green + temp;
554 }else if(alpha>REDWINKEL) // Winkelbereich
555 {
556 if (alpha>YELLOWWINKEL)
557 {
558 red = 1- alpha / (GREENWINKEL - YELLOWWINKEL)
559 + YELLOWWINKEL / ( GREENWINKEL - YELLOWWINKEL);
560 green = 1;
561 }
562 else
563 {
564 red = 1;
565 green = alpha / (YELLOWWINKEL - REDWINKEL)
566 - REDWINKEL / (YELLOWWINKEL - REDWINKEL);
567 }
568 red=red - temp * red + temp;
569 green=green - temp * green + temp;
570 blue = temp;
571 }
572 Color=0;
573 colors->red=red;
574 colors->green=green;
575 colors->blue=blue;
576 Color = GetColorFloatToInt(red, green, blue);
577 }else
578 { // 1 - (R / r) *255
579 Color = -1;
580 }
581 return Color; // Rueckgabe der Farbe fuer die Zeichnung
582 }
583
584 /**
585 * SetColorPalette -- Setzen der FarbauswahlRechtecks
586 *
587 * Color Diese Farbe wird als Rechteck in das Fenster geschrieben
588 *
589 *
590 * ACHTUNG das Rechteck wird immer an die gleiche Position geschrieben, es ist noch nicht
591 * im resizeCallBack mit drin
592 */
SetColorPalette(int Color)593 void SetColorPalette(int Color)
594 {
595 SDC dc = swCreateDC(canvas);
596 int i, k;
597 int start_x=10, start_y=10, end_x=50, end_y=50;
598
599 swSetFGColor(dc, Color);
600
601 for(i=start_x;i<end_x;i++)
602 {
603 for(k=start_y;k<end_y;k++)
604 {
605 swDrawPoint(dc, i , k);
606 }
607 }
608 swDestroyDC(dc);
609 }
610
611 /**
612 * ClearCircleCursor -- Loeschen des FarbKreis Cursor
613 *
614 * x X-Position des Farbkreis Cursor
615 *
616 * y Y-Position des Farbkreis Cursor
617 */
ClearCircleCursor(int x,int y)618 void ClearCircleCursor(int x, int y)
619 {
620 SDC dc = swCreateDC(canvas);
621 struct Colors colors = {0,0,0};
622 int i, k, Color;
623
624 for(i=0;i<=8;i++)
625 {
626 for(k=0;k<=8 - 1;k++);
627 {
628 Color = GetColorCircle((x + k) - 4, (y + i) - 4, &colors);
629 if(Color!=-1)
630 {
631 Color = GetColorFloatToInt(colors.red, colors.green, colors.blue);
632 swSetFGColor(dc, Color);
633 swDrawPoint(dc, (x + k) - 4 , (y + i) - 4);
634 }else
635 {
636 swSetFGColor(dc, swGetWindowColor(canvas, SW_COLOR_WINDOW_BG));
637 swDrawPoint(dc, (x + k) - 4 , (y + i) - 4);
638 }
639 Color = GetColorCircle((x + i) - 4, (y + k) - 4, &colors);
640 if(Color!=-1)
641 {
642 swSetFGColor(dc, Color);
643 swDrawPoint(dc, (x + i) - 4 , (y + k) - 4);
644 }else
645 {
646 swSetFGColor(dc, swGetWindowColor(canvas, SW_COLOR_WINDOW_BG));
647 swDrawPoint(dc, (x + i) - 4 , (y + k) - 4);
648 }
649 }
650 }
651 for(i=8;i>=0;i--)
652 {
653 for(k=8;k>=0 + 1;k--);
654 {
655 Color = GetColorCircle((x + k) - 4, (y + i) - 4, &colors);
656 if(Color!=-1)
657 {
658 swSetFGColor(dc, Color);
659 swDrawPoint(dc, (x + k) - 4 , (y + i) - 4);
660 }else
661 {
662 swSetFGColor(dc, swGetWindowColor(canvas, SW_COLOR_WINDOW_BG));
663 swDrawPoint(dc, (x + k) - 4 , (y + i) - 4);
664 }
665 Color = GetColorCircle((x + i) - 4, (y + k) - 4, &colors);
666 if(Color!=-1)
667 {
668 swSetFGColor(dc, Color);
669 swDrawPoint(dc, (x + i) - 4 , (y + k) - 4);
670 }else
671 {
672 swSetFGColor(dc, swGetWindowColor(canvas, SW_COLOR_WINDOW_BG));
673 swDrawPoint(dc, (x + i) - 4 , (y + k) - 4);
674 }
675 }
676 }
677 swDestroyDC(dc);
678 }
679
680
681 /**
682 * DrawCircleCursor -- Setzen des FarbKreis Cursor
683 *
684 * x X-Position des Farbkreis Cursor
685 *
686 * y Y-Position des Farbkreis Cursor
687 */
DrawCircleCursor(int x,int y)688 void DrawCircleCursor(int x, int y)
689 {
690 SDC dc = swCreateDC(canvas);
691 int i, k;
692
693 swSetFGColor(dc, 0);
694 for(i=0;i<=8;i++)
695 {
696 for(k=0;k<=8 - 1;k++);
697 {
698 swDrawPoint(dc, (x + k) - 4 , (y + i) - 4);
699 swDrawPoint(dc, (x + i) - 4 , (y + k) - 4);
700 }
701 }
702 for(i=8;i>=0;i--)
703 {
704 for(k=8;k>=0 + 1;k--);
705 {
706 swDrawPoint(dc, (x + k) - 4 , (y + i) - 4);
707 swDrawPoint(dc, (x + i) - 4 , (y + k) - 4);
708 }
709 }
710 swDestroyDC(dc);
711 }
712
713 /**
714 * SetCircleCursor -- Ermoeglicht eine Animation des Farbkreis Cursor
715 *
716 * x neue X-Position
717 *
718 * y neue Y-Position
719 *
720 * Color neue Farbe in der Farbbalken Cursor erstellt werden soll
721 */
SetCircleCursor(int x,int y)722 void SetCircleCursor(int x, int y)
723 {
724 static int xo, yo;
725
726 if((x!=xo)||(y!=yo))
727 {
728 ClearCircleCursor(xo, yo);
729 DrawCircleCursor(x, y);
730 xo = x;
731 yo = y;
732 }
733 }
734
735
736 /**
737 * GetCircleCursor -- Ermittelt die Cursor Position des Farbkreises per ScrollBar
738 * einstellung
739 *
740 * RedValue Der Rotanteil des RedScrollBar
741 *
742 * GreenValue Der Gruenanteil des RedScrollBar
743 *
744 * BlueValue Der Blauanteil des RedScrollBar
745 */
GetCircleCursor(int ColorNew)746 void GetCircleCursor(int ColorNew)
747 {
748 int Color, ColorIndex, x, y, i, k, again;
749 int red, green, blue, Radius, k_merk, i_merk;
750 int RedValue, GreenValue, BlueValue;
751 struct Colors colors = {0,0,0};
752 struct window_size window;
753 float minwert=FLT_MAX, absolutwert;
754 bool merk=false;
755
756 SDC dc = swCreateDC(canvas);
757
758 Color = SetGetColorPoint(5, false);
759
760 RedValue = (Color & 0xff);;
761 GreenValue = ((Color & 0xff00) >> 8);
762 BlueValue = ((Color & 0xff0000) >> 16);
763
764 GetPositions(&window, false);
765
766 x = window.x0 - (int) window.Radius;
767 y = window.y0 - (int) window.Radius;
768 again = 2 * (int) window.Radius;
769
770 i_merk=window.x0;
771 k_merk=window.y0;
772
773
774 for(i=y;i<=again+y;i++)
775 {
776 for(k=x;k<=again+x;k++)
777 {
778 Color = GetColorCircle(k, i, &colors);
779 if(Color!=-1)
780 {
781 red = Round_float_to_int(colors.red * MAXFARBANTEIL);
782 green = Round_float_to_int(colors.green * MAXFARBANTEIL);
783 blue = Round_float_to_int(colors.blue * MAXFARBANTEIL);
784
785 if((RedValue==red)&&(GreenValue==green)&&(BlueValue==blue))
786 {
787 SetCircleCursor(k, i);
788 return;
789 } else
790 {
791 absolutwert = (float)fabs((float)(red - RedValue)) +
792 (float)fabs((float)(green - GreenValue)) +
793 (float)fabs((float)(blue - BlueValue));
794
795 if(minwert>absolutwert)
796 {
797 minwert = absolutwert;
798 k_merk = k;
799 i_merk = i;
800 }
801 }
802 }
803 }
804 }
805 SetCircleCursor(k_merk, i_merk);
806 swDestroyDC(dc);
807 }
808
809 /**
810 * SetTextColorsValues -- Setzt alle Farbwerte in den jeweiligen Textfeldern der ScrollBars
811 * ein fuer die installisierung gedacht
812 *
813 * value Farbe fuer die jeweiligen Farbsetztung
814 */
SetTextColorsValues(int value)815 void SetTextColorsValues(int value)
816 {
817 static float Red = 0, Green = 0, Blue = 0;
818 char ColorValue[20];
819
820 SetColorPalette(value);
821 Red = (value & 0xff) / ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
822 Green = ((value & 0xff00) >> 8) / ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
823 Blue = ((value & 0xff0000) >> 16) / ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
824 mysnprintf(ColorValue,20," %1.2f", Red / AUFLOESUNG);
825 swSetText(RedTextEdit, ColorValue);
826 mysnprintf(ColorValue,20," %1.2f", Green / AUFLOESUNG);
827 swSetText(GreenTextEdit, ColorValue);
828 mysnprintf(ColorValue,20," %1.2f", Blue/ AUFLOESUNG);
829 swSetText(BlueTextEdit, ColorValue);
830 }
831
832 /**
833 * SetTextValue -- Setzt ein Textfeld eines ScrollBar in das jeweilige Textfeld ein
834 *
835 * value Wert fuer die jeweiligen Farbsetztung
836 *
837 * textedit um den Wert in das richtige Textfeld einzusetzen
838 */
SetTextValue(float value,SWND textedit)839 void SetTextValue(float value, SWND textedit)
840 {
841 char ColorValue[20];
842
843 mysnprintf(ColorValue,20," %1.2f",value / AUFLOESUNG);
844 swSetText(textedit, ColorValue);
845 }
846
847 /**
848 * ClearValueBarCursor -- Loeschen des Farbbalken Cursor
849 *
850 * y Y-Position des Farbbalken Cursor
851 */
ClearValueBarCursor(int y)852 void ClearValueBarCursor(int y)
853 {
854 SDC dc = swCreateDC(canvas);
855 int x_again = VALUEBARWIDTH, i, ColorBar=0, x;
856 struct window_size window;
857
858 GetPositions(&window, false);
859
860 x = window.x0 + (int) window.Radius + 30;
861 x_again = VALUEBARWIDTH;
862
863 ColorBar = GetBarValue(y);
864
865 swSetFGColor(dc, ColorBar);
866
867 for(i=x;i<=x+x_again;i++)
868 swDrawPoint(dc, i , y);
869
870 swDestroyDC(dc);
871 }
872
873 /**
874 * DrawValueBarCursor -- Setzen des Farbbalken Cursor
875 *
876 * y Y-Position des Farbbalken Cursor
877 *
878 * Color Farbe des Farbbalken Cursor der in dem er wieder gesetzt werden soll
879 */
DrawValueBarCursor(int y,int Color)880 void DrawValueBarCursor(int y, int Color)
881 {
882 SDC dc = swCreateDC(canvas);
883 int x_again = VALUEBARWIDTH, i, ColorBar=0, x, ColorTemp, Red, Green, Blue;
884 struct window_size window;
885 float win;
886
887 GetPositions(&window, false);
888
889 ColorTemp = SetGetColorPoint(0, false);
890 Red = (ColorTemp & 0xff);
891 Green = (ColorTemp & 0xff00) >> 8;
892 Blue = (ColorTemp & 0xff0000) >> 16;
893
894
895 ColorBar = Color ^ 0xffffff;
896
897 x = window.x0 + (int) window.Radius + 30;
898 x_again = VALUEBARWIDTH;
899
900 swSetFGColor(dc, ColorBar);
901
902 for(i=x;i<=x+x_again;i++)
903 swDrawPoint(dc, i , y);
904
905 win = (float) y;
906
907 win -= ((float)window.y0 - window.Radius);
908
909 win /= (2 * window.Radius);
910 win *= AUFLOESUNG;
911
912 y = Round_float_to_int(win);
913
914
915 swDestroyDC(dc);
916 }
917
918 /**
919 * SetBarValueCursor -- Ermoeglicht eine Animation des Farbbalken Cursor
920 *
921 * y neue Y-Position
922 *
923 * Color neue Farbe in der Farbbalken Cursor erstellt werden soll
924 */
SetBarValueCursor(int y,int Color)925 void SetBarValueCursor(int y, int Color)
926 {
927 static int yo=10;
928 struct window_size window;
929
930 GetPositions(&window, false);
931
932 if(y!=yo)
933 {
934 ClearValueBarCursor(yo);
935 DrawValueBarCursor(y, Color);
936 yo = y;
937 }
938
939 }
940
941 /**
942 * RedTextEditInput -- Callback fuer den Textfeld des Rotanteils. Liest erst den eingegebenen Text ein
943 * und wandelt den Text in ein double um. Danach liest diese Funktion die aktuelle
944 * Farbe ein, holt sich daraus den Rotanteil. Prueft nun erstmal ob der eingegebene
945 * Text in dem gueltigen Eingabe Bereich ist. Wenn es passt dann gibt er den neuen
946 * Rotanteil als Text aus in dem RotTextFeld(RedTextEdit), nun wird der RedScrollBar
947 * auf dem Rotanteil gesetzt und die geaenderte Farbe wird gesetzt in der
948 * SetGetColorPoint Funktion, die dafuer geschrieben wurde. Die ColorPalette wird
949 * gesetzt und der Farbbalken wird auch gesetzt und noch die Farbewird im Farbkreis
950 * ueberprueft. Wenn der eingegebene Farbanteil nicht in dem Eingabe Bereich liegt,
951 * wird der alte Farbanteil in dem entsprechenden TextFenster geschrieben.
952 */
953 static void
RedTextEditInput(void * data,void * command)954 RedTextEditInput(void *data, void *command)
955 {
956 char TextInput[10];
957 float RedValue, RedColorTemp, Red;
958 double Value;
959 int Color;
960 bool Valuemerk;
961
962 swGetText(RedTextEdit, TextInput, 10);
963 Value = atof(TextInput);
964
965 RedValue = (float) Value * AUFLOESUNG;
966 Color = SetGetColorPoint(5, false);
967 Red = ((float) (Color & 0xff)) / ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
968 Color = (Color & 0xff) ^ Color;
969 RedColorTemp = (float) Color;
970 RedColorTemp += ((RedValue) * ((float)MAXFARBANTEIL/(float)AUFLOESUNG));
971 Color += (int) RedColorTemp;
972
973 if((RedValue<=AUFLOESUNG)&&(RedValue>=0.0))
974 {
975 SetTextValue(RedValue, RedTextEdit);
976 swScrollBarSetValue(RedScrollBar, (int) RedValue);
977 SetGetColorPoint(Color, true);
978 SetColorPalette(Color);
979 SetBarValue();
980 GetCircleCursor(Color);
981 }else
982 {
983 SetTextValue(Red, RedTextEdit);
984 }
985
986
987 }
988
989 /**
990 * GreenTextEditInput -- Callback fuer den Textfeld des Gruenanteils. Liest erst den eingegebenen Text ein
991 * und wandelt den Text in ein double um. Danach liest diese Funktion die aktuelle
992 * Farbe ein, holt sich daraus den Gruenanteil. Prueft nun erstmal ob der eingegebene
993 * Text in dem gueltigen Eingabe Bereich ist. Wenn es passt dann gibt er den neuen
994 * Gruenanteil als Text aus in dem GruenTextFeld(GreenTextEdit), nun wird der GreenScrollBar
995 * auf dem Gruenanteil gesetzt und die geaenderte Farbe wird gesetzt in der
996 * SetGetColorPoint Funktion, die dafuer geschrieben wurde. Die ColorPalette wird
997 * gesetzt und der Farbbalken wird auch gesetzt und noch die Farbe wird im Farbkreis
998 * ueberprueft. Wenn der eingegebene Farbanteil nicht in dem Eingabe Bereich liegt,
999 * wird der alte Farbanteil in dem entsprechenden TextFenster geschrieben.
1000 */
1001 static void
GreenTextEditInput(void * data,void * command)1002 GreenTextEditInput(void *data, void *command)
1003 {
1004 char TextInput[10];
1005 float GreenValue, GreenColorTemp, Green;
1006 double Value;
1007 int Color, GreenColor;
1008 bool Valuemerk;
1009
1010 swGetText(GreenTextEdit, TextInput, 10);
1011 Value = atof(TextInput);
1012 GreenValue = (float) Value * AUFLOESUNG;
1013
1014 Color = SetGetColorPoint(0, false);
1015 Green = ((float) ((Color & 0xff00) >> 8)) / ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1016 Color = (Color & 0xff00) ^ Color;
1017 GreenColorTemp = GreenValue * ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1018 GreenColor = (int) GreenColorTemp;
1019 Color += (GreenColor << 8);
1020
1021 if((GreenValue<=AUFLOESUNG)&&(GreenValue>=0.0))
1022 {
1023 SetTextValue(GreenValue, GreenTextEdit);
1024 swScrollBarSetValue(GreenScrollBar, (int) GreenValue);
1025 SetGetColorPoint(Color, true);
1026 SetColorPalette(Color);
1027 SetBarValue();
1028 GetCircleCursor(Color);
1029 }else
1030 {
1031 SetTextValue(Green, GreenTextEdit);
1032 }
1033 }
1034
1035 /**
1036 * BlueTextEditInput -- Callback fuer den Textfeld des Blauanteils. Liest erst den eingegebenen Text ein
1037 * und wandelt den Text in ein double um. Danach liest diese Funktion die aktuelle
1038 * Farbe ein, holt sich daraus den Blauanteil. Prueft nun erstmal ob der eingegebene
1039 * Text in dem gueltigen Eingabe Bereich ist. Wenn es passt dann gibt er den neuen
1040 * Blauanteil als Text aus in dem BlauTextFeld(BlueTextEdit), nun wird der BlueScrollBar
1041 * auf dem Blauanteil gesetzt und die geaenderte Farbe wird gesetzt in der
1042 * SetGetColorPoint Funktion, die dafuer geschrieben wurde. Die ColorPalette wird
1043 * gesetzt und der Farbbalken wird auch gesetzt und noch die Farbewird im Farbkreis
1044 * ueberprueft. Wenn der eingegebene Farbanteil nicht in dem Eingabe Bereich liegt,
1045 * wird der alte Farbanteil in dem entsprechenden TextFenster geschrieben.
1046 */
1047 static void
BlueTextEditInput(void * data,void * command)1048 BlueTextEditInput(void *data, void *command)
1049 {
1050 char TextInput[10];
1051 float BlueValue, BlueColorTemp, Blue;
1052 double Value;
1053 int Color, BlueColor;
1054 bool Valuemerk;
1055
1056 swGetText(BlueTextEdit, TextInput, 10);
1057 Value = atof(TextInput);
1058 BlueValue = Value * AUFLOESUNG;
1059
1060 Color = SetGetColorPoint(0, false);
1061 Blue = ((float) ((Color & 0xff0000) >> 16)) / ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1062 Color = (Color & 0xff0000) ^ Color;
1063 BlueColorTemp = BlueValue * ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1064 BlueColor = (int) BlueColorTemp;
1065
1066 Color += (BlueColor << 16);
1067
1068
1069 if((BlueValue<=AUFLOESUNG)&&(BlueValue>=0.0))
1070 {
1071 SetTextValue(BlueValue, BlueTextEdit);
1072 swScrollBarSetValue(BlueScrollBar, (int) BlueValue);
1073 SetGetColorPoint(Color, true);
1074 SetColorPalette(Color);
1075 SetBarValue();
1076 GetCircleCursor(Color);
1077 }else
1078 {
1079 SetTextValue(Blue, BlueTextEdit);
1080 }
1081
1082 }
1083
1084 /**
1085 * CloseButtonCallback -- ein Callback fuer den Close Button, wenn er gedrueckt wurde, wird die ganze
1086 * Farbfunktion abgebrochen und die alte Farbe an dune zurueck gegeben.
1087 *
1088 * ACHTUNG: diese Funktion ist nicht fertig gestellt und bedarf fuer die einbindung in dune noch einige
1089 * Schritte
1090 */
1091 void
CloseButtonCallback(void * data,void * id)1092 CloseButtonCallback(void *data, void *id)
1093 {
1094 float RedValue, GreenValue, BlueValue;
1095
1096 OldColor(&RedValue, &GreenValue, &BlueValue, false);
1097
1098 // Alte Farbwwerte ausgeben, weil man hier mit das Programm unterbricht
1099 printf("Red: %1.2f ,Green: %1.2f ,Blue: %1.2f\n", RedValue, GreenValue, BlueValue);
1100
1101 swExit();
1102 }
1103
1104 /**
1105 * OkayButtonCallback -- ein Callback fuer den Okay Button, wenn er gedrueckt wurde, wird die ganze
1106 * Farbfunktion unterbrochen und der neue also die ausgewaehlte Farbe an dune
1107 * zurueck gegeben.
1108 *
1109 * ACHTUNG: diese Funktion ist nicht fertig gestellt und bedarf fuer die einbindung in dune noch einige
1110 * Schritte
1111 */
1112 void
OkeyButtonCallback(void * data,void * id)1113 OkeyButtonCallback(void *data, void *id)
1114 {
1115 float RedValue, GreenValue, BlueValue;
1116 int Color;
1117
1118 Color = SetGetColorPoint(5, false);
1119 RedValue = ((float) (Color & 0xff)) / (float)MAXFARBANTEIL;
1120 GreenValue = ((float) ((Color & 0xff00) >> 8)) / (float)MAXFARBANTEIL;
1121 BlueValue = ((float) ((Color & 0xff0000) >> 16)) / (float)MAXFARBANTEIL;
1122
1123
1124 // Neue Farbwwerte ausgeben, weil man hier mit diesem Programm eine neue Farbe ausgewaehlt hat
1125 printf("Red: %1.2f ,Green: %1.2f ,Blue: %1.2f\n", RedValue, GreenValue, BlueValue);
1126
1127 swExit();
1128 }
1129
1130 /**
1131 * SetValue_ScrollBar -- Setzt alle Farbwerte in den Scrollbars ein, errechnet vorher die aktuelle Farbe
1132 * dafuer aus.
1133 */
SetValue_ScrollBar(int Color)1134 void SetValue_ScrollBar(int Color)
1135 {
1136 int Red, Green, Blue;
1137 float ColorTemp;
1138
1139 Red = (Color & 0xff);
1140 Green = (Color >> 8) & 0xff;
1141 Blue = (Color >> 16) & 0xff;
1142
1143 ColorTemp = (float) Red;
1144 ColorTemp /= ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1145 Red = (int) ColorTemp;
1146 ColorTemp = (float) Green;
1147 ColorTemp /= ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1148 Green = (int) ColorTemp;
1149 ColorTemp = (float) Blue;
1150 ColorTemp /= ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1151 Blue = (int) ColorTemp;
1152
1153 swScrollBarSetValue(RedScrollBar, Red);
1154 swScrollBarSetValue(GreenScrollBar, Green);
1155 swScrollBarSetValue(BlueScrollBar, Blue);
1156
1157 }
1158
1159 /**
1160 * RedScrollCallback --
1161 */
1162 void
RedScrollCallback(void * data,int type,int value)1163 RedScrollCallback(void *data, int type, int value)
1164 {
1165 SDC dc = swCreateDC(canvas);
1166 int i, k;
1167 int Color;
1168 float value_float, ColorTemp;
1169 bool Valuemerk;
1170
1171 SFONT font = swFindFont("helvetica", SW_PLAIN, 14);
1172
1173 Color = SetGetColorPoint(5, false);
1174 ColorTemp = (Color & 0xff) ^ Color;
1175 ColorTemp += (float) (value * ((float)MAXFARBANTEIL/(float)AUFLOESUNG));
1176 Color = (int) ColorTemp;
1177 SetGetColorPoint(Color, true);
1178 SetColorPalette(Color);
1179
1180 value_float = (float) value;
1181
1182 SetTextValue(value_float, RedTextEdit);
1183 SetBarValue();
1184 GetCircleCursor(Color);
1185
1186 swDestroyDC(dc);
1187
1188 }
1189
1190
1191 void
GreenScrollCallback(void * data,int type,int value)1192 GreenScrollCallback(void *data, int type, int value)
1193 {
1194 SDC dc = swCreateDC(canvas);
1195 int Color, GreenColor;
1196 float value_float, GreenColorTemp;
1197 bool Valuemerk;
1198
1199 SFONT font = swFindFont("helvetica", SW_PLAIN, 14);
1200
1201 Color = SetGetColorPoint(0, false);
1202 Color = (Color & 0xff00) ^ Color;
1203 GreenColorTemp = (float) value;
1204 GreenColorTemp *= ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1205 GreenColor = (int) GreenColorTemp;
1206 Color += (GreenColor << 8);
1207 SetGetColorPoint(Color, true);
1208 SetColorPalette(Color);
1209
1210 value_float = (float) value;
1211
1212 SetTextValue(value_float, GreenTextEdit);
1213 SetBarValue();
1214 GetCircleCursor(Color);
1215
1216 swDestroyDC(dc);
1217 }
1218
1219 void
BlueScrollCallback(void * data,int type,int value)1220 BlueScrollCallback(void *data, int type, int value)
1221 {
1222
1223 SDC dc = swCreateDC(canvas);
1224 int Color, BlueColor;
1225 float value_float, BlueColorTemp;
1226 bool Valuemerk;
1227
1228 SFONT font = swFindFont("helvetica", SW_PLAIN, 14);
1229
1230 Color = SetGetColorPoint(5, false);
1231 Color = (Color & 0xff0000) ^ Color;
1232 BlueColorTemp = (float) value;
1233 BlueColorTemp *= ((float)MAXFARBANTEIL/(float)AUFLOESUNG);
1234 BlueColor = (int) BlueColorTemp;
1235 Color += (BlueColor << 16);
1236 SetGetColorPoint(Color, true);
1237 SetColorPalette(Color);
1238
1239 value_float = (float) value;
1240
1241 SetTextValue(value_float, BlueTextEdit);
1242 SetBarValue();
1243 GetCircleCursor(Color);
1244
1245 swDestroyDC(dc);
1246
1247
1248 }
1249
SetCircle()1250 void SetCircle()
1251 {
1252 SDC dc = swCreateDC(canvas);
1253 struct window_size window;
1254 struct Colors colors = {0,0,0};
1255 int Color, i, k, x0, y0, again, Radius;
1256
1257 GetPositions(&window, false);
1258
1259 Radius = (int) window.Radius;
1260 x0 = window.x0 - Radius;
1261 y0 = window.y0 - Radius;
1262 again = 2 * Radius;
1263
1264 for(i=y0;i<=again+y0;i++)
1265 {
1266 for(k=x0;k<=again+x0;k++)
1267 {
1268 Color = GetColorCircle(k, i, &colors);
1269 if (Color!=-1)
1270 {
1271 swSetFGColor(dc, Color);
1272 swDrawPoint(dc, k , i);
1273 }
1274 }
1275 }
1276
1277 swDestroyDC(dc);
1278
1279
1280 }
1281
1282 static void
mouseCallback(void * data,int x,int y,int modifiers)1283 mouseCallback(void *data, int x, int y, int modifiers)
1284 {
1285 int Color, ColorTemp, x0, y0, x3 , y3;
1286 struct window_size window;
1287 struct Colors colors = {0,0,0};
1288 float r, r2, x1, y1, x2, y2;
1289 static bool CircleMerk=false, ValueBarMerk=false;
1290 int x_again, y_again;
1291
1292
1293
1294 if(drawing)
1295 {
1296 SDC dc = swCreateDC(canvas);
1297 GetPositions(&window, false);
1298 x0 = x;
1299 y0 = y;
1300
1301 x3 = x - window.x0;
1302 y3 = y - window.y0;
1303
1304
1305 r2 = (x3 * x3) + (y3 * y3);
1306 r = sqrt(r2); // r-achse berechnen (Groesse des Kreises)
1307
1308 if(!ValueBarMerk)
1309 if((r<=window.Radius)||(CircleMerk)) // Pruefen ob die Koordinate im Kreis ist
1310 {
1311 CircleMerk = true;
1312 if(r<=window.Radius)
1313 {
1314 ColorTemp = GetColorCircle(x0, y0, &colors);
1315 if(ColorTemp!=-1)
1316 Color = ColorTemp;
1317 SetGetColorPoint(Color, true);
1318 SetValue_ScrollBar(Color);
1319 SetTextColorsValues(Color);
1320 SetCircleCursor(x3 + window.x0, y3 + window.y0);
1321 } else
1322 {
1323 x1 = (float) x0 - (float) window.x0;
1324 y1 = (float) y0 - (float) window.y0;
1325 x2 = window.x0 + ((x1 * window.Radius) / (sqrt((x1 * x1) + (y1 * y1))));
1326 y2 = window.y0 + ((y1 * window.Radius) / (sqrt((x1 * x1) + (y1 * y1))));
1327 SetCircleCursor((int) x2, (int) y2);
1328 ColorTemp = GetColorCircle((int) x2, (int) y2, &colors);
1329 if(ColorTemp!=-1)
1330 Color = ColorTemp;
1331 SetGetColorPoint(Color, true);
1332 SetValue_ScrollBar(Color);
1333 SetTextColorsValues(Color);
1334 }
1335 }
1336 x0 = window.x0 + (int) window.Radius + 30;
1337 y0 = window.y0 - (int) window.Radius;
1338 x_again = VALUEBARWIDTH;
1339 y_again = 2 * (int) window.Radius;
1340
1341 if(!CircleMerk)
1342 if(((y<=y_again+y0)&&(y>y0))&&((x<=x_again+x0)&&(x>=x0)) ||
1343 (ValueBarMerk)&&((y<=y_again+y0)&&(y>y0)))
1344 {
1345 ColorTemp = GetBarValue(y);
1346 if(ColorTemp!=-1)
1347 Color = ColorTemp;
1348 ValueBarMerk = true;
1349 SetValue_ScrollBar(Color);
1350 SetTextColorsValues(Color);
1351 SetBarValueCursor(y, Color);
1352 SetColorPalette(Color);
1353 }else
1354 {
1355 }
1356 swDestroyDC(dc);
1357 }else
1358 {
1359 if(CircleMerk)
1360 SetBarValue();
1361 CircleMerk = false;
1362 ValueBarMerk = false;
1363 }
1364 }
1365
1366
1367 static void
keyCallback(void * data,int key,int state,int x,int y,int modifiers)1368 keyCallback(void *data, int key, int state, int x, int y, int modifiers)
1369 {
1370
1371 if (key == SW_MOUSE1)
1372 {
1373 drawing = state;
1374 mouseCallback(data, x, y, modifiers);
1375 }
1376
1377 }
1378
1379
1380
1381 static void
resizeCallback(void * data,int x,int y)1382 resizeCallback(void *data, int x, int y)
1383 {
1384 SDC dc = swCreateDC(canvas);
1385
1386 int Color;
1387 struct Colors colors = {0,0,0};
1388 struct window_size window;
1389
1390 swSetFGColor(dc, swGetWindowColor(canvas, SW_COLOR_WINDOW_BG));
1391 swFillRect(dc, 0, 0, x, y);
1392
1393 window.x_window = x;
1394 window.y_window = y;
1395
1396 GetPositions(&window, true);
1397
1398 swDestroyDC(dc);
1399 }
1400
1401
1402 static void
exposeCallback(void * data,int x,int y,int width,int height)1403 exposeCallback(void *data, int x, int y, int width, int height)
1404 {
1405 SDC dc = swCreateDC(canvas);
1406 int Color, x0, y0;
1407 struct Colors colors = {0,0,0};
1408
1409
1410 swSetFGColor(dc, swGetWindowColor(canvas, SW_COLOR_WINDOW_BG));
1411 swFillRect(dc, x, y, width, height);
1412
1413 Color = SetGetColorPoint(0, false);
1414 SetGetColorPoint(Color, true);
1415 SetValue_ScrollBar(Color);
1416 SetTextColorsValues(Color);
1417 SetColorPalette(Color);
1418 SetCircle();
1419 SetBarValue();
1420
1421 swDestroyDC(dc);
1422 }
1423
ColorPaletteCircle(float * Red,float * Green,float * Blue)1424 void ColorPaletteCircle(float *Red, float *Green, float *Blue)
1425 {
1426
1427 SWND window;
1428
1429 int ScrollBarWidth = 200;
1430 int ScrollBarHeight = 15;
1431 int TextEditWidth = 30;
1432 int TextEditHeight = 15;
1433 int ButtonWidth = 80;
1434
1435 int Color, ColorTemp;
1436
1437 float RedValue, GreenValue, BlueValue;
1438
1439 RedValue = *Red;
1440 GreenValue = *Green;
1441 BlueValue = *Blue;
1442
1443 OldColor(&RedValue, &GreenValue, &BlueValue, true);
1444
1445 Color = Round_float_to_int((RedValue) * ((float)MAXFARBANTEIL));
1446 ColorTemp = Round_float_to_int((GreenValue) * ((float)MAXFARBANTEIL));
1447 Color += ColorTemp << 8;
1448 ColorTemp = Round_float_to_int((BlueValue) * ((float)MAXFARBANTEIL));
1449 Color += ColorTemp << 16;
1450
1451 SetGetColorPoint(Color, true);
1452
1453 window = swCreateMainWindow("Palettes", 300, 200, X_WINDOWSIZE, Y_WINDOWSIZE);
1454 // ("Name des Fensters", X-Postition, Y-Position, X-Size, Y-Size);
1455
1456 canvas = swCreateCanvas("", 0, 0, 800, 800, window);
1457 // ("", X-Begin of draw, Y-Begin of draw, X-Size of draw, Y-Size of draw
1458 // ,window);
1459
1460
1461 CloseButton = swCreateButton("Close", 180, Y_ScrollBar_TextEdit + 3* Y_ABSTAND, ButtonWidth, 20, canvas);
1462 OkeyButton = swCreateButton("OK", 20, Y_ScrollBar_TextEdit + 3* Y_ABSTAND, ButtonWidth, 20, canvas);
1463
1464 RedScrollBar = swCreateScrollBar(SW_HORIZONTAL, X_ScrollBar, Y_ScrollBar_TextEdit, ScrollBarWidth,
1465 ScrollBarHeight, 0, AUFLOESUNG + ScrollBarVisit, 0, ScrollBarVisit,
1466 canvas);
1467 GreenScrollBar = swCreateScrollBar(SW_HORIZONTAL, X_ScrollBar, Y_ScrollBar_TextEdit + Y_ABSTAND,
1468 ScrollBarWidth, ScrollBarHeight, 0, AUFLOESUNG + ScrollBarVisit,
1469 0, ScrollBarVisit, canvas);
1470
1471 BlueScrollBar = swCreateScrollBar(SW_HORIZONTAL, X_ScrollBar, Y_ScrollBar_TextEdit + 2 * Y_ABSTAND,
1472 ScrollBarWidth, ScrollBarHeight, 0, AUFLOESUNG + ScrollBarVisit,
1473 0, ScrollBarVisit, canvas);
1474
1475
1476 RedTextEdit = swCreateTextEdit(SW_SINGLE_LINE,
1477 X_TEXTEDIT, Y_ScrollBar_TextEdit, TextEditWidth, TextEditHeight, canvas);
1478 GreenTextEdit = swCreateTextEdit(SW_SINGLE_LINE,
1479 X_TEXTEDIT, Y_ScrollBar_TextEdit + Y_ABSTAND, TextEditWidth, TextEditHeight, canvas);
1480 BlueTextEdit = swCreateTextEdit(SW_SINGLE_LINE,
1481 X_TEXTEDIT, Y_ScrollBar_TextEdit + 2* Y_ABSTAND, TextEditWidth, TextEditHeight, canvas);
1482
1483
1484 swTextEditSetSelection(RedTextEdit, 1, 2);
1485 swTextEditSetSelection(GreenTextEdit, 1, 4);
1486 swTextEditSetSelection(BlueTextEdit, 1, 4);
1487
1488 swSetCommandCallback(RedTextEdit, RedTextEditInput);
1489 swSetCommandCallback(GreenTextEdit, GreenTextEditInput);
1490 swSetCommandCallback(BlueTextEdit, BlueTextEditInput);
1491 swSetExposeCallback(canvas, exposeCallback);
1492 swSetKeyCallback(canvas, keyCallback);
1493 swSetCommandCallback(CloseButton, CloseButtonCallback);
1494 swSetCommandCallback(OkeyButton, OkeyButtonCallback);
1495
1496 swSetScrollBarCallback(RedScrollBar, RedScrollCallback);
1497 swSetScrollBarCallback(GreenScrollBar, GreenScrollCallback);
1498 swSetScrollBarCallback(BlueScrollBar, BlueScrollCallback);
1499 swSetMouseCallback(canvas, mouseCallback);
1500 swSetResizeCallback(window, resizeCallback);
1501 swShowWindow(window);
1502 swMainLoop();
1503 swDestroyWindow(window);
1504
1505 }
1506
1507
1508 #ifdef WIN32
WinMain(HINSTANCE hInstance,HINSTANCE prevInstance,LPSTR lpCmdLine,int nCmdShow)1509 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE prevInstance,
1510 LPSTR lpCmdLine, int nCmdShow)
1511 #else
1512 int main(int argc, char **argv)
1513 #endif
1514 {
1515
1516 #ifdef WIN32
1517 swInitialize(hInstance);
1518 #else
1519 swInitialize(&argc, argv, 0);
1520 #endif
1521
1522 float Red=0.40, Green=0.50, Blue=0.60;
1523
1524 ColorPaletteCircle(&Red, &Green, &Blue);
1525
1526 return 0;
1527 }
1528