Monday, 5 May 2014

Writing a StrPix-like program with Lazarus – 10

When we use the mouse wheel with the mouse pointer over Image1 we don’t scroll through the pages.

What we need to do is link Image1’s MouseWheel event handler to ComboBox1’s Change event handler.

Select Image1 either on the form or in the Object Inspector.

Click on the Events tab in the Object inspector and then click OnMouseWheel.

Click on the 3 dot button to create the empty method.


Add the following code to the method.

procedure TForm1.Image1MouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  i: integer;
  with ComboBox1 do
    //Worth it?
    if Items.Count=0 then exit;
    i := ItemIndex;
    //Change according to direction
    if (WheelDelta>0) then
      i := i - 1
      i := i + 1;
    //Check range
    if i < 0 then
      i := 0
    else if i >= Items.Count then
      i := Items.Count - 1;
    //Any change?
    if i <> ItemIndex then
      //Apply it
      ItemIndex := i;
      //Fire OnChange
      if assigned(OnChange) then

Build and run the program and open a *.wad file and point the mouse over Image1.

Use the mouse wheel to “scroll” through the pages.

In the previous post I forgot to set ComboBox1 as read only so we will fix that now.

Click on ComboBox1 in the Object Inspector and click on the ReadOnly property and change it to True in the dropdown and then save the project.


If you click on a texture map page in StrPix or PixStr or TextureAdd or WadExplorer, if a texture exists under the mouse pointer, it is highlighted by surrounding it with a coloured rectangle.


The texture information is stored as a list of texinfos in the variable wad.textureTableData.

A texinfo defines a rectangle in a texture map page.

In the next post we will link the position of the mouse pointer when the mouse is clicked on Image1 to a texinfo in wad.textureTableData and highlight that rectangle in the texture map.

prev | next

No comments:

Post a Comment