summaryrefslogtreecommitdiff
path: root/dw/image.cc
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-10-07 22:34:33 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-10-17 21:01:25 +0200
commit572b9346d5d844822b1a0cc1f22e15fb898135b4 (patch)
treeaffb6d1aa00ddc0622ba491963ba1e54b68eabd0 /dw/image.cc
parent51e023b7eb12e87a172e1d60e62ecc7448eff836 (diff)
Use the aspect ratio of the content box
The requisition box includes the margin, padding and border. To compute the aspect ratio of the image we need to remove them to get the content box. Once the adjustment is done, we add the borders again.
Diffstat (limited to 'dw/image.cc')
-rw-r--r--dw/image.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/dw/image.cc b/dw/image.cc
index ba3348de..79331afb 100644
--- a/dw/image.cc
+++ b/dw/image.cc
@@ -181,6 +181,9 @@ void Image::sizeRequestSimpl (core::Requisition *requisition)
DEBUG_MSG(1, "-- Image::sizeRequestSimpl() begins\n");
+ DEBUG_MSG(1, "Image::sizeRequestImpl border: w=%d h=%d\n",
+ boxDiffWidth(), boxDiffHeight());
+
/* First set a naive size based on the image properties if given */
if (buffer) {
@@ -207,7 +210,7 @@ void Image::sizeRequestSimpl (core::Requisition *requisition)
requisition->ascent += boxOffsetY ();
requisition->descent += boxRestHeight ();
- DEBUG_MSG(1, "initial requisition: w=%d, h=%d\n",
+ DEBUG_MSG(1, "Image: initial requisition (with border): w=%d, h=%d\n",
requisition->width, requisition->ascent + requisition->descent);
/* Then correct the size if needed, so it fits within the available space in
@@ -217,7 +220,7 @@ void Image::sizeRequestSimpl (core::Requisition *requisition)
correctRequisition (requisition, core::splitHeightPreserveDescent, true,
true);
- DEBUG_MSG(1, "corrected requisition: w=%d, h=%d\n",
+ DEBUG_MSG(1, "Image: corrected requisition: w=%d, h=%d\n",
requisition->width, requisition->ascent + requisition->descent);
DBG_OBJ_MSGF ("resize", 1, "=> %d * (%d + %d)",
@@ -264,6 +267,13 @@ void Image::sizeAllocateImpl (core::Allocation *allocation)
allocation->x, allocation->y, allocation->width,
allocation->ascent, allocation->descent);
+ DEBUG_MSG(1, "Image::sizeAllocateImpl x=%d y=%d w=%d h=(%d + %d)\n",
+ allocation->x, allocation->y, allocation->width,
+ allocation->ascent, allocation->descent);
+
+ DEBUG_MSG(1, "Image::sizeAllocateImpl border: w=%d h=%d\n",
+ boxDiffWidth(), boxDiffHeight());
+
int newBufWidth = allocation->width - boxDiffWidth ();
int newBufHeight =
@@ -274,6 +284,9 @@ void Image::sizeAllocateImpl (core::Allocation *allocation)
(newBufWidth != bufWidth || newBufHeight != bufHeight)) {
DBG_OBJ_MSG ("resize", 1, "replacing buffer");
+ DEBUG_MSG(1, "Image::sizeAllocateImpl new buffer size: w=%d h=%d\n",
+ newBufWidth, newBufHeight);
+
core::Imgbuf *oldBuffer = buffer;
buffer = oldBuffer->getScaledBuf (newBufWidth, newBufHeight);
oldBuffer->unref ();
@@ -286,6 +299,10 @@ void Image::sizeAllocateImpl (core::Allocation *allocation)
DBG_OBJ_SET_NUM ("bufHeight", bufHeight);
}
+ DEBUG_MSG(1, "Image::sizeAllocateImpl x=%d y=%d w=%d h=(%d + %d)\n",
+ allocation->x, allocation->y, allocation->width,
+ allocation->ascent, allocation->descent);
+
DBG_OBJ_LEAVE ();
}