- unit Instruments;
-
-
- interface
-
-
- uses
- Classes, Controls, Graphics, Types,
- SysUtils, Dialogs;
-
-
- type
-
-
- TInstrumentContext = packed record
- MixValue: Real;
- MaxValue: Real;
- defaultValue: Real;
- Inctrment: Real;
- AOwner: TComponent;
- AParent: TWinControl;
- AHeight: Integer;
- AWidth: Integer;
- end;
-
-
-
-
- TInstrument = class(TCustomControl)
- private
- // FEData: TInstrumentContext;
- FCurValue: Real;
- FMixValue: Real;
- FMaxValue: Real;
- FIncrement: Real;
- FUnit: string;
- FCenter: TPoint;
- FRadius: Integer;
- procedure DrawCircle(Center: TPoint; Radius: Integer);
- protected
- procedure Paint; override;
- procedure DrawWatch;
- procedure DrawRuling;
- procedure DrawPointer;
- public
- constructor Create(EquipContext: TInstrumentContext; AUnit: string);
- function SpeedUp: Real;
- function SpeedDown: Real;
- procedure KeyPress(var Key: Char); override;
- published
- // property EData: TInstrumentContext read FEData write FEData;
- property CurSpeed: Real read FCurValue write FCurValue;
- property MixSpeed: Real read FMixValue;
- property MaxSpeed: Real read FMaxValue;
- property Increment: Real read FIncrement write FIncrement;
- property EUnit: string read FUnit;
- function PosCenter: TPoint;
- end;
-
-
- const
- RulingWidth = 20;
-
-
- implementation
-
-
- { TInstrument }
-
-
- function TInstrument.PosCenter: TPoint;
- begin
- Result.X := ClientWidth div 2;
- Result.Y := ClientHeight div 2;
- FCenter := Result;
- FRadius := ClientWidth div 2;
- end;
-
-
- constructor TInstrument.Create(EquipContext: TInstrumentContext;
- AUnit: string);
- function Min(A, B: Integer): Integer;
- begin
- if A>B then
- Result := B
- else
- Result := A;
- end;
- begin
- inherited Create(EquipContext.AOwner);
- with EquipContext do
- begin
- FCurValue := defaultValue;
- FMaxValue := MaxValue;
- FMixValue := MixValue;
- FIncrement := Inctrment;
- FUnit := AUnit;
- Parent := AParent;
- Height := Min(AHeight, AWidth);
- Width := Height;
- end;
- PosCenter;
- DoubleBuffered := True;
- end;
-
-
- procedure TInstrument.DrawPointer;
- var
- iPointer: array[0..2] of TPoint;
- a: Real;
- begin
- a := 0.75*PI-1.5*PI*FCurValue/FMaxValue;
- iPointer[0].X := Round((FRadius-RulingWidth)*(1-Sin(a)))+(FCenter.X-FRadius+RulingWidth);
- iPointer[0].Y := Round((FRadius-RulingWidth)*(1-Cos(a)))+(FCenter.Y-FRadius+RulingWidth);
- iPointer[1].X := Round((FRadius/20)*(1+Sin(a-0.5*PI)) + (FCenter.X-FRadius/20));
- iPointer[2].X := Round((FRadius/20)*(1-Sin(a-0.5*PI)) + (FCenter.X-FRadius/20));
- iPointer[1].Y := Round((FRadius/20)*(1+Cos(a-0.5*PI)) + (FCenter.X-FRadius/20));
- iPointer[2].Y := Round((FRadius/20)*(1-Cos(a-0.5*PI)) + (FCenter.X-FRadius/20));
- Canvas.Brush.Color := clBlack;
- Canvas.Pen.Style := psClear;
- DrawCircle(FCenter, Trunc(FRadius/10));
- Canvas.Polygon(iPointer);
- end;
-
-
- procedure TInstrument.DrawRuling;
- var
- CurV, a: Real;
- X, Y: Integer;
- begin
- Canvas.Pen.Style := psSolid;
- CurV := 0;
- repeat
- a := 0.75*PI-1.5*PI*CurV/FMaxValue;
- X := Trunc((FRadius-1)*(1-Sin(a)))+(FCenter.X-FRadius+1);
- Y := Trunc((FRadius-1)*(1-Cos(a)))+(FCenter.Y-FRadius+1);
- Canvas.MoveTo(FCenter.X, FCenter.Y);
- Canvas.LineTo(X, Y);
- CurV := CurV + Trunc(FMaxValue/10);
- until CurV > FMaxValue;
- CurV := 0;
- repeat
- a := 0.75*PI-1.5*PI*CurV/FMaxValue;
- X := Trunc((FRadius-10)*(1-Sin(a)))+(FCenter.X-FRadius+10);
- Y := Trunc((FRadius-10)*(1-Cos(a)))+(FCenter.Y-FRadius+10);
- Canvas.MoveTo(FCenter.X, FCenter.Y);
- Canvas.LineTo(X, Y);
- CurV := CurV + Trunc(FMaxValue/50);
- until CurV > FMaxValue;
- Canvas.Pen.Style := psClear;
- Canvas.Brush.Color := clWhite;
- DrawCircle(FCenter, FRadius-RulingWidth);
- end;
-
-
- procedure TInstrument.DrawWatch;
- begin
- Canvas.Brush.Color := clLime;
- Canvas.Pen.Style := psClear;
- Canvas.Pie(FCenter.X-FRadius, FCenter.Y-FRadius,
- FCenter.X+FRadius, FCenter.Y+FRadius,
- FCenter.X+1, FCenter.Y-1,
- FCenter.X-1, FCenter.Y+1);
- Canvas.Brush.Color := clYellow;
- Canvas.Pie(FCenter.X-FRadius, FCenter.Y-FRadius,
- FCenter.X+FRadius, FCenter.Y+FRadius,
- FCenter.X+1, FCenter.Y,
- FCenter.X+1, FCenter.Y-1);
- Canvas.Brush.Color := clRed;
- Canvas.Pie(FCenter.X-FRadius, FCenter.Y-FRadius,
- FCenter.X+FRadius, FCenter.Y+FRadius,
- FCenter.X+1, FCenter.Y+1,
- FCenter.X+1, FCenter.Y);
- end;
-
-
- procedure TInstrument.Paint;
- begin
- DrawWatch;
- DrawRuling;
- DrawPointer;
- end;
-
-
- function TInstrument.SpeedUp: Real;
- begin
- FCurValue := FCurValue + FIncrement;
- if FCurValue > FMaxValue then
- FCurValue := FMaxValue;
- Result := FCurValue;
- Invalidate;
- end;
-
-
- function TInstrument.SpeedDown: Real;
- begin
- FCurValue := FCurValue - FIncrement;
- if FCurValue < FMixValue then
- FCurValue := FMixValue;
- Result := FCurValue;
- Invalidate;
- end;
-
-
- procedure TInstrument.DrawCircle(Center: TPoint; Radius: Integer);
- begin
- Canvas.Ellipse(Center.X-Radius, Center.Y-Radius,
- Center.X+Radius, Center.Y+Radius);
- end;
-
-
- procedure TInstrument.KeyPress(var Key: Char);
- begin
- inherited;
- if (Key = 'W') or (Key = 'w') then
- SpeedUp
- else if (Key = 'S') or (Key = 's') then
- SpeedDown;
- end;
-
-
- end.
© 著作权归作者所有
举报
打赏
0 赞
0 收藏
分享
加载中

其他人还在看
本文是Netty系列笔记第2篇 Netty是网络应用框架,所以从最本质的角度来看,是对网络I/O模型的封装使用。 因此,要深刻理解Netty的高性能,也必须从网络I/O模型说起。 看完本文,可以回答这三个问题: 五种I/O模型...
作者 | 毕玄 来源|阿里巴巴云原生公众号 对于程序员而言,我始终认为代码是展现能力的关键,一个优秀程序员写的代码,和一个普通程序员写的代码是很容易看出差别的,代码作为程序员的硬实力和名片的展示,怎么提升...
WebRTC 无疑推动和改变了互联网视频,而这仅仅是刚刚开始,除了大家熟悉的 WebRTC-PC、Simulcast 和 SVC,有太多的新技术和新架构出现在 WebRTC 新的标准中,比如 WebTransport、WebCodecs、AV1、E2EE、SFrame、M...
今天碰到群里小伙伴问,线上程序好像有多个不同版本的Netty包,怎么去看到底加载了哪一个? 在说如何看之前,先来说说,当你开始意识到项目里有多个不同版本的Jar包,都是因为遇到了这几个异常: java.lang.NoSu...
简介: 只有了解风险,才能及时应对,保障服务高可用。 不久前,也就是11月16日,澳大利亚交易所(Australian Securities Exchange, ASX)上线了一个新的交易系统,但因为出现故障而被迫关闭。这是其 2016 年因硬...
摘要:在业界中有一个比较成熟的工具,针对大表的场景,可以在线进行Alter变更,且不会出现锁表的风险。除此之外,它还有其他的一些优点,让我们开始探索吧。 背景 大家在日常工作中,往往需要对数据库的表结构做...
权限控制,或者说访问控制,广泛应用于各个系统中。抽象地说,是某个主体(subject)对某个客体(object)需要实施某种操作(operation),而系统对这种操作的限制就是权限控制。 在网络中,为了保护网络资源的安...
看多了应用服务的高可用架构,我们来看看数据库的高可用吧。 数据存储高可用的方案本质都是通过将数据复制到多个存储设备,通过数据冗余的方式来实现高可用。常见的高可用架构有主备、主从、主主、集群、分区等,...
本文来源:ServerlessLife 公众号。 引言 最近查阅 Serverless 相关资讯,注意到一个 Ruby Serverless 框架——Jets。 心中便有一些疑问:为什么会有这个项目?它是用来做什么的?作为一门小众语言,有哪些 Serv...
说明: 本文是2020年深圳Qcon全球软件开发大会《专题:现代数据架构》专场、dbaplus专场:万亿级数据库MongoDB集群性能优化实践、mongodb2020年终盛会分享,分享内容如下(体验万亿级mongodb服务层、存储引擎、高并...
选择专区和圈子:{{title}}
{{o.name}}
{{m.name}}