From a4268ac91399941d397c0166f9c5ab55a57569bf Mon Sep 17 00:00:00 2001 From: Terraneo Federico <fede.tft@miosix.org> Date: Thu, 24 Nov 2016 09:53:00 +0100 Subject: [PATCH] Updated Windows driver --- drivers/display_win.cpp | 77 ++++++++++++++++++------- drivers/display_win.h | 123 +++++++++++++++++----------------------- 2 files changed, 111 insertions(+), 89 deletions(-) diff --git a/drivers/display_win.cpp b/drivers/display_win.cpp index 8e7e362..58217c3 100644 --- a/drivers/display_win.cpp +++ b/drivers/display_win.cpp @@ -37,17 +37,36 @@ using namespace std; namespace mxgui { +void registerDisplayHook(DisplayManager& dm) +{ + dm.registerDisplay(&DisplayImpl::instance()); +} + // // class DisplayImpl // -DisplayImpl::DisplayImpl(): - buffer(0), - font(droid11), - last(), - beginPixelCalled(false), - backend(WinBackend::instance()) + +DisplayImpl& DisplayImpl::instance() { - setTextColor(Color(0xffff), Color(0x0000)); + 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) @@ -146,6 +165,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; @@ -184,25 +214,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() { @@ -227,6 +251,21 @@ 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), + font(droid11), + last(), + beginPixelCalled(false), + backend(WinBackend::instance()) +{ + setTextColor(make_pair(Color(0xffff), Color(0x0000))); +} + } //namespace mxgui #endif // #if !defined(_MIOSIX) && defined(_WINDOWS) diff --git a/drivers/display_win.h b/drivers/display_win.h index 6568723..5c0d0dd 100644 --- a/drivers/display_win.h +++ b/drivers/display_win.h @@ -53,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 @@ -79,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 @@ -93,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 @@ -104,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 @@ -112,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 @@ -120,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. @@ -131,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 @@ -150,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 @@ -171,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 @@ -179,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 @@ -363,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 = SIMULATOR_DISP_WIDTH; static const short int height = SIMULATOR_DISP_HEIGHT; -- GitLab