col := ColorInput.asColor;
col.R(Round(RedCtl.asFloat));
ColorOutput.asColor(col);
| Procedure | Description |
|---|---|
function TAlphaColor.A: integer; overload; |
Get the alpha (transparency) component of the color |
procedure TAlphaColor.A(V: integer); overload; |
Set the alpha (transparency) component of the color |
function TAlphaColor.R: integer; overload; |
Get the red component of the color |
procedure TAlphaColor.R(V: integer); overload; |
Set the red component of the color |
function TAlphaColor.G: integer; overload; |
Get the green component of the color |
procedure TAlphaColor.G(V: integer); overload; |
Set the green component of the color |
function TAlphaColor.B: integer; overload; |
Get the blue component of the color |
procedure TAlphaColor.B(V: integer); overload; |
Set the blue component of the color |
////////////////////////////////////////////////////////////////////////////////
// Color Channels Demo - illustrates reading and writing the individual ARGB
// components of a TAlphaColor. Use "read color" to inspect the incoming color
// and "apply color" to push edited channel values to the output.
////////////////////////////////////////////////////////////////////////////////
const DEFAULT_COLOR = $FF2196F3; // opaque blue used to seed the module
var
ReadBtn : TParameter;
ApplyBtn : TParameter;
ColorInput : TParameter;
ColorOutput: TParameter;
AlphaCtl : TParameter;
RedCtl : TParameter;
GreenCtl : TParameter;
BlueCtl : TParameter;
InfoOut : TParameter;
procedure UpdateChannelControls(const colorVal: TAlphaColor);
begin
AlphaCtl.asFloat(colorVal.A); // expose current alpha channel (0..255)
RedCtl.asFloat(colorVal.R); // expose current red channel (0..255)
GreenCtl.asFloat(colorVal.G); // expose current green channel (0..255)
BlueCtl.asFloat(colorVal.B); // expose current blue channel (0..255)
end;
procedure PushChannelsToOutput;
var
colorVal: TAlphaColor;
begin
colorVal := ColorInput.asColor; // start from the current input swatch
colorVal.A(Round(AlphaCtl.asFloat)); // apply edited alpha value
colorVal.R(Round(RedCtl.asFloat)); // apply edited red value
colorVal.G(Round(GreenCtl.asFloat)); // apply edited green value
colorVal.B(Round(BlueCtl.asFloat)); // apply edited blue value
ColorOutput.asColor(colorVal); // push the modified color to the output swatch
UpdateChannelControls(colorVal); // refresh controls in case values were clipped
InfoOut.asString('Output updated with custom ARGB channels.');
end;
procedure Init;
begin
ModuleColor($FF512DA8);
ReadBtn := CreateParam('read color', ptButton, pioInput);
ApplyBtn := CreateParam('apply color', ptButton, pioInput);
ColorInput := CreateParam('color in', ptColor, pioInput);
ColorOutput := CreateParam('color out', ptColor, pioOutput);
AlphaCtl := CreateParam('alpha', ptDataFader, pioInput);
RedCtl := CreateParam('red', ptDataFader, pioInput);
GreenCtl := CreateParam('green', ptDataFader, pioInput);
BlueCtl := CreateParam('blue', ptDataFader, pioInput);
InfoOut := CreateParam('info', ptTextField, pioOutput);
ColorInput.asColor(DEFAULT_COLOR);
ColorOutput.asColor(DEFAULT_COLOR);
// Configure the channel faders to match the byte range of each color component.
AlphaCtl.Min(0); AlphaCtl.Max(255);
RedCtl.Min(0); RedCtl.Max(255);
GreenCtl.Min(0); GreenCtl.Max(255);
BlueCtl.Min(0); BlueCtl.Max(255);
UpdateChannelControls(ColorInput.asColor);
InfoOut.asString('Press "apply color" after tweaking the channel sliders.');
end;
procedure Callback(N: integer);
var
sampledColor: TAlphaColor;
begin
if N = ReadBtn then
begin
sampledColor := ColorInput.asColor;
UpdateChannelControls(sampledColor);
ColorOutput.asColor(sampledColor);
InfoOut.asString('Channel sliders refreshed from the input color.');
end;
if N = ApplyBtn then
PushChannelsToOutput;
end;
version 7.0.250121
Edit All Pages