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

Username:   Password: 
 RegisterRegister   
 ASAP! My buttons (not GUI buttons) won't work.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neja




PostPosted: Fri Jan 16, 2004 12:13 am   Post subject: ASAP! My buttons (not GUI buttons) won't work.

I have to make a paint program for comp sci class (naturally). The problem I'm having is that when you click on a "button" (It's not GUI, I'm not to fond of it) it doesn't do what it's supposed to. This is for the tools. The Paint, the spray can, the eraser and the text aren't supposed to work because I haven' created them yet. Basically, you click on, let's say, the pencil, and then you go to the canvas and draw. Absolutly nothing happens. I have no idea why. It's driving me insane and I really hope someone helps.
Here's the basics of my code and I think what I'm missing is another if statement and probably another Mouse.Where, but I have no idea where.
Note: Some variables aren't needed, I'm just copying and pasting directly.

** For some reason, it's not posting my whole entire meassage, so anything that's missing, I'll put up as a reply A.S.A.P.
Sponsor
Sponsor
Sponsor
sponsor
Neja




PostPosted: Fri Jan 16, 2004 12:17 am   Post subject: (No subject)

code:

import GUI in "%oot/lib/GUI"
var newx, newy, newb : int := 0     % Mouse at the current frame.
var oldx, oldy : int := 0                           % Mouse at last frame
var colourdraw:=7                         % Colour the lines will be.
var Files, Edit, Views, Image, Skins, Help, x, y, btnNumber, btnUpDown,
    buttons, x2, y2 : int

% "Canvas" Again, I don't like GUI too much.
  drawfillbox (113, 66, 640, 400, 0)
    drawbox (113, 66, 640, 400, 7)
    Draw.Box (115, 68, 638, 398, 7)
    drawfill (114, 67, 1, 7)

proc Tools   % Ignore
    % Border.
    Draw.Box (8, 65, 96, 400, 7)
    Draw.Box (10, 67, 94, 398, 7)
    Draw.Fill (9, 66, 1, 7)
    % Columns & rows.
    Draw.Line (51, 151, 51, 400, 7)
    Draw.Box (12, 69, 92, 149, 7)
    for rowy : 151 .. 398 by 50
        Draw.Line (10, rowy, 94, rowy, 7)
    end for
    % Pencil.
    Draw.FillBox (27, 365, 33, 379, 43)
    Draw.FillArc (30, 365, 3, 5, 173, 0, 41)
    Draw.Line (27, 380, 30, 386, 26)
    Draw.Line (30, 386, 33, 380, 26)
    % Eraser.
    Draw.FillBox (60, 366, 74, 370, 68)
    Draw.Line (60, 370, 74, 384, 68)
    Draw.Line (74, 384, 88, 384, 68)
    Draw.Line (88, 384, 74, 370, 68)
    Draw.Line (88, 384, 88, 380, 68)
    Draw.Line (88, 380, 74, 366, 68)
    Draw.Fill (73, 371, 67, 68)
    Draw.Fill (87, 380, 68, 68)
    % Paint.
    Draw.FillBox (21, 314, 39, 331, 54)
    Draw.FillBox (25, 314, 35, 331, 53)
    Draw.Line (30, 314, 30, 331, 0)
    Draw.Arc (30, 331, 9, 10, 0, 180, 7)
    % Spray can.
    Draw.FillBox (68, 315, 80, 331, 54)
    Draw.FillBox (71, 315, 76, 331, 53)
    Draw.Line (74, 315, 74, 331, 0)
    Draw.FillBox (66, 333, 68, 336, 30)
    Draw.FillArc (74, 331, 6, 10, 0, 180, 30)
    var xvalue, yvalue : int
    for count : 1 .. 30
        xvalue := Rand.Int (53, 65)
        yvalue := Rand.Int (330, 339)
        Draw.Dot (xvalue, yvalue, 0)
    end for
    % Line.
    Draw.Line (17, 265, 42, 290, 54)
    % Text.
    var fontexample : int
    fontexample := Font.New ("serif:26")
    assert fontexample > 0
    Font.Draw ("A", 62, 265, fontexample, 54)
    % Oval/circle.
    Draw.Oval (30, 226, 10, 10, 7)
    Draw.Fill (30, 226, 54, 7)
    % Box.
    Draw.Box (61, 216, 85, 236, 7)
    Draw.Fill (62, 217, 54, 7)
    % Star.
    Draw.FillStar (15, 164, 45, 189, 54)
    Draw.Star (15, 164, 45, 189, 7)
    % Maple leaf.
    Draw.FillMapleLeaf (58, 164, 86, 189, 54)
    Draw.MapleLeaf (58, 164, 86, 189, 7)
    % Current tool in use.
    Draw.Box (8, 10, 52, 55, 7)
    Draw.Box (10, 12, 50, 53, 7)
    Draw.Fill (9, 11, 1, 7)
    Draw.Box (52, 10, 96, 55, 7)
    Draw.Box (54, 12, 94, 53, 7)
    Draw.Fill (53, 11, 1, 7)
end Tools
%***************************MAINLINE************************
Tools

Help := GUI.CreateMenu ("Help")
item (24) := GUI.CreateMenuItem (name (24), nothing)
item (25) := GUI.CreateMenuItem (name (25), nothing)
loop
    oldx := newx
    oldy := newy
 Mouse.Where (newx, newy, newb)
    if newb = 1 then
        View.ClipSet (115, 68, 638, 398)
        drawbox (113, 66, 640, 400, 7)
        Draw.Box (115, 68, 638, 398, 7)
        drawfill (114, 67, 1, 7)
        drawline (newx, newy, oldx, oldy, colourdraw)
        View.ClipOff
    elsif newx > 10 and newx < 51 and newy > 351 and newy < 398 and
            newb = 1 then
        % Pencil.
        View.ClipSet (115, 68, 638, 398)
        drawbox (113, 66, 640, 400, 7)
        Draw.Box (115, 68, 638, 398, 7)
        drawfill (114, 67, 1, 7)
        drawline (newx, newy, oldx, oldy, colourdraw)
        View.ClipOff
    elsif newx > 10 and newx < 51 and newy > 351 and newy < 398 and
            newb = 1 then
        % Eraser.

    elsif newx > 10 and newx < 51 and newy > 351 and newy < 398 and
            newb = 1 then
        % Paint.

    elsif newx > 10 and newx < 51 and newy > 351 and newy < 398 and
            newb = 1 then
        % Spray can.

    elsif newx > 10 and newx < 51 and newy > 251 and newy < 301 and
            Mouse.ButtonMoved ("down") and Mouse.ButtonMoved ("up") then
        % Line.
        View.ClipSet (115, 68, 638, 398)
        loop
            Mouse.ButtonWait ("down", x, y, btnNumber, btnUpDown)
            x2 := x
            y2 := y
            loop
                drawbox (113, 66, 640, 400, 7)
                Draw.Box (115, 68, 638, 398, 7)
                drawfill (114, 67, 1, 7)
                Draw.Line (x, y, x2, y2, 0) % Erase previous line
                exit when Mouse.ButtonMoved ("up")
                Mouse.Where (x2, y2, buttons)
                Draw.Line (x, y, x2, y2, colourdraw)  % Draw line to position
            end loop
            Mouse.ButtonWait ("up", x2, y2, btnNumber, btnUpDown)
            Draw.Line (x, y, x2, y2, colourdraw)  % Draw line to final position
        end loop
        View.ClipOff
    elsif newx > 10 and newx < 51 and newy > 351 and newy < 398 and
            newb = 1 then
        % Text.


    elsif newx > 10 and newx < 51 and newy > 201 and newy < 251 and
            newb = 1 then
        % Cirlce.
        View.ClipSet (115, 68, 638, 398)
        loop
            Mouse.ButtonWait ("down", x, y, btnNumber, btnUpDown)
            newx := x
            y2 := y
            loop
                drawbox (113, 66, 640, 400, 7)
                Draw.Box (115, 68, 638, 398, 7)
                drawfill (114, 67, 1, 7)
                Draw.Oval (x, y, x2, y2, 0) % Erase previous line
                exit when Mouse.ButtonMoved ("up")
                Mouse.Where (x2, y2, buttons)
                Draw.Oval (x, y, x2, y2, colourdraw)  % Draw line to position
            end loop
            Mouse.ButtonWait ("up", x2, y2, btnNumber, btnUpDown)
            Draw.Oval (x, y, x2, y2, colourdraw)  % Draw line to final position
        end loop
        View.ClipOff
    elsif newx > 51 and newx < 94 and newy > 201 and newy < 251 and
            newb = 1 then
        % Box.
        View.ClipSet (115, 68, 638, 398)
        loop
            Mouse.ButtonWait ("down", x, y, btnNumber, btnUpDown)
            x2 := x
            y2 := y
            loop
                drawbox (113, 66, 640, 400, 7)
                Draw.Box (115, 68, 638, 398, 7)
                drawfill (114, 67, 1, 7)
                Draw.Box (x, y, x2, y2, 0) % Erase previous line
                exit when Mouse.ButtonMoved ("up")
                Mouse.Where (x2, y2, buttons)
                Draw.Box (x, y, x2, y2, colourdraw)  % Draw line to position
            end loop
            Mouse.ButtonWait ("up", x2, y2, btnNumber, btnUpDown)
            Draw.Box (x, y, x2, y2, colourdraw)  % Draw line to final position
        end loop
        View.ClipOff
    elsif newx > 10 and newx < 51 and newy > 151 and newy < 251 and
            newb = 1 then
        % Star.
        View.ClipSet (115, 68, 638, 398)
        loop
            Mouse.ButtonWait ("down", x, y, btnNumber, btnUpDown)
            x2 := x
            y2 := y
            loop
                drawbox (113, 66, 640, 400, 7)
                Draw.Box (115, 68, 638, 398, 7)
                drawfill (114, 67, 1, 7)
                Draw.Star (x, y, x2, y2, 0) % Erase previous line
                exit when Mouse.ButtonMoved ("up")
                Mouse.Where (x2, y2, buttons)
                Draw.Star (x, y, x2, y2, colourdraw)  % Draw line to position
            end loop
            Mouse.ButtonWait ("up", x2, y2, btnNumber, btnUpDown)
            Draw.Star (x, y, x2, y2, colourdraw)  % Draw line to final position
        end loop
        View.ClipOff
    elsif newx > 51 and newx < 92 and newy > 149 and newy < 201 and
            newb = 1 then
        % Maple Leaf.
        View.ClipSet (115, 68, 638, 398)
        loop
            Mouse.ButtonWait ("down", x, y, btnNumber, btnUpDown)
            x2 := x
            y2 := y
            loop
                drawbox (113, 66, 640, 400, 7)
                Draw.Box (115, 68, 638, 398, 7)
                drawfill (114, 67, 1, 7)
                Draw.MapleLeaf (x, y, x2, y2, 0) % Erase previous leaf.
                exit when Mouse.ButtonMoved ("up")
                Mouse.Where (x2, y2, buttons)
                Draw.MapleLeaf (x, y, x2, y2, colourdraw) % Leaf line to        %position.
            end loop
            Mouse.ButtonWait ("up", x2, y2, btnNumber, btnUpDown)
            Draw.MapleLeaf (x, y, x2, y2, colourdraw)  % Leaf line to final     %position.
        end loop
        View.ClipOff
    elsif newx > 0 and newx < 650 and newy > 439 then
% This is here because I am using the menu thingy from GUI
exit when GUI.ProcessEvent     
end if
end loop
Neja




PostPosted: Fri Jan 16, 2004 12:18 am   Post subject: (No subject)

The GUI.ProcessEvent is beacue I have a menu (It couldn't be helped.)


If youw ant the whole entire code, just ask. I'm really desperate.
Thank you.
Tony




PostPosted: Fri Jan 16, 2004 12:38 am   Post subject: (No subject)

well right away I can see that your GUI.ProcessEvent is inside an if statment... that means your GUI will work only sometimes Confused

Actually it should have a loop of its own Thinking
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Neja




PostPosted: Fri Jan 16, 2004 12:57 am   Post subject: (No subject)

I had that earlier, but the problem that then arises is that once you click on the menu, you can't go back to drawing.
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: