Page 1 of 1

Box drawing problem

Posted: Tue Jun 15, 2010 9:59 am
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

Re: Box drawing problem

Posted: Tue Jun 15, 2010 10:27 am
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)

Re: Box drawing problem

Posted: Tue Jun 15, 2010 12:07 pm
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

Re: Box drawing problem

Posted: Tue Jun 15, 2010 1:31 pm
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

Re: Box drawing problem

Posted: Fri Jun 18, 2010 10:49 pm
by marc_256
To Demivec,

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

Thanks for the work around.

Re: Box drawing problem

Posted: Sat Jun 19, 2010 12:07 am
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

Re: Box drawing problem

Posted: Sat Jun 19, 2010 9:39 am
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

Re: Box drawing problem

Posted: Fri Jun 25, 2010 9:27 am
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

Re: Box drawing problem

Posted: Fri Jun 25, 2010 9:39 am
by infratec
Hi Marc,

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

Bernd

Re: Box drawing problem

Posted: Fri Jun 25, 2010 10:17 am
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

Re: Box drawing problem

Posted: Fri Jun 25, 2010 10:22 am
by marc_256
Thanks for the help to a newbie... :wink:

Marc

Re: Box drawing problem

Posted: Fri Jun 25, 2010 10:29 am
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