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

Username:   Password: 
 RegisterRegister   
 [source code] Custom GUI
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tony




PostPosted: Sun Apr 20, 2003 12:43 am   Post subject: [source code] Custom GUI

I'd like this thread to run the same way text effects does. If you have something to submit - do it here. An exelent way to fight boredem, start rewriting window's GUI in turing!

To start things off, here's something tuirng's GUI defenatly missed -> Percentage Bar

code:

procedure GUIpercent(x1,y1,x2,y2,num:int)

drawfillbox(x1-2,y1-2,x2+2,y2+2, grey)
drawbox(x1-2,y1-2,x2+2,y2+2, black)

for i:1..round((x2-x1)*num/100) by 10
drawfillbox(x1 + i, y1, x1 + i + 7, y2, blue)
end for

end GUIpercent


Highly customizable. You use it the same way you use drawbox, just add additional parameter at the end - percentage as integer (where 50 means 50%) Ofcourse you can change the colors, size of boxes, etc.

And here's the code to make the procedure run:
code:

for i:1..100
locate(1,1)
put i, "%"

GUIpercent(100,100,500,110,i)  %<- this line

delay(100)
end for


You can put it in a loop and watch it go up Very Happy locate with a put is there just to show you how persantages go in reality and how it shows in reguard to the visual display.

Oh, and in case you're wondering... Yes, it could go higher then 100%. The boxes break out of the box and just keep on going. If the fact that you placed a loading in your program to make it look cool doesnt piss off the users, making them wait till 200% sure will Twisted Evil
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Apr 20, 2003 1:16 am   Post subject: (No subject)

here's another simple one -> list

Basically it just lists your array into a box placed where you want. It is dynamically sized so you just need x1,y1,x2 parameters + your array.

code:

procedure GUIlist(x1:int, y1:int, x2:int, name:array 1..* of string)

var fontID:int := Font.New("compsci:12")

drawfillbox(x1,y1,x2, y1 - round(sizeof(name)/256)*15 -4 ,grey)
drawbox(x1,y1,x2, y1 - round(sizeof(name)/256)*15 -4 ,black)

for i:1..round(sizeof(name)/256)
Font.Draw(name(i),x1+2, y1 - i*15-2, fontID, black)
end for

Font.Free(fontID)

end GUIlist


Once again, you can customize colors and fonts to suite your programming needs. Please note that alignmet was calculated for a size 12 font. Other values (the *15 one) needs to be adjusted if you change the font to align properly.

Ofcourse here's the code to test it quickly

code:

var n:array 1..10 of string
n(1) := "Tony"
n(2) := "Dan"
n(3) := "compsci"
n(4) := "programming"
n(5) := "blah"
n(6) := "GUI"
n(7) := "custom"
n(8) := "wacom"
n(9) := "warcraft"
n(10) := "blizzard"

GUIlist(200,300,300,n)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Catalyst




PostPosted: Thu May 22, 2003 6:38 pm   Post subject: (No subject)

heres a button class and interface module
it is set up so that it can be easily expanded upon

note:314th post (woo pi)



interface.t
 Description:

Download
 Filename:  interface.t
 Filesize:  5.04 KB
 Downloaded:  382 Time(s)

Tony




PostPosted: Thu May 22, 2003 6:57 pm   Post subject: (No subject)

awesome.. looks much better (not to mention customazation options) then turing's GUI Very Happy

+20Bits
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Catalyst




PostPosted: Thu May 22, 2003 11:39 pm   Post subject: (No subject)

updated the interface post, now has picture support (replace any fillcolor)
and scales the picture to fit the button
Homer_simpson




PostPosted: Fri May 23, 2003 2:13 pm   Post subject: (No subject)

I had created some ccg before i will submit them when i get home
Andy




PostPosted: Sat Jun 07, 2003 6:40 pm   Post subject: (No subject)

well, its been 2 weeks, and i'm pretty sure ur home by now, so can we see ur ccg?
Homer_simpson




PostPosted: Sat Jun 07, 2003 10:53 pm   Post subject: (No subject)

oops... i totally forgot about that...
it aint completed but here it is :
code:
Mouse.ButtonChoose ("multibutton")

var bfont : int := Font.New ("System:12")
type txtbox :
    record
        text : string
        active, cd, drawn : boolean
        ctime : int
    end record
function timedelay (var r : int, t : int) : boolean
    var tt : int
    if r = 0 then
        clock (r)
        result false
    end if
    clock (tt)
    if tt - r >= t then
        r := tt
        result true
    else
        result false
    end if
end timedelay
function mouseover (x1, y1, x2, y2 : int, var button : int) : boolean
    var x, y, b : int
    mousewhere (x, y, b)
    button := b
    if x >= x1 and x <= x2 then
        if y >= y1 and y <= y2 then
            result true
        end if
    end if
    result false
end mouseover
procedure button (x1, y1, x2, y2, bgcolor, textcolor : int, s : string, var pressed : boolean)
    var kd := 0
    if mouseover (x1, y1, x2, y2, kd) then
        drawline (x1, y1, x2, y1, 30)
        drawline (x2, y1, x2, y2, 30)
        drawline (x2, y2, x1, y2, 25)
        drawline (x1, y2, x1, y1, 25)
        if kd = 1 then
            pressed := true
            drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, 1)
            Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2) + 1, ((y1 + ((y2 - y1) div 2)) - 4) - 1, bfont, 14)
        else
            pressed := false
            drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, bgcolor)
            Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2) + 1, ((y1 + ((y2 - y1) div 2)) - 4) - 1, bfont, textcolor)
        end if

    else
        drawline (x1, y1, x2, y1, 25)
        drawline (x2, y1, x2, y2, 25)
        drawline (x2, y2, x1, y2, 30)
        drawline (x1, y2, x1, y1, 30)
        drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, bgcolor)
        Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2), (y1 + ((y2 - y1) div 2)) - 4, bfont, textcolor)
    end if
end button
procedure button2 (x1, y1, x2, y2, c, textcolor : int, s : string)
    drawline (x1, y1, x2, y1, 30)
    drawline (x2, y1, x2, y2, 30)
    drawline (x2, y2, x1, y2, 25)
    drawline (x1, y2, x1, y1, 25)
    drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, c)
    %Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2), (y1 + ((y2 - y1) div 2)) - 4, bfont, textcolor)
    Font.Draw (s, x1 + 5, (y1 + ((y2 - y1) div 2)) - 4, bfont, textcolor)
end button2
procedure textfield (x, y, l, c, cb, cursortime : int, var txt : txtbox)
    var ch : char
    var st, st2 := txt.text
    var keydown := 0
    if not txt.drawn then
        button2 (x, y, x + l, y + 20, c, cb, st)
        txt.drawn := true
    end if
    if txt.active then
        if hasch then
            ch := getchar
            if ch = chr (8) then
                st2 := st
                st := ""
                for i : 1 .. Str.length (st2) - 1
                    st := st + st2 (i)
                end for
            else
                if ch not= chr (10) then
                    if (Font.Width (st, bfont) + 10) < l then
                        st := st + ch
                    end if
                end if
            end if
            button2 (x, y, x + l, y + 20, c, cb, st)
            txt.text := st
        end if

        if timedelay (txt.ctime, cursortime) then
            if txt.cd then
                drawline (x + Font.Width (st, bfont) + 7, y + 3, x + Font.Width (st, bfont) + 7, y + 17, c)
                txt.cd := not txt.cd
            else
                drawline (x + Font.Width (st, bfont) + 7, y + 3, x + Font.Width (st, bfont) + 7, y + 17, cb)
                txt.cd := not txt.cd
            end if
            View.Update
            delay (5)
        end if
        if not mouseover (x, y, x + l, y + 20, keydown) and (keydown not= 0) then
            txt.active := false
        end if
    else
        if mouseover (x, y, x + l, y + 20, keydown) and (keydown not= 0) then
            txt.active := true
        end if
    end if
end textfield
procedure resettextbox (var txt : txtbox)
    txt.text := ""
    txt.ctime := 0
    txt.cd := false
    txt.active := false
    txt.drawn := false
end resettextbox
procedure resetmenu (var arr : array 1 .. * of boolean)
    for i : 1 .. upper (arr)
        arr (i) := false
    end for
end resetmenu
procedure normalizekeyboard
    if hasch then
        var ch := getchar
    end if
end normalizekeyboard

%                           main program starts here%                           main program starts here%                           main program starts here
%                           main program starts here%                           main program starts here%                           main program starts here
%                           main program starts here%                           main program starts here%                           main program starts here
colorback (8)
cls
View.Set ("offscreenonly")
var txt1 : txtbox     % Declaring a textbox named txt1
resettextbox (txt1)     % Giving the txt1 null values so we dont get errors
var menu : array 1 .. 3 of boolean     %declaring an array of booleans for our button menu
resetmenu (menu)     %giving our menu null value so we dont get errors
loop
    textfield (100, 100, 350, white, black, 1000, txt1)%draws a textfield at coord 100,100 and length of 350 background color white and textcolorback cursor blinks every 1 second and the values will be assigned to txt1
    button (500, 100, 600, 120, grey, black, "Button 1", menu (1))%draws a button with coordinates 500, 100, 600, 120 and grey for background color and black for text color
    button (500, 130, 600, 150, grey, black, "Button 2", menu (2))
    button (500, 160, 600, 180, grey, black, "Button 3", menu (3))
    normalizekeyboard     %We have to put this function at the end so we dont face keyboard bugs
    locate (1, 1)
    put "txt1.text :", txt1.text
    put "txt1.active :", txt1.active
    put "txt1.drawn :", txt1.drawn
    put "button 1:", menu (1)
    put "button 2:", menu (2)
    put "button 3:", menu (3)
    View.Update
    delay (5)
end loop


I'm gonna turn it into a module,add some more things to it(radio, Textbox) and do some tutorials on it...
Do u think it's worth it?!
Sponsor
Sponsor
Sponsor
sponsor
Catalyst




PostPosted: Sun Jun 08, 2003 2:08 am   Post subject: (No subject)

i made some GUI a bit ago (no idea why)
i only made buttons, and a menu
i didnt put customization options into the menu tho (cant even choose,xy)
they can be added pretty easily if needed



interface.t
 Description:

Download
 Filename:  interface.t
 Filesize:  14.12 KB
 Downloaded:  290 Time(s)

Homer_simpson




PostPosted: Sun Jun 08, 2003 3:22 am   Post subject: (No subject)

you had posted the same thing on this thread before... lol Laughing
Catalyst




PostPosted: Sun Jun 08, 2003 2:08 pm   Post subject: (No subject)

i am losing my mind..... Shocked
i didnt have the menu tho
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: