Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Mouse Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
marshymell0




PostPosted: Thu May 18, 2006 5:40 pm   Post subject: Mouse Help

Well what I have is a picture that I want the user to move around. The procedure I followed was:
1. Put picture onto screen
2.Take a snapshot of the picture
3.Wait for user to click mouse
4.Move the picture according to mouse
5.If the user's mouse goes out of the boundary, reset the location (only a certain area is allowed to move the picture)

This is what I came up with.
code:
proc GATE
    var btnNumber, btnUpDown : int
    var bgID := Pic.New (300 - picwidth, 150 - picheight, 300 + picwidth, 150 + picheight)
    Pic.Draw (gate, 300 + picwidth, 150 + picheight, picMerge)
    Mouse.ButtonWait ("down", mouseX, mouseY, btnNumber, btnUpDown)
    loop
        x2 := mouseX
        y2 := mouseY
        if mouseX < 205 then
            x2 := 205
        end if
        if mouseX > maxx then
            x2 := maxx - 1
        end if
        if mouseY < 130 then
            y2 := 130
        end if
        if mouseY > maxy then
        end if
        Mouse.Where (mouseX, mouseY, button)
        Pic.Draw (bgID, x2, y2, picMerge)
        bgID := Pic.New (300 - picwidth, 150 - picheight, 300 + picwidth, 150 + picheight)
        Pic.Draw (gate, mouseX, mouseY, picMerge)
        delay (50)
        exit when Mouse.ButtonMoved ("up")
    end loop
end GATE


The problem is, when I move the picture around, it drags along sort of a "trail" of the old picture, and the restrictions don't work. I'm thinking somehting is wrong with the co-ordinates of the bgID, but I can't figure out what. And it's in a procedure because the user clicks a button to start moving the picture. Thanks.
Sponsor
Sponsor
Sponsor
sponsor
TheOneTrueGod




PostPosted: Thu May 18, 2006 5:43 pm   Post subject: (No subject)

Well, problem number one is theres no cls, however, if you have other things being drawn, and other things moving while the picture is moving, simply inserting a cls will not help you. You're going to have to get rid of that nested loop, and find another way to do it.

If this is the only thing you have to do, all you have to do is insert a cls.
blaster009




PostPosted: Thu May 18, 2006 5:55 pm   Post subject: (No subject)

Like mentioned above, you need to cls the screen. Otherwise, it keeps the picture of what was there before. You might also want to look into View.Update and View.Set in order to prevent flicker.
marshymell0




PostPosted: Thu May 18, 2006 7:55 pm   Post subject: (No subject)

well the reason why I'm not using view.update and cls is because this is part of a program (as in a section of the output screen), which is sort of like a canvus/paint thing. Bascially, this procedure is for a button, and when the user clicks, he/she can drag a picture around wherever he/she wants, without it going out of the canvus. So if I cls, and the person had put other pictures on the canvus before, then the whole canvus in which the user draws/adds things will be gone. THat's why I have two pictures, one to overrwrite the other one so that a "trail" doesn't appear.

That's why I don't use something like just drawfillbox overtop of it in the loop.

Another problem is how do I make it so that if the user clicks the button again, the old picture is not deleted. As in, the user can click the button as many times as possible, and keep moving the picture around. Because right now, because the picture is assigned to only one variable, I can only have the picture displayed once. Confused
TheOneTrueGod




PostPosted: Thu May 18, 2006 9:05 pm   Post subject: (No subject)

If thats the case, then you can't do it with the nested loop. You have to update it's position every iteration of the main loop.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: