Shop OBEX P1 Docs P2 Docs Learn Events
How does mouse detect?? [With VGA too] — Parallax Forums

How does mouse detect?? [With VGA too]

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2009-06-22 20:30 in Propeller 1
I am writing a code for a device that involves a mouse, graphics, and tv driver. I have everything figured out exept how to click on a filled box with text in it; much like that on this computer. Here is the part of my code that hadles the visual and mouse:
· repeat
··· gr.clear
··· tvmessage2(20,172,80,20,@m1)
··· tvmessage2(20,150,80,20,@m2)
··· tvmessage2(20,128,80,20,@m3)
··· tvmessage2(20,106,80,20,@m4)
··· tvmessage2(20,84,80,20,@m5)
··· mousex := mousex + mouse.delta_x #> 0 <# SCREEN_WIDTH
··· mousey := mousey + mouse.delta_y #> 0 <# SCREEN_HEIGHT
··· gr.colorwidth(1,0)
··· gr.pix(mousex, mousey, 0, @pointer)
·····
··· gr.copy(onscreen_buffer)

The "tvmessage2" is a PRI routine I have written that allows you to plot a box anywhere at any size and the text still be centered in the middle. That aside, this will plot 5 text boxes and a mouse pointer(it looks like a computer pointer) that will move with the mouse delta. I want you to be able to click on a box(anywhere in the box) and it go to·another screen layout. I cannot figure out how to do this!roll.gif Please Help!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Toys are microcontroled.
Robots are microcontroled.
I am microcontroled.



If it's not Parallax then don't even bother. :-)

Propeller SRAM TV driver winner: ==NOT COMPLEATED:·1 1/2·WEEKS UNTIL ENDING TIME==

Post Edited (microcontrolled) : 6/22/2009 8:31:46 PM GMT

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,572
    edited 2009-03-11 19:55
    microcontroled1204,

    Typically you check to see if the mouse pointer is within an imaginary box superimposed over the area you want to click.· I say imaginary, because it could be confined to anywhere on the screen.· At the same time you check if the mouse button is pressed or not.

    Say for instance that the box takes up a 10x10 pixel square·with an upper right coordinate of· 15,15

    mock code:

    X = 15·· ' Box X coordinate
    Y = 15·· ' Box Y coordinate
    Xs = 10· ' Box X size
    Ys = 10· ' Box Y size

    Mx = MouseX
    My = MouseY
    Mb = MouseButton

    If Mx·> X and Mx < X+Xs and My > Y and My·< Y+Ys and Mb = 1 then ... <- Mouse is over box and button1 is pressed if this is true




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-03-12 15:37
    This is how I put it(in between the pix and copy commands):

    if mousex>20<100 and mousey>172<192 and mouse.button(1)==TRUE
    tvmessage(@next)
    else
    return

    When I run the program with this snippint of code in it the screen is blank. Does anyone know what I am doing wrong? I am a beginner at this sort of thing and I do not really know if this is not vailid Spin code. Please tell me how to put this in a good form. I'll keep trying!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank you for reading!·

    ···
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-12 15:49
    You can't combine operators as you've shown ("mousex>20<100"). Follow Beau's example.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-03-12 17:08
    It is now working correctly! Thank you for the help!!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank you for reading!·

    ···
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-06-22 20:30
    How does it work with VGA? I know nothing about VGA so are the pixals different or what?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Toys are microcontroled.
    Robots are microcontroled.
    I am microcontroled.



    If it's not Parallax then don't even bother. :-)

    Propeller SRAM TV driver winner: ==NOT COMPLEATED:·1 1/2·WEEKS UNTIL ENDING TIME==
Sign In or Register to comment.