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

Username:   Password: 
 RegisterRegister   
 making a botton?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
toothyC




PostPosted: Tue Apr 29, 2008 8:36 am   Post subject: making a botton?

I was hoping to open a new window when I press the start botton...
but it's not working...
wut's wrong with these code?


    %Creat start botton
    procedure OpenNewWin (x, y : int)
      if x > 142 and x < 209 and y > 97 and y < 118 then
        Window.Close (winID)
        winID := Window.Open ("graphics:800;399, nobuttonbar")

      end if

    end OpenNewWin

    var startButton : int := GUI.CreateButton (142, 97, 30, "START", OpenNewWin)
Sponsor
Sponsor
Sponsor
sponsor
darkangel




PostPosted: Wed Apr 30, 2008 3:58 pm   Post subject: Re: making a botton?

DO NOT use Turing's GUI!!!!!
It is highly inefficient and can get very confusing, very fast.
instead make you own.
Here's my homemade GUI

code:

%main program.
 import G in "module.tu"

proc doNothin
    put "Doing nothin"
    %this is where you would open the window
end doNothin

View.Set ("offscreenonly")
loop
    exit when G.button (100, 150, "QUIT")

    G.procButton (300, 150, "Do something", doNothin)

    if G.button (200, 200, "Change Stuff") then
        G.colorChange (brightgreen, green, black)
        G.fontChange ("OCR A Std:12:bold")
    end if
delay (50)
end loop

code:

%the module
unit
module G % for (G)raphic
    export button, procButton, colorChange, fontChange

    %Mouse Vars
    var mx, my, mz : int

    %Font, I made this a universal var so it could be changed.
    var bFont := Font.New ("OCR A Std:12")

    var c1, c2, fc : int
    c1 := 29 %Top color
    c2 := 25 %Bottom color
    fc := black %font color
    % When the button is "pressed" the colors alternate

    function button (x, y : int, text : string) : boolean
        Mouse.Where (mx, my, mz)
        var w := Font.Width (text, bFont) + 10
        if mx > x and mx < x + w and my > y and my < y + 20 and mz = 1 then
            Draw.FillBox (x, y, x + w, y + 20, c1)
            Draw.FillBox (x + 2, y + 1, x + w - 1, y + 20 - 2, c2)
            Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
            View.Update
            delay (200)
            result true
        else
            Draw.FillBox (x, y, x + w, y + 20, c2) %25
            Draw.FillBox (x + 1, y + 2, x + w - 2, y + 20 - 1, c1) %29
            Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
            View.Update
            result false
        end if
    end button

    procedure procButton (x, y : int, text : string, po : proc xx)
        Mouse.Where (mx, my, mz)

        var w := Font.Width (text, bFont) + 10
        if mx > x and mx < x + w and my > y and my < y + 20 and mz = 1 then
            Draw.FillBox (x, y, x + w, y + 20, c1)
            Draw.FillBox (x + 2, y + 1, x + w - 1, y + 20 - 2, c2)
            Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
            View.Update
            po
            delay (200)
        else
            Draw.FillBox (x, y, x + w, y + 20, c2) %25
            Draw.FillBox (x + 1, y + 2, x + w - 2, y + 20 - 1, c1) %29
            Font.Draw (text, x + (w div 2) - (Font.Width (text, bFont) div 2), y + 5, bFont, fc)
            View.Update
        end if
    end procButton

    proc colorChange (front, back, font : int)
        c1 := front
        c2 := back
        fc := font
    end colorChange

    proc fontChange (newFont : string)
        bFont := Font.New (newFont)
    end fontChange
end G

And don't stop there, this is a simplified version of a GUI, make your own and tweak it to your own liking.

( My module has buttons that call procedures, give a true or false result, able to change colors, able to change fonts )
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: