EasyMessage - Allegro Custom Message Box Class

(1/1)

Richard Marks:
EasyMessage - Allegro Custom Message Box Class


EasyMessage is a class that you can use in your Allegro programs to easily display a message to 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_message.h"
Create an instance of the EasyMessage classCode:

EasyMessage msg(EasyCentered, "Hello World!");

You can output your text in any of 3 positions.

EasyCentered
EasyLeft
EasyRight

It should be obvious how the text will be displayed with that.

One thing to note, is that you can have multi-line messages using the \n character in the message string.
However, it does not work by itself. You must enter "\n \n" (a space between two \n characters)

You can also pass a title text, and the label text for the button.

The class constructor is below.
Code:

EasyMessage(EasyOptions options = EasyCentered, const char* message = "", const char* title = "Message", const char* buttonlabel = "OK");

The defaults are given to show you what it will default to.

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_message.cpp and change the defines:
Code:

// config
#define EASYMESSAGE_DIALOGBOX_TOP_BORDER_WIDTH 2
#define EASYMESSAGE_DIALOGBOX_BOTTOM_BORDER_WIDTH 4
#define EASYMESSAGE_DIALOGBOX_LEFT_BORDER_WIDTH 1
#define EASYMESSAGE_DIALOGBOX_RIGHT_BORDER_WIDTH 1

// colors
#define EASYMESSAGE_DIALOGBOX_BORDER_COLOR makecol(150, 145, 135)
#define EASYMESSAGE_DIALOGBOX_BACKGROUND_COLOR makecol(193, 189, 181)
#define EASYMESSAGE_DIALOGBOX_MESSAGE_BORDER_COLOR makecol(150, 145, 135)
#define EASYMESSAGE_DIALOGBOX_MESSAGE_BACKGROUND_COLOR makecol(193, 189, 181)
#define EASYMESSAGE_DIALOGBOX_MESSAGE_TEXT_COLOR makecol(0, 0, 0)
#define EASYMESSAGE_DIALOGBOX_BUTTON_BORDER_COLOR makecol(150, 145, 135)
#define EASYMESSAGE_DIALOGBOX_BUTTON_BACKGROUND_COLOR makecol(193, 189, 181)
#define EASYMESSAGE_DIALOGBOX_BUTTON_TEXT_COLOR makecol(0, 0, 0)
#define EASYMESSAGE_DIALOGBOX_TITLE_BACKGROUND_COLOR makecol(42, 86, 168)
#define EASYMESSAGE_DIALOGBOX_TITLE_TEXT_COLOR makecol(172, 184, 200)


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

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.                                                           *
  ****************************************************************************
*/

Navigation

[0] Message Index