diff --git a/drivers/display_qt.cpp b/drivers/display_qt.cpp index adbd45860d5bd9c9a6711db2a5651ee2d08cf36c..f63235fa598f4705fd270f5266687043a154e6ec 100644 --- a/drivers/display_qt.cpp +++ b/drivers/display_qt.cpp @@ -37,14 +37,36 @@ using namespace std; namespace mxgui { +void registerDisplayHook(DisplayManager& dm) +{ + dm.registerDisplay(&DisplayImpl::instance()); +} + // // class DisplayImpl // -DisplayImpl::DisplayImpl(): buffer(0), textColor(), font(droid11), last(), - beginPixelCalled(false), backend(QTBackend::instance()) +DisplayImpl& DisplayImpl::instance() { - setTextColor(Color(SIMULATOR_FGCOLOR),Color(SIMULATOR_BGCOLOR)); + static DisplayImpl instance; + return instance; +} + +void DisplayImpl::doTurnOn() +{ + //Unsupported for this display, so just ignore +} + +void DisplayImpl::doTurnOff() +{ + //Unsupported for this display, so just ignore +} + +void DisplayImpl::doSetBrightness(int brt) {} + +pair<short int, short int> DisplayImpl::doGetSize() const +{ + return make_pair(height,width); } void DisplayImpl::write(Point p, const char *text) @@ -140,6 +162,17 @@ void DisplayImpl::scanLine(Point p, const Color *colors, unsigned short length) beginPixelCalled=false; } +Color *DisplayImpl::getScanLineBuffer() +{ + if(buffer==0) buffer=new Color[getWidth()]; + return buffer; +} + +void DisplayImpl::scanLineBuffer(Point p, unsigned short length) +{ + scanLine(p,buffer,length); +} + void DisplayImpl::drawImage(Point p, const ImageBase& img) { short int xEnd=p.x()+img.getWidth()-1; @@ -178,25 +211,19 @@ void DisplayImpl::drawRectangle(Point a, Point b, Color c) line(Point(a.x(),b.y()),a,c); } -void DisplayImpl::turnOn() +void DisplayImpl::setTextColor(pair<Color,Color> colors) { - //Unsupported for this display, so just ignore + Font::generatePalette(textColor,colors.first,colors.second); } -void DisplayImpl::turnOff() +pair<Color,Color> DisplayImpl::getTextColor() const { - //Unsupported for this display, so just ignore + return make_pair(textColor[3],textColor[0]); } -void DisplayImpl::setTextColor(Color fgcolor, Color bgcolor) -{ - Font::generatePalette(textColor,fgcolor,bgcolor); -} +void DisplayImpl::setFont(const Font& font) { this->font=font; } -void DisplayImpl::setFont(const Font& font) -{ - this->font=font; -} +Font DisplayImpl::getFont() const { return font; } void DisplayImpl::update() { @@ -222,6 +249,17 @@ DisplayImpl::pixel_iterator DisplayImpl::begin(Point p1, Point p2, IteratorDirec return pixel_iterator(p1,p2,d,this); } +DisplayImpl::~DisplayImpl() +{ + if(buffer) delete[] buffer; +} + +DisplayImpl::DisplayImpl(): buffer(0), textColor(), font(droid11), last(), + beginPixelCalled(false), backend(QTBackend::instance()) +{ + setTextColor(make_pair(Color(SIMULATOR_FGCOLOR),Color(SIMULATOR_BGCOLOR))); +} + } //namespace mxgui #endif //_MIOSIX diff --git a/drivers/display_qt.h b/drivers/display_qt.h index e8e02ee741349e99192fedf93ae4c778040dd923..ceeba04bb1a8aa69b5f7efd7e5184afd308182a8 100644 --- a/drivers/display_qt.h +++ b/drivers/display_qt.h @@ -36,6 +36,7 @@ #if !defined(_MIOSIX) && !defined(_WINDOWS) #include <config/mxgui_settings.h> +#include "display.h" #include "point.h" #include "color.h" #include "font.h" @@ -52,22 +53,43 @@ namespace mxgui { -class DisplayImpl +class DisplayImpl : public Display { public: /** - * Constructor. - * Do not instantiate objects of this type directly from application code, - * use Display::instance() instead. + * \return an instance to this class (singleton) */ - DisplayImpl(); + static DisplayImpl& instance(); + + /** + * Turn the display On after it has been turned Off. + * Display initial state is On. + */ + void doTurnOn() override; + + /** + * Turn the display Off. It can be later turned back On. + */ + void doTurnOff() override; + + /** + * Set display brightness. Depending on the underlying driver, + * may do nothing. + * \param brt from 0 to 100 + */ + void doSetBrightness(int brt) override; + + /** + * \return a pair with the display height and width + */ + std::pair<short int, short int> doGetSize() const override; /** * Write text to the display. If text is too long it will be truncated * \param p point where the upper left corner of the text will be printed * \param text, text to print. */ - void write(Point p, const char *text); + void write(Point p, const char *text) override; /** * Write part of text to the display @@ -78,13 +100,13 @@ public: * \param b Lower right corner of clipping rectangle * \param text text to write */ - void clippedWrite(Point p, Point a, Point b, const char *text); + void clippedWrite(Point p, Point a, Point b, const char *text) override; /** * Clear the Display. The screen will be filled with the desired color * \param color fill color */ - void clear(Color color); + void clear(Color color) override; /** * Clear an area of the screen @@ -92,7 +114,7 @@ public: * \param p2 lower right corner of area to clear * \param color fill color */ - void clear(Point p1, Point p2, Color color); + void clear(Point p1, Point p2, Color color) override; /** * This member function is used on some target displays to reset the @@ -103,7 +125,7 @@ public: * member function, for example line(), you have to call beginPixel() again * before calling setPixel(). */ - void beginPixel(); + void beginPixel() override; /** * Draw a pixel with desired color. You have to call beginPixel() once @@ -111,7 +133,7 @@ public: * \param p point where to draw pixel * \param color pixel color */ - void setPixel(Point p, Color color); + void setPixel(Point p, Color color) override; /** * Draw a line between point a and point b, with color c @@ -119,7 +141,7 @@ public: * \param b second point * \param c line color */ - void line(Point a, Point b, Color color); + void line(Point a, Point b, Color color) override; /** * Draw an horizontal line on screen. @@ -130,17 +152,13 @@ public: * \param length length of colors array. * p.x()+length must be <= display.width() */ - void scanLine(Point p, const Color *colors, unsigned short length); + void scanLine(Point p, const Color *colors, unsigned short length) override; /** * \return a buffer of length equal to this->getWidth() that can be used to * render a scanline. */ - Color *getScanLineBuffer() - { - if(buffer==0) buffer=new Color[getWidth()]; - return buffer; - } + Color *getScanLineBuffer() override; /** * Draw the content of the last getScanLineBuffer() on an horizontal line @@ -149,17 +167,14 @@ public: * \param length length of colors array. * p.x()+length must be <= display.width() */ - void scanLineBuffer(Point p, unsigned short length) - { - scanLine(p,buffer,length); - } + void scanLineBuffer(Point p, unsigned short length) override; /** * Draw an image on the screen * \param p point of the upper left corner where the image will be drawn * \param i image to draw */ - void drawImage(Point p, const ImageBase& img); + void drawImage(Point p, const ImageBase& img) override; /** * Draw part of an image on the screen @@ -170,7 +185,7 @@ public: * \param b Lower right corner of clipping rectangle * \param i Image to draw */ - void clippedDrawImage(Point p, Point a, Point b, const ImageBase& img); + void clippedDrawImage(Point p, Point a, Point b, const ImageBase& img) override; /** * Draw a rectangle (not filled) with the desired color @@ -178,71 +193,37 @@ public: * \param b lower right corner of the rectangle * \param c color of the line */ - void drawRectangle(Point a, Point b, Color c); - - /** - * \return the display's height - */ - short int getHeight() const { return height; } - - /** - * \return the display's width - */ - short int getWidth() const { return width; } - - /** - * Turn the display On after it has been turned Off. - * Display initial state is On. - */ - void turnOn(); - - /** - * Turn the display Off. It can be later turned back On. - */ - void turnOff(); - - /** - * Set display brightness. Depending on the underlying driver, - * may do nothing. - * \param brt from 0 to 100 - */ - void setBrightness(int brt) {} + void drawRectangle(Point a, Point b, Color c) override; /** * Set colors used for writing text * \param fgcolor text color * \param bgcolor background color */ - void setTextColor(Color fgcolor, Color bgcolor); - - /** - * \return the current foreground color. - * The foreground color is used to draw text on screen - */ - Color getForeground() const { return textColor[3]; } + void setTextColor(std::pair<Color,Color> colors) override; /** - * \return the current background color. - * The foreground color is used to draw text on screen + * \return a pair with the foreground and background colors. + * Those colors are used to draw text on screen */ - Color getBackground() const { return textColor[0]; } + std::pair<Color,Color> getTextColor() const override; /** * Set the font used for writing text * \param font new font */ - void setFont(const Font& font); + void setFont(const Font& font) override; /** * \return the current font used to draw text */ - Font getFont() const { return font; } + Font getFont() const override; /** * Make all changes done to the display since the last call to update() * visible. This backends require it. */ - void update(); + void update() override; /** * Pixel iterator. A pixel iterator is an output iterator that allows to @@ -362,12 +343,15 @@ public: /** * Destructor */ - ~DisplayImpl() - { - if(buffer) delete[] buffer; - } + ~DisplayImpl() override; private: + /** + * Constructor. + * Do not instantiate objects of this type directly from application code. + */ + DisplayImpl(); + static const short int width=FrameBuffer::width; static const short int height=FrameBuffer::height;