jvcllaz: Improve High-DPI behavior of JvTMTimeline demo.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6618 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-08-28 21:28:32 +00:00
parent b9a474c8ca
commit 2ae3da274d
15 changed files with 2874 additions and 509 deletions

View File

@ -41,6 +41,9 @@ type
{ TTMTimeLineMainForm } { TTMTimeLineMainForm }
TTMTimeLineMainForm = class(TForm) TTMTimeLineMainForm = class(TForm)
Images: TImageList;
Images_150: TImageList;
Images_200: TImageList;
LbImages: TListBox; LbImages: TListBox;
Panel1: TPanel; Panel1: TPanel;
LblImages: TLabel; LblImages: TLabel;
@ -52,7 +55,6 @@ type
mnuEditMemo: TMenuItem; mnuEditMemo: TMenuItem;
mnuGotoDate: TMenuItem; mnuGotoDate: TMenuItem;
StatusBar: TStatusBar; StatusBar: TStatusBar;
il16: TImageList;
gbWidths: TGroupBox; gbWidths: TGroupBox;
gbDates: TGroupBox; gbDates: TGroupBox;
gbAppearance: TGroupBox; gbAppearance: TGroupBox;
@ -182,17 +184,30 @@ const
procedure TTMTimeLineMainForm.FormCreate(Sender: TObject); procedure TTMTimeLineMainForm.FormCreate(Sender: TObject);
var var
i : integer; i : integer;
sz: TSize;
tm: TLCLTextMetric;
h: Integer;
begin begin
//ForceCurrentDirectory := true; // <--- wp //ForceCurrentDirectory := true; // <--- wp
dtpSelDate.Date := Date;
dtpFirstDate.Date := Date-7;
dtpImageDate.Date := Date+7;
JvTimeLine1 := TJvTMTimeline.Create(self); JvTimeLine1 := TJvTMTimeline.Create(self);
JvTimeLine1.Parent := self; JvTimeLine1.Parent := self;
JvTimeLine1.PopUpMenu := popTimeline; JvTimeLine1.PopUpMenu := popTimeline;
JvTimeLine1.OnChange := @DoDateChange; JvTimeLine1.OnChange := @DoDateChange;
JvTimeLine1.OnClick := @DoClick; JvTimeLine1.OnClick := @DoClick;
JvTimeLine1.OnDblClick := @DoDblClick; JvTimeLine1.OnDblClick := @DoDblClick;
JvTimeLine1.Images := il16; if Screen.SystemFont.PixelsPerInch < 120 then
JvTimeLine1.Images := Images
else if Screen.SystemFont.PixelsPerInch < 168 then
JvTimeLine1.Images := Images_150
else
JvTimeLine1.Images := Images_200;
JvTimeLine1.Align := alClient; JvTimeLine1.Align := alClient;
JvTimeLine1.Constraints.MinHeight := 60; JvTimeLine1.Constraints.MinHeight := Scale96ToFont(60);
JvTimeLine1.Hint := JvTimeLine1.Hint :=
'Double-click a date to edit it''s memo content.' + 'Double-click a date to edit it''s memo content.' +
LineEnding + LineEnding +
@ -200,23 +215,22 @@ begin
JvTimeLine1.Date := dtpFirstDate.Date; JvTimeLine1.Date := dtpFirstDate.Date;
JvTimeLine1.SelDate := dtpSelDate.Date; JvTimeLine1.SelDate := dtpSelDate.Date;
dtpSelDate.Date := Date;
dtpFirstDate.Date := Date-7;
dtpImageDate.Date := Date+7;
udDayWidth.Position := JvTimeLine1.DayWidth; udDayWidth.Position := JvTimeLine1.DayWidth;
udButtonWidth.Position := JvTimeLine1.ButtonWidth; udButtonWidth.Position := JvTimeLine1.ButtonWidth;
chkReadOnly.Checked := JvTimeLine1.ReadOnly; chkReadOnly.Checked := JvTimeLine1.ReadOnly;
lbObjFontStyle.Checked[2] := true; lbObjFontStyle.Checked[2] := true;
for i := 0 to il16.Count - 1 do
LbImages.Items.Add(IntToStr(i));
LblKeyboardNavigation.Font.Style := [fsBold]; LblKeyboardNavigation.Font.Style := [fsBold];
LbImages.ItemHeight := Max(il16.Height, abs(LbImages.Font.Height)) + IMAGE_DIST;
i := LbImages.Canvas.TextWidth('99'); h := abs(Screen.SystemFont.Height);
LbImages.Width := Max( for i := 0 to JvTimeLine1.Images.Count - 1 do
il16.Width + 4 * abs(LbImages.Font.Height) + 3 * Scale96ToFont(IMAGE_DIST), LbImages.Items.Add(IntToStr(i));
LblImages.Width LbImages.ItemHeight := Max(JvTimeLine1.Images.Height, h + 2 * Scale96ToFont(IMAGE_DIST));
); LbImages.Width := JvTimeLine1.Images.Width + 2* h + 2 * Scale96ToFont(IMAGE_DIST);
udDayWidth.Position := jvTimeLine1.DayWidth;
Statusbar.Panels[0].Width := Scale96ToFont(120);
Statusbar.Panels[1].Width := Scale96ToFont(220);
ActiveControl := JvTimeLine1; ActiveControl := JvTimeLine1;
end; end;
@ -408,13 +422,13 @@ begin
end; end;
LbImages.Canvas.FillRect(ARect); LbImages.Canvas.FillRect(ARect);
InflateRect(ARect, -IMAGE_DIST, 0); InflateRect(ARect, -IMAGE_DIST, 0);
il16.Draw( JvTimeLine1.Images.Draw(
LbImages.Canvas, ARect.Left, LbImages.Canvas, ARect.Left,
(ARect.Top + ARect.Bottom - il16.Height) div 2, (ARect.Top + ARect.Bottom - JvTimeLine1.Images.Height) div 2,
Index Index
); );
LbImages.Canvas.TextOut( LbImages.Canvas.TextOut(
ARect.Left + il16.Width + IMAGE_DIST, ARect.Left + JvTimeLine1.Images.Width + IMAGE_DIST,
(ARect.Top + ARect.Bottom - h) div 2, (ARect.Top + ARect.Bottom - h) div 2,
IntToStr(Index) IntToStr(Index)
); );
@ -526,7 +540,7 @@ begin
if i > -1 then if i > -1 then
begin begin
Ico := TIcon.Create; Ico := TIcon.Create;
il16.GetIcon(i,Ico); JvTimeLine1.Images.GetIcon(i,Ico);
end end
else else
Ico := nil; Ico := nil;
@ -628,6 +642,7 @@ procedure TTMTimeLineMainForm.StatusBarResize(Sender: TObject);
begin begin
StatusBar.Panels[0].Text := Format('Visible days: %d',[JvTimeLine1.VisibleDays]); StatusBar.Panels[0].Text := Format('Visible days: %d',[JvTimeLine1.VisibleDays]);
StatusBar.Panels[1].Text := Format('Last visible date: %s',[DateToStr(JvTimeLine1.LastVisibleDate)]); StatusBar.Panels[1].Text := Format('Last visible date: %s',[DateToStr(JvTimeLine1.LastVisibleDate)]);
StatusBar.Panels[2].Text := 'Icons used: Fugue icons (http://p.yusukekamiyamane.com)';
end; end;
// display options: // display options:

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

