Cursor in ruby tutorial

There is one thing I can say about your previous example here …

… is that the pixel indices are zero based and therefore if cursors were standard on 64 pixels square, … then your y index is out of bounds because the first index is 0 and the last is 63.


I think Thomas has explained it in an older topic here somewhere.

On Windows at 100% display scaling the cursors are the same size as the large toolbar icons. (ie, 24 x 24 pixels, … small icons being based upon 16 x 16 pixels.) [The Ruby API documentation does not really note any difference between the Win and MacOS platforms.]

Which brings us to …

if(RUBY_PLATFORM =~ /darwin/)

BTW, Ruby doesn’t use parenthesis around conditional expressions unless we need to control the order of evaluation. Doing this makes code harder to read.

The test against the global RUBY_PLATFORM has always been discouraged in favor of other methods. Use it as a last resort. Since SketchUp 2014 the API has had the Sketchup::platform module method which should be preferred …

if Sketchup.platform == :platform_osx

If you support pre-2014 SketchUp versions (running Ruby 1.8.x) the method call to Sketchup::platform would raise a NoMethodError so a rescue in modifier position can trap this and use the fallback …

if Sketchup.platform == :platform_osx rescue RUBY_PLATFORM =~ /darwin/

Most coders set a platform constant(s) at the top of their extension module so that the platform test is only done once when the module loads. All conditional expressions depending upon platform then reference the boolean constant(s).

WIN = Sketchup.platform == :platform_win
MAC = !WIN

Continuing on the cursor subject …

SketchUp’s display scaling (aka scaled resolution on Mac) support will automatically scale up toolbar button images, cursors and click apertures. This should mean if you base your cursor hotpoint coordinates on the standard, then SketchUp should scale the location as appropriate for the users display scale setting.

If it doesn’t then it is a bug in the API and should be logged in the API Issue Tracker.

  • I’ll try and see if I can find Thomas’ previous example in the forum.
1 Like