NOGDUS $1670.00 has been donated to NOGDUS!
September 21, 2017, 03:50:12 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: EasyInput - Allegro Text Entry Class  (Read 29774 times)
0 Members and 1 Guest are viewing this topic.
Richard Marks
Administrator
Offline Offline

Respect: 3425
« on: September 11, 2009, 11:12:54 PM »

EasyInput - Allegro Text Entry Class


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 and header file.
Add the files to your Allegro project.
#include the file in whatever source you need to get input from the user.
Code:
#include "class_easy_input.h"
Create an instance of the EasyInput class
Code:
EasyInput entry("What is your name?");
Get the results of the entry.
Code:
std::string name = entry.get();

You can also get integers, and floating point numbers from the user as well by using the following methods:
Code:
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:
Code:
// 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. Smiley

The license is below.
Code:
/*
  ****************************************************************************
  * 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.                                                           *
  ****************************************************************************
*/
Logged

Richard Marks
Administrator
Offline Offline

Respect: 3425
« Reply #1 on: September 26, 2012, 02:06:44 AM »

A working example of using this class can be seen here:

https://gist.github.com/3786505
Logged

Richard Marks
Administrator
Offline Offline

Respect: 3425
« Reply #2 on: 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.
Logged

Tags:
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
.: Theme by Richard Marks :.
Valid XHTML 1.0! Valid CSS!