NOGDUS

Articles, Tutorials, and other things. => Allegro Game Programming => : Richard Marks September 11, 2009, 11:12:54 PM



: EasyInput - Allegro Text Entry Class
: Richard Marks September 11, 2009, 11:12:54 PM
EasyInput - Allegro Text Entry Class

(http://storage.ccpssolutions.com/richard/easyinput/easyinput.png)
EasyInput is a class that you can use in your Allegro programs to easily get input from the user.

It consists of two files that you can download and add to your project.

Installation and usage
Download the class source file (http://storage.ccpssolutions.com/richard/easyinput/class_easy_input.cpp) and header file (http://storage.ccpssolutions.com/richard/easyinput/class_easy_input.h).
Add the files to your Allegro project.
#include the file in whatever source you need to get input from the user.
:
#include "class_easy_input.h"
Create an instance of the EasyInput class
:
EasyInput entry("What is your name?");
Get the results of the entry.
:
std::string name = entry.get();

You can also get integers, and floating point numbers from the user as well by using the following methods:
:
int age = entry.get_int();
float cash = entry.get_float();

You MUST create the instance of the class AFTER you have initialized Allegro and have set the video mode.

If you want to change the colors and border sizes, edit class_easy_input.cpp and change the defines:
:
// config
#define EASYINPUT_DIALOGBOX_WIDTH SCREEN_W / 2
#define EASYINPUT_DIALOGBOX_HEIGHT 96
#define EASYINPUT_DIALOGBOX_TOP_BORDER_WIDTH 2
#define EASYINPUT_DIALOGBOX_BOTTOM_BORDER_WIDTH 4
#define EASYINPUT_DIALOGBOX_LEFT_WIDTH 1
#define EASYINPUT_DIALOGBOX_RIGHT_WIDTH 1

// colors
#define EASYINPUT_DIALOGBOX_BORDER_COLOR makecol(150, 145, 135)
#define EASYINPUT_DIALOGBOX_BACKGROUND_COLOR makecol(193, 189, 181)
#define EASYINPUT_DIALOGBOX_ENTRY_BORDER_COLOR makecol(150, 145, 135)
#define EASYINPUT_DIALOGBOX_ENTRY_BACKGROUND_COLOR makecol(255, 255, 255)
#define EASYINPUT_DIALOGBOX_ENTRY_TEXT_COLOR makecol(0, 0, 0)
#define EASYINPUT_DIALOGBOX_TITLE_BACKGROUND_COLOR makecol(42, 86, 168)
#define EASYINPUT_DIALOGBOX_TITLE_TEXT_COLOR makecol(172, 184, 200)
#define EASYINPUT_DIALOGBOX_CARET_OVERWRITE_COLOR makecol(255, 0, 0)

If you have any questions, just ask me. :)

The license is below.
:
/*
  ****************************************************************************
  * Copyright (c) 2009, Richard Marks, CCPS Solutions,                       *
  * Undefined Aeon Software.                                                 *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  * "Software"), to deal in the Software without restriction, including      *
  * without limitation the rights to use, copy, modify, merge, publish,      *
  * distribute, distribute with modifications, sub-license, and/or sell      *
  * copies of the Software, and to permit persons to whom the Software is    *
  * furnished to do so, subject to the following conditions:                 *
  *                                                                          *
  * The above copyright notice and this permission notice shall be included  *
  * in all copies or substantial portions of the Software.                   *
  *                                                                          *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  *
  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
  *                                                                          *
  * Except as contained in this notice, the name(s) of the above copyright   *
  * holders shall not be used in advertising or otherwise to promote the     *
  * sale, use or other dealings in this Software without prior written       *
  * authorization.                                                           *
  ****************************************************************************
*/


: Re: EasyInput - Allegro Text Entry Class
: Richard Marks September 26, 2012, 02:06:44 AM
A working example of using this class can be seen here:

https://gist.github.com/3786505


: Re: EasyInput - Allegro Text Entry Class
: Richard Marks November 20, 2012, 03:40:36 PM
This class requires the C++ Standard Template Library, and as such, your project much be compiled as a C++ program.


Sorry, the copyright must be in the template.
Please notify this forum's administrator that this site is missing the copyright message for SMF so they can rectify the situation. Display of copyright is a legal requirement. For more information on this please visit the Simple Machines website.