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

Username:   Password: 
 RegisterRegister   
 get font?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
LegendsEnd




PostPosted: Mon Apr 17, 2006 2:11 pm   Post subject: get font?

When using a get command, the text you enter is always the same font. I know I can do it the hard way and use getch + font.draw but is there a way to just plain change the font of get?
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Mon Apr 17, 2006 3:17 pm   Post subject: (No subject)

Well i don't know if you can with the "get" command, so i have another suggestion, make your own function to do this for you... Here ill help you with the basics, though i leave you to touch it up, and make it better Smile

code:

%% a function to get different text:  I made this really fast so you need to touch it up:

%%i can tell you this ::  It had no backspace in it, you can fix that though right?

fcn gets (xpos : int, ypos : int, text_color : int) : string %will return the word
    var font : int := Font.New ("Palatino:24:bold,italic")  %%type of font want to use
    var ch : string (1)
    var user_text : string := ""    %%the word you make

    loop
        getch (ch)
        exit when ch = (KEY_ENTER)
        user_text += ch
        Font.Draw (user_text, xpos, ypos, font, text_color)
    end loop

    result user_text
end gets


%%the test
var name : string := ""

%%%%IF YOU USE THIS, LOCATE THE x/Y with the QUESTION!
put "What is your name?"
name := gets (100, 200, 123)     %%%gets ( xpos, ypos, color_num)
put name    %%to see if it works


Hope this helps you out a bit...
Delos




PostPosted: Mon Apr 17, 2006 4:24 pm   Post subject: Re: get font?

LegendsEnd wrote:
When using a get command, the text you enter is always the same font. I know I can do it the hard way and use getch + font.draw but is there a way to just plain change the font of get?


No. I'm afraid you'll have to go the 'hard' way. The idea behind 'get' is that it is used in an all-text environment, hence there would not be the possibility of changing fonts. Once you move up to a graphical environment, that all changes and you can start implementing fancy curly writing and what not.
Token's code isn't too bad. Take note of his use of parameters, that sort of thing is vital to any code that is even half decent.
It will take quite a bit of touching up, but that code is workable. (My personaly preference would be for it to return a single character, then perform the loop outside of the function, but hey - different styles mayhaps).

By the way, I'm going to start calling you Toe for completely logical reasons. Tell me what they are and I'll reward you!
Bored




PostPosted: Mon Apr 17, 2006 5:06 pm   Post subject: (No subject)

Well if you want the text to stay the same throughout the program you can go to turing preferences and click its run time or pun window or something allong that sort. You then select the text you want from the text and text size menus. But if you want to change the font during the program like one for in game and one for menu, or something along those ways your going to have to do it the hard way because there is no built in function to change the font mid-program.
TokenHerbz




PostPosted: Mon Apr 17, 2006 5:08 pm   Post subject: (No subject)

i didn't get that bored, and i read it a few times...
Cervantes




PostPosted: Mon Apr 17, 2006 5:26 pm   Post subject: (No subject)

He's saying you can change the default font used for put and get by going like this: File -> Preferences -> Run Window, then selecting the font.

However, this only changes the font used for put and get on your computer. If you send your program to someone else to run it, they would also have to change their preferences to see the text the way you intended.
TokenHerbz




PostPosted: Mon Apr 17, 2006 9:53 pm   Post subject: (No subject)

i dont have edit feature Sad I need mod powers to edit my post,

Anyways this is your fault i gotta repost my UPDATED function, we need an edit...


Here i made it so it back spaces for you.. there might be a better way but this works

code:

setscreen ("offscreenonly")

%% a function to get different text:  I made this really fast so you need to touch it up:
%%i can tell you this ::  It had no backspace in it, you can fix that though right?

fcn gets (xpos : int, ypos : int, text_color : int) : string %will return the word
    var font : int := Font.New ("Palatino:24:bold,italic")  %%type of font want to use
    var ch : string (1)
    var user_text : string := ""
    var text : flexible array 1 .. 0 of string    %%the word you make

    loop
        cls
        getch (ch)
        exit when ch = (KEY_ENTER)
        if ch not= (KEY_BACKSPACE) then
            new text, upper (text) + 1
            for i : 1 .. upper (text)
                text (upper (text)) := ch
            end for
        else        %%we kill a letter
            new text, upper (text) - 1
        end if
        %%draw the text
        user_text := ""
        for i : 1 .. upper (text)
            user_text += text (i)
        end for
        Font.Draw (user_text, xpos, ypos, font, text_color)     %%display
        View.Update
        delay (20)
    end loop

    result user_text    %%this will be used to assign the variable
end gets


%%the test
var name : string := ""

%%%%IF YOU USE THIS, LOCATE THE x/Y with the QUESTION!
put "What is your name?"
name := gets (100, 200, 123)     %%%gets ( xpos, ypos, color_num)
put name    %%to see if it works


You can improve it if you wish Smile
do_pete




PostPosted: Tue Apr 18, 2006 11:52 am   Post subject: (No subject)

Here's a better way of doing it:
code:
fcn font_get (x, y, fnt, clr : int) : string
    View.Set ("nocursor,offscreenonly")
    var input_text : string := ""

    loop
        var input_char : string (1)
        getch (input_char)
        exit when input_char = KEY_ENTER
        if input_char = KEY_BACKSPACE then
            if length (input_text) > 0 then
                input_text := input_text (1 .. length (input_text) - 1)
            end if
        else
            input_text += input_char
        end if
        Font.Draw (input_text, x, y, fnt, clr)
        View.Update
        cls
    end loop

    result input_text
end font_get


And here's how you would use it:

code:
var input := font_get (100, 100, Font.New ("times new roman:12:bold"), black)
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Tue Apr 18, 2006 2:36 pm   Post subject: (No subject)

oooooo thats cool Smile
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  [ 9 Posts ]
Jump to:   


Style:  
Search: