RISC OS sketchpad program
On page 70 of the RISC OS BBC BASIC Reference Manual this program is listed, which "draws lines as
you move the mouse around and hold down its buttons":
you move the mouse around and hold down its buttons":
10 MODE MODE 20 MOVE 0,0 30 REPEAT 40 MOUSE x,y,button 50 GCOL button + 1 40 DRAW x,y 50 UNTIL FALSEI don't understand how this program is supposed to work. If no mouse buttons are pressed button is (presumably) set to zero, and line 50 will then do a GCOL 1. Surely that will cause a line to be drawn, when it shouldn't be. Or have I misunderstood something?
0
Comments
-
I guess nobody has commented because there's no RISC OS-specific expertise here, is there somewhere better to ask the question? I'd like to think it's simply an error in the manual, but since it was revised in 2017 and again in 2021 (with "minor corrections") that's not very likely.
I'd test the code myself in RPCEmu but (although I'm sure I once knew) I've completely forgotten how to enable using the Windows mouse to control the pointer in the emulator, I can't even move the mouse into the window.0 -
Try *POINTER to wake the mouse up.
Looking at the code it will always be drawing, and the colour depends on how many buttons you have held down.0 -
Try *POINTER to wake the mouse up.Looking at the code it will always be drawing
So it does look likely to be an error in the documentation that has never been spotted. To fix it one would presumably have to arrange to do GCOL 5,0 (no-op) when none of the buttons are pressed, something like:50 IF button GCOL button+1 ELSE GCOL 5,0
That does indeed seem to work. Is there some way of feeding it back to the RISC OS documentation team?
1 -
You can drop the ELSE bit entirely, as if it's a no-op, then the code is more efficient just not having it. You can also remove the +1 offset else colour 1 can not be selected. (In MODE 1 left and right buttons will return 5, which maps to 1)
After *POINTER, you can turn the mouse on with MOUSE ON, and changing mode switches it off again.
Regarding documentation bugs, I see others have reported documentation bugs in the Bugs section of the RISC OS Open forums. Indeed, you might remember this from a couple of years ago concerning STR$ and @% - https://www.riscosopen.org/forum/forums/4/topics/17046
(In Matrix Brandy, changing MODE turns the pointer on if windowed, off if full-screen.)0 -
You can drop the ELSE bit entirely
And even that wouldn't work, because if you don't execute the DRAW statement at all the 'graphics cursor' won't be updated when the mouse is moved. So when you do press the button it will draw a line from where you last pressed the button to the new location, which is not what you want.You can also remove the +1 offset else colour 1 can not be selected.
With the +1 pressing the left mouse button does GCOL 5 (equivalent to GCOL 1) and pressing the right mouse button does a GCOL 2, which is ideal.After *POINTER, you can turn the mouse on with MOUSE ON, and changing mode switches it off again.In Matrix Brandy, changing MODE turns the pointer on if windowed, off if full-screen.
0 -
Try MODE 9 - it's like MODE 2 but with MODE 1's resolution. Then you have access to colours 0 to 7 depending on which mouse buttons you hold down (or 1 to 8 if you keep the offset).
Yeah, I misremembered the no-op nature, that GCOL makes all the drawing a no-op, not the GCOL call itself being a no-op. Oops.
Regarding the mouse pointer, like RISC OS, doing MOUSE x,y,b still returns values even if the pointer is not displayed. Perhaps due to the RPCEmu mouse hook patching, you need to do *POINTER first, after which it will still work even after MOUSE OFF.0