View File

@ -0,0 +1,6 @@
jvcustomoutlookbardownarrow.png
jvcustomoutlookbardownarrow_150.png
jvcustomoutlookbardownarrow_200.png
jvcustomoutlookbaruparrow.png
jvcustomoutlookbaruparrow_150.png
jvcustomoutlookbaruparrow_200.png

View File

@ -0,0 +1,9 @@
jvcustomtmtimelinemilestonelarge.png
jvcustomtmtimelinemilestonelarge_150.png
jvcustomtmtimelinemilestonelarge_200.png
jvcustomtmtimelinescrollleft.png
jvcustomtmtimelinescrollleft_150.png
jvcustomtmtimelinescrollleft_200.png
jvcustomtmtimelinescrollright.png
jvcustomtmtimelinescrollright_150.png
jvcustomtmtimelinescrollright_200.png

View File

@ -1,2 +1,2 @@
lazres ../../../resource/jvtmtimeline.res jvcustomtmtimelinescrollleft.png jvcustomtmtimelinescrollright.png jvcustomtmtimelinemilestonelarge.png lazres ../../../resource/jvtmtimeline.res @jvtmtimeline.txt
lazres ../../../resource/jvoutlookbar.res jvcustomoutlookbardownarrow.png jvcustomoutlookbardownarrow_150.png jvcustomoutlookbardownarrow_200.png jvcustomoutlookbaruparrow.png jvcustomoutlookbaruparrow_150.png jvcustomoutlookbaruparrow_200.png lazres ../../../resource/jvoutlookbar.res @jvoutlookbar.txt

