Page 1 of 1
Sliding image
Posted: Wed Sep 21, 2016 8:31 pm
by Giorgio Garabello
I'm writing a SBASIC and EasyPTR4 program.
I need to load an image into a menu (or, better, in a part of the menu)
The image can be more big in the menu themselve, in which case I have to have the ability to view the scrollbar.
I know there are programs in SBASIC who do it (like BMP D. Jones), then you can achieve it ... but I have no idea how to do.
Can someone help me?
Giorgio
Re: Sliding image
Posted: Wed Sep 21, 2016 10:58 pm
by tofro
- Prepare a window save area on the heap with WSAIN and proper size (can be bigger than the screen)
- Load the full image into memory (not to the screen, use L_WSA)
- copy what fits into your window from memory into your application window (use WSARS)
- when the user scrolls, copy the new position of your partial display from the big save area to the application window using WSARS, use width and height of your window for the cutout size
The point is that the scrollbar defines the position of the cutout from the memory image that is copied to the screen. This is like moving the cutout that is actually displayed around with the scrollbars.
Tobias
Re: Sliding image
Posted: Thu Sep 22, 2016 10:24 am
by Giorgio Garabello
tofro wrote:
- Prepare a window save area on the heap with WSAIN and proper size (can be bigger than the screen)
Ok this is clar
[*]Load the full image into memory (not to the screen, use L_WSA)
ok
[*]copy what fits into your window from memory into your application window (use WSARS)
ok
[*]when the user scrolls, copy the new position of your partial display from the big save area to the application window using WSARS, use width and height of your window for the cutout size[/list]
The point is that the scrollbar defines the position of the cutout from the memory image that is copied to the screen. This is like moving the cutout that is actually displayed around with the scrollbars.
This part is clear to me as a concept, but I did not understand how to achieve technically, what commands I have to use to make the scroll?
Re: Sliding image
Posted: Thu Sep 22, 2016 12:18 pm
by tofro
Giorgio Garabello wrote:
This part is clear to me as a concept, but I did not understand how to achieve technically, what commands I have to use to make the scroll?
Maybe it's best to have a concrete example (code is entirely untested and just from the top of my head...):
Let's assume (for the ease of maths), your application window for display is 100x100, your picture is 1000x1000
Code: Select all
999 REMark returns address of back buffer in address, x and y size in x% and y%
1000 DEFine PROCEDURE LoadPicture (filename$, x%, y%, address)
1010 address = L_WSA (filename$, x%, y%)
1020 ENDDefine
1025 :
1030 REMark draw part of the picture at address with a left/top offset of x|y to our window
1035 REMark note we assume here x% and y% are < 900, so we always stay within the back buffer
1100 DEFine PROCEDURE DrawPicture (channel, address, x%, y%)
1110 REMark Clear application window to black
1120 BLOCK #channel, 0, 0, 100, 100, 0
1130 REMark Now cut a 100x100 area out of the back buffer and paint it
1135 REMark note we want the back buffer to stay, so use the \ separator
1140 WSARS #channel, address \ 100, 100, 0, 0, x%, y%
1150 END DEFine
1160 :
and your Menu loop would somehow look like this (only relevant parts for pan and scroll)
Code: Select all
2000 REPeat MenuLoop
2010 .....
2100 MDRAW #ch%, "menuFile",....
2105 REMark assume appWinCh was somehow established, e.g with MWLINK or MWINDOW
2100 DrawPicture (appwinCh, pictureAddress, currX, currY)
2110 menuReturn = MCALL (ch% \ ...)
2120 IF (menuReturn > 65536) THEN
2130 IF (menuReturn && $FFFF = appWinNum) THEN : REMark make sure we got the right appl. Window
2140 upper = menuReturn / 65536
2150 opCode = upper && 15
2160 pixPos = INT (upper / 16)
2165 IF pixPos <> -1 THEN
2166 REMark scrollbar arrows not hit
2170 IF opCode = 0 THEN : REMark scrollbar hit
2180 currY = 1000 * scrollbarHeighinPixels / pixPos
2185 IF currY > 900 : currY = 900
2190 ENDIF
2191 ELSE
2192 REMark handle arrows here
2193 ENDIF
2200 :
2200 IF opCode = 4 THEN : REMark Pan bar hit
2210 currX = 1000 * panBarWidthinPixels / pixPos
2215 IF currX > 900 : currX = 900
2220 ENDIF
....
3000 END REPeat
Re: Sliding image
Posted: Thu Sep 22, 2016 3:08 pm
by Giorgio Garabello
Very clear, thanks!
I've done some preliminar test writing few rows
COM_CH% = FOPEN ("CON_")
MDRAW #COM_CH%,WIN3_MENU_men
COM_ADDRESS = L_WSA(WIN3_TEST_pic,X_SIZE%,Y_SIZE%)
WSARS #COM_CH%,COM_ADDRESS \ 200,80,0,0,0,0
REPEAT CR_MAIN
RETCODE = MCALL(#COM_CH%)
IF RETCODE = -6
EXIT CR_MAIN
END IF
END REPEAT CR_MAIN
It works but....
1) to scroll or pan the image i need to have scrollbars... how can draw it?
2) this work if the X/Y size of the application subwindow menu is known ..but i'vea resizable menu..there's any function that returs these value?
(sorry for my bad english)
Giorgio
Re: Sliding image
Posted: Thu Sep 22, 2016 4:38 pm
by tofro
Giorgio Garabello wrote:
1) to scroll or pan the image i need to have scrollbars... how can draw it?
Check MAWBARR
Giorgio Garabello wrote:
2) this work if the X/Y size of the application subwindow menu is known ..but i'vea resizable menu..there's any function that returs these value?
Check PVAL - allows you to get to the size of a window
Tobias
Re: Sliding image
Posted: Thu Sep 22, 2016 10:20 pm
by Giorgio Garabello
tofro wrote:Giorgio Garabello wrote:
1) to scroll or pan the image i need to have scrollbars... how can draw it?
Check MAWBARR
Ok
Giorgio Garabello wrote:
2) this work if the X/Y size of the application subwindow menu is known ..but i'vea resizable menu..there's any function that returs these value?
Check PVAL - allows you to get to the size of a window
Tobias
mmmm. no pval return the size of the window...not the ize of the specific menu application...