1////////////////////////////////////////////////////////////////////////////////
2// //
3// This software is supplied under the terms of a license agreement or //
4// nondisclosure agreement with Mitov Software and may not be copied //
5// or disclosed except in accordance with the terms of that agreement. //
6// Copyright(c) 2002-2016 Mitov Software. All Rights Reserved. //
7// //
8////////////////////////////////////////////////////////////////////////////////
9
10#ifndef _MITOV_COLOR_h
11#define _MITOV_COLOR_h
12
13#include <Mitov.h>
14#include "Mitov_RandomGenerator.h"
15
16namespace Mitov
17{
18#define Min Min
19#define Max Max
20//---------------------------------------------------------------------------
21 class RandomColor : public Mitov::CommonRandomGenerator<Mitov::TColor>
22 {
23 typedef Mitov::CommonRandomGenerator<Mitov::TColor> inherited;
24
25 public:
26 virtual void GenerateValue()
27 {
28 FValue.Red = random( Min.Red, Max.Red + 1 );
29 FValue.Green = random( Min.Green, Max.Green + 1 );
30 FValue.Blue = random( Min.Blue, Max.Blue + 1 );
31 }
32
33 virtual void SystemInit()
34 {
35 int AMin = MitovMin( Min.Red, Max.Red );
36 int AMax = MitovMax( Min.Red, Max.Red );
37
38 Min.Red = AMin;
39 Max.Red = AMax;
40
41 AMin = MitovMin( Min.Green, Max.Green );
42 AMax = MitovMax( Min.Green, Max.Green );
43
44 Min.Green = AMin;
45 Max.Green = AMax;
46
47 AMin = MitovMin( Min.Blue, Max.Blue );
48 AMax = MitovMax( Min.Blue, Max.Blue );
49
50 Min.Blue = AMin;
51 Max.Blue = AMax;
52
53 inherited::SystemInit();
54 }
55
56 public:
57 RandomColor() :
58 inherited( 0, 0xFFFFFF )
59 {
60 }
61
62 };
63//---------------------------------------------------------------------------
64 class BasicColorSource : public CommonSource
65 {
66 public:
67 TColor InitialValue;
68
69 };
70//---------------------------------------------------------------------------
71 class AnalogToColor : public BasicColorSource
72 {
73 public:
74 OpenWire::SinkPin RedInputPin;
75 OpenWire::SinkPin GreenInputPin;
76 OpenWire::SinkPin BlueInputPin;
77
78 protected:
79 TColor FValue;
80
81 protected:
82 void DoReceiveRed( void *_Data )
83 {
84 unsigned char AValue = (*(float *)_Data ) * 255;
85 if( FValue.Red == AValue )
86 return;
87
88 FValue.Red = AValue;
89 OutputPin.Notify( &FValue );
90 }
91
92 void DoReceiveGreen( void *_Data )
93 {
94 unsigned char AValue = (*(float *)_Data ) * 255;
95 if( FValue.Green == AValue )
96 return;
97
98 FValue.Green = AValue;
99 OutputPin.Notify( &FValue );
100 }
101
102 void DoReceiveBlue( void *_Data )
103 {
104 unsigned char AValue = (*(float *)_Data ) * 255;
105 if( FValue.Blue == AValue )
106 return;
107
108 FValue.Blue = AValue;
109 OutputPin.Notify( &FValue );
110 }
111
112 virtual void SystemStart()
113 {
114 FValue = InitialValue;
115 OutputPin.Notify( &FValue );
116 }
117
118 public:
119 AnalogToColor()
120 {
121 RedInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&AnalogToColor::DoReceiveRed );
122 GreenInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&AnalogToColor::DoReceiveGreen );
123 BlueInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&AnalogToColor::DoReceiveBlue );
124 }
125
126 };
127//---------------------------------------------------------------------------
128 class ColorToAnalog : public CommonSink
129 {
130 public:
131 OpenWire::SourcePin RedOutputPin;
132 OpenWire::SourcePin GreenOutputPin;
133 OpenWire::SourcePin BlueOutputPin;
134
135 protected:
136 virtual void DoReceive( void *_Data )
137 {
138 TColor &AColor = *(TColor *)_Data;
139 RedOutputPin.Notify( &AColor.Red );
140 GreenOutputPin.Notify( &AColor.Green );
141 BlueOutputPin.Notify( &AColor.Blue );
142 }
143
144 };
145//---------------------------------------------------------------------------
146#undef Min
147#undef Max
148}
149
150#endif