diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-04-29 09:58:19 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-04-29 09:58:19 +0200 |
commit | 8c67847e50cb1b2f9fd5ffdc59f2309ab05bd4a5 (patch) | |
tree | df8cf396bd762a52a51a36feaece7d82c7d5ee6f | |
parent | 9d3499d7fd0c88fe161b4484ec7f6685b8a934a8 (diff) | |
download | fpGUI-8c67847e50cb1b2f9fd5ffdc59f2309ab05bd4a5.tar.xz |
New "Select Color" dialog added to fpGUI.
Not 100% complete yet, but the first tab is working.
-rw-r--r-- | src/corelib/gdi/fpgui_toolkit.lpk | 6 | ||||
-rw-r--r-- | src/corelib/x11/fpgui_toolkit.lpk | 6 | ||||
-rw-r--r-- | src/gui/colordialog.inc | 318 | ||||
-rw-r--r-- | src/gui/fpg_dialogs.pas | 11 |
4 files changed, 336 insertions, 5 deletions
diff --git a/src/corelib/gdi/fpgui_toolkit.lpk b/src/corelib/gdi/fpgui_toolkit.lpk index 36e40d61..89a5466d 100644 --- a/src/corelib/gdi/fpgui_toolkit.lpk +++ b/src/corelib/gdi/fpgui_toolkit.lpk @@ -31,7 +31,7 @@ <Description Value="fpGUI Toolkit"/>
<License Value="LGPL 2 with static linking exception."/>
<Version Minor="7"/>
- <Files Count="75">
+ <Files Count="76">
<Item1>
<Filename Value="..\stdimages.inc"/>
<Type Value="Include"/>
@@ -332,6 +332,10 @@ <Filename Value="..\..\gui\fpg_editbtn.pas"/>
<UnitName Value="fpg_editbtn"/>
</Item75>
+ <Item76>
+ <Filename Value="..\..\gui\colordialog.inc"/>
+ <Type Value="Include"/>
+ </Item76>
</Files>
<LazDoc Paths="..\..\..\docs\xml\corelib\;..\..\..\docs\xml\corelib\x11\;..\..\..\docs\xml\corelib\gdi\;..\..\..\docs\xml\gui\"/>
<RequiredPkgs Count="1">
diff --git a/src/corelib/x11/fpgui_toolkit.lpk b/src/corelib/x11/fpgui_toolkit.lpk index 9f5476d3..5f26eaaf 100644 --- a/src/corelib/x11/fpgui_toolkit.lpk +++ b/src/corelib/x11/fpgui_toolkit.lpk @@ -32,7 +32,7 @@ <License Value="LGPL 2 with static linking exception. "/> <Version Minor="7"/> - <Files Count="79"> + <Files Count="80"> <Item1> <Filename Value="../stdimages.inc"/> <Type Value="Include"/> @@ -349,6 +349,10 @@ <Filename Value="../../gui/fpg_editbtn.pas"/> <UnitName Value="fpg_editbtn"/> </Item79> + <Item80> + <Filename Value="../../gui/colordialog.inc"/> + <Type Value="Include"/> + </Item80> </Files> <LazDoc Paths="../../../docs/xml/corelib/;../../../docs/xml/corelib/x11/;../../../docs/xml/corelib/gdi/;../../../docs/xml/gui/"/> <RequiredPkgs Count="1"> diff --git a/src/gui/colordialog.inc b/src/gui/colordialog.inc new file mode 100644 index 00000000..6f7576be --- /dev/null +++ b/src/gui/colordialog.inc @@ -0,0 +1,318 @@ +{ + fpGUI - Free Pascal GUI Toolkit + + Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this + distribution, for details of the copyright. + + See the file COPYING.modifiedLGPL, included in this distribution, + for details about redistributing fpGUI. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + Description: + This unit contains the Color Selection dialog. +} + + +{%mainunit fpg_dialogs.pas} + +{$IFDEF read_interface} + +type + + TfpgColorSelectDialog = class(TfpgBaseDialog) + private + {@VFD_HEAD_BEGIN: ColorSelectDialog} + PageControl1: TfpgPageControl; + TabSheet1: TfpgTabSheet; + TabSheet2: TfpgTabSheet; + ComboBox1: TfpgComboBox; + ColorListBox1: TfpgColorListBox; + Label1: TfpgLabel; + Label2: TfpgLabel; + ColorWheel: TfpgColorWheel; + ValueBar: TfpgValueBar; + edR: TfpgSpinEdit; + edG: TfpgSpinEdit; + edB: TfpgSpinEdit; + Label3: TfpgLabel; + Label4: TfpgLabel; + Label5: TfpgLabel; + pnlColorPreview: TfpgBevel; + {@VFD_HEAD_END: ColorSelectDialog} + FViaRGB: Boolean; // to prevent recursive changes + function GetSelectedColor: TfpgColor; + procedure SetSelectedColor(const AValue: TfpgColor); + procedure ColorChanged(Sender: TObject); + procedure RGBChanged(Sender: TObject); + procedure UpdateRGBComponents; + public + constructor Create(AOwner: TComponent); override; + procedure AfterCreate; override; + property SelectedColor: TfpgColor read GetSelectedColor write SetSelectedColor; + end; + + +function fpgSelectColorDialog(APresetColor: TfpgColor = clBlack): TfpgColor; + +{$ENDIF read_interface} + + + +{$IFDEF read_implementation} + + +function fpgSelectColorDialog(APresetColor: TfpgColor): TfpgColor; +var + frm: TfpgColorSelectDialog; +begin + Result := APresetColor; + frm := TfpgColorSelectDialog.Create(nil); + try + frm.ColorWheel.SetSelectedColor(APresetColor); + if frm.ShowModal = mrOK then + Result := frm.ValueBar.SelectedColor; + finally + frm.Free; + end; +end; + +{ TfpgColorSelectDialog } + +function TfpgColorSelectDialog.GetSelectedColor: TfpgColor; +begin + // +end; + +procedure TfpgColorSelectDialog.SetSelectedColor(const AValue: TfpgColor); +begin + // +end; + +procedure TfpgColorSelectDialog.ColorChanged(Sender: TObject); +begin +// UpdateHSVComponents; + if not FViaRGB then + UpdateRGBComponents; + pnlColorPreview.BackgroundColor := ValueBar.SelectedColor; +end; + +procedure TfpgColorSelectDialog.RGBChanged(Sender: TObject); +var + rgb: TRGBTriple; + c: TfpgColor; +begin + FViaRGB := True; // prevent recursive updates + rgb.Red := edR.Value; + rgb.Green := edG.Value; + rgb.Blue := edB.Value; + c := RGBTripleTofpgColor(rgb); + ColorWheel.SetSelectedColor(c); // This will trigger ColorWheel and ValueBar OnChange event + FViaRGB := False; +end; + +procedure TfpgColorSelectDialog.UpdateRGBComponents; +var + rgb: TRGBTriple; + c: TfpgColor; +begin + c := ValueBar.SelectedColor; + rgb := fpgColorToRGBTriple(c); + edR.Value := rgb.Red; + edG.Value := rgb.Green; + edB.Value := rgb.Blue; +end; + +constructor TfpgColorSelectDialog.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FViaRGB := false; +end; + + +procedure TfpgColorSelectDialog.AfterCreate; +begin + {%region 'Auto-generated GUI code' -fold} + {@VFD_BODY_BEGIN: ColorSelectDialog} + Name := 'ColorSelectDialog'; + SetPosition(316, 186, 328, 375); + WindowTitle := 'Color Select Dialog'; + Hint := ''; + WindowPosition := wpOneThirdDown; + + PageControl1 := TfpgPageControl.Create(self); + with PageControl1 do + begin + Name := 'PageControl1'; + SetPosition(4, 4, 320, 332); + Anchors := [anLeft,anRight,anTop,anBottom]; + ActivePageIndex := 0; + Hint := ''; + TabOrder := 1; + end; + + TabSheet1 := TfpgTabSheet.Create(PageControl1); + with TabSheet1 do + begin + Name := 'TabSheet1'; + SetPosition(3, 24, 314, 305); + Text := 'Color Wheel'; + end; + + TabSheet2 := TfpgTabSheet.Create(PageControl1); + with TabSheet2 do + begin + Name := 'TabSheet2'; + SetPosition(3, 24, 314, 305); + Text := 'Predefined'; + end; + + ComboBox1 := TfpgComboBox.Create(TabSheet2); + with ComboBox1 do + begin + Name := 'ComboBox1'; + SetPosition(8, 24, 299, 22); + Anchors := [anLeft,anRight,anTop]; + FontDesc := '#List'; + Hint := ''; + TabOrder := 1; + end; + + ColorListBox1 := TfpgColorListBox.Create(TabSheet2); + with ColorListBox1 do + begin + Name := 'ColorListBox1'; + SetPosition(8, 72, 299, 224); + Anchors := [anLeft,anRight,anTop,anBottom]; + ColorPalette := cpStandardColors; + FontDesc := '#List'; + Hint := ''; + HotTrack := False; + PopupFrame := False; + TabOrder := 2; + end; + + Label1 := TfpgLabel.Create(TabSheet2); + with Label1 do + begin + Name := 'Label1'; + SetPosition(8, 6, 328, 16); + FontDesc := '#Label1'; + Hint := ''; + Text := 'Select a color palette'; + end; + + Label2 := TfpgLabel.Create(TabSheet2); + with Label2 do + begin + Name := 'Label2'; + SetPosition(8, 54, 328, 16); + FontDesc := '#Label1'; + Hint := ''; + Text := 'Available colors:'; + end; + + ColorWheel := TfpgColorWheel.Create(TabSheet1); + with ColorWheel do + begin + Name := 'ColorWheel'; + SetPosition(8, 8, 204, 204); + end; + + ValueBar := TfpgValueBar.Create(TabSheet1); + with ValueBar do + begin + Name := 'ValueBar'; + SetPosition(240, 8, 64, 204); + OnChange := @ColorChanged; + end; + + edR := TfpgSpinEdit.Create(TabSheet1); + with edR do + begin + Name := 'edR'; + SetPosition(92, 216, 52, 24); + MaxValue := 255; + MinValue := 0; + OnChange := @RGBChanged; + end; + + edG := TfpgSpinEdit.Create(TabSheet1); + with edG do + begin + Name := 'edG'; + SetPosition(92, 244, 52, 24); + MaxValue := 255; + MinValue := 0; + OnChange := @RGBChanged; + end; + + edB := TfpgSpinEdit.Create(TabSheet1); + with edB do + begin + Name := 'edB'; + SetPosition(92, 272, 52, 24); + MaxValue := 255; + MinValue := 0; + OnChange := @RGBChanged; + end; + + Label3 := TfpgLabel.Create(TabSheet1); + with Label3 do + begin + Name := 'Label3'; + SetPosition(8, 220, 80, 16); + Alignment := taRightJustify; + FontDesc := '#Label1'; + Hint := ''; + Text := 'Red'; + end; + + Label4 := TfpgLabel.Create(TabSheet1); + with Label4 do + begin + Name := 'Label4'; + SetPosition(8, 248, 80, 16); + Alignment := taRightJustify; + FontDesc := '#Label1'; + Hint := ''; + Text := 'Green'; + end; + + Label5 := TfpgLabel.Create(TabSheet1); + with Label5 do + begin + Name := 'Label5'; + SetPosition(8, 276, 80, 16); + Alignment := taRightJustify; + FontDesc := '#Label1'; + Hint := ''; + Text := 'Blue'; + end; + + pnlColorPreview := TfpgBevel.Create(TabSheet1); + with pnlColorPreview do + begin + Name := 'pnlColorPreview'; + SetPosition(248, 232, 52, 52); + Hint := ''; + end; + + {@VFD_BODY_END: ColorSelectDialog} + {%endregion} + + // link colorwheel and valuebar + ColorWheel.ValueBar := ValueBar; + + // position standard dialog buttons + btnCancel.Left := Width - FDefaultButtonWidth - FSpacing; + btnCancel.Top := Height - btnCancel.Height - FSpacing; + btnOK.Left := btnCancel.Left - FDefaultButtonWidth - 6; + btnOK.Top := btnCancel.Top; +end; + + +{$ENDIF read_implementation} + diff --git a/src/gui/fpg_dialogs.pas b/src/gui/fpg_dialogs.pas index d70fd3dd..69f45b7e 100644 --- a/src/gui/fpg_dialogs.pas +++ b/src/gui/fpg_dialogs.pas @@ -47,7 +47,10 @@ uses fpg_combobox, fpg_panel, fpg_memo, - fpg_tree; + fpg_tree, + fpg_ColorWheel, + fpg_spinedit, + fpg_tab; type TfpgMsgDlgType = (mtAbout, mtWarning, mtError, mtInformation, mtConfirmation, @@ -205,6 +208,7 @@ type {$I promptuserdialog.inc} {$I selectdirdialog.inc} {$I charmapdialog.inc} +{$I colordialog.inc} @@ -517,14 +521,14 @@ begin btnCancel := CreateButton(self, Width-FDefaultButtonWidth-FSpacing, 370, FDefaultButtonWidth, rsCancel, @btnCancelClick); btnCancel.Name := 'btnCancel'; - btnCancel.ImageName := 'stdimg.Cancel'; // Do NOT localize + btnCancel.ImageName := 'stdimg.cancel'; // Do NOT localize btnCancel.ShowImage := True; btnCancel.Anchors := [anRight, anBottom]; btnCancel.TabOrder := 2; btnOK := CreateButton(self, btnCancel.Left-FDefaultButtonWidth-FSpacing, 370, FDefaultButtonWidth, rsOK, @btnOKClick); btnOK.Name := 'btnOK'; - btnOK.ImageName := 'stdimg.OK'; // Do NOT localize + btnOK.ImageName := 'stdimg.ok'; // Do NOT localize btnOK.ShowImage := True; btnOK.Anchors := [anRight, anBottom]; btnOK.TabOrder := 1; @@ -1426,6 +1430,7 @@ end; {$I promptuserdialog.inc} {$I selectdirdialog.inc} {$I charmapdialog.inc} +{$I colordialog.inc} end. |