WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Boxes Functions
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

BoxDataClear and Stack Management &
Contents of Graphics Windows Disappearing

Keywords: BoxDataClear	Stack Management   

Question:

I've notice a serious problem with the otherwise excellent graphics functions. I'm using version 96M, 32 bit. The commands I'm using are:

BoxesUp("0,0,1000,1000",@NORMAL)
BoxNew(2,"0,0,1000,1000",2)
BoxColor(2,GREY,0)
When I manually minimize the graphics window and then restore it, everything that's been written to the window is gone. Likewise, if I cover the window with another window, everything covered is erased. And in some cases, a ghost image of the second window stays on the graphics window and only disappears if I minimize the graphics window and then restore it.

Obviously the graphics routines are not properly repainting the contents of the window. Is there a solution?

Answer:

It sounds like a stack management problem where you are doing a premature BoxDataClear.

The three lines of script you provided did not do much and immediately exited so there was no time to see what was going on. I modified the supplied script a bit so as to be able to actually see what was going on.

The script will keep the window around till you hit the ESCAPE key...


BLUE="0,0,255"
RED="255,0,0"
BoxesUp("0,0,1000,1000",@NORMAL)
BoxNew(2,"0,0,1000,1000",2)
BoxColor(2,BLUE,0)
BoxDrawRect(2,"0,0,1000,1000",2)
BoxColor(2,RED,0)
BoxDrawCircle(2,"300,200,700,800",2)
WaitForKey("{ESC}","","","","")
Using this script I do not see any paint problems when minimizing and restoring or covering with another window.

I still suspect you are clearing the drawing stack too soon. When a repaint occurs it will only repaint up to the end of the defined drawing stack, and it a portion of it was cleared...well then the cleared items are not repainted.

Question (continued thread):

Undoubtedly my liberal use of the BoxDataClear() command is why the contents of the graphics window are disappearing. The problem is that my program draws hundreds (and potentially thousands) of boxes to the window, in a couple of different colors. If I don't include BoxDataClear() at regular intervals in the instruction stream then I get a 10108: "Box command stack full" error. This occurs after about 140 BoxColor(), BoxDrawRect() pairs.

Is there some way of increasing the size of the command stack beyond this rather modest limit to avoid getting the "stack full" error? Any known work-around if someone wants to draw a lot of stuff to the screen, and have it stay there?

Answer (continued thread):

The graphics stack is... umm... about 169 elements deep. You can get quite a lot in there with that.

The trick is to draw all the fixed elements first, then Insert a BoxDataTag, then draw the rapidly varying elements. Also, for BoxDrawText, make sure you set the subsequent erase flags to @TRUE.

Right before you redraw the rapidly varying elements, then do a BoxDataClear for the named tag. I guess the idea is to do the BoxDataClear before the drawing of the last portion, rather than after. As in:


;; sample script for BoxDataClear
BoxesUp("100,100,900,900", @normal) 
BoxColor(1,"255,255,0",0)
BoxDrawRect( 1, "0,0,1000,1000", 2) 
BoxDataTag(1, "tag1")	   ;INSERT THE TAG HERE BEFORE VARYING ELEMENTS
BoxDrawText(1, "0,200,1000,1000", "WinBatch Box Example - BoxDataClear ", @false, 1)
BoxCaption(1, "WinBatch BoxDataClear Example")


;BoxColor(1,"0,0,255", 0)  ;THIS BOX IS CAUSING A PROBLEM WHEN NOT COMMENTED OUT

BoxPen(1,"255,0,0",25)
BoxDrawRect(1,"350,350,650,650", 1)
BoxDrawLine(1, "350,700,800,700")
TimeDelay(2)

BoxDataClear(1, "tag1")	 ;SET THIS BEFORE THE NEXT VARYING TEXT: BOXDRAWTEXT
BoxDrawText(1, "0,200,1000,1000", "BoxDataClear - Clearing Tags to redraw contents", @true, 1)	;SET TO @TRUE

TimeDelay(3)

BoxColor(1,"255,0,0", 0)

BoxPen(1,"0,0,255",50)
BoxDrawRect(1,"350,350,650,650", 1)
BoxDrawLine(1, "350,700,800,700")
TimeDelay(4)

Question (thread continued):

The graphics being displayed using box commands disappears from the box if I move another window in place, covering the box. Likewise, if I minimize or maximize the window containing graphics, it disappears. I use effective stack management to draw about 3000+ elements and can see the graphics as long as I do not cover the window. What can I do to fix this problem?

Answer:

What happens is that when you do a BoxDataClear, then everything below the corresponding BoxDataTag is deleted.

When it is deleted, it cannot be redrawn if required - say by covering it temporarily with another window or iconizing it then showing it.

Only the items above the BoxDataTag are preserved to be re-drawn.

With your technique of frequent dataclears you are able to draw many many items, but these items are not preserved if a redraw is required.

My best suggestion is a "Screen Refresh" button which, when pressed, redraws the entire window.


Similar Question with Example of How to Revise Code with BoxDataTag and BoxDataClear

Question:

I'm trying to implement a simple progress bar. The bar dies part way through due to a stack error. Any idea why?

Here's a snippet of code to test with:


BoxOpen("BarTest","Checking for stack error 10108 on Box function")
BoxTextFont(1, "Terminal", 80, 0, 1)

BarLen = 50
;BarChr1 = Num2Char(176)
;BarChr2 = Num2Char(178)
BarChr1 = "-"
BarChr2 = "*"

nThings=200

For i = 1 to nThings
BarDone = (BarLen * i) / nThings
PctBar = StrCat("[",StrFill(BarChr2,BarDone),StrFill(BarChr1,BarLen-BarDone),"]")
StatusMsg = StrCat("Progress: ",PctBar,@CrLf,"Item '",i,"'")
BoxText(StatusMsg)
Next i 

Answer:

Your use of the BoxTextFont instruction kicked all your BOX functions into the advanced area whre you need to worry about "Drawing Stack Management". See WinBatch manual or winbatch.hlp file for more information.

I added some code to make this script work. See the added BoxDataTag and BoxDataClear functions added.


BoxOpen("BarTest","Checking for stack error 10108 on Box function")
BoxTextFont(1, "Terminal", 80, 0, 1)

BarLen = 50
;BarChr1 = Num2Char(176)
;BarChr2 = Num2Char(178)
BarChr1 = "-"
BarChr2 = "*"

nThings=200

BoxDataTag(1,"tiptop")
For i = 1 to nThings
    BoxDataClear(1,"tiptop")
    BarDone = (BarLen * i) / nThings
    PctBar = StrCat("[",StrFill(BarChr2,BarDone),StrFill(BarChr1,BarLen-BarDone),"]")
    StatusMsg = StrCat("Progress: ",PctBar,@CrLf,"Item '",i,"'")
    BoxText(StatusMsg)
Next i 

Article ID:   W12754
Filename:   BoxDataClear and Stack Management.txt
File Created: 2001:01:25:15:15:58
Last Updated: 2001:01:25:15:15:58