diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-10-01 13:23:01 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-10-01 13:23:01 +0200 |
commit | 92e9d30fc3500c49e55a44a23b4a726b8016ddf7 (patch) | |
tree | b5a37cf9c29d8f9689d32c893630572fb05ebd32 /uidesigner | |
parent | 3f5a719c9ff49083147230979fea496818b27fdc (diff) | |
download | fpGUI-92e9d30fc3500c49e55a44a23b4a726b8016ddf7.tar.xz |
uidesigner: Implemented a TfpgColor property editor
Now finally we should be able to edit color values in the Object Inspector.
Known Limitations
* Color names like clRed are not parsed yet. Such values will be read
and written back as TfpgColor($FF0000) instead. I'm working on
fixing this.
Diffstat (limited to 'uidesigner')
-rw-r--r-- | uidesigner/uidesigner.lpr | 2 | ||||
-rw-r--r-- | uidesigner/vfdformparser.pas | 24 | ||||
-rw-r--r-- | uidesigner/vfdprops.pas | 95 |
3 files changed, 118 insertions, 3 deletions
diff --git a/uidesigner/uidesigner.lpr b/uidesigner/uidesigner.lpr index a7fa44e5..968a45dc 100644 --- a/uidesigner/uidesigner.lpr +++ b/uidesigner/uidesigner.lpr @@ -23,7 +23,7 @@ uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} - Classes, SysUtils, fpg_main, vfdmain, vfdresizer, vfdforms, + Classes, SysUtils, fpg_base, fpg_main, vfdmain, vfdresizer, vfdforms, vfdfile, newformdesigner, vfdwidgets, vfdformparser, vfdeditors, vfdwidgetclass, vfdutils, vfdprops, vfddesigner, vfdpropeditgrid; diff --git a/uidesigner/vfdformparser.pas b/uidesigner/vfdformparser.pas index e08d9ce2..693107e0 100644 --- a/uidesigner/vfdformparser.pas +++ b/uidesigner/vfdformparser.pas @@ -25,6 +25,7 @@ interface uses Classes, SysUtils, + fpg_base, fpg_main, fpg_widget, fpg_form, @@ -59,6 +60,7 @@ function CheckSymbol(var s: string; const sym: string): boolean; function GetIntValue(var s: string): integer; function GetBoolValue(var s: string): boolean; function GetFloatValue(var s: string): extended; +function GetColorValue(var s: string): integer; implementation @@ -240,6 +242,28 @@ begin // Result := u8(Result); end; +function GetColorValue(var s: string): integer; +var + n: integer; + ns: string; +begin + SkipSpaces(s); + GetIdentifier(s); // extract 'TfpgColor' identifier + CheckSymbol(s, '('); + SkipSpaces(s); + ns := ''; + n := 1; + while (n <= length(s)) and (s[n] in ['$','0'..'9','a'..'f','A'..'F']) do + begin + ns := ns + s[n]; + Inc(n); + end; + Result := StrToIntDef(ns, clWindowBackground); + Delete(s, 1, length(ns)); + SkipSpaces(s); + CheckSymbol(s, ')'); +end; + function GetIdentifier(var s: string): string; var n: integer; diff --git a/uidesigner/vfdprops.pas b/uidesigner/vfdprops.pas index 8eb3c896..b0c659fe 100644 --- a/uidesigner/vfdprops.pas +++ b/uidesigner/vfdprops.pas @@ -92,6 +92,16 @@ type function CreateEditor(AOwner: TComponent): TVFDPropertyEditor; override; procedure OnExternalEdit(wg: TfpgWidget); override; end; + + + TPropertyColor = class(TVFDWidgetProperty) + public + function ParseSourceLine(wg: TfpgWidget; const line: string): boolean; override; + function GetPropertySource(wg: TfpgWidget; const ident: string): string; override; + function GetValueText(wg: TfpgWidget): string; override; + function CreateEditor(AOwner: TComponent): TVFDPropertyEditor; override; + procedure OnExternalEdit(wg: TfpgWidget); override; + end; TGPEType = (gptInteger, gptString, gptFloat); @@ -657,7 +667,7 @@ begin try SetEnumProp(wg, Name, sval); except - Writeln('invalid enum value: "' + sval + '" for ' + Name); +// Writeln('invalid enum value: "' + sval + '" for ' + Name); Result := False; end; end; @@ -767,7 +777,7 @@ end; function TPropertyFloat.GetPropertySource(wg: TfpgWidget; const ident: string): string; begin - Result := ident + Name + ' := ' + FloatToStr(GetFloatProp(wg, Name)) + ';' + LineEnding + Result := ident + Name + ' := ' + FloatToStr(GetFloatProp(wg, Name)) + ';' + LineEnding; end; function TPropertyFloat.GetValueText(wg: TfpgWidget): string; @@ -782,5 +792,86 @@ begin etype := gptFloat; end; +{ TPropertyColor } + +function TPropertyColor.ParseSourceLine(wg: TfpgWidget; const line: string): boolean; +var + s: string; + ival: integer; +begin + s := line; + Result := False; + if UpperCase(GetIdentifier(s)) <> UpperCase(Name) then + Exit; + + Result := CheckSymbol(s, ':='); + if Result then + begin + ival := GetColorValue(s); + Result := CheckSymbol(s, ';'); + end; + + if Result then + try + SetOrdProp(wg, Name, ival); + except +// Writeln('invalid ordinal value: "', ival, '" for ', Name); + Result := False; + end; +end; + +function TPropertyColor.GetPropertySource(wg: TfpgWidget; const ident: string): string; +var + PropInfo: PPropInfo; + i: integer; + c: TfpgColor; + nc: TfpgColor; +begin + PropInfo := GetPropInfo(wg.ClassType, Name); + i := GetOrdProp(wg, Name); + if PropInfo^.Default <> i then + begin + if fpgIsNamedColor(TfpgColor(i)) then + Result := ident + Name + ' := TfpgColor($' + IntToHex(i, 8) + ');' + LineEnding + else + begin + c := fpgColorToRGB(TfpgColor(i)); + Result := ident + Name + ' := TfpgColor($' + IntToHex(c, 6) + ');' + LineEnding; + end; + end + else + Result := ''; +end; + +function TPropertyColor.GetValueText(wg: TfpgWidget): string; +var + PropInfo: PPropInfo; + i: integer; + c: TfpgColor; +begin + PropInfo := GetPropInfo(wg.ClassType, Name); + i := GetOrdProp(wg, Name); + c := fpgColorToRGB(TfpgColor(i)); + Result := '$' + IntToHex(c, 6); +end; + +function TPropertyColor.CreateEditor(AOwner: TComponent): TVFDPropertyEditor; +begin + Result := TExternalPropertyEditor.Create(AOwner, self); +end; + +procedure TPropertyColor.OnExternalEdit(wg: TfpgWidget); +var + PropInfo: PPropInfo; + i: integer; + c: TfpgColor; +begin + PropInfo := GetPropInfo(wg.ClassType, Name); + i := GetOrdProp(wg, Name); + c := fpgColorToRGB(TfpgColor(i)); + c := fpgSelectColorDialog(c); + SetOrdProp(wg, Name, c); +end; + end. |