mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Replicate cursor screen backup to chat message display, removing explicit memory management.
Incidentally, this makes Blitter::GetBytesPerPixel unneeed.
This commit is contained in:
parent
bbd64bbe2b
commit
071fdab236
|
@ -48,7 +48,6 @@ public:
|
||||||
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
||||||
|
|
||||||
const char *GetName() override { return "32bpp-anim"; }
|
const char *GetName() override { return "32bpp-anim"; }
|
||||||
int GetBytesPerPixel() override { return 6; }
|
|
||||||
void PostResize() override;
|
void PostResize() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,7 +30,6 @@ public:
|
||||||
size_t BufferSize(uint width, uint height) override;
|
size_t BufferSize(uint width, uint height) override;
|
||||||
void PaletteAnimate(const Palette &palette) override;
|
void PaletteAnimate(const Palette &palette) override;
|
||||||
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
||||||
int GetBytesPerPixel() override { return 4; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up the colour in the current palette.
|
* Look up the colour in the current palette.
|
||||||
|
|
|
@ -33,7 +33,6 @@ public:
|
||||||
bool NeedsAnimationBuffer() override;
|
bool NeedsAnimationBuffer() override;
|
||||||
|
|
||||||
const char *GetName() override { return "40bpp-anim"; }
|
const char *GetName() override { return "40bpp-anim"; }
|
||||||
int GetBytesPerPixel() override { return 5; }
|
|
||||||
|
|
||||||
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ public:
|
||||||
size_t BufferSize(uint width, uint height) override;
|
size_t BufferSize(uint width, uint height) override;
|
||||||
void PaletteAnimate(const Palette &palette) override;
|
void PaletteAnimate(const Palette &palette) override;
|
||||||
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
Blitter::PaletteAnimation UsePaletteAnimation() override;
|
||||||
int GetBytesPerPixel() override { return 1; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BLITTER_8BPP_BASE_HPP */
|
#endif /* BLITTER_8BPP_BASE_HPP */
|
||||||
|
|
|
@ -198,11 +198,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual const char *GetName() = 0;
|
virtual const char *GetName() = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get how many bytes are needed to store a pixel.
|
|
||||||
*/
|
|
||||||
virtual int GetBytesPerPixel() = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post resize event
|
* Post resize event
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,7 +32,6 @@ public:
|
||||||
Blitter::PaletteAnimation UsePaletteAnimation() override { return Blitter::PALETTE_ANIMATION_NONE; };
|
Blitter::PaletteAnimation UsePaletteAnimation() override { return Blitter::PALETTE_ANIMATION_NONE; };
|
||||||
|
|
||||||
const char *GetName() override { return "null"; }
|
const char *GetName() override { return "null"; }
|
||||||
int GetBytesPerPixel() override { return 0; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the blitter that does nothing. */
|
/** Factory for the blitter that does nothing. */
|
||||||
|
|
|
@ -58,7 +58,7 @@ static std::chrono::steady_clock::time_point _chatmessage_dirty_time;
|
||||||
* the left and pixels from the bottom. The height is the maximum height.
|
* the left and pixels from the bottom. The height is the maximum height.
|
||||||
*/
|
*/
|
||||||
static PointDimension _chatmsg_box;
|
static PointDimension _chatmsg_box;
|
||||||
static uint8_t *_chatmessage_backup = nullptr; ///< Backup in case text is moved.
|
static ReusableBuffer<uint8_t> _chatmessage_backup; ///< Backup in case text is moved.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if there are any chat messages to display.
|
* Test if there are any chat messages to display.
|
||||||
|
@ -103,7 +103,6 @@ void NetworkReInitChatBoxSize()
|
||||||
{
|
{
|
||||||
_chatmsg_box.y = 3 * FONT_HEIGHT_NORMAL;
|
_chatmsg_box.y = 3 * FONT_HEIGHT_NORMAL;
|
||||||
_chatmsg_box.height = MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + ScaleGUITrad(NETWORK_CHAT_LINE_SPACING)) + ScaleGUITrad(4);
|
_chatmsg_box.height = MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + ScaleGUITrad(NETWORK_CHAT_LINE_SPACING)) + ScaleGUITrad(4);
|
||||||
_chatmessage_backup = ReallocT(_chatmessage_backup, static_cast<size_t>(_chatmsg_box.width) * _chatmsg_box.height * BlitterFactory::GetCurrentBlitter()->GetBytesPerPixel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initialize all buffers of the chat visualisation. */
|
/** Initialize all buffers of the chat visualisation. */
|
||||||
|
@ -156,7 +155,7 @@ void NetworkUndrawChatMessage()
|
||||||
|
|
||||||
_chatmessage_visible = false;
|
_chatmessage_visible = false;
|
||||||
/* Put our 'shot' back to the screen */
|
/* Put our 'shot' back to the screen */
|
||||||
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
|
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup.GetBuffer(), width, height);
|
||||||
/* And make sure it is updated next time */
|
/* And make sure it is updated next time */
|
||||||
VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
|
VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
|
||||||
|
|
||||||
|
@ -208,10 +207,9 @@ void NetworkDrawChatMessage()
|
||||||
}
|
}
|
||||||
if (width <= 0 || height <= 0) return;
|
if (width <= 0 || height <= 0) return;
|
||||||
|
|
||||||
assert(blitter->BufferSize(width, height) <= static_cast<size_t>(_chatmsg_box.width) * _chatmsg_box.height * blitter->GetBytesPerPixel());
|
|
||||||
|
|
||||||
/* Make a copy of the screen as it is before painting (for undraw) */
|
/* Make a copy of the screen as it is before painting (for undraw) */
|
||||||
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
|
uint8_t *buffer = _chatmessage_backup.Allocate(BlitterFactory::GetCurrentBlitter()->BufferSize(width, height));
|
||||||
|
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), buffer, width, height);
|
||||||
|
|
||||||
_cur_dpi = &_screen; // switch to _screen painting
|
_cur_dpi = &_screen; // switch to _screen painting
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue