Get the value of the color from the ColorPicker

How would I get the color from the colorpicker when it's changed by the user?


The Overview sample displays the color picker and if I select some text in the text control the color is changed, but how would I get the value returned from the picker when it's clicked?

tia

The color picker is predefined picker that interacts with other native controls. We have investigated this but it is unclear how to implement an event that triggers when a color is selected. We will add this on our todolist for further investigation.


Kind Regards, 
Pieter

Thanks PIeter, I had a quick look at it today, and it's not that simple. One thought I had was to make a component that you can hook up to a control with an NSView (maybe a form - not sure how firemonkey implements forms - are they NSViews?). The component can make the control the first responder, and capture the changeColor event. The component can then fire an event with the color received, I think that might work.


cheers,
Dave

Hi, 


The root view is actually a FMXView which inherits from NSView (declared in FMX.Platform.Mac) and already implements keyboard, mouse handling etc... color changes are not triggered and it is also unclear how to intercept this from outside the FMX.Platform.Mac source.

Kind Regards, 
Pieter

Here we go - create a firemonkey app, pop a TMSFMXNativeToolbar with a Color picker button, and a Tbutton on the form. Click the color picker button to display the picker, click button1 and from now on any color selected is displayed. Needs a lot of cleaning up now :-)


Dave


unit Unit6;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
  Macapi.Appkit, FMX.TMSNativeNSBaseControl, FMX.TMSNativeNSToolBar,
  Macapi.ObjectiveC, System.TypInfo, Macapi.ObjCRuntime, Macapi.CocoaTypes;

type

  TNSColorPickerEventHandler = class(TOCLocal)
  private
    FControl: NSColorPanel;
  protected
    function GetObjectiveCClass: PTypeInfo; override;
  public
    procedure colorChanged(Sender: Pointer); cdecl;
  end;

  INSColorPickerEventHandler = interface(NSObject)
  ['{5CC917F8-7E3E-4D21-81CC-E0076DCDCCF7}']
    procedure colorChanged(Sender: Pointer); cdecl;
  end;

  TForm6 = class(TForm)
    Button1: TButton;
    TMSFMXNativeNSToolbar1: TTMSFMXNativeNSToolbar;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    FColorPanel : NSColorPanel;
    FColorEvent: TNSColorPickerEventHandler;
  end;


var
  Form6: TForm6;

implementation

{$R *.fmx}

procedure TForm6.Button1Click(Sender: TObject);
begin
  FColorPanel :=TNSColorPanel.Wrap(TNSColorPanel.OCClass.sharedColorPanel);
  FColorEvent := TNSColorPickerEventHandler.Create;
  FColorEvent.FControl := FColorPanel;

  FColorPanel.setTarget(FColorEvent.GetObjectID);
  FColorPanel.setAction(sel_getUid('colorChanged:'));

end;


{ TNSColorPickerEventHandler }

procedure TNSColorPickerEventHandler.colorChanged(Sender: Pointer);
begin
  ShowMessage(
    'r: ' + FloatToStr(FControl.color.redComponent) +
    ' g: ' + FloatToStr(FControl.color.greenComponent) +
    ' b: ' + FloatToStr(FControl.color.blueComponent));

end;

function TNSColorPickerEventHandler.GetObjectiveCClass: PTypeInfo;
begin
  Result := TypeInfo(INSColorPickerEventHandler);
end;

end.

Thanks, we will look into incorporating this into the toolbar component as an additional event.


Kind Regards,
Pieter

Great, would you have a rough idea when that would be?


Dave

Tomorrow we will release an update of TMS mCL, 


Kind Regards, 
Pieter

Wow, that's pretty impressive. Thanks