Skip to content

Commit 1145c84

Browse files
committed
UI: added xpm validation check.
1 parent 5d2f3b6 commit 1145c84

File tree

7 files changed

+35
-15
lines changed

7 files changed

+35
-15
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2021-07-04 (12.22)
2+
SDL: Fix Live edit when start path contains unicode characters
3+
14
2021-07-02 (12.22)
25
UI: Fix to make image save and load compatible
36

documentation/sbasic_ref.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Graphics,command,PSET,621,"PSET [STEP] x,y [, color| COLOR color]","Draw a pixel
9595
Graphics,command,RECT,622,"RECT [STEP] x,y [,|STEP x2,y2] [, color| COLOR color] [FILLED]","Draws a rectangular parallelogram."
9696
Graphics,command,SHOWPAGE,1429,"SHOWPAGE","This command is used to display pending graphics operations allowing for smooth animations."
9797
Graphics,command,VIEW,623,"VIEW [x1,y1,x2,y2 [,color [,border-color]]]","Defines a viewport. The viewport defined by VIEW is disabled by a VIEW command with no parameters."
98-
Graphics,command,WINDOW,624,"WINDOW [x1,y1,x2,y2]","The WINDOW command allows you to redefine the corners of the display screen as a pair of ""world"" coordinates. WINDOW is also overloaded as a function, returning a system object providing access to the following sub-commands: graphicsScreen1, graphicsScreen2, textScreen, alert, ask, menu, message, showKeypad, insetTextScreen"
98+
Graphics,command,WINDOW,624,"WINDOW [x1,y2,x2,y1]","The WINDOW command allows you to redefine the corners of the display screen as a pair of ""world"" coordinates. WINDOW is also overloaded as a function, returning a system object providing access to the following sub-commands: graphicsScreen1, graphicsScreen2, textScreen, alert, ask, menu, message, showKeypad, insetTextScreen"
9999
Graphics,constant,XMAX,1526,"XMAX","Holds the screen width in pixels"
100100
Graphics,constant,YMAX,1527,"YMAX","Holds the screen height in pixels."
101101
Graphics,function,PEN,627,"PEN (0..14)","Returns the PEN/MOUSE data."

src/common/device.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,12 +1070,19 @@ void panic(const char *fmt, ...);
10701070
void lwrite(const char *buf);
10711071

10721072
/**
1073-
* @ingroup dev_f
1073+
* @ingroup dev
10741074
*
10751075
* resize the window coordinate system
10761076
*/
10771077
void dev_resize(int width, int height);
10781078

1079+
/**
1080+
* @ingroup dev
1081+
*
1082+
* adjust the point to the window coordinate system
1083+
*/
1084+
void dev_map_point(int *x, int *y);
1085+
10791086
#if defined(__cplusplus)
10801087
}
10811088
#endif

src/common/screen.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,8 @@ void dev_resize(int width, int height) {
431431
setsysvar_int(SYSVAR_XMAX, width - 1);
432432
setsysvar_int(SYSVAR_YMAX, height - 1);
433433
}
434+
435+
void dev_map_point(int *x, int *y) {
436+
*x = W2X(*x);
437+
*y = W2Y(*y);
438+
}

src/lib/xpm.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ void set_pixels(uint8_t *image, int w, int x, int y, uint32_t c) {
4141
#endif
4242
}
4343

44-
int xpm_decode32(uint8_t **image, unsigned *width, unsigned *height,
45-
const char *const *xpm) {
44+
int xpm_decode32(uint8_t **image, unsigned *width, unsigned *height, const char *const *xpm) {
4645
int ncolors, chars_per_pixel;
4746
int next_line = 0;
4847

@@ -61,20 +60,24 @@ int xpm_decode32(uint8_t **image, unsigned *width, unsigned *height,
6160
return 1;
6261
}
6362

63+
int maxColors = chars_per_pixel == 1 ? NUM_BASE : (NUM_BASE * NUM_BASE);
64+
if (ncolors >= maxColors) {
65+
return 1;
66+
}
67+
6468
// note that this array is unsigned char and skips the first line:
6569
const uint8_t *const* data = (const uint8_t*const*)(xpm + next_line + 1);
66-
int i, x, y;
67-
uint32_t colors[chars_per_pixel == 1 ? NUM_BASE : (NUM_BASE * NUM_BASE)];
70+
uint32_t colors[maxColors];
6871

69-
for (i = 0; i < ncolors; i++) {
70-
const uint8_t* p = *data++;
72+
for (int i = 0; i < ncolors; i++) {
73+
const uint8_t *p = *data++;
7174
int index = (*p++) - FIRSTCHAR;
72-
uint32_t *c; // where to store color
7375
if (chars_per_pixel == 2) {
7476
int next = (*p++) - FIRSTCHAR;
7577
index = index * NUM_BASE + next;
7678
}
77-
c = colors + index;
79+
// where to store color
80+
uint32_t *c = &colors[index];
7881

7982
// look for "c word", or last word if none:
8083
while (*p && isspace(*p)) {
@@ -98,17 +101,17 @@ int xpm_decode32(uint8_t **image, unsigned *width, unsigned *height,
98101
*image = malloc((*width) * (*height) * sizeof(uint32_t));
99102

100103
if (chars_per_pixel == 1) {
101-
for (y = 0; y <* height; y++) {
104+
for (int y = 0; y <* height; y++) {
102105
const uint8_t *p = data[y];
103-
for (x = 0; x < *width; x++) {
106+
for (int x = 0; x < *width; x++) {
104107
int index = *(p++) - FIRSTCHAR;
105108
set_pixels(*image, *width, x, y, colors[index]);
106109
}
107110
}
108111
} else {
109-
for (y = 0; y < *height; y++) {
112+
for (int y = 0; y < *height; y++) {
110113
const uint8_t *p = data[y];
111-
for (x = 0; x < *width && *p; x++) {
114+
for (int x = 0; x < *width && *p; x++) {
112115
int index = (*p++) - FIRSTCHAR;
113116
int next = (*p++) - FIRSTCHAR;
114117
index = index * NUM_BASE + next;

src/ui/image.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void ImageDisplay::draw(int x, int y, int w, int h, int cw) {
102102
srcRect.top = MIN(_buffer->_height, _offsetTop);
103103
srcRect.width = MIN(w, MIN(_buffer->_width, _width));
104104
srcRect.height = MIN(h, MIN(_buffer->_height, _height));
105+
dev_map_point(&dstPoint.x, &dstPoint.y);
105106

106107
if (unsigned(srcRect.top + srcRect.height) > _buffer->_height) {
107108
srcRect.height = _buffer->_height - srcRect.top;

src/ui/system.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ void System::handleEvent(MAEvent &event) {
512512
_touchCurY = event.point.y;
513513
_output->pointerMoveEvent(event);
514514
if (_output->hasHover() ||
515-
_output->overMenu(_touchCurX, _touchCurY)) {
515+
_output->overMenu(_touchCurX, _touchCurY) ||
516+
(_touchX != -1 && _touchY != -1)) {
516517
showCursor(kHand);
517518
} else if (_output->hasMenu()) {
518519
showCursor(kArrow);

0 commit comments

Comments
 (0)