Author Topic: _RESIZEWIDTH / _RESIZEHEIGHT question.  (Read 1195 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
_RESIZEWIDTH / _RESIZEHEIGHT question.
« on: May 19, 2019, 11:40:12 am »
I stepped outside of my comfortable SCREEN 0 today, and noticed the horrors of the outside graphics world!

Did you folks know that _RESIZE commands works great, except the resizing doesn't effect the screen image parameters. So if you set SCREEN _NEWIMAGE(640, 480, 32) and put in a simple character typing routine, the character get typed to the right margin of the screen, and then the next character gets automatically printed to the left margin of the next row. That's as expected, but now increase or decrease the width with a _RESIZE statement, and guess what? The characters typed are still controlled by the original screen image width of 640! The same is true for good ol' SCREEN 0.

So we try to control what happens with something like:

IF x >= wdth / 8 THEN x = 1: y = y + 1: BEEP: ELSE y = CSRLIN: x = POS(0)

OK, that works for downsizing the width, but fails if the width is enlarged past the initial image value. So make a 640 x 480 screen over 640 wide, and it ignores x > wdth / 8 and just puts the character down one row when the value of wdth / 8 exceeds the original 80 columns set in either the default SCREEN 0 mode or with its graphics counterpart, SCREEN _NEWIMAGE(640, 480, 32).

So is this something that needs some work? Should _RESIZEWIDTH reset the left margin set by the SCREEN statement?

Some sample code to try out below. Just hold down a key, and wait for the text to reach the left margin, and start the next lne. Next, drag the left margin of the window to decrease the width. Start typing again and notice it complies with the shorter width, because of that x > wdth routine, I mentioned earlier. Next, drag the screen out to wider than it was originally. Start typing again, but this time notice there is no "BEEP" and it just starts a new line for characters after it reaches that 80th column. You can't get it to continue typing to the end, so it is actually ignoring that x > wdth routine. That's not right.

Example Code:

Code: QB64: [Select]
  1. DEFINT A-Z
  2.     FUNCTION SetLayeredWindowAttributes& (BYVAL hwnd AS LONG, BYVAL crKey AS LONG, BYVAL bAlpha AS _UNSIGNED _BYTE, BYVAL dwFlags AS LONG)
  3.     FUNCTION GetWindowLong& ALIAS "GetWindowLongA" (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
  4.     FUNCTION SetWindowLong& ALIAS "SetWindowLongA" (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
  5. ' Needed for acquiring the hWnd of the window
  6. DIM Myhwnd AS LONG ' Get hWnd value
  7. _TITLE "Translucent window test"
  8. Myhwnd = _WINDOWHANDLE
  9. ' Set screen
  10. SCREEN _NEWIMAGE(640, 480, 32)
  11.  
  12. '''SCREEN 0    ' Same problem in text screen.
  13.  
  14. ' Main loop
  15. Level = 200
  16. LOCATE 1, 1: PRINT "Press F1/F2 to change opacity:"; Level;
  17. LOCATE 2, 1: PRINT "Drag to change window size:"; wdth; hght
  18. SetWindowOpacity Myhwnd, Level
  19.  
  20. y = 3: x = 1
  21.     _LIMIT 30
  22.     IF wdth <> _RESIZEWIDTH OR hght <> _RESIZEHEIGHT THEN
  23.         wdth = _RESIZEWIDTH: hght = _RESIZEHEIGHT
  24.         LOCATE 2, 1: PRINT "Drag to change window size:"; wdth; hght
  25.     END IF
  26.     b$ = INKEY$
  27.     IF LEN(b$) THEN
  28.         IF b$ = CHR$(27) THEN SYSTEM
  29.         IF LEN(b$) = 2 THEN
  30.             IF b$ = CHR$(0) + CHR$(59) AND Level < 255 THEN Level = Level + 1: SetWindowOpacity Myhwnd, Level
  31.             IF b$ = CHR$(0) + CHR$(60) AND Level > 0 THEN Level = Level - 1: SetWindowOpacity Myhwnd, Level
  32.             LOCATE 1, 1: PRINT "Press F1/F2 to change opacity"; Level;
  33.         ELSE
  34.             LOCATE y, x: PRINT b$;
  35.             IF x >= wdth / 8 THEN x = 1: y = y + 1: BEEP: ELSE y = CSRLIN: x = POS(0)
  36.         END IF
  37.     END IF
  38. '====================================================================\
  39. SUB SetWindowOpacity (hwnd AS LONG, Level)
  40. DIM Msg AS LONG
  41. CONST G = -20
  42. CONST LWA_ALPHA = &H2
  43. CONST WS_EX_LAYERED = &H80000
  44. Msg = GetWindowLong(hwnd, G)
  45. Msg = Msg OR WS_EX_LAYERED
  46. action = SetWindowLong(hwnd, G, Msg)
  47. action = SetLayeredWindowAttributes(hwnd, 0, Level, LWA_ALPHA)
  48.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: _RESIZEWIDTH / _RESIZEHEIGHT question.
« Reply #1 on: May 20, 2019, 11:05:56 pm »
Well, crickets...

I just don't see why $RESIZE was not created with automatic screen image resizing. It's easy enough to do with a _RESIZE function but I really think that should have been built in. Of course refreshing the screen contents is a whole other matter.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
Re: _RESIZEWIDTH / _RESIZEHEIGHT question.
« Reply #2 on: May 21, 2019, 12:15:12 pm »
Pete I like the opacity of it. So cool. My computer has sunglasses now. The resize part is also interesting.
QB64 is the best!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: _RESIZEWIDTH / _RESIZEHEIGHT question.
« Reply #3 on: May 21, 2019, 12:49:52 pm »
Yeah, Fill pointed me to that Windows API effect, in the WIKI. I like it, but I'm a rank amateur at Windows API crap. I've only figured about four things out on my own so far. I want a persistent window, but I did some research and discovered Windows blocks more than one re-focus of a window. From that point on, any attempt to re-focus it just causes the icon in the flash tray to flash. What a bunch of... anyway, minimizing and maximizing causes the screen to return in the upper right hand corner. That's fine, if you are using the whole screen, but not for a less than full screen, positioned window. Sure, _SCREENMOVE will move it back, but the lag caused by the API call makes that effect look so stupid. :( Positioning using the API seems to be a daunting task; so I really don't want to waste my life on that right now. Wait... Holy batshit, man... I just thought of something... Have to go give it a tray! Fingers crossed, and F**k Bill Gates and the source he codes Win on.

Pete

EDIT: Well wooo-f'ing-hooo! From discussing the above, it dawned on me there might be more parameters to ShowWindow than just hide, minimize, and maximize. Two parameters that will work to make the illusion of a persistent window are (1) for Normal and (9) for restore. Both will remember the window position, without the going through the daunting task of learning all those API window positioning tricks. Thanks Jack! I don't know if I would have thought of this without replying to your post.

 - Pete
 
« Last Edit: May 21, 2019, 01:00:44 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
Re: _RESIZEWIDTH / _RESIZEHEIGHT question.
« Reply #4 on: May 21, 2019, 05:41:27 pm »
Great. I will take credit for all of it. I know what an API is but can't do a thing with them. Good luck.
QB64 is the best!