Author Topic: LOCATE problem  (Read 3456 times)

0 Members and 1 Guest are viewing this topic.

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
LOCATE problem
« on: October 09, 2021, 05:42:55 am »
Hi,
I was testing my program in an other PC, with a smaller screen then mine, and I found that it doesn't work.

I was astonisched by that, because I have figured this problem and in order to avoid it, any image descends from _DESKTOPWIDTH and _DESKTOPHEIGHT and it is smaller. so, the images must fit the screen, and I didn't thought to LOCATE.

the image attached is a result of 2 images. the graphic is pasted with _PUTIMAGE over the bigger image, containing data. data are written on the right of the bigger image with locate. but the problem is that if in my screen, LOCATE ,192 put the data as in the picture attached, in smaller screens, LOCATE ,192 is "outside" of the screen.

I ask you if there is a way in order to always have the data written as in the picture, in all the screens.

Thank's you.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: LOCATE problem
« Reply #1 on: October 09, 2021, 06:45:29 am »
Instead of an absolute coordinate, LOCATE via a scaleable one.

For example, the screen you displayed has a width of 232 characters, or so, I'm guessing.   Let's pretend it's 232 characters anyway, for this explanation, so you have 40 characters reserved on the right of the screen to print your text in.

Instead of a hardcoded LOCATE ,192 -- which might be offscreen on some smaller screens -- simply LOCATE , maxWidth - 40 instead.

On screens that are 232 characters wide, you print starting at position192.
On screens that are only 200 characters wide, you print starting at position 160.



Of course, if you want ALL screens to look the same regardless of resolution, use TWO screens in your program.

WorkScreen is the one you draw and render everything on.  Make it the size you need to hold your data.
DisplayScreen is set to the users desktop height and width.

Simply make the DisplayScreen the visible one, and _PUTIMAGE the WorkScreen on it, to scale to the proper resolution.



Or add a $RESIZE command to the top of your code.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: LOCATE problem
« Reply #2 on: October 09, 2021, 06:48:08 am »
_PUTIMAGE should have a way to keep things in frame. If you _putimage both graphic AND data to an intermediate image sized to accept both, then _putimage that intermediate image to the screen, such that it shrinks things to fit, would that keep things still readable and without distortion? AH, I see Steve beat me to it, same idea essentially.


Here's a little sub I've been using lately that shrinks and justifies images to fit in defined spaces without altering their aspect ratio.
Code: QB64: [Select]
  1. SUB Image_Resize (xpos AS INTEGER, ypos AS INTEGER, xlim AS INTEGER, ylim AS INTEGER, i AS LONG, d AS LONG, xj AS STRING, yj AS STRING)
  2.  
  3.     'Syntax: upper left x, upper left y, lower right x, lower right y, image handle, destination handle, horizontal justification, vertical justification
  4.     'horizontal justifications= "l" left, "c" center, "r" right
  5.     'vertical justifications= "u" up, "c" center, "d" down
  6.     DIM AS INTEGER xs, ys, xp, yp, xl, yl
  7.     DIM AS SINGLE rt, xrt, yrt
  8.     xrt = (xlim - xpos) / _WIDTH(i) '                           width of area divided by width of image
  9.     yrt = (ylim - ypos) / _HEIGHT(i) '                          height of area divided by height of image
  10.     rt = -xrt * (xrt < yrt) + -yrt * (yrt <= xrt) '             pick the smaller of the two ratios to fit area
  11.     xs = _WIDTH(i) * rt '                                       final image size ratio in x
  12.     ys = _HEIGHT(i) * rt '                                      final image size ratio in y
  13.  
  14.     xp = -xpos * (xj = "l") + -(_SHR(xlim - xpos, 1) + xpos - _SHR(xs, 1)) * (xj = "c") + -(xlim - xs) * (xj = "r")
  15.     xl = xp + xs
  16.     yp = -ypos * (yj = "u") + -(_SHR(ylim - ypos, 1) + ypos - _SHR(ys, 1)) * (yj = "c") + -(ylim - ys) * (yj = "d")
  17.     yl = yp + ys
  18.     _PUTIMAGE (xp, yp)-(xl, yl), i, d
  19.  
  20. END SUB 'Image_Resize
  21.  

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: LOCATE problem
« Reply #3 on: October 10, 2021, 03:16:05 am »
OldMoses,
Quote
such that it shrinks things to fit, would that keep things still readable and without distortion?

I don't remember very well, because I made this test month ago, but there were distortions.

SMcNeill,
thank's you! I don't know how it was possible that I negleted this LOCATE problem!

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: LOCATE problem
« Reply #4 on: October 12, 2021, 08:34:19 am »
Solved, now the program works until 1024x768 pixel resolution. Thank's.