Computer Science Canada

Paint Program:Staying on the canvas.

Author:  Neja [ Wed Jan 07, 2004 10:11 pm ]
Post subject:  Paint Program:Staying on the canvas.

How to I get the drawing part to stay on the canvas? (This is for drawing lines) I've fixed it so that if you click somewhere outside the canvas, it won't work, but if you click for the first point of the line to be on the canvas and then click somewhere outside the canvas, it will draw the line (like it's not supposed to). THis is for a paint program I'm supposed to make and I really suck at programming. Instead of posting the whole program, I'll just post the essential part of it;

  var canvas : int := GUI.CreateCanvas (112, 65, 640, 400)
    Draw.Line (113, 66, 113, 400, 7)
    Draw.Line (113, 66, 640, 66, 7)
    Draw.Fill (113, 65, 1, 7)

 var x, y, btnNumber, btnUpDown, buttons : int
    var newx, newy : int
        Mouse.ButtonWait ("down", x, y, btnNumber, btnUpDown)
        newx := x
        newy := y
        if newx > 112 and newx < maxx and newy > 75 and newy < maxy and x > 112
                and y > 75 then
                Draw.Line (x, y, newx, newy, 0)  % Erase previous line
                exit when Mouse.ButtonMoved ("up")
                Mouse.Where (newx, newy, buttons)
                Draw.Line (x, y, newx, newy, 1)  % Draw line to position
            end loop
            % I think this is where I should put Mouse.Where, put I'm new with most of these commands and I'm not sure how I would use it.
            Mouse.ButtonWait ("up", newx, newy, btnNumber, btnUpDown)
            Draw.Line (x, y, newx, newy, 2)      % Draw line to final position
        end if
    end loop

And if you all look you'll see that most of this code is in the Turing Refrence. No, I'm not stealing, I'm trying to learn this code and how to keep the lines within a set perimeter so I can apply it to my program.

Author:  Neja [ Wed Jan 07, 2004 10:15 pm ]
Post subject: 

Oh! I apologize. I didn't realize chibitenshi_03 has a similar problem. Never mind this then.