Skip to content

Commit 073316d

Browse files
committed
bflibrary: Proper way for keeping rescaled sprite sizes
Previous attempt at keeping the scaling size was not very good. This time we're ensuring sprites are scaled to exactly the expected size, not by enlarging first pixel, but by adding one pixel to several first rows of the sprite. Previously I considered a flag to enable the new scaling, but that is not how engines should work - app requests size, engine should deliver. Not deliver something similar, but exactly what was asked.
1 parent 9d7bca0 commit 073316d

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

bflibrary/include/bfscreen.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,24 @@ typedef enum ScreenMode TbScreenMode;
7070
typedef struct TbSprite TbSprite;
7171

7272
enum TbDrawFlags {
73+
/** while drawing sprites, flip them horizontally (left-to-right) */
7374
Lb_SPRITE_FLIP_HORIZ = 0x0001,
75+
/** while drawing sprites, flip them vertically (top-to-bottom) */
7476
Lb_SPRITE_FLIP_VERTIC = 0x0002,
77+
/** while drawing sprites, use transparency with sprite data in
78+
* upper part of the color mixing array */
7579
Lb_SPRITE_TRANSPAR4 = 0x0004,
80+
/** while drawing sprites, use transparency with sprite data in
81+
* lower part of the color mixing array */
7682
Lb_SPRITE_TRANSPAR8 = 0x0008,
83+
/** while drawing sprites and shapes, draw the outline shape only */
7784
Lb_SPRITE_OUTLINE = 0x0010,
85+
/** while drawing text, horizontally align to left of provided coordinates */
7886
Lb_TEXT_HALIGN_LEFT = 0x0020,
87+
/** while drawing text or sprites, ignore original colors and use DrawColour
88+
* instead */
7989
Lb_TEXT_ONE_COLOR = 0x0040,
90+
/** while drawing text, horizontally align to right of provided coordinates */
8091
Lb_TEXT_HALIGN_RIGHT = 0x0080,
8192
Lb_TEXT_HALIGN_CENTER = 0x0100,
8293
Lb_TEXT_HALIGN_JUSTIFY = 0x0200,

bflibrary/src/general/spr_scl.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,18 @@ void LbSpriteSetScalingWidthClippedArray(long * xsteps_arr, long x, long swidth,
7979
w--;
8080
pwidth += 2;
8181
} while (w > 0);
82-
// Set the first coordiate again to avoid missing first lines on high size factor
83-
xsteps_arr[0] = x;
82+
// Increase few pixels size by one to avoid missing first lines on high size factor
83+
w = xsteps_arr[0] - x;
84+
pwidth = xsteps_arr;
85+
while (w > 0)
86+
{
87+
if (pwidth[0] > 0)
88+
pwidth[0]--;
89+
if (pwidth[0] + pwidth[1] < gwidth)
90+
pwidth[1]++;
91+
w--;
92+
pwidth += 2;
93+
}
8494
}
8595

8696
void LbSpriteSetScalingWidthClipped(long x, long swidth, long dwidth, long gwidth)
@@ -122,8 +132,16 @@ void LbSpriteSetScalingWidthSimpleArray(long * xsteps_arr, long x, long swidth,
122132
}
123133
pwidth += 16;
124134
} while (w > 0);
125-
// Set the first coordiate again to avoid missing first lines on high size factor
126-
xsteps_arr[0] = x;
135+
// Increase few pixels size by one to avoid missing first lines on high size factor
136+
w = xsteps_arr[0] - x;
137+
pwidth = xsteps_arr;
138+
while (w > 0)
139+
{
140+
pwidth[0] -= w;
141+
pwidth[1]++;
142+
w--;
143+
pwidth += 2;
144+
}
127145
}
128146

129147
void LbSpriteSetScalingWidthSimple(long x, long swidth, long dwidth)

0 commit comments

Comments
 (0)