View File

@ -508,7 +508,7 @@ uses
JvThemes, JvThemes,
JvConsts, JvJVCLUtils; JvConsts, JvJVCLUtils;
{$R ..\..\resource\JvOutlookBar.res} {$R ..\..\resource\jvoutlookbar.res}
type type
THackOutlookBar = class(TJvCustomOutlookBar); THackOutlookBar = class(TJvCustomOutlookBar);
@ -612,6 +612,16 @@ begin
end; end;
end; end;
function HighDpi_Suffix: String;
begin
Result := '';
if Screen.SystemFont.PixelsPerInch >= 168 then
Result := Result + '_200'
else
if Screen.SystemFont.PixelsPerInch >= 120 then
Result := Result + '_150';
end;
//=== { TJvOutlookBarEdit } ================================================== //=== { TJvOutlookBarEdit } ==================================================
@ -2050,12 +2060,7 @@ begin
if (UpButton.Glyph.Width = 0) then begin if (UpButton.Glyph.Width = 0) then begin
png := TPortableNetworkGraphic.Create; png := TPortableNetworkGraphic.Create;
try try
resName := 'jvcustomoutlookbaruparrow'; resName := 'jvcustomoutlookbaruparrow' + HighDPI_Suffix;
if Screen.SystemFont.PixelsPerInch > 130 then
resName := resName + '_200'
else
if Screen.SystemFont.PixelsPerInch > 105 then
resName := resName + '_150';
png.LoadFromResourceName(HInstance, resName); png.LoadFromResourceName(HInstance, resName);
UpButton.Glyph.Assign(png); UpButton.Glyph.Assign(png);
finally finally
@ -2071,11 +2076,7 @@ begin
DownButton.SetBounds(ClientWidth - w - margin, R.Bottom - margin - h, w, h); DownButton.SetBounds(ClientWidth - w - margin, R.Bottom - margin - h, w, h);
png := TPortableNetworkGraphic.Create; png := TPortableNetworkGraphic.Create;
try try
resName := 'jvcustomoutlookbardownarrow'; resName := 'jvcustomoutlookbardownarrow' + HighDPI_Suffix;
if Screen.SystemFont.PixelsPerInch > 130 then
resName := resName + '_200'
else if Screen.SystemFont.PixelsPerInch > 105 then
resName := resName + '_150';
png.LoadFromResourceName(HInstance, resName); png.LoadFromResourceName(HInstance, resName);
DownButton.Glyph.Assign(png); DownButton.Glyph.Assign(png);
finally finally

View File

