Canvas Enhancement: Respect User defined Ordinates

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Canvas Enhancement: Respect User defined Ordinates

Post by IdeasVacuum »

With a Canvas Gadget for output, both the 2D Drawing Library: SetOrigin() and the Vector Drawing Library: TranslateCoordinates(), FlipCoordinatesX(), FlipCoordinatesY(), allow the developer control of where geometry emanates.

However, the output of Canvas mouse coordinates currently ignores User defined origins. It would be better if the Canvas mouse could be in synch with the Drawing Library in use.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Canvas Enhancement: Respect User defined Ordinates

Post by Derren »

Couldn't you just apply the same factor to the mouse coordinates?

i.e. if you stretch everything to 200% you need to divide the mouse coordinates by 2.
If you flipped coordinates, you need to multiply by -1 and if you set an origin, you need add or subtract this value.

Also, I'm not sure, because I hardly use the Vector-Library, at least not to its potential.
But isn't it the case, that you can use different transformations for different parts of the image?

i.e. I can draw a box 10x10 and then apply some transformations and draw another box 10x10 but it is drawn stretched or flipped?

I mean, take a look at this image from the help file:
Image

At which MousePosition would you like to have 0/0? at the top left of the canvas? at the top left of the blue or the red ruler?

Since you would draw a whole picture and THEN check for mouse coordinates, you would only get the "user defined" system of the last drawing opration.
And if you decide to draw another box in a corner to display some additional info, you might change the coordinates again and then your whole mouse-code is suddenly wonky
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Canvas Enhancement: Respect User defined Ordinates

Post by IdeasVacuum »

Hi Derren

That's exactly what I am doing and it's OK, but two operations for the final value should not have to happen. Imagine how the Newbies get along with this.....
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Canvas Enhancement: Respect User defined Ordinates

Post by kenmo »

They are separate libraries... the Gadget library gives you the real MouseX and MouseY, regardless of any drawing that has been done!
(Also, you often read the mouse coordinates outside of any Start/Stop drawing block, so how would it know what to convert?)

That is what the ConvertCoordinateX() ConvertCoordinateY() functions are for... you can map mouse --> drawing and drawing --> mouse.

Code: Select all

Procedure CB()
  If EventType() = #PB_EventType_MouseMove
    mx = GetGadgetAttribute(0, #PB_Canvas_MouseX)
    my = GetGadgetAttribute(0, #PB_Canvas_MouseY)
    If StartVectorDrawing(CanvasVectorOutput(0))
      VectorSourceColor(RGBA(255, 255, 240, 255))
      FillVectorOutput()
      
      VectorSourceColor(RGBA(0, 0, 255, 255))
      TranslateCoordinates(200, 200)
      ScaleCoordinates(2, 2)
      FlipCoordinatesX(0)
      RotateCoordinates(0, 0, 30)
      AddPathEllipse(0, 0, 100, 50)
      FillPath()
      VectorSourceColor(RGBA(255,255,160,128))
      AddPathCircle(0, 0, 12)
      FillPath()
      
      ; Draw circle by mapping MouseX MouseY to transformed vector coordinates
      ConvertedX.d = ConvertCoordinateX(mx, my, #PB_Coordinate_Device, #PB_Coordinate_User)
      ConvertedY.d = ConvertCoordinateY(mx, my, #PB_Coordinate_Device, #PB_Coordinate_User)
      AddPathCircle(ConvertedX, ConvertedY, 10)
      VectorSourceColor(RGBA(0, 255, 0, 192))
      FillPath()
      
      ClearDebugOutput()
      Debug "(" + Str(mx) + ", " + Str(my) + ")"
      Debug "  maps to:"
      Debug "(" + StrD(ConvertedX) + ", " + StrD(ConvertedY) + ")"
      
      ; Draw circle as normal MouseX MouseY coordinates
      ResetCoordinates()
      AddPathCircle(mx, my, 5)
      VectorSourceColor(RGBA(255, 0, 0, 192))
      FillPath()
      
      StopVectorDrawing()
    EndIf
  EndIf
EndProcedure

OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500)
BindGadgetEvent(0, @CB())

Repeat
  Event = WaitWindowEvent()
Until (Event = #PB_Event_CloseWindow)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Canvas Enhancement: Respect User defined Ordinates

Post by IdeasVacuum »

.... not drawing a picture as such, but making 2D plans from 3D models - The mouse is used a lot to verify dimensions and make modifications. I highlight entities on mouse-over and pick, so anything not directly concerned with the goal is an expense, especially when entities get into the hundreds.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Canvas Enhancement: Respect User defined Ordinates

Post by IdeasVacuum »

Hi Kenmo

First and foremost, at least the Vector Lib has something - I missed that. :oops:

How would the Canvas Gadget know? It could have it's own Set Ordinates function, instead only the default.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Canvas Enhancement: Respect User defined Ordinates

Post by IdeasVacuum »

Actually, ConvertCoordinateX/Y does not fit well with my program as it only works after a StartVectorDrawing() call. It's actually easier to continue with my own conversion code without that restriction.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply