Recent

Author Topic: Graphics editor - square/circle  (Read 2926 times)

Tallmios

  • Newbie
  • Posts: 3
Graphics editor - square/circle
« on: October 11, 2015, 10:28:11 pm »
I've created a graphics editor using Pascal through Turbo Delphi. 
Drawing a rectangle/ellipse works like this:
https://i.gyazo.com/aea5ea17c3fadcaf106c9f53acae49ff.gif  (the cursor is desynchronised in the gif, but works correctly in the program). 
How would I go about drawing a square/circle with the right mouse button, similarly to how Microsoft Paint allows you right angles/circles/squares when you're holding shift?

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1209
    • Burdjia
Re: Graphics editor - square/circle
« Reply #1 on: October 12, 2015, 02:13:50 pm »
When drawing, just check if Shift is pressed, if so then check which one is smaller (width or height) and use it as both values.  Something like this:
Code: Pascal  [Select][+][-]
  1.   BEGIN
  2.     Width := MouseX - OriginX; Height := MouseY - OriginY;
  3.     IF ShiftPressed THEN
  4.     BEGIN
  5.       IF Width < Height THEN
  6.         DrawEllipse (OrigX, OrigY, Width, Width)
  7.       ELSE
  8.         DrawEllipse (OrigX, OrigY, Height, Height)
  9.     END
  10.     ELSE
  11.       DrawEllipse (OrigX, OrigY, Width, Height)
  12.   END;
  13.  
If you're asking how to know if Shift is pressed, it is different in each framework/library you're using (i.e. SDL, FCL, Allegro, ...).
« Last Edit: October 13, 2015, 10:47:55 am by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Tallmios

  • Newbie
  • Posts: 3
Re: Graphics editor - square/circle
« Reply #2 on: October 12, 2015, 10:26:42 pm »
Thank you. I'll try your code out. In my program it's going to be a function of RMB and I've already sorted that out.

 

TinyPortal © 2005-2018