It is currently Sat Jan 23, 2021 12:15 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Canvas Enhancement: Respect User defined Ordinates
PostPosted: Fri Mar 27, 2020 12:52 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6281
Location: Wales, UK
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Enhancement: Respect User defined Ordinates
PostPosted: Fri Mar 27, 2020 11:30 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 304
Location: Germany
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Enhancement: Respect User defined Ordinates
PostPosted: Fri Mar 27, 2020 1:56 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6281
Location: Wales, UK
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Enhancement: Respect User defined Ordinates
PostPosted: Fri Mar 27, 2020 3:08 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1869
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:
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)

_________________
On GitHub: PB Includes - IDE Tools - Color Themes - IDE Branches - TabBarGadget Mods


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Enhancement: Respect User defined Ordinates
PostPosted: Fri Mar 27, 2020 4:09 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6281
Location: Wales, UK
.... 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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Enhancement: Respect User defined Ordinates
PostPosted: Fri Mar 27, 2020 9:50 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6281
Location: Wales, UK
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Enhancement: Respect User defined Ordinates
PostPosted: Fri Mar 27, 2020 11:27 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6281
Location: Wales, UK
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye