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

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




PostPosted: Tue May 31, 2005 8:23 pm   Post subject: Highlighting Text

Is there any way to highlight these boxes if you're mouse scrolls over it?


code:

    Pic.Draw (backround, 0, 0, picMerge)
    Font.Draw ("#2. In the 1949/1950 NBA season, the Syracuse Nationals still existed.", 50, 580, font1, white)
    Font.Draw ("Which name do they go under now?", 230, 560, font1, white)
    loop
        drawbox (600, 500, 225, 550, white)
        Font.Draw ("Boston Celtics", 330, 520, font1, white)
        mousewhere (x, y, button)
        if button = 1 then
            if (x >= 225 and x <= 600) and (y >= 500 and y <= 550) then
                cls
                Pic.Draw (wrongback, 0, 0, picMerge)
                Music.PlayFile ("boo.wav")
                Font.Draw ("Incorrect!", 350, 580, font1, white)
                var wrong : int := Pic.FileNew ("wronganswer.bmp")
                Pic.Draw (wrong, 325, 200, picCopy)
                delay (2000)
                exit
            end if
        end if
        drawbox (600, 450, 225, 400, white)
        Font.Draw ("Atlanta Hawks", 330, 420, font1, white)
        mousewhere (x, y, button)
        if button = 1 then
            if (x >= 225 and x <= 600) and (y >= 400 and y <= 450) then
                cls
                Pic.Draw (wrongback, 0, 0, picMerge)
                Music.PlayFile ("boo.wav")
                Font.Draw ("Incorrect!", 350, 580, font1, white)
                var wrong : int := Pic.FileNew ("wronganswer.bmp")
                Pic.Draw (wrong, 325, 270, picCopy)
                delay (2000)
                exit
            end if
        end if
        drawbox (600, 350, 225, 300, white)
        Font.Draw ("Philidelphia 76ers", 330, 320, font1, white)
        mousewhere (x, y, button)
        if button = 1 then
            if (x >= 225 and x <= 600) and (y >= 300 and y <= 350) then
                cls
                Music.PlayFile ("clapping.wav")
                Font.Draw ("Correct!", 350, 580, font1, white)
                counter := counter + 1
                var sixers : int := Pic.FileNew ("sixers.jpg")
                Pic.Draw (sixers, 100, 200, picCopy)
                Font.Draw ("The Syracuse Nationals ceased to exist after 1963.", 125, 150, font1, yellow)
                delay (3000)
                exit
            end if
        end if
        drawbox (600, 250, 225, 200, white)
        Font.Draw ("Toronto Raptors", 330, 220, font1, white)
        mousewhere (x, y, button)
        if button = 1 then
            if (x >= 225 and x <= 600) and (y >= 200 and y <= 250) then
                cls
                Pic.Draw (wrongback, 0, 0, picMerge)
                Music.PlayFile ("boo.wav")
                Font.Draw ("Incorrect!", 350, 580, font1, white)
                var wrong : int := Pic.FileNew ("wronganswer.bmp")
                Pic.Draw (wrong, 325, 200, picCopy)
                delay (2000)
                exit
            end if
        end if
    end loop





Thanks Smile
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed Jun 01, 2005 3:13 pm   Post subject: (No subject)

If your mouse is over it, alter the value of the the variable that stores the colour of the box.

Here's the function I used for checking this in my button class:
Turing:

    % This function accomplishes two tasks.  First, it sets the appropraite colour for the button.
    % Second, it returns true if the button is released, false if it is not.
    fcn clicked : boolean %make sure released is called before check in the loop.  Reason: button.pressed
        var x, y, btn : int %mouse
        if button.show & button.active then
            Mouse.Where (x, y, btn)
            if x >= button.x1 and x <= button.x2 and y >= button.y1 and y <= button.y2 then
                if btn ~= 0 then
                    button.pressed := true %it's pressed if the button is down
                    button.clr.current := button.clr.select
                    button.boarder.clr.top_left := black
                    button.boarder.clr.bottom_right := white
                    button.label_.xDraw := button.label_.x + 1
                    button.label_.yDraw := button.label_.y - 1
                else
                    button.clr.current := button.clr.highlight
                    button.boarder.clr.top_left := white
                    button.boarder.clr.bottom_right := black
                    if button.pressed then %if the mouse button is released but button.pressed is true, then the button has just been released
                        button.released := true
                        button.pressed := false
                    end if
                    button.label_.xDraw := button.label_.x
                    button.label_.yDraw := button.label_.y
                end if
            else
                button.pressed := false
                button.clr.current := button.clr.main
                button.boarder.clr.top_left := white
                button.boarder.clr.bottom_right := black
                button.label_.xDraw := button.label_.x
                button.label_.yDraw := button.label_.y
            end if
            if button.released then
                button.released := false
                result true
            end if
        end if
        result false
    end clicked

This works such that the function returns true when the button is released. It also adjusts the colours of the edges of the button so that it looks like it's being depressed.
Edit: oh, and the xDraw and yDraw are where the label will be drawn. It changes when the button is pressed to make it look more realistic.
Malazan




PostPosted: Wed Jun 01, 2005 11:26 pm   Post subject: (No subject)

Eek. It gives me an error saying "button cannot be followed by a '.' Shifty
Cervantes




PostPosted: Thu Jun 02, 2005 5:52 pm   Post subject: (No subject)

Yeah, I'm using records. Check the tutorial section for a nice read. Smile
Also, that was meant as an example of how to check if your mouse is over it and how to change the colours. I don't expect you to copy and paste that code into your program.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: