Box drawing problem

Just starting out? Need help? Post your questions and find answers here.
marc_256
Addict
Addict
Posts: 837
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Box drawing problem

Post by marc_256 »

Still a newbie,
So ...

For my CAD/CAM program,
I'm drawing a grid on the screen,
and 4 boxes with the same start point ( see code)
The result is, that the 4 boxes start on a different start point !!!!!
depending on what for direction they are drawn.

?? Is this normal ??

Marc

Code: Select all

If OpenWindow(1, 10, 10, 800, 600, "BOX TEST ...", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)

		StartDrawing(WindowOutput(1))

			DrawingMode(#PB_2DDrawing_Outlined)

			LineXY(200, 180, 200, 420, RGB(200, 0, 0))
			LineXY(400, 180, 400, 420, RGB(200, 0, 0))
			LineXY(600, 180, 600, 420, RGB(200, 0, 0))

			LineXY(180, 200, 620, 200, RGB(200, 0, 0))
			LineXY(180, 300, 620, 300, RGB(200, 0, 0))
			LineXY(180, 400, 620, 400, RGB(200, 0, 0))

			Box(400, 300,  200,  100, RGB(100, 100, 100))
			Box(400, 300, -200,  100, RGB(100, 100, 100))
			Box(400, 300, -200, -100, RGB(100, 100, 100))
			Box(400, 300,  200, -100, RGB(100, 100, 100))

			Circle(400, 300, 20, RGB(200, 0, 0))

		StopDrawing()
EndIf
		
Repeat
		Select WaitWindowEvent()
			Case #PB_Event_CloseWindow
				Quit = 1
		EndSelect
		
Until Event = #PB_Event_CloseWindow

End
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Box drawing problem

Post by STARGÅTE »

>> ?? Is this normal ??

Yes,
LineXY <> Box

LineXY(0,0,2,0) draws 3 Pixel (0,0)(1,0)(2,0)
The same in Box is:
Box(0,0,3,1) !
So if Height=0 it draws no box
If Height < 0 , the startpoint of Box is shift:
Box(0,0,-3,1) = Box(0-3,0,3,1) = Box(-3,0,3,1)
and this box draw 3 pixel: (-3,0)(-2,0)(-1,0) , and NOT (0,0)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
marc_256
Addict
Addict
Posts: 837
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Box drawing problem

Post by marc_256 »

Thanks STARGATE

I have a mechanical background,
so this is NOT logic if you start in ONE point,
They have to start there not in side of it.
So I use 4x LineXY() now instead of Box()

Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Box drawing problem

Post by Demivec »

STARGÅTE wrote:>> ?? Is this normal ??

Yes,
LineXY <> Box

LineXY(0,0,2,0) draws 3 Pixel (0,0)(1,0)(2,0)
The same in Box is:
Box(0,0,3,1) !
So if Height=0 it draws no box
If Height < 0 , the startpoint of Box is shift:
Box(0,0,-3,1) = Box(0-3,0,3,1) = Box(-3,0,3,1)
and this box draw 3 pixel: (-3,0)(-2,0)(-1,0) , and NOT (0,0)
@STARGÅTE: I agree with marc_256 in that the behavior of Box() does not make sense. You've given a good description of it, but it would seem the way it is working isn't good nor is it logical.

Currently the box being drawn does not contain the starting point if either the width or the height is less than zero. I guess a feature request would be needed for something like BoxXY(x1,y1,x2,y2).

@marc_256: Here's another workaround procedure which corrects for this sillyness and produces more logical results. Just use boxNew(x, y, width, height, color) wherever Box() would have been used.

Code: Select all

Procedure boxNew(x, y, width, height, color) ;color must be supplied
  Protected hs, ws
  If height < 1: hs = 1: EndIf
  If width < 1: ws = 1: EndIf
  Box(x + ws , y + hs, width, height, color)
EndProcedure
marc_256
Addict
Addict
Posts: 837
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Box drawing problem

Post by marc_256 »

To Demivec,

Yes, this will be a good one (BoxXY x1,y1,x2,y2)

Thanks for the work around.
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Box drawing problem

Post by Demivec »

marc_256 wrote:Yes, this will be a good one (BoxXY x1,y1,x2,y2)

Thanks for the work around.
Your welcome. :)

I have made other feature requests for drawing functions in the past. I have received comments that they would be looked into but none of them have been implemented yet.

Here is a further simplification of the work-around, which you may have already made.

Code: Select all

Procedure boxNew(x, y, width, height, color) ;color must be supplied
  If height < 1: y + 1: EndIf
  If width < 1: x + 1: EndIf
  Box(x, y, width, height, color)
EndProcedure
infratec
Always Here
Always Here
Posts: 7588
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Box drawing problem

Post by infratec »

So why not:

Code: Select all

Procedure BoxXY(x1, y1, x2, y2, Colour = -1)
  If Colour = -1
    Box(x1, y1, x2 - x1 + 1, y2 - y1 + 1)
  Else
    Box(x1, y1, x2 - x1 + 1, y2 - y1 + 1, Colour)
  EndIf
EndProcedure
Best regards,
Bernd
marc_256
Addict
Addict
Posts: 837
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Box drawing problem

Post by marc_256 »

Before starting my CAD/CAM/CNC program for good,
I test some other software...

Normally a box start point = box start point
NOT 1 pixels at the left or above.

Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 7588
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Box drawing problem

Post by infratec »

Hi Marc,

I just tried my function with your example, and I see what you mean.
Stay tuned.

Bernd
infratec
Always Here
Always Here
Posts: 7588
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Box drawing problem

Post by infratec »

Hi Marc,

here it is:

Code: Select all

Procedure BoxXY(x1, y1, x2, y2, Colour = -1)
  
  If x2 < x1
    x = x1
    x1 = x2
    x2 = x + 1
  Else
    x2 + 1
  EndIf
  xw = x2 - x1
  
  
  If y2 < y1
    y = y1
    y1 = y2
    y2 = y + 1
  Else
    y2 + 1
  EndIf
  yw = y2 - y1
  
  
  If Colour = -1
    Box(x1, y1, xw, yw)
  Else
    Box(x1, y1, xw, yw, Colour)
  EndIf
EndProcedure


If OpenWindow(1, 10, 10, 800, 600, "BOX TEST ...", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget)
  
  CreateImage(0, 800, 600)
  
  StartDrawing(ImageOutput(0))

  DrawingMode(#PB_2DDrawing_Outlined)

  LineXY(200, 180, 200, 420, RGB(200, 0, 0))
  LineXY(400, 180, 400, 420, RGB(200, 0, 0))
  LineXY(600, 180, 600, 420, RGB(200, 0, 0))

  LineXY(180, 200, 620, 200, RGB(200, 0, 0))
  LineXY(180, 300, 620, 300, RGB(200, 0, 0))
  LineXY(180, 400, 620, 400, RGB(200, 0, 0))

  ;Box(400, 300,  200,  100, RGB(100, 100, 100))
  ;Box(400, 300, -200,  100, RGB(100, 100, 100))
  ;Box(400, 300, -200, -100, RGB(100, 100, 100))
  ;Box(400, 300,  200, -100, RGB(100, 100, 100))
  
  BoxXY(400, 300,  600,  400, RGB(100, 100, 100))
  BoxXY(400, 300,  200,  400, RGB(100, 100, 100))
  BoxXY(400, 300,  200,  200, RGB(100, 100, 100))
  BoxXY(400, 300,  600,  200, RGB(100, 100, 100))
  
  Circle(400, 300, 20, RGB(200, 0, 0))
  
  StopDrawing()
  
  ImageGadget(0, 0, 0, 800, 600, ImageID(0))
      
  Repeat
    
    Event = WaitWindowEvent()
    
  Until Event = #PB_Event_CloseWindow

EndIf

End
Hope this solves your problem,

Bernd
Last edited by infratec on Fri Jun 25, 2010 10:26 am, edited 1 time in total.
marc_256
Addict
Addict
Posts: 837
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Box drawing problem

Post by marc_256 »

Thanks for the help to a newbie... :wink:

Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 7588
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Box drawing problem

Post by infratec »

Hi Marc,

you are welcome!

And the Box() procedure is not the highlight of PureBASIC. :(
But there are many many others :!:

I corrected the above stuff to make use of an ImageGadget(),
because than the drawing is automatically refreshed.

Bernd
Post Reply