mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 13:05:09 +00:00
LibWeb: Add CanvasRenderingContext2D.drawImage(image, x, y)
This function allows you to draw a loaded <img> element into a canvas.
This commit is contained in:
parent
370befbf52
commit
067ea5a2e0
4 changed files with 47 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <LibGfx/Painter.h>
|
||||
#include <LibWeb/DOM/CanvasRenderingContext2D.h>
|
||||
#include <LibWeb/DOM/HTMLCanvasElement.h>
|
||||
#include <LibWeb/DOM/HTMLImageElement.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
|
@ -82,6 +83,22 @@ void CanvasRenderingContext2D::stroke_rect(float x, float y, float width, float
|
|||
did_draw(rect);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::draw_image(const HTMLImageElement& image_element, float x, float y)
|
||||
{
|
||||
if (!image_element.bitmap())
|
||||
return;
|
||||
|
||||
auto painter = this->painter();
|
||||
if (!painter)
|
||||
return;
|
||||
|
||||
auto src_rect = image_element.bitmap()->rect();
|
||||
Gfx::FloatRect dst_rect = { x, y, (float)image_element.bitmap()->width(), (float)image_element.bitmap()->height() };
|
||||
auto rect = m_transform.map(dst_rect);
|
||||
|
||||
painter->draw_scaled_bitmap(enclosing_int_rect(rect), *image_element.bitmap(), src_rect);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::scale(float sx, float sy)
|
||||
{
|
||||
dbg() << "CanvasRenderingContext2D::scale(): " << sx << ", " << sy;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue