![]() |
Forum Index : Microcontroller and PC projects : Dragging an image with mouse with frame sync
Author | Message | ||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
I am trying to get dragging an image with a mouse working without annoying flickering. I have tried both sprites and blitting from page 1, but both have the screen refresh artifacts. I can't find any way to draw a small image with explicit frame synchronization. I know that page copy does have a frame sync option, but I don't want to draw the entire screen, just move a small image around. Apologies if this has been covered before; please point me toward a post. Thanks! -Bill |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
CMM2? I've had mixed results using GETSCANLINE. Also, the MODE command has an optional interrupt parameter - maybe useful. Visit Vegipete's *Mite Library for cool programs. |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Yes, sorry: CMM2 -Bill |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Thanks for the info, vegipete! I think I might be able to get it to work using the mode 'int' param, which I have never noticed before. I can see why trying to use GETSCANLINE would be wonky. -Bill |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Hmm, well I tried using the 'int' parameter on the MODE command, but it seems as if the routine that gets called from the MODE 'int' is suppressed while the mouse button is down. Or at least that is the symptom: when the mouse button is held down, the image that I want to drag does not move, and then reappears at the new mouse position when the button is released. The only place I do any drawing is in the MODE interrupt routine, which gets passed the mouse x, y location in the mouse left click interrupt routine. I'm guessing that MMBasic only has one level of interrupts available, so the mouse interrupt preempts the MODE one. -Bill |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
You should never do anything substantial in an interrupt routine. Just set a flag and then do the work elsewhere. If you want to do stuff while the mouse is pressed then I personally wouldn't use interrupts at all but rather poll for the mouse press. Also make sure that you aren't continuously updating the image. Make sure that you only do it if the mouse has moved by a non-trivial amount mode 1 page write 1 box 0,0,50,50,5,rgb(red),rgb(blue) sprite read 1,0,0,50,50 controller mouse open 0 cls do lastx=x lasty=y x=mouse(x,0) y=mouse(y,0) if abs(x-lastx)>=2 or abs(y-lasty)>=2 then sprite show 1,x,y,1 page copy 1 to 0,b loop Edited 2022-03-10 04:00 by matherp |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Thanks for the good advice, Peter! I will try those ideas. -Bill |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
My sliderule works happily doing full page copies. SUB moveslide IF slidepos <> oldpos OR cursorpos <> oldcursorpos THEN SPRITE HIDE 4 IF slidepos <> oldpos THEN SPRITE SHOW 3, slidepos, ABline, 0 SPRITE SHOW 4, cursorpos,Tedge-5,0 oldpos = slidepos oldcursorpos = cursorpos PAGE COPY 1 TO 0 ,b ENDIF END SUB Full program: https://www.c-com.com.au/mmhelp/sliderule.htm It's 12 months since I have done any changes so might have missed out on a few firmware improvements but still seems to move smoothly for me. Jim VK7JH MMedit |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
PAGE DISPLAY could be useful too, using page flipping. Visit Vegipete's *Mite Library for cool programs. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |