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

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




PostPosted: Sun May 28, 2006 5:22 pm   Post subject: My First Class

Im testing out Classes now, and I can't think at the moment (low on food energy), so how would I implement my box_fill proc in a way so when I let go of the mouse, it fills the area and the drawfillbox(0,0,maxx,maxy,black) doesn't erase the filled box.

code:

class Picture
    export initialize, box_outline, box_fill

    var x_box_pos, y_box_pos, x_size, y_size, pic_colour : int

    proc initialize (x_box_pos_, y_box_pos_, x_size_, y_size_, pic_colour_ : int)
        x_box_pos := x_box_pos_
        y_box_pos := y_box_pos_
        x_size := x_size_
        y_size := y_size_
        pic_colour := pic_colour_
    end initialize

    proc box_outline
        drawbox (x_box_pos, y_box_pos, x_size, y_size, pic_colour)
    end box_outline

    proc box_fill
        drawfillbox (x_box_pos, y_box_pos, x_size, y_size, pic_colour)
    end box_fill

end Picture

var rect : ^Picture
new Picture, rect

class New_Mouse
    import Mouse, Picture, rect
    export mouse_where

    var x_mouse_pos, y_mouse_pos, mouse_click, start, finish : int

    proc mouse_where
        loop
            drawfillbox (0, 0, maxx, maxy, black)
            Mouse.Where (x_mouse_pos, y_mouse_pos, mouse_click)
            if (mouse_click = 0) then
                start := x_mouse_pos
                finish := y_mouse_pos
            end if
            Picture (rect).initialize (x_mouse_pos, y_mouse_pos, start, finish, red)
            Picture (rect).box_fill
            View.Update
        end loop
    end mouse_where

end New_Mouse

var loc : ^New_Mouse
new New_Mouse, loc

View.Set ("offscreenonly")
New_Mouse (loc).mouse_where
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Sun May 28, 2006 6:00 pm   Post subject: (No subject)

Well what you could do and what is also used in some paint programs is simply taking a picture of the screen, a screen shot.

Now, rather than drawing the black background, you draw the last saved picture image, where the first picture would be a big black box. Then once the user releases the box, take a picture before you update the screen and voila, new background.

Then if you wanted to expand from that, you could keep an array of images where it displays the last taken picture - so that if the user wanted to undo anything you just resort to one of the previous pictures. But i know you're not trying to make paint, just learn classes Smile.

That's my thought at least (unless you want to save co-ordinates)
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  [ 2 Posts ]
Jump to:   


Style:  
Search: