📄 teeprocs.pas
字号:
// Main procedure to translate a control (or Form)
Procedure TeeTranslateControl(AControl:TControl);
// Replaces "Search" char with "Replace" char
// in all occurrences in AString parameter.
// Returns "AString" with replace characters.
Function ReplaceChar(AString:String; Search:{$IFDEF NET}String{$ELSE}Char{$ENDIF}; Replace:Char=#0):String;
// Returns "P" calculating 4 rotated corners using Angle parameter
// Note: Due to a C++ Builder v5 bug, this procedure is not a function.
Procedure RectToFourPoints(Const ARect:TRect; const Angle:Double; var P:TFourPoints);
Function TeeAntiAlias(Panel:TCustomTeePanel):TBitmap;
Procedure DrawBevel(Canvas:TTeeCanvas; Bevel:TPanelBevel; var R:TRect;
Width:Integer; Round:Integer=0);
// Internal use. Reads and saves a boolean from / to TRegistry / Inifile
// Used by TGalleryPanel, TChartEditor and TeeDesignOptions
function TeeReadBoolOption(const AKey:String; DefaultValue:Boolean):Boolean;
procedure TeeSaveBoolOption(const AKey:String; Value:Boolean);
Function TeeReadIntegerOption(const AKey:String; DefaultValue:Integer):Integer;
procedure TeeSaveIntegerOption(const AKey:String; Value:Integer);
{$IFDEF CLR}
var HInstance : THandle=0; // WORKAROUND..pending.
{$ENDIF}
implementation
Uses {$IFDEF CLR}
System.Runtime.InteropServices,
System.Reflection,
System.IO,
System.Drawing,
{$ENDIF}
{$IFNDEF D5}
DsgnIntf,
{$ENDIF}
Math, TypInfo,
{$IFDEF LINUX}
IniFiles,
{$ELSE}
Registry,
{$ENDIF}
TeeConst;
{.$DEFINE MONITOR_REDRAWS}
{$IFDEF MONITOR_REDRAWS}
var RedrawCount:Integer=0;
{$ENDIF}
{$IFNDEF CLR}
{$R TeeResou.res}
{$ENDIF}
{$IFDEF CLX}
Const
LOGPIXELSX = 0;
LOGPIXELSY = 1;
{$ENDIF}
var Tee19000101:TDateTime=0; { Optimization for TeeRoundDate function, 5.02 }
{ Same as IntToStr but faster }
Function TeeStr(Num:Integer):String;
begin
Str(Num,Result);
end;
// Returns one of the sample colors in default ColorPalette constant array
Function GetDefaultColor(Const Index:Integer):TColor;
Begin
result:=ColorPalette[Low(ColorPalette)+(Index mod Succ(High(ColorPalette)))]; // 6.02
end;
{$IFDEF D5}
Function DaysInMonth(Year,Month:Word):Word;
begin
result:=MonthDays[IsLeapYear(Year),Month]
end;
{$ELSE}
Function DaysInMonth(Year,Month:Word):Word;
Const DaysMonths:Array[1..12] of Byte=(31,28,31,30,31,30,31,31,30,31,30,31);
Begin
result:=DaysMonths[Month];
if (Month=2) and IsLeapYear(Year) then Inc(result);
End;
{$ENDIF}
Function DateTimeDefaultFormat(Const AStep:Double):String;
Begin
if AStep<=1 then result:=ShortTimeFormat
else result:=ShortDateFormat;
end;
Function NextDateTimeStep(Const AStep:Double):Double;
var t : TDateTimeStep;
Begin
for t:=Pred(dtOneYear) downto Low(DateTimeStep) do
if AStep>=DateTimeStep[t] then
Begin
result:=DateTimeStep[Succ(t)];
exit;
end;
result:=DateTimeStep[dtOneYear];
end;
Function FindDateTimeStep(Const StepValue:Double):TDateTimeStep;
begin
for result:=Pred(High(DateTimeStep)) downto Low(DateTimeStep) do
if Abs(DateTimeStep[result]-StepValue)<DateTimeStep[Low(DateTimeStep)] then
Exit;
result:=dtNone;
end;
{ draw a simulated checkbox on Canvas }
Procedure TeeDrawCheckBox( x,y:Integer; Canvas:TCanvas; Checked:Boolean;
ABackColor:TColor; CheckBox:Boolean=True);
{$IFDEF CLX}
Procedure DoHorizLine(x1,x2,y:Integer);
begin
with Canvas do
begin
MoveTo(x1,y);
LineTo(x2,y);
end;
end;
Procedure DoVertLine(x,y1,y2:Integer);
begin
with Canvas do
begin
MoveTo(x,y1);
LineTo(x,y2);
end;
end;
{$ENDIF}
var t : Integer;
begin
{$IFNDEF CLX}
if CheckBox then t:=DFCS_BUTTONCHECK
else t:=DFCS_BUTTONRADIO;
if Checked then t:=t or DFCS_CHECKED;
DrawFrameControl(Canvas.Handle,Bounds(x,y,13,13),DFC_BUTTON,t);
{$ELSE}
With Canvas do
begin
// RadioButton ????
Pen.Style:=psSolid;
Pen.Width:=1;
Pen.Color:=clGray;
DoHorizLine(x+TeeCheckBoxSize,x,y);
LineTo(x,y+TeeCheckBoxSize+1);
ABackColor:=ColorToRGB(ABackColor);
if (ABackColor=clWhite) {$IFDEF CLX}or (ABackColor=1){$ENDIF} then
Pen.Color:=clSilver
else
Pen.Color:=clWhite;
DoHorizLine(x,x+TeeCheckBoxSize+1,y+TeeCheckBoxSize+1);
LineTo(x+TeeCheckBoxSize+1,y-1);
Pen.Color:=clBlack;
DoHorizLine(x+TeeCheckBoxSize-1,x+1,y+1);
LineTo(x+1,y+TeeCheckBoxSize);
Brush.Style:=bsSolid;
Brush.Color:=clWindow;
Pen.Style:=psClear;
Rectangle(x+2,y+2,x+TeeCheckBoxSize+1,y+TeeCheckBoxSize+1);
if Checked then
begin
Pen.Style:=psSolid;
Pen.Color:=clWindowText;
for t:=1 to 3 do DoVertLine(x+2+t,y+4+t,y+7+t);
for t:=1 to 4 do DoVertLine(x+5+t,y+7-t,y+10-t);
end;
end;
{$ENDIF}
end;
{ TCustomPanelNoCaption }
Constructor TCustomPanelNoCaption.Create(AOwner: TComponent);
begin
inherited;
ControlStyle:=ControlStyle-[csSetCaption {$IFDEF CLX},csNoFocus{$ENDIF} ];
end;
type TChartPenAccess=class {$IFDEF CLR}sealed{$ENDIF} (TChartPen);
{ TCustomTeePanel }
Constructor TCustomTeePanel.Create(AOwner: TComponent);
begin
inherited;
IEventListeners:=TTeeEventListeners.Create;
Width := 400;
Height:= 250;
FApplyZOrder :=True;
FDelphiCanvas:=inherited Canvas;
FView3D :=True;
FView3DOptions:=TView3DOptions.Create({$IFDEF TEEVCL}Self{$ENDIF});
InternalCanvas:=TTeeCanvas3D.Create;
InternalCanvas.ReferenceCanvas:=FDelphiCanvas;
FMargins:= TeeRect( TeeDefHorizMargin,TeeDefVerticalMargin,
TeeDefHorizMargin,TeeDefVerticalMargin);
FPrintProportional:=True;
FPrintResolution:=TeeNormalPrintDetail;
PrintMargins:=TeeRect( TeeDefault_PrintMargin,TeeDefault_PrintMargin,
TeeDefault_PrintMargin,TeeDefault_PrintMargin);
FOriginalCursor:=Cursor;
FPanning:=TZoomPanning.Create;
FShadow:=TTeeShadow.Create(CanvasChanged);
FBorder:=TChartHiddenPen.Create(CanvasChanged);
FBorder.EndStyle:=esFlat;
TChartPenAccess(FBorder).DefaultEnd:=esFlat;
if TeeEraseBack then
TeeEraseBack:=not (csDesigning in ComponentState);
AutoRepaint:=True;
{$IFDEF CLX}
QWidget_setBackgroundMode(Handle,QWidgetBackgroundMode_NoBackground);
{$ENDIF}
end;
Destructor TCustomTeePanel.Destroy;
Begin
FreeAndNil(InternalCanvas);
FBorder.Free;
FShadow.Free;
FView3DOptions.Free;
FPanning.Free;
FreeAndNil(IEventListeners);
inherited;
end;
Procedure TCustomTeePanel.CanvasChanged(Sender:TObject);
Begin
Invalidate;
end;
{$IFNDEF CLX}
procedure TCustomTeePanel.CreateParams(var Params: TCreateParams);
begin
inherited;
// OpenGL:
// Params.WindowClass.Style:=Params.WindowClass.Style or CS_OWNDC;
if Color=clNone then
Params.ExStyle:=Params.ExStyle or WS_EX_TRANSPARENT; { 5.02 }
InternalCanvas.View3DOptions:=nil;
end;
{$ENDIF}
Procedure TCustomTeePanel.SetShadow(Value:TTeeShadow);
begin
FShadow.Assign(Value);
end;
Procedure TCustomTeePanel.InternalDraw(Const UserRectangle:TRect); // virtual; abstract;
begin
end;
procedure TCustomTeePanel.SetView3DOptions(Value:TView3DOptions);
begin
FView3DOptions.Assign(Value);
end;
procedure TCustomTeePanel.SetView3D(Value:Boolean);
Begin
if FView3D<>Value then // 6.0
begin
SetBooleanProperty(FView3D,Value);
BroadcastTeeEvent(TTeeView3DEvent.Create).Free;
end;
end;
Procedure TCustomTeePanel.Draw;
begin
Draw(FDelphiCanvas,GetClientRect);
end;
type
TCanvasAccess=class {$IFDEF CLR}sealed{$ENDIF} (TTeeCanvas3D);
Procedure TCustomTeePanel.Draw(UserCanvas:TCanvas; Const UserRect:TRect);
Procedure AdjustChartBounds;
Function GetMargin(Value,Range:Integer):Integer;
begin
if MarginUnits=muPercent then result:=Value*Range div 100
else result:=Value;
end;
Var tmpW : Integer;
tmpH : Integer;
tmpBorder : Integer;
begin
RectSize(FChartBounds,tmpW,tmpH);
// Calculate amount of pixels for border and bevels...
tmpBorder:=BorderWidth;
if BevelInner<>bvNone then Inc(tmpBorder,BevelWidth);
if BevelOuter<>bvNone then Inc(tmpBorder,BevelWidth);
if Border.Visible then Inc(tmpBorder,Border.Width);
// Apply margins
With FChartBounds do
ChartRect:=TeeRect( Left + tmpBorder + GetMargin(MarginLeft,tmpW),
Top + tmpBorder + GetMargin(MarginTop,tmpH),
Right - tmpBorder - GetMargin(MarginRight,tmpW),
Bottom- tmpBorder - GetMargin(MarginBottom,tmpH) );
end;
Begin
{$IFDEF CLX}
UserCanvas.Start;
try
{$ENDIF}
FChartBounds:=InternalCanvas.InitWindow(UserCanvas,FView3DOptions,Color,FView3D,UserRect);
AdjustChartBounds;
RecalcWidthHeight;
InternalDraw(FChartBounds);
{$IFDEF MONITOR_REDRAWS}
Inc(RedrawCount);
InternalCanvas.TextAlign:=TA_LEFT;
InternalCanvas.Font.Size:=8;
TCanvasAccess(InternalCanvas).IFont:=nil;
InternalCanvas.TextOut(0,0,TeeStr(RedrawCount));
{$ENDIF}
InternalCanvas.ShowImage(UserCanvas,FDelphiCanvas,UserRect);
{$IFDEF CLX}
finally
UserCanvas.Stop;
end;
{$ENDIF}
end;
procedure TCustomTeePanel.Paint;
{$IFDEF TEEOCX}
procedure TeeFpuInit;
asm
FNINIT
FWAIT
FLDCW Default8087CW
end;
{$ENDIF}
begin
{$IFDEF TEEOCX}
TeeFPUInit;
{$ENDIF}
{$IFDEF CLX}
if csDestroying in ComponentState then Exit;
{$ENDIF}
if (not FPrinting) and (not InternalCanvas.ReDrawBitmap) then Draw;
end;
{$IFDEF CLX}
type
TMetafileCanvas=class(TCanvas)
public
Constructor Create(Meta:TMetafile; Ref:Integer);
end;
{ TMetafileCanvas }
Constructor TMetafileCanvas.Create(Meta: TMetafile; Ref: Integer);
begin
inherited Create;
end;
{$ENDIF}
Function TCustomTeePanel.TeeCreateMetafile( Enhanced:Boolean; Const Rect:TRect ):TMetafile;
var tmpCanvas : TMetafileCanvas;
begin
result:=TMetafile.Create;
{ bug in Delphi 3.02 : graphics.pas metafile reduces width/height.
Fixed in Delphi 4.0x and BCB4. }
result.Width :=Max(1,Rect.Right-Rect.Left);
result.Height:=Max(1,Rect.Bottom-Rect.Top);
result.Enhanced:=Enhanced;
tmpCanvas:=TMetafileCanvas.Create(result,0);
try
DrawToMetaCanvas(tmpCanvas,Rect);
finally
tmpCanvas.Free;
end;
end;
Procedure TCustomTeePanel.SetBrushCanvas( AColor:TColor; ABrush:TChartBrush;
ABackColor:TColor);
begin
if (ABrush.Style<>bsSolid) and (AColor=ABackColor) then
if ABackColor=clBlack then AColor:=clWhite else AColor:=clBlack;
Canvas.AssignBrushColor(ABrush,AColor,ABackColor);
end;
Function TeeGetDeviceCaps(Handle:{$IFDEF CLX}QPaintDeviceH
{$ELSE}TTeeCanvasHandle
{$ENDIF}; Cap:Integer):Integer;
begin
{$IFDEF CLX}
result:=1;
{$ELSE}
result:=GetDeviceCaps(Handle,Cap);
{$ENDIF}
end;
Function TCustomTeePanel.IsScreenHighColor:Boolean;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -