Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Simple textbox

This thread is locked; no one can reply to it. rss feed Print
Simple textbox
traxy15
Member #15,511
February 2014

Can i create simple textbox using only allegro5 or with winapi?

Antone333
Member #15,545
March 2014

you want something like this? i put this in the game im working on.

you tell it the display you want it to work with, then the title of the box. the heading and then the text. NULL is there making when you press the buttons on the message box it starts with 1 but i think if you put a different number there then it will start with that number. ALLEGRO_MESSAGEBOX_QUESTION makes the questionmark icon show up. ALLEGRO_MESSAGEBOX_YES_NO makes the buttons yes and no show up. if you leave it blank it will say 'Ok'

o for this it says:
Would you like to cut some wood?
Yes No

if yes is pressed 1 is returned. if no is pressed 2 is returned. and if for some reason the box does not open 0 is naturally returned or it just becomes an error.

this uses allegro 5 by the way. and you must load in the header file too.

#SelectExpand
1#include <allegro5/allegro_native_dialog.h> 2 3al_show_native_message_box(GameDisplay, 4 "Tree", 5 "Wood Cutting", 6 "Would you like to cut some wood?", 7 NULL, 8 ALLEGRO_MESSAGEBOX_QUESTION | ALLEGRO_MESSAGEBOX_YES_NO);

traxy15
Member #15,511
February 2014

Well, i need a dialog box with some text field where i can write some value. Something like "Write a value: ".

Antone333
Member #15,545
March 2014

I dont believe allegro has a text input box. because i would very much like to be able to use that too if you can find something. Good luck with your searches!

i want to use if so the user can input a character name.

What is your name? __________

So your name is___________? Cool!

something like that.

jmasterx
Member #11,410
October 2009

Looks like you need a TextBox. Have you looked into the idea of perhaps trying one of the many great third-party GUI APIs available for Allegro 5 :)?

traxy15
Member #15,511
February 2014

I think that i will have to use some GUI lib, or new thread with winapi. I wanted to keep it simple,but allegro5 doesn`t support any text boxes.

jmasterx
Member #11,410
October 2009

If you use WinAPI, it won't look as customized and your game will not be portable.

Here is the standard list of GUI APIs

TGUI2 - This API has been used in several games in the App Store. I'm not 100% sure if it has a TextBox though. I can't find a working link to its GIT repo, but maybe the developer can help.

GWEN - This API was made by the same guy that made Garry's Mod. It has some nice features for events and it's pretty easy to customize. It has a Frame and a TextBox for your needs. https://github.com/garrynewman/GWEN Main issue is it lacks documentation and support.

Agui - This is a GUI API I developed for myself and released open-sourced. It was always intended for me and my projects, so the way it does certain things is not necessarily everyone's preference. It fully supports Unicode. Every function is documented (well, almost). I've been using it for years and it works great for me. I support it a lot via a.cc forum questions. It is used in this game http://www.factorio.com/ and other projects I have seen. The thing people dislike most about it is the skinning. You have to subclass each Widget to use custom bitmap drawing on them. I wanted it this way for myself so I would have no restrictions on how things look and feel. I was also new to C++ programming when I made it ;) The TextBox and TextField are the Widgets I spent most time in so they feel and act as close as possible to Windows' ones. https://github.com/jmasterx/Agui

There are other GUI APIs. Edgar's Eagle 5 is great, though I'm not sure what state its source code is in, he might comment. But those 3 above I think are the most common, alive ones that are ready to use.

If I have forgotten to mention an API, I apologize and will be happy to edit this post to include it.

Antone333
Member #15,545
March 2014

@Jmasterx

so i downloaded Agui and am looking through it. for the text input box sort of thing you would use TextBoxListener.h correct?

and i was wondering. could you explain how to go about installing a new library like this? its always been something i struggled with and thus why i use dev c++ because of devpaks.org it makes things super simple to get up and running.

i figure i just copy and paste the include files into the include of devc++ and the src respectively but then do i need to set a linker in my project somewhere in order to use it?

traxy15
Member #15,511
February 2014

I found some bypass, using winapi32 only. I used ResEdit to create box, and used
char* result = (char*)DialogBox((HINSTANCE)GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG),al_get_win_window_handle(display),YourDialogProc);

It`s just level editor. It`s only for me, and i think that using big GUI lib for such small thing is bad idea;

jmasterx
Member #11,410
October 2009

@Antone333 I don't have time to write an explanation, I've written some guides in the past, you can search the forum.

If I have time Ill look for it or write something up.

@traxy15
What about using a tool like C# .NET winforms to make your level editor? This is drag & drop GUI :)

traxy15
Member #15,511
February 2014

I use it when i`m making some bigger windows app. For just one textbox in whole level editor i just need some simple function.

Antone333
Member #15,545
March 2014

Ok no need to go out of your way. i will look on my own.

Edgar Reynaldo
Member #8,592
May 2007
avatar

jmasterx said:

There are other GUI APIs. Edgar's Eagle 5 is great, though I'm not sure what state its source code is in, he might comment.

I've been really swamped with school, especially my History class, which I withdrew from to keep up with my other classes, so I haven't been able to spend much time on it lately. Specific to the gui, right now there are dumb, grid, and relative layouts with flow, table, and splitter layouts in the works. I only have the button widget ported, as I wanted to rewrite it to be more generic, but I have a ton of widgets to port from Eagle 4 to Eagle 5. So right now there's not a lot to see, but it is easy to write your own widgets, and most things a widget would do are supported. There are a ton of other nice features to Eagle though, that make a programmer's life much easier, and makes applications easier to write. Still no docs, but the headers are written in an easily understood fashion. I am a big fan of self documenting code. Aka, I haven't gotten to it yet.TM If you're interested, you can check out the code from sourceforge through the link in my sig. /OT

I have a flexible text entry widget in Eagle 4 that I can show you if you're interested in seeing how I did it. It's single line text entry only at this point, but has support for integer, floating point, or text entry. However if I was building a gui app I would probably go with jmasterx's text editor from AGUI, as it's multi-line. Or someone else's. I don't have experience with any other gui lib's text boxes.

pkrcel
Member #14,001
February 2012

Antone333 said:

Ok no need to go out of your way. i will look on my own.

Antone, AGUI would be the perfect candidate to do what you are doing with multiple displays in your project.

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Go to: