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

Username:   Password: 
 RegisterRegister   
 Custom Created GUI(added text field)
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Sun Apr 13, 2003 3:16 pm   Post subject: Custom Created GUI(added text field)

Here's the first CCG(custom created GUI) i made. Some people(me=Þ) find GUI a little hard to use so i made these to make it a little easier. 8)

code:
var bfont : int := Font.New ("System:12")
var menu1 := 0
View.Set ("offscreenonly")

function mouseover (x1, y1, x2, y2 : int) : boolean
    var mousex, mousey, mouseb : int
    mousewhere (mousex, mousey, mouseb)
    if mousex >= x1 and mousex <= x2 then
        if mousey >= y1 and mousey <= y2 then
            result true
        end if
    end if
    result false
end mouseover

procedure button (x1, y1, x2, y2, c, tc : int, s : string, num : int, var i : int, font : int)
    var mousex, mousey, mouseb : int
    mousewhere (mousex, mousey, mouseb)

    if mouseover (x1, y1, x2, y2) 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 mouseb = 1 then
            i := num
            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, font, 14)
        else
            drawfillbox (x1 + 1, y1 + 1, x2 - 1, y2 - 1, c)
            Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2) + 1, ((y1 + ((y2 - y1) div 2)) - 4) - 1, font, tc)
        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, c)
        Font.Draw (s, (x1 + ((x2 - x1) div 2)) - (Font.Width (s, bfont) div 2), (y1 + ((y2 - y1) div 2)) - 4, font, tc)
    end if
end button



loop
    locate (1, 1)
    put "key ", menu1, " pressed"
    button (15, 320, 115, 340, 8, 16, "Button 1", 1, menu1, bfont)
    button (15, 290, 115, 310, 8, 16, "Button 2", 2, menu1, bfont)
    button (15, 260, 115, 280, 8, 16, "Button 3", 3, menu1, bfont)
    button (15, 230, 115, 250, 8, 16, "Button 4", 4, menu1, bfont)
    View.Update
    delay (10)
end loop



i am currently working on other CCGs but if there's any bugs please report here.
Sponsor
Sponsor
Sponsor
sponsor
Asok




PostPosted: Sun Apr 13, 2003 3:49 pm   Post subject: (No subject)

Quote:
button (15, 320, 115, 340, 8, 16, "Button 1", mousex, mousey, 1, menu1, mouseb)


Adding more paramaters makes something harder as opposed to easier.

nonetheless, good cusom GUI, I'm not sure if you're using 4.x but I'd reccomend a View.Update in there to reduce the flashing.
Homer_simpson




PostPosted: Sun Apr 13, 2003 4:00 pm   Post subject: (No subject)

Thx
I tried view update but for some strange reason it slows down the program (very slow =( )
and i know that more parameters makes it harded to use but it gives it more functionalities although i could make the mousex and mousey inside the procedure...
FwuffyTheBunny




PostPosted: Mon Apr 14, 2003 11:52 am   Post subject: (No subject)

Hmmm, well whut exactly is a GUI? Wink
Tony




PostPosted: Mon Apr 14, 2003 3:38 pm   Post subject: (No subject)

GUI - Graphic User Interface

basically means any way of getting/putting information OTHER then by typing ~text. Includes buttons, textboxs, images, etc.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Homer_simpson




PostPosted: Thu Apr 17, 2003 11:46 am   Post subject: (No subject)

code:
var bfont : int := Font.New ("System:12")
procedure button2 (x1, y1, x2, y2, c, tc : 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, tc)
    Font.Draw (s, x1 + 5, (y1 + ((y2 - y1) div 2)) - 4, bfont, tc)
end button2
function textfield (x, y, l, c, cb : int) : string
    var ch : char
    var st, st2 := ""
    button2 (x, y, x + l, y + 20, c, cb, st)
    loop
        if hasch then
            ch := getchar
            if ch not= chr (10) then
                if ch = chr (8) then
                    st2 := st
                    st := ""
                    for i : 1 .. Str.length (st2) - 1
                        st := st + st2 (i)
                    end for
                else
                    if (Font.Width (st, bfont) + 10) < l then
                        st := st + ch
                    end if
                end if
                button2 (x, y, x + l, y + 20, c, cb, st)
            else
                result st
            end if
        end if

        delay (10)
        drawline (x + Font.Width (st, bfont) + 7, y + 3, x + Font.Width (st, bfont) + 7, y + 17, c)
        delay (10)
        drawline (x + Font.Width (st, bfont) + 7, y + 3, x + Font.Width (st, bfont) + 7, y + 17, cb)

    end loop
end textfield


colorback (8)
cls
var s := textfield (10, 300, 500, 0, 16)
put s


this is the text field
BigBear




PostPosted: Wed Jan 30, 2008 9:45 pm   Post subject: Re: Custom Created GUI(added text field)

I think your buttons are really cool but how would you use them to run code or procedures.
Euphoracle




PostPosted: Thu Jan 31, 2008 7:28 am   Post subject: RE:Custom Created GUI(added text field)

Pointer to a function or procedure?
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Thu Jan 31, 2008 8:02 am   Post subject: RE:Custom Created GUI(added text field)

5 year-old post?
SNIPERDUDE




PostPosted: Tue Mar 18, 2008 3:03 pm   Post subject: RE:Custom Created GUI(added text field)

As for parameters, keep it simple.
On my newest version I reduced the parameters for simplicity, but added a customization proc to make things more advanced. It is styed similar to that of setscreen

ex:
buttonProperties ("text:green, back: white, etc...
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  [ 10 Posts ]
Jump to:   


Style:  
Search: