Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:56 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

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 States
Posts: 405
Posted: 04:52pm 09 Mar 2022
Copy link to clipboard 
Print this post

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: Canada
Posts: 1132
Posted: 04:59pm 09 Mar 2022
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 05:08pm 09 Mar 2022
Copy link to clipboard 
Print this post

Yes, sorry: CMM2
-Bill
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 05:12pm 09 Mar 2022
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 05:31pm 09 Mar 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10310
Posted: 05:40pm 09 Mar 2022
Copy link to clipboard 
Print this post

  Quote  The only place I do any drawing is in the MODE interrupt routine,

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 States
Posts: 405
Posted: 06:16pm 09 Mar 2022
Copy link to clipboard 
Print this post

Thanks for the good advice, Peter! I will try those ideas.

-Bill
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:39pm 09 Mar 2022
Copy link to clipboard 
Print this post

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: Canada
Posts: 1132
Posted: 09:08pm 09 Mar 2022
Copy link to clipboard 
Print this post

PAGE DISPLAY could be useful too, using page flipping.
Visit Vegipete's *Mite Library for cool programs.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025