Changeset 111 for trunk/Messg.pas
- Timestamp:
- Feb 2, 2018, 4:40:46 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Messg.pas
r104 r111 5 5 6 6 uses 7 ScreenTools, 8 9 LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes, Graphics, Controls, Forms, ButtonBase, 10 ButtonA, 11 ButtonB, Area; 7 ScreenTools, LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes, 8 Graphics, Controls, Forms, ButtonBase, ButtonA, ButtonB, Area, DrawDlg; 12 9 13 10 const … … 15 12 16 13 type 17 TDrawDlg = class(TForm)18 public19 constructor Create(AOwner: TComponent); override;20 procedure SmartInvalidate; virtual;21 protected22 TitleHeight: integer;23 // defines area to grip the window for moving (from top)24 procedure InitButtons();25 procedure OnEraseBkgnd(var m: TMessage); message WM_ERASEBKGND;26 procedure OnHitTest(var Msg: TMessage); message WM_NCHITTEST;27 end;28 29 TBaseMessgDlg = class(TDrawDlg)30 procedure FormCreate(Sender: TObject);31 procedure FormPaint(Sender: TObject);32 public33 MessgText: string;34 protected35 Lines, TopSpace: integer;36 procedure SplitText(preview: boolean);37 procedure CorrectHeight;38 end;39 40 14 TMessgDlg = class(TBaseMessgDlg) 41 15 Button1: TButtonA; … … 60 34 mkYesNo = 3; 61 35 62 Border = 3;63 MessageLineSpacing = 20;64 65 36 var 66 37 MessgDlg: TMessgDlg; … … 69 40 procedure SoundMessage(SimpleText, SoundItem: string); 70 41 42 71 43 implementation 72 44 73 45 {$R *.lfm} 74 75 constructor TDrawDlg.Create(AOwner: TComponent);76 begin77 inherited;78 TitleHeight := 0;79 end;80 81 procedure TDrawDlg.OnEraseBkgnd(var m: TMessage);82 begin83 end;84 85 procedure TDrawDlg.OnHitTest(var Msg: TMessage);86 var87 i: integer;88 ControlBounds: TRect;89 begin90 if BorderStyle <> bsNone then91 inherited92 else93 begin94 if integer((Msg.LParam shr 16) and $ffff) >= Top + TitleHeight then95 Msg.result := HTCLIENT96 else97 begin98 for i := 0 to ControlCount - 1 do99 if Controls[i].Visible then100 begin101 ControlBounds := Controls[i].BoundsRect;102 if (integer(Msg.LParam and $ffff) >= Left + ControlBounds.Left) and103 (integer(Msg.LParam and $ffff) < Left + ControlBounds.Right) and104 (integer((Msg.LParam shr 16 ) and $ffff) >= Top + ControlBounds.Top) and105 (integer((Msg.LParam shr 16) and $ffff) < Top + ControlBounds.Bottom) then106 begin107 Msg.result := HTCLIENT;108 exit;109 end;110 end;111 Msg.result := HTCAPTION112 end;113 end114 end;115 116 procedure TDrawDlg.InitButtons();117 var118 cix: integer;119 // ButtonDownSound, ButtonUpSound: string;120 begin121 // ButtonDownSound:=Sounds.Lookup('BUTTON_DOWN');122 // ButtonUpSound:=Sounds.Lookup('BUTTON_UP');123 for cix := 0 to ComponentCount - 1 do124 if Components[cix] is TButtonBase then125 begin126 TButtonBase(Components[cix]).Graphic := GrExt[HGrSystem].Data;127 // if ButtonDownSound<>'*' then128 // DownSound:=HomeDir+'Sounds' + DirectorySeparator + ButtonDownSound + '.wav';129 // if ButtonUpSound<>'*' then130 // UpSound:=HomeDir+'Sounds' + DirectorySeparator + ButtonUpSound + '.wav';131 if Components[cix] is TButtonA then132 TButtonA(Components[cix]).Font := UniFont[ftButton];133 if Components[cix] is TButtonB then134 TButtonB(Components[cix]).Mask := GrExt[HGrSystem].Mask;135 end;136 end;137 138 procedure TDrawDlg.SmartInvalidate;139 var140 i: integer;141 r0, r1: HRgn;142 begin143 r0 := CreateRectRgn(0, 0, ClientWidth, ClientHeight);144 for i := 0 to ControlCount - 1 do145 if not(Controls[i] is TArea) and Controls[i].Visible then146 begin147 with Controls[i].BoundsRect do148 r1 := CreateRectRgn(Left, Top, Right, Bottom);149 CombineRgn(r0, r0, r1, RGN_DIFF);150 DeleteObject(r1);151 end;152 InvalidateRgn(Handle, r0, false);153 DeleteObject(r0);154 end;155 156 procedure TBaseMessgDlg.FormCreate(Sender: TObject);157 begin158 Left := (Screen.Width - Width) div 2;159 Canvas.Font.Assign(UniFont[ftNormal]);160 Canvas.Brush.Style := bsClear;161 MessgText := '';162 TopSpace := 0;163 TitleHeight := Screen.Height;164 InitButtons();165 end;166 167 procedure TBaseMessgDlg.FormPaint(Sender: TObject);168 var169 i, cix: integer;170 begin171 PaintBackground(self, 3 + Border, 3 + Border, ClientWidth - (6 + 2 * Border),172 ClientHeight - (6 + 2 * Border));173 for i := 0 to Border do174 Frame(Canvas, i, i, ClientWidth - 1 - i, ClientHeight - 1 - i,175 $000000, $000000);176 Frame(Canvas, Border + 1, Border + 1, ClientWidth - (2 + Border),177 ClientHeight - (2 + Border), MainTexture.clBevelLight,178 MainTexture.clBevelShade);179 Frame(Canvas, 2 + Border, 2 + Border, ClientWidth - (3 + Border),180 ClientHeight - (3 + Border), MainTexture.clBevelLight,181 MainTexture.clBevelShade);182 SplitText(false);183 184 for cix := 0 to ControlCount - 1 do185 if (Controls[cix].Visible) and (Controls[cix] is TButtonBase) then186 BtnFrame(Canvas, Controls[cix].BoundsRect, MainTexture);187 end;188 189 procedure TBaseMessgDlg.SplitText(preview: boolean);190 var191 Start, Stop, OrdinaryStop, LinesCount: integer;192 s: string;193 begin194 Start := 1;195 LinesCount := 0;196 while Start < Length(MessgText) do197 begin198 Stop := Start;199 while (Stop < Length(MessgText)) and (MessgText[Stop] <> '\') and200 (BiColorTextWidth(Canvas, Copy(MessgText, Start, Stop - Start + 1)) <201 ClientWidth - 56) do202 inc(Stop);203 if Stop <> Length(MessgText) then204 begin205 OrdinaryStop := Stop;206 repeat207 dec(OrdinaryStop)208 until (MessgText[OrdinaryStop + 1] = ' ') or209 (MessgText[OrdinaryStop + 1] = '\');210 if (OrdinaryStop + 1 - Start) * 2 >= Stop - Start then211 Stop := OrdinaryStop212 end;213 if not preview then214 begin215 s := Copy(MessgText, Start, Stop - Start + 1);216 LoweredTextOut(Canvas, -1, MainTexture,217 (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,218 19 + Border + TopSpace + LinesCount * MessageLineSpacing, s);219 end;220 Start := Stop + 2;221 inc(LinesCount)222 end;223 if preview then224 Lines := LinesCount;225 end;226 227 procedure TBaseMessgDlg.CorrectHeight;228 var229 i: integer;230 begin231 ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;232 Top := (Screen.Height - ClientHeight) div 2;233 for i := 0 to ControlCount - 1 do234 Controls[i].Top := ClientHeight - (34 + Border);235 end;236 46 237 47 procedure TMessgDlg.FormCreate(Sender: TObject);
Note:
See TracChangeset
for help on using the changeset viewer.