Retro FPS

Tag: creepy game

Delphi And RTTI… Moving Controls At Runtime

by on Sep.18, 2013, under giLE2D Dev

Developing giLE2D in Delphi 2010 has been GREAT FUN! I’ve been using Delphi since version 1 (1995).

I wanted to produce a map editor that would not rely on any expensive hardware acceleration, but still have good performance. Here enters TWinControl and its decendants, with the help of GDIPCustomItem…!

While in most situations you arrange all the controls on a Delphi form in a “fixed” position, there are situations when you need to allow a user to change the placement and dimension of controls at run-time.

This is the foundation of the editor… using run time type information (RTTI) to get the job done.

I played around with trying to use a TPanel with a child TImage control to represent sprites, but I just didn’t have the time to incorporate the flexibility I needed for such an object. I am, though, a proud licensee of the fabulous TMS Component library for Delphi. One of their controls gave me exactly what I needed to represent sprites.

The control, TAdvGlowButton, is a descendant of TWinControl (essential here, because I need a window handle HWND for reference). It comes with excess baggage, but I can strip this baggage using RTTI and inherit from it to implement my own interface to the object. It has an implementation of an interface to handle GDI image types, such as TGA and of course, the ubiquitous PNG, so painting and re-drawing the object, not to mention its support for embedded images, made it a no-brainer. The only concern was the GDI handle count under an OS like WinXP (which I do not intend to fully support anyway).

For example, I strip all of its MouseDown, MouseMove and MouseUp events and implement my own at runtime. That way, the end-user can drag and place the control anywhere on the map surface.

You end up getting a nice class implementation:

type   TMethodArray = array of TMethod;
 TMover = class(TComponent)   
  ...   
  ...   
  ...   
  private  
     OnClickMethods : TMethodArray;   
    MouseDownMethods : TMethodArray;   
    MouseMoveMethods : TMethodArray;  
    MouseUpMethods : TMethodArray;   
    KeyDownMethods : TMethodArray;

 

All these event methods can be juxtaposed at my own whim (making the control either static or moveable).

For example, in the RTTI mousemove replacement:

procedure TMover.ControlMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
const
  minWidth = 20;
  minHeight = 20;
var
  newPos: TPoint;
begin
  if inReposition then
  begin
    with TSpriteBlock(Sender) do // TWinControl
    begin
      GetCursorPos(newPos);
      Screen.Cursor := crSize;
      Left := Left - oldPos.X + newPos.X;
      Top := Top - oldPos.Y + newPos.Y;
      oldPos := newPos;
      // pass all sprite properties
      PopulateProperties(TSpriteBlock(Sender), fmMain.Inspector);
    end;
    pbGrid.Update; //Repaint;
    PositionNodes(TWinControl(Sender));
    NeedSave := True;
  end;
end;

Totally Delphi, totally not much code and TOTALLY re-useable!! Delphi really kicks ass… it amazes me still!

As you may have guessed, TSpriteBlock is the inherited class from TAdvGlowButton! Great!

Anyway, hope this insight has been interesting to geeks and non-geeks alike!

Comments Off on Delphi And RTTI… Moving Controls At Runtime :, , , more...

Announcement – ATTA Begins Development!

by on Nov.27, 2012, under A Terrible Truth: Anthropophagus

In September 2012, we announced that development on “A Terrible Truth: Anthropophagus™” or  ATTA™, had begun in ernest (and in the RetroFPS Dev Offices)!

ATTA

A Terrible Truth: Anthropophagus

Our lead developer, Gary Denyer, gives us a glimpse into the storyline of this First-Person Psychological Horror:   Gary: The main protagonist is a Scottish lad who tried to make good… rejecting his rich ancestral family background…

My name is Jivan Voldemort.

Although by my name you would never guess, I am from the outer hebridean island of Lewis, Scotland.

I am from an ancient ancestral family, a family whom I have tried to forget. I was never one to follow tradition.

I decided to pursue my life outwith the old country, and made my living in the United States.

My life was normal: a normal house, my own family: I was happy.

A few days ago my Mother called, leaving a frantic message for me. She said that they had come for her, that they were going to change her too…

“Scary shit, eh?”, remarked Gary. “The story has as much twists and turns as Rapunzels hair-do”, he added.

When asked what the ultimate goal of ATTA was, from a player perspective, Gary went on to say: “In ATTA we believe we have something that will truly be the ultimate pants – filler. We dearly want each person who plays ATTA to feel like they have to have three pairs of clean pants close at hand while they play…”

Comments Off on Announcement – ATTA Begins Development! :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...