Author Topic: Question on VIEW & WINDOW in 32 bit display  (Read 4090 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Question on VIEW & WINDOW in 32 bit display
« on: June 19, 2019, 08:02:53 am »
I've been working on a graphic vector movement display with full code at:
https://www.qb64.org/forum/index.php?topic=1429.0

I set up a display window thus

A& = _NEWIMAGE(1200, 700, 32)

In a later SUB I do this:

    _DEST A&
    CLS
    c = 3 'color variable (local)

    '0=black,1=blue,2=green,3=aqua,4=red,5=purple,6=brown,7=white
    '8=gray, +8=bright color, except 14=yellow,

    COLOR clr&(c) '                                                    color array set up in main module

    VIEW (560, 18)-(1180, 638), , clr&(c) '                     set graphics port on right side w/box
    WINDOW (-1000, 1000)-(1000, -1000) '                        set relative cartesian coords

Now any graphics commands go in the box, just as I wanted, but now I would like to set up another window next to it to contain mouse click targets without affecting the existing graphic port. This code was originally from SCREEN 12

I've tried invoking VIEW with new position parameters, and by itself. The former does funny things to the existing port, while the later has no effect and graphic commands still go in the existing port. Obviously, I'm either missing something or what I'm trying to do cannot be done in this mode. I'm not very experienced with graphics work of this magnitude.

Should I rather be just doing a series of _PUTIMAGEs for mouse buttons instead?

Any solutions or insights are appreciated.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #1 on: June 19, 2019, 09:42:56 am »
Hi OldMoses

here my little contribution to your issue...
I have never used intensively this tecnique but I know it in theory so here a little code example to let you see how you can combine viewport , resetting of cohordinates and graphic instructions

Code: QB64: [Select]
  1. ' Graphic viewport with absolute cohordinate
  2. VIEW SCREEN(1, 1)-(200, 50), 2, 7 ' viewport1
  3. MakeG ' this draws in absolute cohordinates
  4. VIEW SCREEN(1, 51)-(200, 100), 12, 14 ' viewport2
  5. MakeG ' also this draws at absolute cohordinates  --> graphic is made on previous port
  6. VIEW (1, 101)-(200, 150), 1, 4 ' viewport3
  7. MakeG ' this draws at relative cohordinate of the viewport
  8. VIEW (201, 1)-(400, 50), 3, 5 ' viewport4
  9. WINDOW SCREEN(1, 1)-(200, 50) ' this set a different cohordinates that mimic those of viewport1
  10. MakeG ' this draws in relative cohordinates
  11.  
  12.  
  13. SUB MakeG
  14.     LINE (10, 2)-(60, 18), 15, BF
  15.     CIRCLE (50, 30), 10, 7

God Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #2 on: June 19, 2019, 12:32:04 pm »
Hi OldMoses,

With a handle for the image, you could work on image updates independently while screen is showing using _SOURCE and _DEST then use _PUTIMAGE to show contents of image anywhere, anytime on current screen such that your image works like a view window.

EDIT: well not like a view window that is stuck and that code works around, more like a floating view port window over the top of current screen. With _PUTIMAGE you have much more flexibility of where to put it and how big to blow it up or shrink or cover whole screen. Use _PRINTSTRING  (like a graphics PRINT) to control where you want to put text to stay away from where you plan to show the image.
« Last Edit: June 19, 2019, 12:51:03 pm by bplus »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #3 on: June 19, 2019, 12:51:51 pm »
Hi OldMoses

here my little contribution to your issue...
I have never used intensively this tecnique but I know it in theory so here a little code example to let you see how you can combine viewport , resetting of cohordinates and graphic instructions

I tried putting this in a 32 bit screen and it came up black, so apparently there's a problem with my approach to displaying my old SCREEN 12 work in the new 32 bit screen.

With a handle for the image, you could work on image updates independently while screen is showing using _SOURCE and _DEST then use _PUTIMAGE to show contents of image anywhere, anytime on current screen such that your image works like a view window.

EDIT: well not like a view window that is stuck and that code works around, more like a floating view port window over the top of current screen.

This sounds like the solution, and shouldn't take much code if I understand it right. I must unlearn what I have learned, lo these many years past.

Thanks, this helps refocus my thinking.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #4 on: June 19, 2019, 12:58:54 pm »
Graphics with 32 in the _NEWIMAGE command needs RGB32 colors, so all those numbers 0 - 15 in screen 12 look like Black in graphics 32 screen.

Here is Screen 12 colors with equivalent RGB32 constants (but I may have changed values to my preferences):
Code: QB64: [Select]
  1. DIM SHARED qb(15)   '<<<<<<<<<< to set up array
  2. qb(0) = &HFF000000
  3. qb(1) = &HFF000088
  4. qb(2) = &HFF008800
  5. qb(3) = &HFF008888
  6. qb(4) = &HFF880000
  7. qb(5) = &HFF880088
  8. qb(6) = &HFF888800
  9. qb(7) = &HFFCCCCCC
  10. qb(8) = &HFF888888
  11. qb(9) = &HFF0000FF
  12. qb(10) = &HFF00FF00
  13. qb(11) = &HFF00FFFF
  14. qb(12) = &HFFFF0000
  15. qb(13) = &HFFFF00FF
  16. qb(14) = &HFFFFFF00
  17. qb(15) = &HFFFFFFFF
  18.  

or learn RGB32: _RGB32(255, 0, 0) is red
_RGB32(0, 0, 255) is blue
_RGB32(255, 255, 0) is yellow
and many many many more combos!

I am sure Johnno or Steve have a more authentic set of color equivalents for 0-15.

Here is some code you can diddle with colors even create constants to paste into code:
https://www.qb64.org/forum/index.php?topic=1363.0


Oh if you'd rather do it by color name here is this:
Code: QB64: [Select]
  1.  
  2. 'easy to remember color names?
  3. CONST blackl = &HFF000000
  4. CONST bluel = &HFF000088
  5. CONST greenl = &HFF008800
  6. CONST cyanl = &HFF008888
  7. CONST redl = &HFF880000
  8. CONST purplel = &HFF880088
  9. CONST yellowl = &HFF888800
  10. CONST whitel = &HFFCCCCCC
  11. CONST blackh = &HFF888888
  12. CONST blueh = &HFF0000FF
  13. CONST greenh = &HFF00FF00
  14. CONST cyanh = &HFF00FFFF
  15. CONST redh = &HFFFF0000
  16. CONST purpleh = &HFFFF00FF
  17. CONST yellowh = &HFFFFFF00
  18. CONST whiteh = &HFFFFFFFF
  19.  

l stands for low or dark, h for high or light, change names to what you prefer (and values for that matter!)


Oh wiki has a screen 12 code sample showing the numbers accurately:
Code: QB64: [Select]
  1. alpha$ = "FF" 'solid alpha colors only
  2. OUT &H3C8, 0: OUT &H3C9, 0: OUT &H3C9, 0: OUT &H3C9, 20 'set black background to dark blue
  3. PRINT "Attribute = Hex value      Red          Green         Blue "
  4. FOR attribute = 0 TO 15
  5.   OUT &H3C7, attribute 'set color attribute to read
  6.   red$ = HEX$(INP(&H3C9) * 4) 'convert port setting to 32 bit values
  7.   grn$ = HEX$(INP(&H3C9) * 4)
  8.   blu$ = HEX$(INP(&H3C9) * 4)
  9.   IF LEN(red$) = 1 THEN red$ = "0" + red$ '2 hex digits required
  10.   IF LEN(grn$) = 1 THEN grn$ = "0" + grn$ 'for low or zero hex values
  11.   IF LEN(blu$) = 1 THEN blu$ = "0" + blu$
  12.   hex32$ = "&H" + alpha$ + red$ + grn$ + blu$
  13.   _PALETTECOLOR attribute, VAL(hex32$) 'VAL converts hex string to a LONG 32 bit value
  14.   IF attribute THEN COLOR attribute 'exclude black color print
  15.   PRINT "COLOR" + STR$(attribute) + " = " + hex32$, red$, grn$, blu$ 'returns closest attribute
  16.  
« Last Edit: June 19, 2019, 01:15:19 pm by bplus »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #5 on: June 19, 2019, 05:31:00 pm »
Doh!! I forgot about the colors. You'd think I would have learned by now, as many times as I've run into that issue.

I did set up a 16 color array in my program, and use it often, but forgot to add one to TempodiBasic's example. I usually use clr&(x) to hold the long values, where the x is the corresponding color in SCREEN 0 thru whatever.

Blundering along...

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #6 on: June 19, 2019, 05:36:08 pm »
to complete the above my code here the sequential difference between the old and the new way to use  a piece of the screen as a different screen with its own cohordinates

Code: QB64: [Select]
  1. ' Graphic viewport with absolute cohordinate
  2. VIEW SCREEN(1, 1)-(200, 50), 2, 7 ' viewport1
  3. MakeG ' this draws in absolute cohordinates
  4. VIEW SCREEN(1, 51)-(200, 100), 12, 14 ' viewport2
  5. MakeG ' also this draws at absolute cohordinates  --> graphic is made on previous port
  6. VIEW (1, 101)-(200, 150), 1, 4 ' viewport3
  7. MakeG ' this draws at relative cohordinate of the viewport
  8. VIEW (201, 1)-(400, 50), 3, 5 ' viewport4
  9. WINDOW SCREEN(1, 1)-(200, 50) ' this set a different cohordinates that mimic those of viewport1
  10. MakeG ' this draws in relative cohordinates
  11.  
  12. LOCATE 24, 1
  13. PRINT "Press a key to see the emulation of these graphic with _QB64 keywords": SLEEP
  14. ' porting to 32bit with canvas surface to draw
  15. A& = _NEWIMAGE(640, 480, 32) ' main viewport= the whole screen
  16. B& = _NEWIMAGE(200, 50, 32) 'viewport1
  17. C& = _NEWIMAGE(200, 50, 32) 'viewport2
  18. D& = _NEWIMAGE(200, 50, 32) 'viewport3
  19. E& = _NEWIMAGE(200, 50, 32) 'viewport4
  20.  
  21. ' Bplus colors for 32 bit similar to screen 12
  22. DIM SHARED qb(15) '<<<<<<<<<< to set up array
  23. qb(0) = &HFF000000
  24. qb(1) = &HFF000088
  25. qb(2) = &HFF008800
  26. qb(3) = &HFF008888
  27. qb(4) = &HFF880000
  28. qb(5) = &HFF880088
  29. qb(6) = &HFF888800
  30. qb(7) = &HFFCCCCCC
  31. qb(8) = &HFF888888
  32. qb(9) = &HFF0000FF
  33. qb(10) = &HFF00FF00
  34. qb(11) = &HFF00FFFF
  35. qb(12) = &HFFFF0000
  36. qb(13) = &HFFFF00FF
  37. qb(14) = &HFFFFFF00
  38. qb(15) = &HFFFFFFFF
  39.  
  40. IF A& < -1 THEN SCREEN A& ' it creates the screen
  41. _DEST B& ' set canvas viewport1
  42. PAINT (1, 1), qb(2)
  43. LINE (1, 1)-(200, 50), qb(7), B
  44. MakeG2 ' this draws on viewport1
  45. _PUTIMAGE (1, 1), B&, A& ' this put on screen (whole original viewport) canvas1
  46.  
  47. _DEST C& ' set canvas viewport2
  48. PAINT (1, 1), qb(12)
  49. LINE (1, 1)-(200, 50), qb(14), B
  50. MakeG2 ' this draws on viewport2 . Note here there is no SCREEN option to use absolute cohordinates of screen
  51. _PUTIMAGE (1, 51), C&, A& ' this put on screen (whole original viewport) canvas2
  52.  
  53. _DEST D& ' set canvas viewport3
  54. PAINT (1, 1), qb(1)
  55. LINE (1, 1)-(200, 50), qb(4), B
  56. MakeG2 ' this draws on viewport3
  57. _PUTIMAGE (1, 101), D&, A& ' this put on screen (whole original viewport) canvas3
  58.  
  59. _DEST E& ' set canvas viewport4
  60. PAINT (1, 1), qb(3)
  61. LINE (1, 1)-(200, 50), qb(5), B
  62. MakeG2 ' this draws on viewport4
  63. _PUTIMAGE (201, 1), E&, A& ' this put on screen (whole original viewport) canvas4
  64.  
  65. LOCATE 24, 1
  66. PRINT "Press a key to quit the emulation of these graphic with _QB64 keywords": SLEEP
  67.  
  68.  
  69. SUB MakeG
  70.     LINE (10, 2)-(60, 18), 15, BF
  71.     CIRCLE (50, 30), 10, 7
  72.  
  73. SUB MakeG2
  74.     LINE (10, 2)-(60, 18), qb(15), BF
  75.     CIRCLE (50, 30), 10, qb(7)
  76.  

as you have noted by comments and running the code in the old mode (view and window) the SCREEN option of command VIEW let  re-drawing the same picture again on  viewport1 at place of drawing on viewport2... this kind of error is not possible using canvas!
Surely you can resize the scale of cohordinates for each canvas and this affects the graphic instructions made in it

try to add this code  just after a definition of a viewport/canvas  with _DEST
Code: QB64: [Select]
  1. WINDOW (1, 1)-(100, 50)
running code you can see how picture drawn is changed in size!
Programming isn't difficult, only it's  consuming time and coffee

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #7 on: June 19, 2019, 09:38:31 pm »
That's what I'm looking to do, only in my case I'm doing a 620x620 image with a relative coordinate system from -1000 to 1000 in both axis. Putting that to the right hand side of a 1200 x 700 screen. I've now abandoned the idea of a view window in A& and am opting for a putimage approach. Only now I can't get it to accept the putimage command.

In the main module:
A& = _NEWIMAGE(1200, 700, 32)
SS& = _NEWIMAGE(620, 620, 32)
SCREEN A&

Then it's into the SUBs were:
_DEST SS&
VIEW (1, 1)-(618, 618), clr&(0), clr&(3) 'the border wouldn't show unless I left a pixel for it
WINDOW (-1000, 1000)-(1000, -1000)

Draw all the stuff I need to draw in SS&
Then:

_PUTIMAGE (560, 18), SS&, A&

Whereupon everything is drawn properly, but instead of floating on the right side with the upper left at {560, 18}, it is up in the left corner and the program crashes with a illegal function call error pointing to whatever line the putimage is in.

« Last Edit: June 20, 2019, 07:40:32 am by OldMoses »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #8 on: June 19, 2019, 10:27:21 pm »
Hi OldMoses,

Did you set _DEST back to A& before _PUTIMAGE?
Code: QB64: [Select]
  1.  
  2. A& = _NEWIMAGE(1200, 700, 32)
  3. SS& = _NEWIMAGE(620, 620, 32)
  4.  
  5.  
  6. _DEST SS&
  7. VIEW (1, 1)-(618, 618), clr&(0), clr&(3) 'the border wouldn't show unless I left a pixel for it
  8. WINDOW (-1000, 1000)-(1000, -1000)
  9. FOR r = 1 TO 1100 STEP 10
  10.     CIRCLE (0, 0), r
  11.  
  12.  
  13. '_DEST A& 'commented out it draws nothing but no error, with comment it draws on screen
  14. _PUTIMAGE (100, 100), SS&, A&
  15.  
  16.  
« Last Edit: June 19, 2019, 10:38:03 pm by bplus »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #9 on: June 19, 2019, 10:50:19 pm »
Hi OldMoses,

Did you set _DEST back to A& before _PUTIMAGE?

Yes, I thought that might be it, but it doesn't seem to make any difference. I know I must be missing something, because I played with the process in some practice code and had no problems, but something is tripping it up in my main project.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #10 on: June 20, 2019, 08:07:58 am »
Found it!

Another stupid oversight on my part. I didn't DIM SHARED the image handles.

Funny how such simple things will stop you cold for hours or days...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #11 on: June 20, 2019, 09:28:39 am »
Found it!

Another stupid oversight on my part. I didn't DIM SHARED the image handles.

Funny how such simple things will stop you cold for hours or days...

Ha! makes you so happy you forget all the misery and frustration from the hour before! Guess I've been down that path a few times. :)

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Question on VIEW & WINDOW in 32 bit display
« Reply #12 on: June 20, 2019, 09:41:04 am »
Ha! makes you so happy you forget all the misery and frustration from the hour before! Guess I've been down that path a few times. :)

I got two happys for the price of one out of this bug.

I found out that when I put images in a _DEST image I also have to SCREEN that image or it dumps the sub images in the outer screen unpredictably. I think this one is ready to push to the program thread finally.