#include <ConsoleApplication.h>
Inheritance diagram for ConsoleApplication:
Collaboration diagram for ConsoleApplication:The base class used to create text oriented, console-like Pooka SDK® applications.
ConsoleApplication class is the base class for developers to create text oriented, console-like Pooka SDK® applications. Although not really a native console, an application based on ConsoleApplication class behaves just like a native console application, providing functions such as text printing, text input and simple graphics drawing by ASCII characters.
Remarks Console Application's "main()" Function
The function consoleMain() is the most important function works as both entry point and terminal of the application, just like its counterpart - the int main (int argc, char *argv[]) in a native console application. Developers should put the application logic inside the consoleMain() function. Once the application control reaches the end of consoleMain(), the application is about to terminate. Alternatively, user can press "Ctrl" + "C" at any time to quit the consoel application.
Note Keep in mind that class ConsoleApplication derives from class OGApplication, therefore it actually inherit all functions and properties from OGApplication. However, ConsoleApplication is intended to be a cross-platform simulation of console application, it is highly recommended that developers should use ConsoleApplication class for the purpose of creating a console-like application.
Remarks Stream Mode vs. Characters Mode
A Pooka SDK® console application has two different display modes, stream mode and character mode. These two modes can be switched from one to the other by function setConsoleMode(). The stream mode is the default mode.
Stream Mode Stream mode displays text like stream, text strings are printed from left to right; new text strings are always appended at the current end of the text. If end of text goes beyond the right boundary, then text line may be broken and wrapped into a new line (depends on the text-wrapping argument in constructor). If end of text goes beyond the bottom boundary, then application scrolls the text content up to have a new empty line space.
Character Mode Character mode print characters, text string, or simple character-based graphics at any position. It uses the application display area like a extreme-low-resolution raster display, with each pixel represented by a character.
Character mode can be very useful if the Pooka SDK® console application want to display very simple graph by characters.
Public Types | |
| enum | CONSOLE_MODE { CONSOLE_STREAM_MODE = 0, CONSOLE_CHAR_MODE = 1 } |
Public Types inherited from Application | |
| enum | GRAPHICS_TYPE { GRAPHICS_INVALID = -1, GRAPHICS_MINIAWT = 0, GRAPHICS_OMNIG = 1, GRAPHICS_OPENGL = 2, GRAPHICS_DIRECTX = 3, GRAPHICS_AUTO = 0x0F } |
| enum | DESKTOP_APP_MENU_TYPE { APP_MENU_NONE = 0, APP_MENU_DEFAULT = 1, APP_MENU_CUSTOM = 2 } |
Public Member Functions | |
| ConsoleApplication (wchar_t *appName, int graphicsEngineType, unsigned int textColor=MiniAWT::Graphics::Color::_POOKA_GREEN, bool wrappingText=true) | |
| virtual | ~ConsoleApplication () |
| virtual void | consoleMain () |
| void | setConsoleMode (int mode) |
| int | getConsoleMode () |
| void | textPrint (wchar_t *message) |
| void | textPrintf (wchar_t *format,...) |
| wchar_t | getChar (wchar_t *message, wchar_t preSetVal=0) |
| wchar_t * | getString (wchar_t *message, wchar_t *preSetVal=0, int inputCharacterLimit=-1) |
| void | pause (wchar_t *message=0) |
| void | setTabSize (int charNum) |
| void | setPixelByChar (int x, int y, wchar_t asciiChar) |
| wchar_t | getCharAtPixel (int x, int y) |
| void | drawLineByChar (int x1, int y1, int x2, int y2, wchar_t asciiChar, int lineThickness=1) |
| void | drawRectByChar (int x, int y, int width, int height, wchar_t asciiChar, int lineThickness=1) |
| void | fillRectByChar (int x, int y, int width, int height, wchar_t asciiChar) |
| void | drawEllipseByChar (int x, int y, int width, int height, wchar_t asciiChar, int lineThickness=1) |
| void | fillEllipseByChar (int x, int y, int width, int height, wchar_t asciiChar) |
| void | drawPolylineByChar (MiniSTL::Type::OGPoint *points, int number, wchar_t asciiChar, int lineThickness=1, bool closePolyline=true) |
| void | fillPolylineByChar (MiniSTL::Type::OGPoint *points, int number, wchar_t asciiChar) |
| void | drawBoxByChar (int x, int y, int width, int height, wchar_t horizontalLineChar, wchar_t verticalLineChar, wchar_t cornerChar) |
| void | drawText (int x, int y, wchar_t *format,...) |
| void | commit () |
| void | flush () |
| int | getCharModeWidth () |
| int | getCharModeHeight () |
| void | setTextSize (int textSize) |
| int | getTextSize () |
| void | setTextFont (MiniAWT::Graphics::BitmapFont *font) |
| MiniAWT::Graphics::BitmapFont * | getTextFont () |
| void | clear () |
| GUI::OGCanvas * | getCanvas () |
| G2D::SceneSprite * | getScene () |
| GUI::Component::LWConsole * | getConsoleComponent () |
| int | hasKeyClicked () |
| bool | isMouseClicked () |
Public Member Functions inherited from OGApplication | |
| OGApplication (wchar_t *appName, int graphicsEngineType) | |
| virtual | ~OGApplication () |
| int | getBestGraphicsEngineType () |
Public Member Functions inherited from Application | |
| virtual void | onCreate () |
| virtual void | onPaused () |
| virtual void | onResumed () |
| virtual void | onTerminate () |
| virtual bool | onTerminationRequested () |
| virtual bool | onBackButtonPressed () |
| virtual void | onFileDropped (wchar_t **fileName, int fileNum, int x, int y) |
| virtual int | onPrepareAppMenu (MiniSTL::DataStructure::Tree *menuTree) |
| virtual void | onAppMenuClicked (wchar_t *menuItemText) |
Public Member Functions inherited from Object | |
| Object () | |
| virtual | ~Object () |
| void | addRef () |
| void | release () |
| virtual wchar_t * | toString () |
| wchar_t * | getClassName (bool keepNameSpace=false) |
| void | syncBegin () |
| void | syncEnd () |
| void | wait (unsigned int timeout=0xFFFFFFFF) |
| void | notify () |
| void | notifyAll () |
Protected Member Functions | |
| void | defaultPreCreationProc () |
| void | defaultPostCreationProc () |
Protected Member Functions inherited from OGApplication | |
| virtual void | defaultPreTerminationProc () |
| virtual void | defaultPostTerminationProc () |
Protected Member Functions inherited from Application | |
| Application (wchar_t *appName) | |
| virtual | ~Application () |
| virtual void | defaultActivationProc (bool active) |
| virtual void | defaultHibernationProc (bool isEntering) |
Additional Inherited Members | |
Static Public Member Functions inherited from OGApplication | |
| static void | setInAppConsoleEnabled (bool enabled, int textSize=MiniAWT::Application::DEFAULT_FONT_SIZE, int textColor=MiniAWT::Graphics::Color::GREEN) |
| static void | setAppTheme (G2D::SpriteTheme *spriteTheme) |
| static G2D::SpriteTheme * | getAppTheme () |
| static void | showToast (wchar_t *message, int textSize, int yPosition, int duration=2000, int textColor=MiniAWT::Graphics::Color::WHITE, int bkgColor=MiniAWT::Graphics::Color::DARKGRAY) |
Static Public Member Functions inherited from Application | |
| static Application::ScheduledTask * | postTask (Window *ownerWindow, Schedulable *schedulable, wchar_t *taskContext, void *taskParameter, bool runOnce=true, int interIterationDelay=0, int firstIterationDelay=0, bool executeContextTasksInSequence=false) |
| static bool | isPostedTaskAlive (Application::ScheduledTask *task) |
| static void | cancelPostedTask (Application::ScheduledTask *task) |
| static void | cancelPostedTask (wchar_t *taskContext) |
| static void | cancelAllPostedTasks (Window *ownerWindow=0) |
| static Application::ScheduledTask * | getPostedTask (wchar_t *taskContext) |
| static MiniSTL::DataStructure::ArrayList * | getPostedTasks () |
| static void | setPowerHungryMode (bool enable) |
| static void | setHibernationEnabled (bool enable) |
| static bool | isHibernating () |
| static void | enterHibernation () |
| static void | quitHibernation () |
| static void | exit () |
| static void | restart (wchar_t *commandLineArguments=L"") |
| static void | update () |
| static void | repaint () |
| static void | setDragAndDropEnabled (bool enabled) |
| static void | setFont (bool setMonoFont, Graphics::BitmapFont *bitmapFont) |
| static Graphics::BitmapFont * | getFont (bool getMonoFont) |
| static Graphics::BitmapFont * | getDefaultFont (bool getMonoFont) |
| static void | sleep (int interval) |
| static void | throwException (wchar_t *message) |
| static void | throwWarning (wchar_t *message) |
| static void | printStackTrace () |
| static wchar_t * | getApplicationName () |
| static wchar_t * | getApplicationLocalStorageDir () |
| static wchar_t * | getAssetsPath () |
| static bool | checkAssetExistence (wchar_t *docBase, wchar_t *fileName) |
| static bool | checkAssetExistence (wchar_t *fullAssetPath) |
| static wchar_t * | getCommandLine () |
| static wchar_t * | getCommandLineArguments () |
| static void | setHardCodedCommandArgument (wchar_t *argument) |
| static void | printf (wchar_t *format,...) |
| static void | print (wchar_t *lineBuf) |
| static void | debugPrintf (wchar_t *format,...) |
| static void | debugPrint (wchar_t *lineBuf) |
| static void | setConsoleTextColor (unsigned int textCol=Graphics::Color::GRAY, unsigned int textBkg=Graphics::Color::BLACK) |
| static void | clearConsole () |
| static void | setLanguageTable (wchar_t *docBase=0, wchar_t *fileName=0) |
| static wchar_t * | getTextFromLanguageTable (wchar_t *LTID, wchar_t *defaultValue) |
| static bool | isPaused () |
| static long | getCurrentTickCount () |
| static void | clearUserInputEvent () |
| static void | setAppWindowSize (int resolutionType) |
| static void | setAppWindowSize (int windowWidth, int windowHeight) |
| static void | setAppImmersiveFullScreen (bool immersiveFullScreen) |
| static bool | isCurrentThreadMainThread () |
| static bool | isMainThreadUnderSync () |
| static void | syncUIThreadBegin () |
| static void | syncUIThreadEnd () |
| static bool | terminationRequested () |
| static void | setCustomSplashImage (Graphics::Bitmap *bitmap, float splashTime) |
Public Attributes inherited from OGApplication | |
| bool | enableKeyboardNavigation |
| Monetization::Ads::AdPane::AdPaneListener * | adPaneListener |
Public Attributes inherited from Application | |
| unsigned int | paddingColor |
| bool | startupCreateConsole |
| bool | startupCreateWindowFrame |
Static Public Attributes inherited from Application | |
| static const unsigned int | DEFAULT_CONSOLE_TEXT_COLOR = Graphics::Color::GRAY |
| static const unsigned int | DEFAULT_CONSOLE_BKG_COLOR = Graphics::Color::BLACK |
| static const int | DEFAULT_FONT_SIZE = 14 |
| static int | graphicsType |
| static bool | restartable |
| static bool | exitEnabled |
| static bool | ableToUpdateImmediately |
| static Application * | instance |
| static bool | allowMultipleInstance |
| static bool | isFirstInstance |
| static int | width |
| static int | height |
| static Content * | content |
| static int | maxIdleTime |
| static float | runningTime |
| static bool | keepActive |
| static Audio::Speaker * | speaker |
| static HibernationListener * | hibernationListener |
| static ExceptionListener * | exceptionListener |
| static MiniSTL::DataStructure::Properties * | languageTable |
| enum CONSOLE_MODE |
Values that represent console modes. See Stream Mode vs. Characters Mode for more details.
| Enumerator | |
|---|---|
| CONSOLE_STREAM_MODE | An enum constant representing the stream mode. See Stream Mode vs. Characters Mode for more details. |
| CONSOLE_CHAR_MODE | An enum constant representing the character mode. See Stream Mode vs. Characters Mode for more details. |
| ConsoleApplication | ( | wchar_t * | appName, |
| int | graphicsEngineType, | ||
| unsigned int | textColor = MiniAWT::Graphics::Color::_POOKA_GREEN, |
||
| bool | wrappingText = true |
||
| ) |
Constructor.
| appName | A C string to specify the application name. Platform For desktop applications, the application name is displayed on application window title bar. Mobile applications do not use this argument, instead, mobile application's name is usually specified by application manifest attribute, refer to platform's developer guide for more details. |
| graphicsEngineType | Type of the graphics engine, must be one of constants defined in MiniAWT::Application::GRAPHICS_TYPE. Tip Pass in MiniAWT::Application::GRAPHICS_AUTO then Pooka SDK® will choose the best graphics engine for the target platform. |
| textColor | The console text color. |
| wrappingText | True to wrapping console text when it goes beyond the right boundary. |
|
virtual |
Destructor.
|
inlinevirtual |
Pooka SDK® console application's main function.
This is the only function where developers put the application logic. See Console Application's "main()" Function for more details.
| void setConsoleMode | ( | int | mode | ) |
Sets console application's display mode.
| mode | The display mode, must be one of constants defined in CONSOLE_MODE. See Stream Mode vs. Characters Mode for more details. |
| int getConsoleMode | ( | ) |
Gets console application's display mode.
| void textPrint | ( | wchar_t * | message | ) |
Prints a text string.
Note This function is only effective under the stream mode .
| message | The text string, specified by a C string. |
| void textPrintf | ( | wchar_t * | format, |
| ... | |||
| ) |
Prints a formatted text string.
The formatted string is populated by a format string and a sequence of additional parameters, each containing a value to be used to replace a format specifier in the format string.
Note This function is only effective under the stream mode .
| format | The format string with format specifier compatible with the printf()/sprintf() functions in C Standard Library. |
| ... | Variable parameters providing additional parameters, providing values to replace format specifiers in the format string. |
| wchar_t getChar | ( | wchar_t * | message, |
| wchar_t | preSetVal = 0 |
||
| ) |
Gets a character from user input.
This function shows a blinking cursor and wait until user input a single character. It behaves just like getchar() function in C Standard Library.
Note This function is only effective under the stream mode .
| message | A text message prompted to the application user about what to input. |
| preSetVal | The default character if user simply hit ENTER key to complete the input. |
| wchar_t* getString | ( | wchar_t * | message, |
| wchar_t * | preSetVal = 0, |
||
| int | inputCharacterLimit = -1 |
||
| ) |
Gets a text string from user input.
This function shows a blinking cursor and wait until user input a text single and confirm by hitting ENTER. It behaves just like * gets() function in C Standard Library.
| message | A text message prompted to the application user about what to input. |
| preSetVal | The default text string if user simply hit ENTER key to complete the input. |
| inputCharacterLimit | The total number of characters that user can input. |
Note This function is only effective under the stream mode .
| void pause | ( | wchar_t * | message = 0 | ) |
Display a text message and pauses the application's execution until user hit any key in keyboard or touch the screen.
Note This function is only effective under the stream mode .
| message | A text message prompted to the application user before pause the application |
| void setTabSize | ( | int | charNum | ) |
Sets tab size.
The tab size indicates how many space characters a single tab is equal to. The default value is 8.
Note This function is only effective under the stream mode .
| charNum | The tab size, measured by the number of space characters. |
| void setPixelByChar | ( | int | x, |
| int | y, | ||
| wchar_t | asciiChar | ||
| ) |
Sets a pixel by a character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the pixel. |
| y | The y coordinate of the pixel. |
| asciiChar | The ASCII character used to set the pixel. |
| wchar_t getCharAtPixel | ( | int | x, |
| int | y | ||
| ) |
Gets the ASCII character at position of the specified pixel.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the pixel. |
| y | The y coordinate of the pixel. |
| void drawLineByChar | ( | int | x1, |
| int | y1, | ||
| int | x2, | ||
| int | y2, | ||
| wchar_t | asciiChar, | ||
| int | lineThickness = 1 |
||
| ) |
Draws a line by character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x1 | The x coordinate of the first pixel. |
| y1 | The y coordinate of the first pixel. |
| x2 | The x coordinate of the second pixel. |
| y2 | The y coordinate of the second pixel. |
| asciiChar | The ASCII character used to draw |
| lineThickness | The line thickness. |
| void drawRectByChar | ( | int | x, |
| int | y, | ||
| int | width, | ||
| int | height, | ||
| wchar_t | asciiChar, | ||
| int | lineThickness = 1 |
||
| ) |
Draws a rectangle by character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the rectangle. |
| y | The y coordinate of the rectangle. |
| width | The width of the rectangle. |
| height | The height of the rectangle. |
| asciiChar | The ASCII character used to draw |
| lineThickness | The line thickness. |
| void fillRectByChar | ( | int | x, |
| int | y, | ||
| int | width, | ||
| int | height, | ||
| wchar_t | asciiChar | ||
| ) |
Fills a rectangle by character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the rectangle. |
| y | The y coordinate of the rectangle. |
| width | The width of the rectangle. |
| height | The height of the rectangle. |
| asciiChar | The ASCII character used to fill. |
| void drawEllipseByChar | ( | int | x, |
| int | y, | ||
| int | width, | ||
| int | height, | ||
| wchar_t | asciiChar, | ||
| int | lineThickness = 1 |
||
| ) |
Draws an ellipse by character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the ellipse. |
| y | The y coordinate of the ellipse. |
| width | The width of the ellipse. |
| height | The height of the ellipse. |
| asciiChar | The ASCII character used to draw |
| lineThickness | The line thickness. |
| void fillEllipseByChar | ( | int | x, |
| int | y, | ||
| int | width, | ||
| int | height, | ||
| wchar_t | asciiChar | ||
| ) |
Fills a ellipse by character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the ellipse. |
| y | The y coordinate of the ellipse. |
| width | The width of the ellipse. |
| height | The height of the ellipse. |
| asciiChar | The ASCII character used to fill. |
| void drawPolylineByChar | ( | MiniSTL::Type::OGPoint * | points, |
| int | number, | ||
| wchar_t | asciiChar, | ||
| int | lineThickness = 1, |
||
| bool | closePolyline = true |
||
| ) |
Draws a poly-line by character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| points | The array of points that compose the poly-line. |
| number | The number of points |
| asciiChar | The ASCII character used to draw. |
| lineThickness | The line thickness. |
| closePolyline | True indicates to close poly-line to make it a polygon. |
| void fillPolylineByChar | ( | MiniSTL::Type::OGPoint * | points, |
| int | number, | ||
| wchar_t | asciiChar | ||
| ) |
Fills poly-line (treat it as a polygon) by character.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| points | The array of points that compose the poly-line. |
| number | The number of points |
| asciiChar | The ASCII character used to fill. |
| void drawBoxByChar | ( | int | x, |
| int | y, | ||
| int | width, | ||
| int | height, | ||
| wchar_t | horizontalLineChar, | ||
| wchar_t | verticalLineChar, | ||
| wchar_t | cornerChar | ||
| ) |
Draw a box by character.
Note this function is different from drawRectByChar() because it can specify different characters used for drawing horizontal line, vertical line and box's corner.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the rectangle. |
| y | The y coordinate of the rectangle. |
| width | The width of the rectangle. |
| height | The height of the rectangle. |
| horizontalLineChar | The ASCII character used to draw box's horizontal lines. |
| verticalLineChar | The ASCII character used to draw box's vertical lines. |
| cornerChar | The ASCII character used to draw box's corners. |
| void drawText | ( | int | x, |
| int | y, | ||
| wchar_t * | format, | ||
| ... | |||
| ) |
Draw a text string.
Note This function is only effective under the character mode .
Caution For efficiency purpose, all drawing functions are buffered in a command buffer after executed, the drawing result will not be output to the application console until the function commit() or flush() is called.
| x | The x coordinate of the text string's first character. |
| y | The y coordinate of the text string's first character. |
| format | The format string with format specifier compatible with the printf()/sprintf() functions in C Standard Library. |
| ... | Variable parameters providing additional parameters, providing values to replace format specifiers in the format string. |
| void commit | ( | ) |
Commits all drawing commands in commands buffer and output their result to the application console.
Note This function is only effective under the character mode .
| void flush | ( | ) |
Commits all drawing commands in commands buffer and output their result to the application console, then clean up the command buffers.
Note The flush() function also clean up the command buffer after commit all drawing commands, as the result, the following drawing functions called after flush() start drawing in an empty console.
Note This function is only effective under the character mode .
| int getCharModeWidth | ( | ) |
Gets the X-resolution (the column number) of the character mode.
| int getCharModeHeight | ( | ) |
Gets the Y-resolution (the row number) of the character mode.
| void setTextSize | ( | int | textSize | ) |
Sets console application's text size.
Note This function should be called inside function consoleMain() to take effect.
| textSize | The desired size of the text in pixels. |
| int getTextSize | ( | ) |
Gets console application's text size.
| void setTextFont | ( | MiniAWT::Graphics::BitmapFont * | font | ) |
Sets the font of this console application.
Note This function should be called inside function consoleMain() to take effect.
| font | The desired font used by this console application. |
| MiniAWT::Graphics::BitmapFont* getTextFont | ( | ) |
Gets the current font of this console application.
| void clear | ( | ) |
Clears the whole console of this console application.
| GUI::OGCanvas* getCanvas | ( | ) |
Gets the GUI::OGCanvas that actually hosts the console.
| G2D::SceneSprite* getScene | ( | ) |
Gets the G2D::SceneSprite that actually hosts the console.
| GUI::Component::LWConsole* getConsoleComponent | ( | ) |
Gets the GUI::Component::LWComponent that actually hosts the console.
| int hasKeyClicked | ( | ) |
Checks whether the application user clicks any key except ENTER key on keyboard. If true, then returns the virtual key code of the key just clicked.
Tip This function provides a simple way to allow application user to interact with the console application. For example, application can interrupt a ongoing task if detect a key is clicked.
Note This function excludes ENTER key since it is used to complete user input and may cause confusion.
| bool isMouseClicked | ( | ) |
Checks whether the application user clicks the pointing device (mouse, touch-screen, track-pad, etc.).
Tip This function provides a simple way to allow application user to interact with the console application. For example, application can interrupt a ongoing task if detect pointing device is clicked.
|
protectedvirtual |
The overridden function of MiniAWT::Application::defaultPreCreationProc() defined in class MiniAWT::Application.
Caution If a sub-class of OGApplication overrides this function, then this function must be called at the beginning of the overridden function.
Reimplemented from OGApplication.
|
protectedvirtual |
The overridden function of MiniAWT::Application::defaultPostCreationProc() defined in class MiniAWT::Application.
Caution If a sub-class of OGApplication overrides this function, then this function must be called at the beginning of the overridden function.
Reimplemented from Application.