<div dir="ltr"><span class="gmail-im" style="color:rgb(80,0,80)">> Welcome to the Cuis community!<div><br></div></span><div>Glad to be here, what a cool project. I'm very fond of small things in software, especially for fun (small in scope that is, not in the amount of work since getting something small isn't easy).</div><div><br></div><div>I'll go ahead and respond about the things I've already done, and leave the rest for a later message.</div><span class="gmail-im" style="color:rgb(80,0,80)"><div><br></div><div>> But then I tried to understand what was going on with your code, and I<br>> found a bug in the Cuis image, Rectangle class >> #center:extent: This<br>> is the real reason for the jerking you see. I just pushed an update for<br>> that. Please pull & install. It will be much better.<br></div><div><br></div></span><div>Amazing! Thank you. I wasn't sure about posting before my car "game" even had roads, now I'm glad I did.</div><span class="gmail-im" style="color:rgb(80,0,80)"><div><br></div><div>> One last comment. You'd add ‘JSON’ as a prerequisite to your package, so</div>> it is loaded automatically if needed.<div><br></div></span><div>Done!</div><span class="gmail-im" style="color:rgb(80,0,80)"><div><br></div><div>> My first thought was "you'd use a PluggableScrollPane". You can put a</div>> simpler morph, that knows nothing about panning and scaling in a<br>> ScrollPane, and play with the halo to scale it. Most likely<br>> PluggableScrollPane could use some tweaks (like handling the scaling,<br>> and the pan / zoom gestures), but it is not far from what you need.<br>> Separating RoadTrip from Zoom/Pan issues, by composing them instead of<br>> subclassing, is better IMO. Besides, in places like City>>drawOn: you're<br>> hiding cities out of bounds yourself, while PluggableScrollPane already<br>> clips for you. At least that what I'd do.<div><br></div></span><div>That does seem better. There's a wrinkle though in my case though: I don't want to set `clipsSubmorphs` to true since I want to be able to use the car's halo to move it off of the map. Having the car drive across the screen to get back to the game has melted people's minds when I show them Cuis. So directly using the strategy of `PluggableScrollPane` is out, since my understanding is it works by a combination of moving the interior morph around while clipping what part of it's shown with `clipsSubmorphs`. I'll think about this some more.</div><div><br></div><div>More to follow once I've tried out your code. Thank you for the help and encouragement.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 1, 2024 at 2:00 PM Juan Vuletich <<a href="mailto:juan@cuis.st">juan@cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Ian,<br>
<br>
Welcome to the Cuis community!<br>
<br>
On 2/29/2024 3:02 PM, Ian Jeffries via Cuis-dev wrote:<br>
> Hi all,<br>
><br>
> I'm working on an idle game for learning geography. The first version <br>
> of it's up here: <a href="https://github.com/seagreen/Cuis-Smalltalk-RoadTrip" rel="noreferrer" target="_blank">https://github.com/seagreen/Cuis-Smalltalk-RoadTrip</a><br>
><br>
> It doesn't do much at the moment, there's just a car that noodles <br>
> around between US cities. However I wanted to go ahead and publish it <br>
> so I could get advice on the zooming and panning mechanism.<br>
><br>
> Previously when I've implemented zoom-and-pan everything was based on <br>
> screen coordinates. On zoom-in I stored a new scaling factor, and then <br>
> when drawing the game applied this scaling factor to the game <br>
> coordinates to get screen coordinates. Easy enough.<br>
><br>
> For RoadTrip though I'm taking advantage of Cuis' local coordinate <br>
> system to keep my coordinates in longitude and latitude all the way to <br>
> the user's display. It's extremely neat the users can pull up the <br>
> morph halo and see a grid in long/lat.<br>
><br>
> But this makes scaling "interesting". On zoom-in when I apply <br>
> `scaleBy:` to the morph the US map wants to shoot up and to the left <br>
> off the screen. I'm currently handling this by moving the <br>
> `morphPosition` after each zoom to offset this, so that while scaleBy <br>
> makes the map jump up and to the left, the morph itself moves within <br>
> its parent down and to the right to make up for it, hopefully keeping <br>
> the map at the same place.<br>
><br>
> Unfortunately I can't figure out how to make it exactly accurate and <br>
> it jerks around a lot when zoomed in. Before putting more debugging <br>
> work into this I wanted to ask if it seems like I'm on the right track <br>
> or if I've missed something obvious.<br>
><br>
> Thanks for the help,<br>
> Ian Jeffries<br>
><br>
<br>
You're example is very interesting, and it sparks several ideas to me...<br>
<br>
My first thought was "you'd use a PluggableScrollPane". You can put a <br>
simpler morph, that knows nothing about panning and scaling in a <br>
ScrollPane, and play with the halo to scale it. Most likely <br>
PluggableScrollPane could use some tweaks (like handling the scaling, <br>
and the pan / zoom gestures), but it is not far from what you need. <br>
Separating RoadTrip from Zoom/Pan issues, by composing them instead of <br>
subclassing, is better IMO. Besides, in places like City>>drawOn: you're <br>
hiding cities out of bounds yourself, while PluggableScrollPane already <br>
clips for you. At least that what I'd do.<br>
<br>
But then I tried to understand what was going on with your code, and I <br>
found a bug in the Cuis image, Rectangle class >> #center:extent: This <br>
is the real reason for the jerking you see. I just pushed an update for <br>
that. Please pull & install. It will be much better.<br>
<br>
Still, I think that the zoom behavior can be improved. The attach <br>
includes a tweaked version of your #zoom:mouse: that first sets the <br>
location to keep the point below the mouse exactly at the same place. <br>
Then, I adjust 'origin' to keep the morph display bounds constant too.<br>
<br>
I'd also rewrite the pan with mouse, and I'd remove <br>
#adjustPositionInOwner: . But I leave that to you.<br>
<br>
One last comment. You'd add ‘JSON’ as a prerequisite to your package, so <br>
it is loaded automatically if needed.<br>
<br>
This is a nice project, and I look forward for its evolution. Thanks!<br>
<br>
Cheers,<br>
<br>
-- <br>
Juan Vuletich<br>
<a href="http://cuis.st" rel="noreferrer" target="_blank">cuis.st</a><br>
<a href="http://github.com/jvuletich" rel="noreferrer" target="_blank">github.com/jvuletich</a><br>
<a href="http://researchgate.net/profile/Juan-Vuletich" rel="noreferrer" target="_blank">researchgate.net/profile/Juan-Vuletich</a><br>
<a href="http://independent.academia.edu/JuanVuletich" rel="noreferrer" target="_blank">independent.academia.edu/JuanVuletich</a><br>
<a href="http://patents.justia.com/inventor/juan-manuel-vuletich" rel="noreferrer" target="_blank">patents.justia.com/inventor/juan-manuel-vuletich</a><br>
<a href="http://linkedin.com/in/juan-vuletich-75611b3" rel="noreferrer" target="_blank">linkedin.com/in/juan-vuletich-75611b3</a><br>
<a href="http://twitter.com/JuanVuletich" rel="noreferrer" target="_blank">twitter.com/JuanVuletich</a><br>
<br>
</blockquote></div>