From 4c76020d1d1603ec67225063ddba7cd70e62acaa Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 13 May 2020 15:18:34 +0100 Subject: [PATCH] Boxx: CWFs, some consts and formatting --- boxstack.cc | 2 +- boxstack.h | 2 +- boxx.cc | 85 ++++++++++++++++++++++++++--------------------------- boxx.h | 46 +++++++++++++---------------- vepg.cc | 1 + 5 files changed, 65 insertions(+), 71 deletions(-) diff --git a/boxstack.cc b/boxstack.cc index eaa0110..dcb1258 100644 --- a/boxstack.cc +++ b/boxstack.cc @@ -221,7 +221,7 @@ void BoxStack::redrawAllBoxes() update(NULL,NULL); // should blt all } -void BoxStack::update(Boxx* toUpdate, Region* regionToUpdate) +void BoxStack::update(Boxx* toUpdate, const Region* regionToUpdate) { // Log::getInstance()->log("BoxStack", Log::DEBUG, "Update called"); if (!initted) return; // it is allowed to call this before init diff --git a/boxstack.h b/boxstack.h index 188f7de..9f96de6 100644 --- a/boxstack.h +++ b/boxstack.h @@ -51,7 +51,7 @@ class BoxStack int remove(Boxx*); void removeAllExceptWallpaper(); void removeAll(); - void update(Boxx*, Region* regionToUpdate = NULL); + void update(Boxx*, const Region* regionToUpdate = NULL); void redrawAllBoxes(); // -- end diff --git a/boxx.cc b/boxx.cc index e0d092f..84e3860 100644 --- a/boxx.cc +++ b/boxx.cc @@ -20,12 +20,13 @@ #include #include "defines.h" -#include "bitmap.h" #include "log.h" +#include "message.h" #include "osd.h" +#include "surface.h" +#include "surfacevector.h" #include "boxx.h" -#include "surfacevector.h" char Boxx::numBoxxes = 0; @@ -132,7 +133,7 @@ void Boxx::setVisible(bool isVisible) visible = isVisible; } -bool Boxx::getVisible() +bool Boxx::getVisible() const { return visible; } @@ -162,73 +163,73 @@ void Boxx::blt(Region& r) surface->updateToScreen(r.x, r.y, r.w, r.h, area.x + r.x, area.y + r.y); } -int Boxx::getScreenX() +int Boxx::getScreenX() const { if (parent) return area.x + parent->getScreenX(); return area.x; } -int Boxx::getScreenY() +int Boxx::getScreenY() const { if (parent) return area.y + parent->getScreenY(); return area.y; } -int Boxx::getRootBoxOffsetX() // convert this to be getX and silently do the parent/not thing? same for Y below? +int Boxx::getRootBoxOffsetX() const // convert this to be getX and silently do the parent/not thing? same for Y below? { if (parent) return area.x + parent->getRootBoxOffsetX(); return 0; } -int Boxx::getRootBoxOffsetY() +int Boxx::getRootBoxOffsetY() const { if (parent) return area.y + parent->getRootBoxOffsetY(); return 0; } -int Boxx::getX() +int Boxx::getX() const { return area.x; } -int Boxx::getY() +int Boxx::getY() const { return area.y; } -int Boxx::getX2() +int Boxx::getX2() const { return area.x + area.w; } -int Boxx::getY2() +int Boxx::getY2() const { return area.y + area.h; } -UINT Boxx::getWidth() +UINT Boxx::getWidth() const { return area.w; } -UINT Boxx::getHeight() +UINT Boxx::getHeight() const { return area.h; } // FIXME Clean up the code to use just one of the following -Region* Boxx::getRegion() +const Region* Boxx::getRegion() const { return &area; } -Region Boxx::getRegionR() +Region Boxx::getRegionR() const { return area; } -void Boxx::getRootBoxRegion(Region* r) +void Boxx::getRootBoxRegion(Region* r) const { // Returns a region that describes the position of this box on the box with the surface // To be used for boxstack->update calls @@ -261,35 +262,31 @@ void Boxx::fillColour(const DrawStyle& colour) int Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour, unsigned int skiplines) { char line[256]; - int lineHeight = getFontHeight() + paraVSpace; + UINT lineHeight = getFontHeight() + paraVSpace; float lineWidth; float thisCharWidth; - int textPos; - int textLength; + int textPos = 0; + int textLength = strlen(text); int linePos; - int ypos; + UINT ypos = y; int printLine; - int leftlines=0; + int leftlines = 0; + int drawLinePos = -skiplines; #if WIN32 // FIXME win pragma #pragma warning(disable : 4146) #endif - int drawLinePos=-skiplines; - - textPos = 0; - textLength = strlen(text); - ypos = y; Region tester; bool haschildren = true; if (children.size() == 0) haschildren = false; bool mchar = false; - Osd *osd = Osd::getInstance(); + Osd* osd = Osd::getInstance(); if (osd->charSet() != 1) mchar = true; OsdVector *osdv = dynamic_cast(osd); - float *charwidtharray = NULL; + float* charwidtharray = NULL; if (osdv) charwidtharray = osdv->getCharWidthArray(); mbstate_t state; @@ -301,7 +298,7 @@ int Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour, unsi lineWidth = 0; // tester reinit tester.h = lineHeight; - tester.y=ypos; + tester.y = ypos; tester.x = x; tester.w = area.w - (2 * paraMargin); @@ -347,7 +344,7 @@ int Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour, unsi } - if ((lineWidth + thisCharWidth + x) > tester.w) + if ((lineWidth + thisCharWidth + static_cast(x)) > static_cast(tester.w)) { // this character would break the right margin if (cur_char == ' ') @@ -367,8 +364,8 @@ int Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour, unsi cur_length = mbrtowc(&cur_char, text + textPos, textLength-textPos, &state); if (cur_length <= 0) { - cur_char='?'; - cur_length=1; + cur_char = '?'; + cur_length = 1; } } else @@ -392,7 +389,7 @@ int Boxx::drawPara(const char* text, int x, int y, const DrawStyle& colour, unsi if (printLine || (linePos > 1)) // if some text was put in line { - if (ypos <= (int)(area.h - lineHeight + paraVSpace)) + if (ypos <= (area.h - lineHeight + paraVSpace)) { if (drawLinePos >= 0) { @@ -481,7 +478,7 @@ void Boxx::drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw) } */ -void Boxx::drawTTChar(int ox, int oy,int x, int y, cTeletextChar c) +void Boxx::drawTTChar(int ox, int oy, int x, int y, cTeletextChar c) { if (parent) parent->drawTTChar(area.x + ox, area.y + oy, x,y,c); else if (surface) surface->drawTTChar(ox, oy,x,y,c); @@ -493,32 +490,32 @@ void Boxx::drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion & re else if (surface) surface->drawBitmap(x, y, bm, region); } -void Boxx::drawJpeg(const char *fileName, int x, int y, int *width, int *height) +void Boxx::drawJpeg(const char* fileName, int x, int y, int *width, int *height) { if (parent) parent->drawJpeg(fileName, area.x + x, area.y + y, width, height); else if (surface) surface->drawJpeg(fileName, x, y, width, height); } -void Boxx::drawMonoBitmap(UCHAR*base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour) +void Boxx::drawMonoBitmap(UCHAR* base, int dx, int dy, unsigned int height,unsigned int width, DrawStyle& nextColour) { if (parent) parent->drawMonoBitmap(base, area.x +dx, area.y + dy, height, width, nextColour); else if (surface) surface->drawMonoBitmap(base, dx,dy, height, width, nextColour); } -void Boxx::drawTVMedia(TVMediaInfo & tvmedia,float x, float y, float width, float height, Corner corner) +void Boxx::drawTVMedia(TVMediaInfo& tvmedia, float x, float y, float width, float height, Corner corner) { - if (parent) parent->drawTVMedia(tvmedia,area.x + x,area.y + y,width, height, corner); + if (parent) parent->drawTVMedia(tvmedia, static_cast(area.x) + x, static_cast(area.y) + y, width, height, corner); else if (surface) { SurfaceVector* surfacevector = dynamic_cast(surface); if (surfacevector) surfacevector->drawTVMedia(tvmedia, x, y, width, height, corner); - else surface->fillblt((int)x, (int)y, (int)width, (int)height, DrawStyle::RED); // Signal that something went wrong + else surface->fillblt(static_cast(x), static_cast(y), static_cast(width), static_cast(height), DrawStyle::RED); // Signal that something went wrong } } void Boxx::drawClippingRectangle(float x, float y, float w, float h) { - if (parent) parent->drawClippingRectangle(area.x + x, area.y + y, w, h); + if (parent) parent->drawClippingRectangle(static_cast(area.x) + x, static_cast(area.y) + y, w, h); else if (surface) { SurfaceVector* surfacevector = dynamic_cast(surface); @@ -572,8 +569,8 @@ Surface* Boxx::getSurface() bool Boxx::mouseMove(int x, int y) { - if ((x >= (int)area.x) && (x<(int)area.x2()) - && (y >= (int)area.y) && (y < (int)area.y2())) + if ( (x >= static_cast(area.x)) && (x < static_cast(area.x2())) + && (y >= static_cast(area.y)) && (y < static_cast(area.y2())) ) { return true; } @@ -585,8 +582,8 @@ bool Boxx::mouseMove(int x, int y) bool Boxx::mouseLBDOWN(int x, int y) { - if ((x >= (int)area.x) && (x<(int)area.x2()) - && (y >= (int)area.y) && (y < (int)area.y2())) + if ( (x >= static_cast(area.x)) && (x < static_cast(area.x2())) + && (y >= static_cast(area.y)) && (y < static_cast(area.y2())) ) { return true; } diff --git a/boxx.h b/boxx.h index e027da7..c29a975 100644 --- a/boxx.h +++ b/boxx.h @@ -20,20 +20,18 @@ #ifndef BOXX_H #define BOXX_H -#include #include +#include "osdvector.h" +#include "bitmap.h" #include "colour.h" #include "region.h" -#include "message.h" - - -#include "surface.h" #include "video.h" #include "tvmedia.h" -#include "osdvector.h" class Bitmap; +class Message; +class Surface; class Boxx { @@ -46,13 +44,11 @@ class Boxx void createBuffer(); // Make this a root view that goes in the BoxStack virtual void draw(); - void setGap(UINT gap); void setBackgroundColour(const DrawStyle& colour); void setVisible(bool isVisible); void setVideoBackground(); - // The following are supposed to be abstract functions // However, it is useful to be able to make instances of Boxx // Therefore the following stubs are provided. @@ -74,20 +70,20 @@ class Boxx */ // Get functions - int getScreenX(); // where is it on screen - int getScreenY(); - int getRootBoxOffsetX(); // where is it relative to the top-parent in the boxstack - int getRootBoxOffsetY(); - int getX(); // where is it relative to its parent - int getX2(); // .. and the right edge - int getY(); - int getY2(); - UINT getWidth(); - UINT getHeight(); - bool getVisible(); - Region* getRegion(); // Not to be used for changing the region - Region getRegionR(); // Same but as an object - void getRootBoxRegion(Region*); + int getScreenX() const; // where is it on screen + int getScreenY() const; + int getRootBoxOffsetX() const; // where is it relative to the top-parent in the boxstack + int getRootBoxOffsetY() const; + int getX() const; // where is it relative to its parent + int getX2() const; // .. and the right edge + int getY() const; + int getY2() const; + UINT getWidth() const; + UINT getHeight() const; + bool getVisible() const; + const Region* getRegion() const; + Region getRegionR() const; // Same but as an object + void getRootBoxRegion(Region*) const; bool getVideoDisplay(VideoDisplay &vd); @@ -107,10 +103,10 @@ class Boxx void drawTextCentre(const char* text, int x, int y, const DrawStyle& colour); //Now deprecated //void drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw=false); - void drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion & region); + void drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion& region); //Now deprecated // void drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw=false); - void drawTVMedia(TVMediaInfo & tvmedia,float x, float y, float width, float height, Corner corner=TopLeft); + void drawTVMedia(TVMediaInfo& tvmedia, float x, float y, float width, float height, Corner corner=TopLeft); void drawClippingRectangle(float x, float y, float w, float h); int getFontHeight(); @@ -141,7 +137,7 @@ class Boxx friend class BoxStack; protected: //get the surface this box is drawing to - Surface *getSurface(); + Surface* getSurface(); // I want a parent box or a surface. Boxx* parent{}; diff --git a/vepg.cc b/vepg.cc index 6607ee1..091a0b7 100644 --- a/vepg.cc +++ b/vepg.cc @@ -34,6 +34,7 @@ #include "vchannellist.h" #include "messagequeue.h" #include "video.h" +#include "surface.h" #include "vepgsettimer.h" #include "wsymbol.h" #include "message.h" -- 2.39.2