Advertisement
Budyx69

hooverimage

Mar 6th, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. var
  2. //CompLabel: TLabel;
  3. CompForm: TSetupForm;
  4. CompImage: TBitmapImage;
  5. LoadingImage: Boolean;
  6. LastMouse: TPoint;
  7. InstallMessage: TLabel;
  8.  
  9. type
  10. TTimerProc = procedure(H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
  11.  
  12. function GetCursorPos(var lpPoint: TPoint): BOOL; external 'GetCursorPos@user32.dll stdcall';
  13. function SetTimer(hWnd: longword; nIDEvent, uElapse: LongWord; lpTimerFunc: LongWord): LongWord; external 'SetTimer@user32.dll stdcall';
  14. function ScreenToClient(hWnd: HWND; var lpPoint: TPoint): BOOL; external 'ScreenToClient@user32.dll stdcall';
  15. function ClientToScreen(hWnd: HWND; var lpPoint: TPoint): BOOL; external 'ClientToScreen@user32.dll stdcall';
  16. function ListBox_GetItemRect(const hWnd: HWND; const Msg: Integer; Index: LongInt; var Rect: TRect): LongInt; external 'SendMessageW@user32.dll stdcall';
  17.  
  18. const
  19. LB_GETITEMRECT = $0198;
  20. LB_GETTOPINDEX = $018E;
  21.  
  22. function WrapTimerProc(Callback: TTimerProc; ParamCount: Integer): LongWord; external 'wrapcallback@files:InnoCallback.dll stdcall';
  23.  
  24. function FindControl(Parent: TWinControl; P: TPoint): TControl;
  25. var
  26. Control: TControl;
  27. WinControl: TWinControl;
  28. I: Integer;
  29. P2: TPoint;
  30. begin
  31. for I := 0 to Parent.ControlCount - 1 do
  32. begin
  33. Control := Parent.Controls[I];
  34. if Control.Visible and (Control.Left <= P.X) and (P.X < Control.Left + Control.Width) and (Control.Top <= P.Y) and (P.Y < Control.Top + Control.Height) then
  35. begin
  36. if Control is TWinControl then
  37. begin
  38. P2 := P;
  39. ClientToScreen(Parent.Handle, P2);
  40. WinControl := TWinControl(Control);
  41. ScreenToClient(WinControl.Handle, P2);
  42. Result := FindControl(WinControl, P2);
  43. if Result <> nil then Exit;
  44. end;
  45. Result := Control;
  46. Exit;
  47. end;
  48. end;
  49. Result := nil;
  50. end;
  51.  
  52. function PointInRect(const Rect: TRect; const Point: TPoint): Boolean;
  53. begin
  54. Result := (Point.X >= Rect.Left) and (Point.X <= Rect.Right) and (Point.Y >= Rect.Top) and (Point.Y <= Rect.Bottom);
  55. end;
  56.  
  57. function ListBoxItemAtPos(ListBox: TCustomListBox; Pos: TPoint): Integer;
  58. var
  59. Count: Integer;
  60. ItemRect: TRect;
  61. begin
  62. Result := SendMessage(ListBox.Handle, LB_GETTOPINDEX, 0, 0);
  63. Count := ListBox.Items.Count;
  64. while Result < Count do
  65. begin
  66. ListBox_GetItemRect(ListBox.Handle, LB_GETITEMRECT, Result, ItemRect);
  67. if PointInRect(ItemRect, Pos) then Exit;
  68. Inc(Result);
  69. end;
  70. Result := -1;
  71. end;
  72.  
  73. procedure HoverComponentChanged(Index: Integer);
  74. var
  75. Image, form_caption: string;
  76. ImagePath, ImageWaitPath: string;
  77. Image_Fail: Boolean;
  78. image_x, image_y: Integer;
  79. begin
  80. CompForm.Caption := 'Bild Vorschau';
  81. form_caption := GetDATString('Description', 'index'+RightStr('000'+IntToStr(Index),3), '', ExpandConstant('{tmp}\Filebase.ini'));
  82. if form_caption <> ''then
  83. begin
  84. CompForm.Caption := form_caption;
  85. end;
  86. Image := GetDATString('Picture', 'index'+RightStr('000'+IntToStr(Index),3), '', ExpandConstant('{tmp}\Filebase.ini'));
  87. if Image <> '' then
  88. begin
  89. Image_Fail := False;
  90. { The ExtractTemporaryFile pumps the message queue, prevent recursion }
  91. if not LoadingImage then
  92. begin
  93. LoadingImage := True;
  94. try
  95. ImagePath := ExpandConstant('{app}\Budyx69_Modpack\DL_Preview\' + Image);
  96. GetPictureSize(ImagePath, image_x, image_y);
  97. //Log('Image: ' + Image + ' '+ intToStr(image_x) + ' ' + IntToStr(image_y));
  98. CompForm.ClientWidth := image_x + 20;
  99. CompForm.ClientHeight := image_y + 20;
  100. CompImage.Width := image_x;
  101. CompImage.Height := image_y;
  102. if not FileExists(ImagePath) then
  103. begin
  104. Image_Fail := True;
  105. ImageWaitPath := ImagePath;
  106. ImagePath := ExpandConstant('{tmp}\wait.bmp');
  107. CompImage.Bitmap.LoadFromFile(ImagePath);
  108. //CompImage.Bitmap.Canvas.Refesh;
  109. end
  110. else
  111. begin
  112. CompImage.Bitmap.LoadFromFile(ImagePath);
  113. end;
  114. finally
  115. LoadingImage := False;
  116. end;
  117. end;
  118. CompForm.Left := WizardForm.Left + WizardForm.Width;
  119. CompForm.Top := WizardForm.Top;
  120. CompForm.Visible := True;
  121. if Image_Fail then
  122. begin
  123. idpDownloadFile('http://dieschwarzenschafe.com/modpack/preview_images/' + Image, ExpandConstant('{app}\Budyx69_Modpack\DL_Preview\' + Image));
  124. ImagePath := ImageWaitPath;
  125. if FileExists(ImagePath) then
  126. begin
  127. CompImage.Bitmap.LoadFromFile(ImagePath);
  128. //CompForm.Left := WizardForm.Left + WizardForm.Width;
  129. //CompForm.Top := WizardForm.Top;
  130. //CompForm.Visible := True;
  131. end
  132. else
  133. begin
  134. Log('Image not found: ' + ImagePath);
  135. end;
  136. end;
  137. end
  138. else
  139. begin
  140. CompForm.Visible := False;
  141. end;
  142. end;
  143.  
  144. procedure HoverTimerProc(H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
  145. var
  146. P: TPoint;
  147. Control: TControl;
  148. Index: Integer;
  149. begin
  150. GetCursorPos(P);
  151. if P <> LastMouse then
  152. begin
  153. LastMouse := P;
  154. ScreenToClient(WizardForm.Handle, P);
  155.  
  156. if (P.X < 0) or (P.Y < 0) or (P.X > WizardForm.ClientWidth) or (P.Y > WizardForm.ClientHeight) then
  157. begin
  158. Control := nil;
  159. end
  160. else
  161. begin
  162. Control := FindControl(WizardForm, P);
  163. end;
  164.  
  165. Index := -1;
  166. if (Control = WizardForm.ComponentsList) and (not WizardForm.TypesCombo.DroppedDown) then
  167. begin
  168. P := LastMouse;
  169. ScreenToClient(WizardForm.ComponentsList.Handle, P);
  170. Index := ListBoxItemAtPos(WizardForm.ComponentsList, P);
  171. end;
  172.  
  173. HoverComponentChanged(Index);
  174. end;
  175. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement