Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Get the value of the color from the ColorPicker

 Post Reply Post Reply
Author
Ninnes David View Drop Down
New Member
New Member
Avatar

Joined: 04 Nov 2014
Posts: 10
Post Options Post Options   Quote Ninnes David Quote  Post ReplyReply Direct Link To This Post Topic: Get the value of the color from the ColorPicker
    Posted: 04 Nov 2014 at 6:43am
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
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3499
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2014 at 2:39am
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
Back to Top
Ninnes David View Drop Down
New Member
New Member
Avatar

Joined: 04 Nov 2014
Posts: 10
Post Options Post Options   Quote Ninnes David Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2014 at 7:57am
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
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3499
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2014 at 9:23am
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
Back to Top
Ninnes David View Drop Down
New Member
New Member
Avatar

Joined: 04 Nov 2014
Posts: 10
Post Options Post Options   Quote Ninnes David Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2014 at 4:40am
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.

Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3499
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2014 at 4:51am
Thanks, we will look into incorporating this into the toolbar component as an additional event.

Kind Regards,
Pieter
Back to Top
Ninnes David View Drop Down
New Member
New Member
Avatar

Joined: 04 Nov 2014
Posts: 10
Post Options Post Options   Quote Ninnes David Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2014 at 6:19am
Great, would you have a rough idea when that would be?

Dave
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3499
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2014 at 6:47am
Tomorrow we will release an update of TMS mCL, 

Kind Regards, 
Pieter
Back to Top
Ninnes David View Drop Down
New Member
New Member
Avatar

Joined: 04 Nov 2014
Posts: 10
Post Options Post Options   Quote Ninnes David Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2014 at 7:06am
Wow, that's pretty impressive. Thanks
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down