From: outchy <ou...@us...> - 2004-09-26 18:20:14
|
Update of /cvsroot/jvcl/dev/donations/Colors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24862/Colors Modified Files: ColorCtrls.pas ColorSpaces.pas ColorSpacesEditors.pas Log Message: Fixed : flickering in TJvFullColorPanel Fixed : flickering in TJvFullColorGroup Added : Editor for TJvFullColorList Nearly all color spaces are implemented (HSI is the same cs than HLS). TODO : fix a bug in TJvLabColorSpace (green doesn't exist) TODO : remove the DEF color space in TJvFullColorPanel (now in TJvFullColorGroup) Index: ColorSpaces.pas =================================================================== RCS file: /cvsroot/jvcl/dev/donations/Colors/ColorSpaces.pas,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ColorSpaces.pas 26 Sep 2004 11:26:30 -0000 1.13 --- ColorSpaces.pas 26 Sep 2004 18:20:03 -0000 1.14 *************** *** 73,77 **** XYZ_MAX = 255; LAB_MIN = 0; ! LAB_MAX = 100; DEF_MIN = 0; DEF_MAX = 255; --- 73,77 ---- XYZ_MAX = 255; LAB_MIN = 0; ! LAB_MAX = 255; DEF_MIN = 0; DEF_MAX = 255; Index: ColorCtrls.pas =================================================================== RCS file: /cvsroot/jvcl/dev/donations/Colors/ColorCtrls.pas,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ColorCtrls.pas 26 Sep 2004 11:26:30 -0000 1.15 --- ColorCtrls.pas 26 Sep 2004 18:19:54 -0000 1.16 *************** *** 530,535 **** PJvFullColorArray = ^TJvFullColorArray; ! TJvFullColorListEvent = procedure(Sender: TObject; Item: TJvFullColor; ! Position: Integer) of object; EJvFullColorListError = class(Exception); --- 530,537 ---- PJvFullColorArray = ^TJvFullColorArray; ! TJvFullColorListOperation = (foAllChanged, foDeleted, foAdded, foChanged); ! ! TJvFullColorListEvent = procedure(Sender: TObject; Index:Integer; ! Operation: TJvFullColorListOperation) of object; EJvFullColorListError = class(Exception); *************** *** 542,547 **** --- 544,551 ---- FOnChange: TJvFullColorListEvent; FUpdateCount: Integer; + FAllocBy: Integer; procedure SetCapacity(const Value: Integer); procedure SetCount(const Value: Integer); + procedure SetAllocBy(const Value: Integer); protected procedure Grow; *************** *** 551,555 **** procedure WriteItems(Writer: TWriter); procedure ReadItems(Reader: TReader); ! procedure Change(AColor: TJvFullColor; AIndex: Integer); public constructor Create; --- 555,559 ---- procedure WriteItems(Writer: TWriter); procedure ReadItems(Reader: TReader); ! procedure Change(AIndex: Integer; AOperation:TJvFullColorListOperation); public constructor Create; *************** *** 557,560 **** --- 561,565 ---- function Add(AColor: TJvFullColor): Integer; + procedure Assign(Source: TPersistent); override; procedure Clear; function Remove(AColor: TJvFullColor): Integer; *************** *** 567,570 **** --- 572,576 ---- procedure EndUpdate; + property AllocBy:Integer read FAllocBy write SetAllocBy; property Items[Index: Integer]: TJvFullColor read GetItem write SetItem; default; property List: PJvFullColorArray read FList; *************** *** 601,605 **** protected procedure Paint; override; ! procedure ItemsChange(Sender: TObject; Item: TJvFullColor; Position: Integer); procedure BrushChange(Sender: TObject); procedure MouseDown(Button: TMouseButton; Shift: TShiftState; --- 607,612 ---- protected procedure Paint; override; ! procedure ItemsChange(Sender: TObject; Index:Integer; ! Operation: TJvFullColorListOperation); procedure BrushChange(Sender: TObject); procedure MouseDown(Button: TMouseButton; Shift: TShiftState; *************** *** 3119,3122 **** --- 3126,3130 ---- FCount:=0; FCapacity:=0; + FAllocBy:=2; end; *************** *** 3134,3144 **** FList^[Result] := AColor; Inc(FCount); ! Change(AColor, Result); end; ! procedure TJvFullColorList.Change(AColor: TJvFullColor; AIndex: Integer); begin if (UpdateCount = 0) and Assigned(FOnChange) then ! FOnChange(Self, AColor, AIndex); end; --- 3142,3170 ---- FList^[Result] := AColor; Inc(FCount); ! Change(Result, foAdded); end; ! procedure TJvFullColorList.Assign(Source: TPersistent); ! var ! Index:Integer; ! begin ! if (Source is TJvFullColorList) then ! with TJvFullColorList(Source) do ! begin ! Self.BeginUpdate; ! Self.Count:=Count; ! for Index:=0 to Self.Count-1 do ! Self.Items[Index]:=Items[Index]; ! Self.EndUpdate; ! Self.Change(-1,foAllChanged); ! end ! else inherited Assign(Source); ! end; ! ! procedure TJvFullColorList.Change(AIndex: Integer; ! AOperation:TJvFullColorListOperation); begin if (UpdateCount = 0) and Assigned(FOnChange) then ! FOnChange(Self, AIndex, AOperation); end; *************** *** 3146,3149 **** --- 3172,3176 ---- begin Capacity := 0; + Change(-1,foAllChanged); end; *************** *** 3155,3171 **** procedure TJvFullColorList.Delete(Index: Integer); - var - Color: TJvFullColor; begin if (Index < 0) or (Index >= FCount) then EJvFullColorListError.CreateFmt(SListIndexError, [Index]); - Color := FList^[Index]; - Dec(FCount); if Index < Count then Move(FList^[Index + 1], FList^[Index], (Count - Index) * SizeOf(TJvFullColor)); ! Change(Color, -1); end; --- 3182,3194 ---- procedure TJvFullColorList.Delete(Index: Integer); begin if (Index < 0) or (Index >= FCount) then EJvFullColorListError.CreateFmt(SListIndexError, [Index]); Dec(FCount); if Index < Count then Move(FList^[Index + 1], FList^[Index], (Count - Index) * SizeOf(TJvFullColor)); ! Change(Index, foDeleted); end; *************** *** 3187,3190 **** --- 3210,3216 ---- FList^[Index1] := FList^[Index2]; FList^[Index2] := Tmp; + + Change(Index1,foChanged); + Change(Index2,foChanged); end; *************** *** 3199,3206 **** procedure TJvFullColorList.Grow; begin ! if Capacity = 0 then ! Capacity := 16 ! else ! Capacity := 2 * Capacity; end; --- 3225,3229 ---- procedure TJvFullColorList.Grow; begin ! Capacity:=Capacity+AllocBy; end; *************** *** 3215,3225 **** procedure TJvFullColorList.Insert(Index: Integer; AColor: TJvFullColor); begin ! if (Index >= Count) or (Index < 0) then EJvFullColorListError.CreateFmt(sListIndexError, [Index]); ! if Count = Capacity then Grow; ! if Index < Count then Move(FList^[Index], FList^[Index + 1], (FCount - Index) * SizeOf(TJvFullColor)); --- 3238,3248 ---- procedure TJvFullColorList.Insert(Index: Integer; AColor: TJvFullColor); begin ! if (Index > Count) or (Index < 0) then EJvFullColorListError.CreateFmt(sListIndexError, [Index]); ! if (Count = Capacity) then Grow; ! if (Index < Count) then Move(FList^[Index], FList^[Index + 1], (FCount - Index) * SizeOf(TJvFullColor)); *************** *** 3227,3231 **** Inc(FCount); ! Change(AColor, Index); end; --- 3250,3254 ---- Inc(FCount); ! Change(Index, foAdded); end; *************** *** 3237,3243 **** procedure TJvFullColorList.ReadItems(Reader: TReader); begin - Reader.ReadListBegin; - BeginUpdate; try Clear; while not Reader.EndOfList do --- 3260,3266 ---- procedure TJvFullColorList.ReadItems(Reader: TReader); begin try + Reader.ReadListBegin; + BeginUpdate; Clear; while not Reader.EndOfList do *************** *** 3245,3250 **** finally EndUpdate; end; - Reader.ReadListEnd; end; --- 3268,3273 ---- finally EndUpdate; + Reader.ReadListEnd; end; end; *************** *** 3256,3259 **** --- 3279,3287 ---- end; + procedure TJvFullColorList.SetAllocBy(const Value: Integer); + begin + FAllocBy := Max(Value,1); + end; + procedure TJvFullColorList.SetCapacity(const Value: Integer); begin *************** *** 3263,3268 **** begin FCount := FCapacity; ! // (rom) this needs a comment to explain the special parameters ! Change(0, -2); end; end; --- 3291,3295 ---- begin FCount := FCapacity; ! Change(-1, foAllChanged); end; end; *************** *** 3271,3276 **** begin FCount := Value; ! if FCount > FCapacity then Capacity := FCount; end; --- 3298,3304 ---- begin FCount := Value; ! if (FCount > FCapacity) then Capacity := FCount; + Change(-1, foAllChanged); end; *************** *** 3281,3292 **** FList^[Index] := Value; end; procedure TJvFullColorList.EndUpdate; begin ! if FUpdateCount > 0 then ! Dec(FUpdateCount); ! // (rom) this needs a comment to explain the special parameters ! Change(0, -2); end; --- 3309,3320 ---- FList^[Index] := Value; + Change(Index,foChanged); end; procedure TJvFullColorList.EndUpdate; begin ! if FUpdateCount > 0 ! then Dec(FUpdateCount) ! else Change(-1,foAllChanged); end; *************** *** 3334,3340 **** begin XOffset:=Width - (FSquareSize*ColCount) - 2; ! XInc:=XOffset div (ColCount+1); ! XOffset:=((XOffset-(XInc*(ColCount-1))) div 2) + 1; ! XPos:=XOffset; RowCount:=(Items.Count div ColCount)+1; --- 3362,3367 ---- begin XOffset:=Width - (FSquareSize*ColCount) - 2; ! XInc:=XOffset div ColCount; ! XPos:=((XOffset-(XInc*(ColCount-1))) div 2) + 1; RowCount:=(Items.Count div ColCount)+1; *************** *** 3342,3356 **** if (RowCount=1) then YInc:=0 ! else YInc:=YOffset div (RowCount+1); ! YOffset:=((YOffset-(YInc*(RowCount-1))) div 2) + 1; ! YPos:=YOffset; end; ! procedure TJvFullColorGroup.ItemsChange(Sender: TObject; Item: TJvFullColor; ! Position: Integer); begin ! FMouseIndex:=-1; ! FSelectedIndex:=EnsureRange(FSelectedIndex,-1,Items.Count-1); ! Refresh; end; --- 3369,3397 ---- if (RowCount=1) then YInc:=0 ! else YInc:=YOffset div RowCount; ! YPos:=YOffset-((YInc*(RowCount+1)) div 2) + 1; end; ! procedure TJvFullColorGroup.ItemsChange(Sender: TObject; Index:Integer; ! Operation: TJvFullColorListOperation); begin ! case Operation of ! foAllChanged : ! begin ! FMouseIndex:=-1; ! FSelectedIndex:=-1; ! Invalidate; ! end; ! foDeleted : ! begin ! FMouseIndex:=-1; ! FSelectedIndex:=EnsureRange(FSelectedIndex,-1,Items.Count-1); ! Invalidate; ! end; ! foAdded : ! Invalidate; ! foChanged : ! InvalidateIndex(Index); ! end; end; *************** *** 3454,3458 **** InvalidateIndex(MouseIndex); ! FMouseIndex:=EnsureRange((RowIndex*ColCount)+ColIndex,0,Items.Count-1); InvalidateIndex(MouseIndex); end; --- 3495,3501 ---- InvalidateIndex(MouseIndex); ! FMouseIndex:=(RowIndex*ColCount)+ColIndex; ! if (MouseIndex>(Items.Count-1)) ! then FMouseIndex:=-1; InvalidateIndex(MouseIndex); end; *************** *** 3506,3539 **** end; var ! Index:Integer; XOffset, YOffset, XInc, YInc:Integer; X, Y:Integer; AEdge:TJvFullColorEdge; begin ! BevelRect(Rect(0, 0, Width - 1, Height - 1),FEdge,bsSolid, Color); ! CalcRects(XOffset,YOffset,XInc,YInc); ! Y:=YOffset; ! X:=XOffset; ! Index:=0; ! while (Index<Items.Count) do ! begin ! if (Index=SelectedIndex) ! then AEdge:=SelectedEdge ! else if (Index=MouseIndex) ! then AEdge:=MouseEdge ! else AEdge:=feFlat; ! BevelRect(Rect(X,Y,X+FSquareSize,Y+FSquareSize),AEdge,Brush.Style, ! ColorSpaceManager.ConvertToID(Items[Index],csRGB)); ! Inc(Index); ! if ((Index mod ColCount)=0) then ! begin ! X:=XOffset; ! Inc(Y,YInc+FSquareSize); ! end ! else Inc(X,XInc+FSquareSize); ! end; end; --- 3549,3608 ---- end; var ! Index, IndexX, IndexY, XMaj:Integer; XOffset, YOffset, XInc, YInc:Integer; X, Y:Integer; AEdge:TJvFullColorEdge; + ClipRect:TRect; begin ! CalcRects(XOffset,YOffset,XInc,YInc); ! BevelRect(Rect(0, 0, Width - 1, Height - 1),FEdge,bsClear, Color); ! Y:=YOffset; ! X:=XOffset; ! ClipRect:=Canvas.ClipRect; ! Index:=0; ! while (Index<Items.Count) do ! begin ! if (Index=SelectedIndex) ! then AEdge:=SelectedEdge ! else if (Index=MouseIndex) ! then AEdge:=MouseEdge ! else AEdge:=feFlat; ! BevelRect(Rect(X,Y,X+FSquareSize,Y+FSquareSize),AEdge,Brush.Style, ! ColorSpaceManager.ConvertToID(Items[Index],csRGB)); ! Inc(Index); ! if ((Index mod ColCount)=0) then ! begin ! X:=XOffset; ! Inc(Y,YInc+FSquareSize); ! end ! else Inc(X,XInc+FSquareSize); ! end; ! ! with Canvas do ! begin ! Brush.Style:=bsSolid; ! Brush.Color:=Color; ! Pen.Color:=Color; ! Y:=YOffset; ! for IndexY:=0 to (Items.Count div ColCount)+1 do ! begin ! Rectangle(Max(ClipRect.Left,1),Max(Y-YInc+1,1), ! Min(ClipRect.Right,Width-2),Min(Y,Height-2)); ! X:=XOffset; ! for IndexX:=0 to ColCount do ! begin ! if ((IndexX+(IndexY*ColCount))>=Items.Count) ! then XMaj:=FSquareSize+1 ! else XMaj:=0; ! Rectangle(Max(X-XInc+1,1),Min(Max(Y,1),Height-2), ! Min(X+XMaj,Width-2),Min(Y+FSquareSize+1,Height-2)); ! Inc(X,XInc+FSquareSize); ! end; ! Inc(Y,YInc+FSquareSize); ! end; ! end; end; Index: ColorSpacesEditors.pas =================================================================== RCS file: /cvsroot/jvcl/dev/donations/Colors/ColorSpacesEditors.pas,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ColorSpacesEditors.pas 25 Sep 2004 16:08:43 -0000 1.6 --- ColorSpacesEditors.pas 26 Sep 2004 18:20:03 -0000 1.7 *************** *** 163,166 **** --- 163,173 ---- end; + TJvFullColorListEditor=class (TClassProperty) + public + function GetAttributes:TPropertyAttributes; override; + procedure Edit; override; + procedure FormApply(Sender:TObject); + end; + procedure Register; *************** *** 172,176 **** {$ENDIF UNITVERSIONING} Math, SysUtils, GraphUtil, DesignConst, TypInfo, ! ColorDialogs, ColorCtrls; const --- 179,183 ---- {$ENDIF UNITVERSIONING} Math, SysUtils, GraphUtil, DesignConst, TypInfo, ! ColorDialogs, ColorCtrls, Forms, JvFullColorListFrm; const *************** *** 679,682 **** --- 686,714 ---- end; + //=== { TJvFullColorListEditor } ============================================= + + procedure TJvFullColorListEditor.Edit; + var + AFullColorListForm:TJvFullColorListForm; + begin + AFullColorListForm:=TJvFullColorListForm.Create(Application); + AFullColorListForm.OnApply:=FormApply; + AFullColorListForm.ColorList:=TJvFullColorList(GetOrdValueAt(0)); + if (AFullColorListForm.Execute) + then FormApply(AFullColorListForm); + AFullColorListForm.Free; + end; + + procedure TJvFullColorListEditor.FormApply(Sender: TObject); + begin + SetOrdValue(Integer((Sender as TJvFullColorListForm).ColorList)); + end; + + function TJvFullColorListEditor.GetAttributes: TPropertyAttributes; + begin + Result:=[paDialog, paVCL]; + end; + + procedure Register; begin *************** *** 691,694 **** --- 723,727 ---- RegisterSelectionEditor(TJvColorSpaceCombo, TJvColorSelection); RegisterSelectionEditor(TJvColorAxisConfigCombo, TJvColorSelection); + RegisterPropertyEditor(TypeInfo(TJvFullColorList), nil, '', TJvFullColorListEditor); end; *************** *** 707,711 **** finalization UnregisterUnitVersion(HInstance); ! {$ENDIF UNITVERSIONING} end. --- 740,744 ---- finalization UnregisterUnitVersion(HInstance); ! {$ENDIF UNITVERSIONING} end. |