Claypool

Courses

Publications

Students

Projects

Service

Downloads

Misc


Dragonfly: GraphicsManager.h Source File
Dragonfly 2.2
A text-based game engine

GraphicsManager.h

00001 ///
00002 /// The graphics manager
00003 ///
00004 
00005 #ifndef __GRAPHICS_MANAGER_H__
00006 #define __GRAPHICS_MANAGER_H__
00007 
00008 #ifdef CYGWIN
00009 #include <ncurses/curses.h>
00010 #else
00011 #include <curses.h>
00012 #endif
00013 
00014 /// Suppots colors, defined by curses:
00015 ///   COLOR_BLACK ("black" in Sprite file)
00016 ///   COLOR_RED ("red" in Sprite file)
00017 ///   COLOR_GREEN ("green" in Sprite file)
00018 ///   COLOR_YELLOW ("yellow" in Sprite file)
00019 ///   COLOR_BLUE ("blue" in Sprite file)
00020 ///   COLOR_MAGENTA ("magenta" in Sprite file)
00021 ///   COLOR_CYAN ("cyan" in Sprite file)
00022 ///   COLOR_WHITE ("white" in Sprite file)
00023 
00024 #define COLOR_DEFAULT COLOR_WHITE //< If color not specified, will use this.
00025 
00026 #include "Manager.h"
00027 #include "Position.h"
00028 #include "Frame.h"
00029 
00030 enum Justification {
00031   LEFT_JUSTIFIED,
00032   CENTER_JUSTIFIED,
00033   RIGHT_JUSTIFIED,
00034 };
00035 
00036 class GraphicsManager : public Manager {
00037 
00038  private:
00039   GraphicsManager();                        ///< Private since a singleton.
00040   GraphicsManager (GraphicsManager const&); ///< Don't allow copy.
00041   void operator=(GraphicsManager const&);   ///< Don't allow assignment.
00042 
00043  protected:
00044   WINDOW *win1, *win2;          ///< Two window buffers for drawing.
00045   WINDOW *curr_win;             ///< Current drawing buffer.
00046   int window_horiz;             ///< Max window width.
00047   int window_vert;              ///< Max window height.
00048 
00049  public:
00050   ~GraphicsManager();
00051 
00052   /// Get the one and only instance of the GraphicsManager.
00053   static GraphicsManager &getInstance();
00054 
00055   /// Get terminal ready for text-based display.
00056   /// Return 0 if ok, else return negative number.
00057   int startUp();
00058 
00059   /// Revert back to normal terminal display.
00060   void shutDown();
00061 
00062   /// Render current display buffer.
00063   /// Return 0 if ok, else -1.
00064   int swapBuffers();
00065 
00066   /// Draw a character at screen location (x,y) (with default color).
00067   /// Return 0 if ok, else -1.
00068   int drawCh(Position world_pos, char ch);
00069 
00070   /// Draw a character at screen location (x,y) with color.
00071   /// Return 0 if ok, else -1.
00072   int drawCh(Position world_pos, char ch, int color);
00073 
00074   /// Draw single sprite frame at screen location (x,y) with color.
00075   /// If centered true then center frame at (x,y).
00076   /// Return 0 if ok, else -1.
00077   int drawFrame(Position world_pos, Frame frame, bool centered, int color);
00078 
00079   /// Draw string at screen location (x,y) with default color.
00080   /// Justified LEFT, CENTER or RIGHT.
00081   /// Return 0 if ok, else -1.
00082   int drawString(Position world_pos, string str, Justification just, int color);
00083 
00084   /// Return display's horizontal maximum.
00085   int getHorizontal();
00086 
00087   /// Return display's vertical maximum.
00088   int getVertical();
00089 
00090   // Return curses window that is being drawn to and not refreshed yet
00091   WINDOW *getCurrentWindow();
00092 
00093   // Return curses window that has already been drawn and refreshed
00094   WINDOW *getBackWindow();
00095 
00096 };
00097 
00098 #endif //__GRAPHICS_MANAGER_H__
00099 
 All Classes Functions Variables Friends