# PureBasic Forum

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

 All times are UTC + 1 hour

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Canvas Enhancement: Respect User defined OrdinatesPosted: Fri Mar 27, 2020 12:52 am
 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

 Post subject: Re: Canvas Enhancement: Respect User defined OrdinatesPosted: Fri Mar 27, 2020 11:30 am
 Enthusiast

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:

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

 Post subject: Re: Canvas Enhancement: Respect User defined OrdinatesPosted: Fri Mar 27, 2020 1:56 pm
 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

 Post subject: Re: Canvas Enhancement: Respect User defined OrdinatesPosted: Fri Mar 27, 2020 3:08 pm

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
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)
FillPath()
VectorSourceColor(RGBA(255,255,160,128))
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)
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()
VectorSourceColor(RGBA(255, 0, 0, 192))
FillPath()

StopVectorDrawing()
EndIf
EndIf
EndProcedure

OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

Repeat
Event = WaitWindowEvent()
Until (Event = #PB_Event_CloseWindow)

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

Top

 Post subject: Re: Canvas Enhancement: Respect User defined OrdinatesPosted: Fri Mar 27, 2020 4:09 pm
 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

 Post subject: Re: Canvas Enhancement: Respect User defined OrdinatesPosted: Fri Mar 27, 2020 9:50 pm
 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.

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

 Post subject: Re: Canvas Enhancement: Respect User defined OrdinatesPosted: Fri Mar 27, 2020 11:27 pm
 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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite