Weekly Qbasic and Qb64 Lesson Topics
March 29, 2024, 10:43:28 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Selecting and Moveing a picture with Mouse

Pages: [1]
  Print  
Author Topic: Selecting and Moveing a picture with Mouse  (Read 347 times)
Mouse Movement
Guest
« on: February 25, 2011, 07:43:17 am »


    This one allows you to click and picture will appear where your mouse is. Escape to exit.
Code:
REM
DEFLNG A-Z
DIM SHARED mx, my, mbl, mbr

video& = _NEWIMAGE(800, 600, 32)
image& = _LOADIMAGE("qb64logo.png", 32)

SCREEN video&
x1 = 100: x2 = x1 + 167: y1 = 100: y2 = y1 + 126

DO
    _LIMIT 30
    MousePoll
    _PUTIMAGE (x1, y1)-(x2, y2), image&, video&
    IF mbl = -1 THEN
        CLS
        x1 = mx: x2 = x1 + 167: y1 = my: y2 = y1 + 126
        _PUTIMAGE (x1, y1)-(x2, y2), image&, video&
        LINE (x1 - 1, y1 - 1)-(x2 + 1, y2 + 1), _RGB32(255, 255, 0), B
    END IF
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SYSTEM

SUB MousePoll ()
DO WHILE _MOUSEINPUT
    mx = _MOUSEX: my = _MOUSEY: mbl = _MOUSEBUTTON(1): mbr = _MOUSEBUTTON(2)
LOOP
END SUB
The picture:http://dl.dropbox.com/u/10291175/qb64logo.png
 Nothing orignal about this, but it is a good demo on getting movement of a object ,with the mouse.
« Last Edit: September 13, 2011, 07:31:06 pm by GarrisonRicketson » Report Spam   Logged

Share on Facebook Share on Twitter

mouse movement
Guest
« Reply #1 on: February 25, 2011, 11:29:47 am »


    A better version that wont let the mouse arrow jump to top left of the picture.
Code:
REM
DEFLNG A-Z
DIM SHARED mx, my, mbl, mbr

video& = _NEWIMAGE(800, 600, 32)
image& = _LOADIMAGE("qb64logo.png", 32)

SCREEN video&
x1 = 100: x2 = x1 + 167: y1 = 100: y2 = y1 + 126

DO
  _LIMIT 30
  MousePoll
  _PUTIMAGE (x1, y1)-(x2, y2), image&, video&
  'check for mouse button down
  IF mbl = -1 THEN
    IF mx > x1 AND mx < x2 THEN
      IF my > y1 AND my < y2 THEN 'mouse over picture
        CLS
        difx = mx - x1: dify = my - y1 'difference between x1 and mx ,y1 and my
        WHILE mbl = -1
          MousePoll
          x1 = mx - difx: y1 = my - dify: x2 = x1 + 157: y2 = y1 + 126
          LINE (x1 - 1, y1 - 1)-(x2 + 1, y2 + 1), _RGB32(255, 255, 0), B
          _PUTIMAGE (x1, y1)-(x2, y2), image&, video&
          PRINT x1, x2, difx, dify, mx, my
          _DISPLAY
          CLS
        WEND
      END IF
    END IF
  END IF
  _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SYSTEM


SUB MousePoll ()
DO WHILE _MOUSEINPUT
  mx = _MOUSEX: my = _MOUSEY: mbl = _MOUSEBUTTON(1): mbr = _MOUSEBUTTON(2)
LOOP
END SUB
The picture:http://dl.dropbox.com/u/10291175/qb64logo.png
 Edit:
I don't know if this works or not, use  it at your own risk. From Garry
« Last Edit: September 13, 2011, 07:32:51 pm by GarrisonRicketson » Report Spam   Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy