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

View File

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

View File

@ -342,6 +342,15 @@ uses
const
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 } ======================================================
@ -402,6 +411,7 @@ end;
constructor TJvCustomTMTimeline.Create(AOwner: TComponent);
var
png: TPortableNetworkGraphic;
resname: String;
begin
inherited Create(AOwner);
DoubleBuffered := True;
@ -452,7 +462,8 @@ begin
Layout := blGlyphTop;
png := TPortableNetworkGraphic.Create;
try
png.LoadFromResourceName(HInstance, 'jvcustomtmtimelinescrollleft');
resName := 'jvcustomtmtimelinescrollleft' + HighDPI_Suffix;
png.LoadFromResourceName(HInstance, resname);
Glyph.Assign(png);
finally
png.Free;
@ -473,7 +484,8 @@ begin
Layout := blGlyphTop;
png := TPortableNetworkGraphic.Create;
try
png.LoadFromResourceName(HInstance, 'jvcustomtmtimelinescrollright');
resname := 'jvcustomtmtimelinescrollright' + HighDPI_Suffix;
png.LoadFromResourceName(HInstance, resname);
Glyph.Assign(png);
finally
png.Free;
@ -594,7 +606,7 @@ end;
function TJvCustomTMTimeline.GetRectForDate(ADate: TDate): TRect;
begin
// 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
OffsetRect(Result, Trunc(ADate - Self.Date) * DayWidth, 0);
// ...and finally compensate for the inital offset
@ -621,6 +633,7 @@ var
png: TPortableNetworkGraphic;
R: TRect;
x, y: Integer;
resname: String;
begin
Tmp := ACanvas.Brush.Color;
try
@ -631,7 +644,8 @@ begin
if ShowTodayIcon then begin
png := TPortableNetworkGraphic.Create;
try
png.LoadFromResourceName(HInstance, 'jvcustomtmtimelinemilestonelarge');
resname := 'jvcustomtmtimelinemilestonelarge' + HighDpi_Suffix;
png.LoadFromResourceName(HInstance, resname);
x := (ARect.Left + ARect.Right - png.Width) div 2;
y := ARect.Top + CanvasMaxTextHeight(ACanvas) + 4;
R := Classes.Rect(x, y, x + png.Width, y + png.Height);