@ -342,6 +342,15 @@ uses
const const
cMagic = 'Jv.TMTIMELINE1'; cMagic = 'Jv.TMTIMELINE1';
function HighDpi_Suffix: String;
begin
Result := '';
if Screen.SystemFont.PixelsPerInch >= 168 then
Result := Result + '_200'
else
if Screen.SystemFont.PixelsPerInch >= 120 then
Result := Result + '_150';
end;
//=== { TJvTLSelFrame } ====================================================== //=== { TJvTLSelFrame } ======================================================
@ -402,6 +411,7 @@ end;
constructor TJvCustomTMTimeline.Create(AOwner: TComponent); constructor TJvCustomTMTimeline.Create(AOwner: TComponent);
var var
png: TPortableNetworkGraphic; png: TPortableNetworkGraphic;
resname: String;
begin begin
inherited Create(AOwner); inherited Create(AOwner);
DoubleBuffered := True; DoubleBuffered := True;
@ -452,7 +462,8 @@ begin
Layout := blGlyphTop; Layout := blGlyphTop;
png := TPortableNetworkGraphic.Create; png := TPortableNetworkGraphic.Create;
try try
png.LoadFromResourceName(HInstance, 'jvcustomtmtimelinescrollleft'); resName := 'jvcustomtmtimelinescrollleft' + HighDPI_Suffix;
png.LoadFromResourceName(HInstance, resname);
Glyph.Assign(png); Glyph.Assign(png);
finally finally
png.Free; png.Free;
@ -473,7 +484,8 @@ begin
Layout := blGlyphTop; Layout := blGlyphTop;
png := TPortableNetworkGraphic.Create; png := TPortableNetworkGraphic.Create;
try try
png.LoadFromResourceName(HInstance, 'jvcustomtmtimelinescrollright'); resname := 'jvcustomtmtimelinescrollright' + HighDPI_Suffix;
png.LoadFromResourceName(HInstance, resname);
Glyph.Assign(png); Glyph.Assign(png);
finally finally
png.Free; png.Free;
@ -594,7 +606,7 @@ end;
function TJvCustomTMTimeline.GetRectForDate(ADate: TDate): TRect; function TJvCustomTMTimeline.GetRectForDate(ADate: TDate): TRect;
begin begin
// all rects are the same size... // all rects are the same size...
Result := Classes.Rect(0, 0, DayWidth, ClientHeight + 1); Result := Classes.Rect(0, 0, DayWidth + 1, ClientHeight + 1);
// ...but we must move the entire rect to the correct date // ...but we must move the entire rect to the correct date
OffsetRect(Result, Trunc(ADate - Self.Date) * DayWidth, 0); OffsetRect(Result, Trunc(ADate - Self.Date) * DayWidth, 0);
// ...and finally compensate for the inital offset // ...and finally compensate for the inital offset
@ -621,6 +633,7 @@ var
png: TPortableNetworkGraphic; png: TPortableNetworkGraphic;
R: TRect; R: TRect;
x, y: Integer; x, y: Integer;
resname: String;
begin begin
Tmp := ACanvas.Brush.Color; Tmp := ACanvas.Brush.Color;
try try
@ -631,7 +644,8 @@ begin
if ShowTodayIcon then begin if ShowTodayIcon then begin
png := TPortableNetworkGraphic.Create; png := TPortableNetworkGraphic.Create;
try try
png.LoadFromResourceName(HInstance, 'jvcustomtmtimelinemilestonelarge'); resname := 'jvcustomtmtimelinemilestonelarge' + HighDpi_Suffix;
png.LoadFromResourceName(HInstance, resname);
x := (ARect.Left + ARect.Right - png.Width) div 2; x := (ARect.Left + ARect.Right - png.Width) div 2;
y := ARect.Top + CanvasMaxTextHeight(ACanvas) + 4; y := ARect.Top + CanvasMaxTextHeight(ACanvas) + 4;
R := Classes.Rect(x, y, x + png.Width, y + png.Height); R := Classes.Rect(x, y, x + png.Width, y + png.Height);