Add variants of Gfx draw functions which take a DPI

This commit is contained in:
Jonathan G Rennison
2022-11-10 18:58:33 +00:00
parent 3b7352132b
commit 5dcffe3142
3 changed files with 25 additions and 23 deletions

View File

@@ -134,6 +134,7 @@ uint32 _gfx_debug_flags;
* Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen. * Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
* *
* @pre dpi->zoom == ZOOM_LVL_NORMAL, right >= left, bottom >= top * @pre dpi->zoom == ZOOM_LVL_NORMAL, right >= left, bottom >= top
* @param dpi Draw pixel info
* @param left Minimum X (inclusive) * @param left Minimum X (inclusive)
* @param top Minimum Y (inclusive) * @param top Minimum Y (inclusive)
* @param right Maximum X (inclusive) * @param right Maximum X (inclusive)
@@ -144,10 +145,9 @@ uint32 _gfx_debug_flags;
* FILLRECT_CHECKER: Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things) * FILLRECT_CHECKER: Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things)
* FILLRECT_RECOLOUR: Apply a recolour sprite to every pixel in the rectangle currently on screen * FILLRECT_RECOLOUR: Apply a recolour sprite to every pixel in the rectangle currently on screen
*/ */
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode) void GfxFillRect(const DrawPixelInfo *dpi, int left, int top, int right, int bottom, int colour, FillRectMode mode)
{ {
Blitter *blitter = BlitterFactory::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
const DrawPixelInfo *dpi = _cur_dpi;
void *dst; void *dst;
const int otop = top; const int otop = top;
const int oleft = left; const int oleft = left;
@@ -406,7 +406,7 @@ static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int
* @return True if the line is likely to be visible, false if it's certainly * @return True if the line is likely to be visible, false if it's certainly
* invisible. * invisible.
*/ */
static inline bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2, int &y2, int width) static inline bool GfxPreprocessLine(const DrawPixelInfo *dpi, int &x, int &y, int &x2, int &y2, int width)
{ {
x -= dpi->left; x -= dpi->left;
x2 -= dpi->left; x2 -= dpi->left;
@@ -421,17 +421,15 @@ static inline bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2
return true; return true;
} }
void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width, int dash) void GfxDrawLine(const DrawPixelInfo *dpi, int x, int y, int x2, int y2, int colour, int width, int dash)
{ {
DrawPixelInfo *dpi = _cur_dpi;
if (GfxPreprocessLine(dpi, x, y, x2, y2, width)) { if (GfxPreprocessLine(dpi, x, y, x2, y2, width)) {
GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash); GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash);
} }
} }
void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour) void GfxDrawLineUnscaled(const DrawPixelInfo *dpi, int x, int y, int x2, int y2, int colour)
{ {
DrawPixelInfo *dpi = _cur_dpi;
if (GfxPreprocessLine(dpi, x, y, x2, y2, 1)) { if (GfxPreprocessLine(dpi, x, y, x2, y2, 1)) {
GfxDoDrawLine(dpi->dst_ptr, GfxDoDrawLine(dpi->dst_ptr,
UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom), UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom),
@@ -444,6 +442,7 @@ void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour)
* Draws the projection of a parallelepiped. * Draws the projection of a parallelepiped.
* This can be used to draw boxes in world coordinates. * This can be used to draw boxes in world coordinates.
* *
* @param dpi Draw pixel info.
* @param x Screen X-coordinate of top front corner. * @param x Screen X-coordinate of top front corner.
* @param y Screen Y-coordinate of top front corner. * @param y Screen Y-coordinate of top front corner.
* @param dx1 Screen X-length of first edge. * @param dx1 Screen X-length of first edge.
@@ -453,7 +452,7 @@ void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int colour)
* @param dx3 Screen X-length of third edge. * @param dx3 Screen X-length of third edge.
* @param dy3 Screen Y-length of third edge. * @param dy3 Screen Y-length of third edge.
*/ */
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3) void DrawBox(const DrawPixelInfo *dpi, int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
{ {
/* .... /* ....
* .. .... * .. ....
@@ -472,16 +471,16 @@ void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
static const byte colour = PC_WHITE; static const byte colour = PC_WHITE;
GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour); GfxDrawLineUnscaled(dpi, x, y, x + dx1, y + dy1, colour);
GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour); GfxDrawLineUnscaled(dpi, x, y, x + dx2, y + dy2, colour);
GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, colour); GfxDrawLineUnscaled(dpi, x, y, x + dx3, y + dy3, colour);
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour); GfxDrawLineUnscaled(dpi, x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, colour);
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour); GfxDrawLineUnscaled(dpi, x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, colour);
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour); GfxDrawLineUnscaled(dpi, x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, colour);
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour); GfxDrawLineUnscaled(dpi, x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, colour);
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour); GfxDrawLineUnscaled(dpi, x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, colour);
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour); GfxDrawLineUnscaled(dpi, x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, colour);
} }
/** /**

View File

@@ -69,6 +69,8 @@ extern std::vector<Dimension> _resolutions;
extern Dimension _cur_resolution; extern Dimension _cur_resolution;
extern Palette _cur_palette; ///< Current palette extern Palette _cur_palette; ///< Current palette
extern DrawPixelInfo *_cur_dpi;
void HandleToolbarHotkey(int hotkey); void HandleToolbarHotkey(int hotkey);
void HandleKeypress(uint keycode, WChar key); void HandleKeypress(uint keycode, WChar key);
void HandleTextInput(const char *str, bool marked = false, const char *caret = nullptr, const char *insert_location = nullptr, const char *replacement_end = nullptr); void HandleTextInput(const char *str, bool marked = false, const char *caret = nullptr, const char *insert_location = nullptr, const char *replacement_end = nullptr);
@@ -106,10 +108,12 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
void DrawCharCentered(WChar c, const Rect &r, TextColour colour); void DrawCharCentered(WChar c, const Rect &r, TextColour colour);
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE); void GfxFillRect(const DrawPixelInfo *dpi, int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
inline void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE) { GfxFillRect(_cur_dpi, left, top, right, bottom, colour, mode); }
void GfxFillPolygon(const std::vector<Point> &shape, int colour, FillRectMode mode = FILLRECT_OPAQUE, GfxFillRectModeFunctor *fill_functor = nullptr); void GfxFillPolygon(const std::vector<Point> &shape, int colour, FillRectMode mode = FILLRECT_OPAQUE, GfxFillRectModeFunctor *fill_functor = nullptr);
void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0); void GfxDrawLine(const DrawPixelInfo *dpi, int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0);
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); inline void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0) { GfxDrawLine(_cur_dpi, left, top, right, bottom, colour, width, dash); }
void DrawBox(const DrawPixelInfo *dpi, int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL); Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL);
Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize = FS_NORMAL); Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize = FS_NORMAL);
@@ -194,8 +198,6 @@ inline int GetCharacterHeight(FontSize size)
/** Height of characters in the large (#FS_MONO) font. @note Some characters may be oversized. */ /** Height of characters in the large (#FS_MONO) font. @note Some characters may be oversized. */
#define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO)) #define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO))
extern DrawPixelInfo *_cur_dpi;
TextColour GetContrastColour(uint8 background, uint8 threshold = 128); TextColour GetContrastColour(uint8 background, uint8 threshold = 128);
/** /**

View File

@@ -2058,7 +2058,8 @@ static void ViewportDrawBoundingBoxes(const ParentSpriteToDrawVector &psd)
Point pt3 = RemapCoords(ps.xmax + 1, ps.ymin , ps.zmax + 1); // top right corner Point pt3 = RemapCoords(ps.xmax + 1, ps.ymin , ps.zmax + 1); // top right corner
Point pt4 = RemapCoords(ps.xmax + 1, ps.ymax + 1, ps.zmin ); // bottom front corner Point pt4 = RemapCoords(ps.xmax + 1, ps.ymax + 1, ps.zmin ); // bottom front corner
DrawBox( pt1.x, pt1.y, DrawBox(_cur_dpi,
pt1.x, pt1.y,
pt2.x - pt1.x, pt2.y - pt1.y, pt2.x - pt1.x, pt2.y - pt1.y,
pt3.x - pt1.x, pt3.y - pt1.y, pt3.x - pt1.x, pt3.y - pt1.y,
pt4.x - pt1.x, pt4.y - pt1.y); pt4.x - pt1.x, pt4.y - pt1.y);