Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » cout / cin Allegro equivalents?

This thread is locked; no one can reply to it. rss feed Print
cout / cin Allegro equivalents?
Irrelevant
Member #2,382
May 2002
avatar

Are there any? If so, what are they?

<code>//----------------//</code>Here be l33tsp33x0rz.

Justin_W
Member #655
September 2000
avatar

For cout, closest things are listed under Text Output in the documentation. Some are far more similar to C's printf though, than cout.

For cin, keyboard routines are what are available for you. These functions rely mostly on key-per-key input as that is more common for games. If you want to parse up some full on sentences, you are going to have to do it yourself. (ie, accept input into a string until the enter key is pressed - not really all that complex unless you want to convert some things into ints and such.. but still can be done in a fairly small amount of code.)

Sounds like keypressed() and readkey() are the ones you might be most interested in looking up.

23yrold3yrold
Member #1,134
March 2001
avatar

Didn't someone write a lib for Allegro that let's you use "cout <<" for writing text to the screen? I dunno if anyone uses it or if it's even around, but I could've sworn I saw it on the news page ages ago ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Irrelevant
Member #2,382
May 2002
avatar

Quote:

just reading keypresses into a string works, unless you want things like backspace. That would be very hard to code.

Ah well. I was just wondering if there was an easier way.

[edit: Just saw 23/3s post. I wannit! ;D]

<code>//----------------//</code>Here be l33tsp33x0rz.

23yrold3yrold
Member #1,134
March 2001
avatar

If you need help dealing with input, you can try my edit box code from my string article in Pixelate 8. Everyone just loves it ;)

Hey, spellcaster, are you smarter than me? ;D

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

spellcaster
Member #1,493
September 2001
avatar

I'm afroaid not.

But coding a simple textinput widget is not that hard. You need a buffer of chars for your string. You need to know the current position of the cursor inside the string (if you want to have a cursor - most games allow you only to append on the end of the string or o delete the last character in a string).

If you use the keypressed() / readkey() functions, this is really simple. If you want to use the key array, you need an extra step: Translating from key{] to actual char values.

This could be done like this:

1typedef struct {
2 int keycode;
3 int c;
4} KeyToChar;
5 
6KeyToChar k2cLUT[COUNT_CHARS] = {
7 { KEY_BACKSPACE, -2 },
8 { KEY_ENTER, -1 },
9 { KEY_A, 'A' },
10 { KEY_B, 'B' },
11 /* etc */
12};
13 
14/* In the code */
15for (a=0; a < COUNT_CHARS; a++) {
16 if (key[k2cLUT[a].keycode]) {
17 switch (k2cLUT[a].c) {
18 case -1:
19 /* Enter pressed. Input finished */
20 break;
21 case -2:
22 /* backspace pressed. Del last char */
23 break;
24 default:
25 /* append k2cLUT{a].c to the string */
26 }
27 }
28}

As I said: Using keypressed() readkey would be more easy to use :)

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Monolith Tyriss
Member #2,523
July 2002

Quickie question for ya.. how do you do those code-boxes like Spellcaster just did in the previous post? They seem really helpful. :> Thanks! ;D

spellcaster
Member #1,493
September 2001
avatar

Whenever you write a post, there's this link "Mock-up is on". Click it :-)

And to answer your question directly, simply put the code into
[CODE] [/CODE]
tags (but use lowercase).

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Goodbytes
Member #448
June 2000
avatar

Somebody already made an ostream equivalent for Allegro... I can't remember what it's called, but it's there. It's on the guy who's maintaining DRS's page.


--
~Goodbytes

Monolith Tyriss
Member #2,523
July 2002

Thanks a lot spellcaster. Should help keep my post sizes smaller. 8-) Tho it also makes me wonder.. is there anything special beyond [CODE] and [/CODE] you need to get that nice white listbox like on your post.. or is that much automatic? :)

spellcaster
Member #1,493
September 2001
avatar

It's automatic. One of the many nice features this forum has :)

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Irrelevant
Member #2,382
May 2002
avatar

I'll try that, spellcaster. I think I was struggling when I tried something along those lines because I was trying to use a C++ string.

The box appears when a certain amuont of lines of code are present. I think it's about 10 - 20.

<code>//----------------//</code>Here be l33tsp33x0rz.

SonShadowCat
Member #1,548
September 2001
avatar

Go to: