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

Username:   Password: 
 RegisterRegister   
 Getting the "Buttons" to work.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neja




PostPosted: Thu Jan 15, 2004 11:51 pm   Post subject: Getting the "Buttons" to 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.

code:

import GUI in "%oot/lib/GUI"
var newx, newy, newb, colourdraw : int := 0     % Mouse at the current frame.
var oldx, oldy : int := 0                           % Mouse at last frame
var drawingcolour : int                             % 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 Colours   %Ignore
    % First line of colours.
    Draw.Box (112, 10, 636, 55, 7)
    for x : 114 .. 614 by 20
        Draw.Box (x, 33, x + 20, 53, 7)
    end for
    % Second line of colours.
    for x : 114 .. 614 by 20
        Draw.Box (x, 12, x + 20, 33, 7)
    end for
    % Button style.
    Draw.Fill (113, 11, 1, 7)
    % Each individual colour box.  This is gonna take some time...
    var colourlocatex : int := 115
    var colourlocatey1 : int := 34
    var colourlocatey2 : int := 16
    % First line.
    Draw.Fill (colourlocatex, colourlocatey1, 1, 7)
    Draw.Fill (colourlocatex + 20, colourlocatey1, 2, 7)
    Draw.Fill (colourlocatex + 40, colourlocatey1, 3, 7)
    Draw.Fill (colourlocatex + 60, colourlocatey1, 4, 7)
    Draw.Fill (colourlocatex + 80, colourlocatey1, 5, 7)
    Draw.Fill (colourlocatex + 100, colourlocatey1, 6, 7)
    Draw.Fill (colourlocatex + 120, colourlocatey1, 7, 7)
    Draw.Fill (colourlocatex + 140, colourlocatey1, 8, 7)
    Draw.Fill (colourlocatex + 160, colourlocatey1, 9, 7)
    Draw.Fill (colourlocatex + 180, colourlocatey1, 10, 7)
    Draw.Fill (colourlocatex + 200, colourlocatey1, 11, 7)
    Draw.Fill (colourlocatex + 220, colourlocatey1, 12, 7)
    Draw.Fill (colourlocatex + 240, colourlocatey1, 13, 7)
    Draw.Fill (colourlocatex + 260, colourlocatey1, 14, 7)
    Draw.Fill (colourlocatex + 280, colourlocatey1, 15, 7)
    Draw.Fill (colourlocatex + 300, colourlocatey1, 16, 7)
    Draw.Fill (colourlocatex + 320, colourlocatey1, 17, 7)
    Draw.Fill (colourlocatex + 340, colourlocatey1, 18, 7)
    Draw.Fill (colourlocatex + 360, colourlocatey1, 19, 7)
    Draw.Fill (colourlocatex + 380, colourlocatey1, 20, 7)
    Draw.Fill (colourlocatex + 400, colourlocatey1, 21, 7)
    Draw.Fill (colourlocatex + 420, colourlocatey1, 22, 7)
    Draw.Fill (colourlocatex + 440, colourlocatey1, 23, 7)
    Draw.Fill (colourlocatex + 460, colourlocatey1, 24, 7)
    Draw.Fill (colourlocatex + 480, colourlocatey1, 25, 7)
    Draw.Fill (colourlocatex + 500, colourlocatey1, 52, 7)
    % Second line.
    Draw.Fill (colourlocatex, colourlocatey2, 26, 7)
    Draw.Fill (colourlocatex + 20, colourlocatey2, 27, 7)
    Draw.Fill (colourlocatex + 40, colourlocatey2, 28, 7)
    Draw.Fill (colourlocatex + 60, colourlocatey2, 29, 7)
    Draw.Fill (colourlocatex + 80, colourlocatey2, 30, 7)
    Draw.Fill (colourlocatex + 100, colourlocatey2, 31, 7)
    Draw.Fill (colourlocatex + 120, colourlocatey2, 32, 7)
    Draw.Fill (colourlocatex + 140, colourlocatey2, 33, 7)
    Draw.Fill (colourlocatex + 160, colourlocatey2, 34, 7)
    Draw.Fill (colourlocatex + 180, colourlocatey2, 35, 7)
    Draw.Fill (colourlocatex + 200, colourlocatey2, 36, 7)
    Draw.Fill (colourlocatex + 220, colourlocatey2, 37, 7)
    Draw.Fill (colourlocatex + 240, colourlocatey2, 38, 7)
    Draw.Fill (colourlocatex + 260, colourlocatey2, 39, 7)
    Draw.Fill (colourlocatex + 280, colourlocatey2, 40, 7)
    Draw.Fill (colourlocatex + 300, colourlocatey2, 41, 7)
    Draw.Fill (colourlocatex + 320, colourlocatey2, 42, 7)
    Draw.Fill (colourlocatex + 340, colourlocatey2, 43, 7)
    Draw.Fill (colourlocatex + 360, colourlocatey2, 44, 7)
    Draw.Fill (colourlocatex + 380, colourlocatey2, 45, 7)
    Draw.Fill (colourlocatex + 400, colourlocatey2, 46, 7)
    Draw.Fill (colourlocatex + 420, colourlocatey2, 47, 7)
    Draw.Fill (colourlocatex + 440, colourlocatey2, 48, 7)
    Draw.Fill (colourlocatex + 460, colourlocatey2, 49, 7)
    Draw.Fill (colourlocatex + 480, colourlocatey2, 50, 7)
    Draw.Fill (colourlocatex + 500, colourlocatey2, 51, 7)
end Colours

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************************
Colours
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)  % IGNORE EVERYTHING AFTER
% THIS
    if newy >= 33 and newy <= 53 and newb = 1 then
        % First line of colours.   
        if newx >= 114 and newx <= 134 then
            colourdraw := 1
        elsif newx >= 134 and newx <= 154 then
            colourdraw := 2
        elsif newx >= 154 and newx <= 174 then
            colourdraw := 3
        elsif newx >= 174 and newx <= 194 then
            colourdraw := 4
        elsif newx >= 194 and newx <= 214 then
            colourdraw := 5
        elsif newx >= 214 and newx <= 234 then
            colourdraw := 6
        elsif newx >= 234 and newx <= 254 then
            colourdraw := 7
        elsif newx >= 254 and newx <= 274 then
            colourdraw := 8
        elsif newx >= 274 and newx <= 294 then
            colourdraw := 9
        elsif newx >= 294 and newx <= 314 then
            colourdraw := 10
        elsif newx >= 314 and newx <= 334 then
            colourdraw := 11
        elsif newx >= 334 and newx <= 354 then
            colourdraw := 12
        elsif newx >= 354 and newx <= 374 then
            colourdraw := 13
        elsif newx >= 374 and newx <= 394 then
            colourdraw := 14
        elsif newx >= 394 and newx <= 414 then
            colourdraw := 15
        elsif newx >= 414 and newx <= 434 then
            colourdraw := 16
        elsif newx >= 434 and newx <= 454 then
            colourdraw := 17
        elsif newx >= 454 and newx <= 474 then
            colourdraw := 18
        elsif newx >= 474 and newx <= 494 then
            colourdraw := 19
        elsif newx >= 494 and newx <= 514 then
            colourdraw := 20
        elsif newx >= 514 and newx <= 534 then
            colourdraw := 21
        elsif newx >= 534 and newx <= 554 then
            colourdraw := 22
        elsif newx >= 554 and newx <= 574 then
            colourdraw := 23
        elsif newx >= 574 and newx <= 594 then
            colourdraw := 24
        elsif newx >= 594 and newx <= 614 then
            colourdraw := 25
        elsif newx >= 614 and newx <= 634 then
            colourdraw := 52
        else
            colourdraw := 7
        end if
        % Second line of colours.
    elsif newy >= 12 and newy <= 33 and newb = 1 then
        if newx >= 114 and newx <= 134 and newb = 1 then
            colourdraw := 26
        elsif newx >= 134 and newx <= 154 then
            colourdraw := 27
        elsif newx >= 154 and newx <= 174 then
            colourdraw := 28
        elsif newx > 174 and newx <= 194 then
            colourdraw := 29
        elsif newx > 194 and newx <= 214 then
            colourdraw := 30
        elsif newx > 214 and newx <= 234 then
            colourdraw := 31
        elsif newx > 234 and newx <= 254 then
            colourdraw := 32
        elsif newx > 254 and newx <= 274 then
            colourdraw := 33
        elsif newx > 274 and newx <= 294 then
            colourdraw := 34
        elsif newx > 294 and newx <= 314 then
            colourdraw := 35
        elsif newx > 314 and newx <= 334 then
            colourdraw := 36
        elsif newx > 334 and newx <= 354 then
            colourdraw := 37
        elsif newx > 354 and newx <= 374 then
            colourdraw := 38
        elsif newx > 374 and newx <= 394 then
            colourdraw := 39
        elsif newx > 394 and newx <= 414 then
            colourdraw := 40
        elsif newx > 414 and newx <= 434 then
            colourdraw := 41
        elsif newx > 434 and newx <= 454 then
            colourdraw := 42
        elsif newx > 454 and newx <= 474 then
            colourdraw := 43
        elsif newx > 474 and newx <= 494 then
            colourdraw := 44
        elsif newx > 494 and newx <= 514 then
            colourdraw := 45
        elsif newx >= 514 and newx <= 534 then
            colourdraw := 46
        elsif newx >= 534 and newx <= 554 then
            colourdraw := 47
        elsif newx >= 554 and newx <= 574 then
            colourdraw := 48
        elsif newx >= 574 and newx <= 594 then
            colourdraw := 49
        elsif newx >= 594 and newx <= 614 then
            colourdraw := 50
        elsif newx >= 614 and newx <= 634 then
            colourdraw := 51
        end if
    else
    end if
    Draw.Fill (55, 14, colourdraw, 201)
 % STOP IGNORING!!


    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


% End




If youw ant the whole entire code, just ask. I'm really desperate.
Thank you.
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: