Author |
Topic: Card graphics not sticking (Read 172 times) |
|
Turtleman
New Member
member is offline


Gender: 
Posts: 29
|
 |
Re: Card graphics not sticking
« Reply #36 on: May 23rd, 2016, 3:48pm » |
|
Got to run right now and may not be able to get back to this until tomorrow. I ran the Profiler and am trying to figure out how to post it along with my code. I'm very anxious to get to the bottom of this. Later!
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Card graphics not sticking
« Reply #37 on: May 23rd, 2016, 4:10pm » |
|
on May 23rd, 2016, 3:48pm, Turtleman wrote:| I hope I've committed some horrendous programming error and that there's a way of speeding things up. |
|
No. You have hit a rare 'edge case', which I have encountered only once before, in a program written by an Australian user. LBB is not suitable for your program - use LB instead.
Richard.
|
|
Logged
|
|
|
|
Turtleman
New Member
member is offline


Gender: 
Posts: 29
|
 |
Re: Card graphics not sticking
« Reply #38 on: May 23rd, 2016, 7:53pm » |
|
Code:Yikes – you're giving up without having even seen the code and running it! Let's not throw in the towel so quickly! If nothing else, it would be good to know what's going on. Code:
'Graphic boxes demo - May 23, 2016
nomainwin
'stylebits #main, 0, _WS_VISIBLE, 0, 0
GridWidth = 40
GridHeight = 25
GridRows = 20
GridColumns = 10
MaxColors = 5
dim counters(GridColumns, GridRows), colors$(MaxColors-1)
restore [FieldValues]
for row = 1 to GridRows
for column = 1 to GridColumns
read n
counters(column, row) = n
next
next
restore [FieldColors]
for i = 0 to MaxColors-1
read color$
colors$(i) = color$
next
BoxWidth = GridColumns * GridWidth
BoxHeight = GridRows * GridHeight
WindowWidth = BoxWidth + 100
WindowHeight = BoxHeight + 100
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
graphicbox #main.gb22, 50, 10,(GridWidth), 25
graphicbox #main.gb23, (1 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb24, (2 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb25, (3 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb26, (4 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb27, (5 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb28, (6 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb29, (7 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb30, (8 * GridWidth +50), 10,(GridWidth), 25
graphicbox #main.gb31, (9 * GridWidth +50), 10,(GridWidth), 25
y = 15
graphicbox #main.gb11, 5, 1 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb12, 5, 2 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb13, 5, 3 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb14, 5, 4 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb15, 5, 5 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb16, 5, 6 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb17, 5, 7 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb18, 5, 8 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb19, 5, 9 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb110, 5, 10 * GridHeight + y, GridWidth,GridHeight
graphicbox #main.gb111, 5, 11 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb112, 5, 12 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb113, 5, 13 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb114, 5, 14 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb115, 5, 15 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb116, 5, 16 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb117, 5, 17 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb118, 5, 18 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb119, 5, 19 * GridHeight + y, GridWidth, GridHeight
graphicbox #main.gb120, 5, 20 * GridHeight + y, GridWidth,GridHeight
graphicbox #main.gb, 50, 40, BoxWidth, BoxHeight
open "Grid" for window as #main
#main, "trapclose [quit.main]"
#main.gb "down; font arial 10; size 1; color black"
#main.gb "when leftButtonUp [IncreaseCounter]"
#main.gb "when leftButtonDouble [IncreaseCounter]"
gosub [InitGrid]
gosub [title]
#main "show"
wait
[quit.main]
Close #main
END
[IncreaseCounter]
row = int( MouseY / GridHeight) + 1
column = int( MouseX / GridWidth) + 1
counters(column, row) = counters(column, row) + 1
if counters(column, row) > (MaxColors - 1) then counters(column, row) = 0
#main.gb "delsegment GridUpdate"
gosub [DrawField]
#main.gb "flush GridUpdate"
wait
[InitGrid]
for row = 1 to GridRows
for column = 1 to GridColumns
gosub [DrawField]
next
next
#main.gb "flush InitGrid"
return
[DrawField]
#main.gb "backcolor "; colors$(counters(column, row))
#main.gb "place "; (column-1)*GridWidth; " "; (row-1)*GridHeight
#main.gb "boxfilled "; column*GridWidth; " "; row*GridHeight
#main.gb "place "; (column-.6)*GridWidth; " "; (row-.4)*GridHeight
if instr(lower$(colors$(counters(column, row))), "dark") > 0 then #main.gb "color white"
#main.gb "\"; counters(column, row)
if instr(lower$(colors$(counters(column, row))), "dark") > 0 then #main.gb "color black"
return
[FieldValues]
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
[FieldColors]
data "red" '0
data "green" '1
data "cyan" '2
data "yellow" '3
data "pink" '4
[title]
'REM 1
#main.gb22, "down; fill yellow; color black; backcolor yellow"
#main.gb22, "place 10 17; font arial 12 bold"
#main.gb22, "\1"
#main.gb22, "flush"
'REM 2
#main.gb23, "down; fill yellow; color black; backcolor yellow"
#main.gb23, "place 10 17; font arial 12 bold"
#main.gb23, "\2"
#main.gb23, "flush"
'REM 3
#main.gb24, "down; fill yellow; color black; backcolor yellow"
#main.gb24, "place 10 17; font arial 12 bold"
#main.gb24, "\3"
#main.gb24, "flush"
'REM 4
#main.gb25, "down; fill yellow; color black; backcolor yellow"
#main.gb25, "place 10 17; font arial 12 bold"
#main.gb25, "\4"
#main.gb25, "flush"
'REM 5
#main.gb26, "down; fill yellow; color black; backcolor yellow"
#main.gb26, "place 10 17; font arial 12 bold"
#main.gb26, "\5"
#main.gb26, "flush"
'REM 6
#main.gb27, "down; fill yellow; color black; backcolor yellow"
#main.gb27, "place 10 17; font arial 12 bold"
#main.gb27, "\6"
#main.gb27, "flush"
'REM 7
#main.gb28, "down; fill yellow; color black; backcolor yellow"
#main.gb28, "place 10 17; font arial 12 bold"
#main.gb28, "\7"
#main.gb28, "flush"
'REM 8
#main.gb29, "down; fill yellow;color black; backcolor yellow"
#main.gb29, "place 10 17; font arial 12 bold"
#main.gb29, "\8"
#main.gb29, "flush"
'REM 9
#main.gb30, "down; fill yellow; color black; backcolor yellow"
#main.gb30, "place 10 17; font arial 12 bold"
#main.gb30, "\9"
#main.gb30, "flush"
'REM 10
#main.gb31, "down; fill yellow; color black; backcolor yellow" 'REM 255, 153, 0"
#main.gb31, "place 5 17; font arial 12 bold"
#main.gb31, "\10"
#main.gb31, "flush"
'REM VERTICAL COLUMN LABELS ----------------------------------------------------------------------
'REM 1
#main.gb11, "down; fill white; color black; backcolor white"
#main.gb11, "place 14 20; font arial 12 bold"
#main.gb11, "\1"
#main.gb11, "flush"
'REM 2 #main.gb91, "down; fill white; color black; backcolor white"
#main.gb12, "place 14 20; font arial 12 bold"
#main.gb12, "\2"
#main.gb12, "flush"
'REM 3
#main.gb13, "down; fill white; color black; backcolor white"
#main.gb13, "place 14 20; font arial 12 bold"
#main.gb13, "\3"
#main.gb13, "flush"
'REM 4
#main.gb14, "down; fill white; color black; backcolor white"
#main.gb14, "place 14 20; font arial 12 bold"
#main.gb14, "\4"
#main.gb14, "flush"
'REM 5
#main.gb15, "down; fill white; color black; backcolor white"
#main.gb15, "place 14 20; font arial 12 bold"
#main.gb15, "\5"
#main.gb15, "flush"
'REM 6
#main.gb16, "down; fill white; color black; backcolor white"
#main.gb16, "place 14 20; font arial 12 bold"
#main.gb16, "\6"
#main.gb16, "flush"
'REM 7
#main.gb17, "down; fill white; color black; backcolor white"
#main.gb17, "place 14 20; font arial 12 bold"
#main.gb17, "\7"
#main.gb17, "flush"
'REM 8
#main.gb18, "down; fill white; color black; backcolor white"
#main.gb18, "place 14 20; font arial 12 bold"
#main.gb18, "\8"
#main.gb18, "flush"
'REM 9
#main.gb19, "down; fill white; color black; backcolor white"
#main.gb19, "place 14 20; font arial 12 bold"
#main.gb19, "\9"
#main.gb19, "flush"
'REM 10
#main.gb110, "down; fill white; color black; backcolor white"
#main.gb110, "place 10 20; font arial 12 bold"
#main.gb110, "\10"
#main.gb110, "flush"
'REM 11
#main.gb111, "down; fill white; color black; backcolor white"
#main.gb111, "place 10 20; font arial 12 bold"
#main.gb111, "\11"
#main.gb111, "flush"
'REM 12
#main.gb112, "down; fill white; color black; backcolor white"
#main.gb112, "place 10 20; font arial 12 bold"
#main.gb112, "\12"
#main.gb112, "flush"
'REM 13
#main.gb113, "down; fill white; color black; backcolor white"
#main.gb113, "place 10 20; font arial 12 bold"
#main.gb113, "\13"
#main.gb113, "flush"
'REM 14
#main.gb114, "down; fill white; color black; backcolor white"
#main.gb114, "place 10 20; font arial 12 bold"
#main.gb114, "\14"
#main.gb114, "flush"
return
|
| « Last Edit: May 23rd, 2016, 8:24pm by Turtleman » |
Logged
|
|
|
|
Turtleman
New Member
member is offline


Gender: 
Posts: 29
|
 |
Re: Card graphics not sticking
« Reply #39 on: May 23rd, 2016, 8:28pm » |
|
Sorry if the code snippet didn't get posted in the right place, but you should see a significant difference in loading speed between LB and LBB, even though I had to cut it down to size. Comments?
|
| « Last Edit: May 23rd, 2016, 8:29pm by Turtleman » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Card graphics not sticking
« Reply #40 on: May 23rd, 2016, 9:20pm » |
|
on May 23rd, 2016, 7:53pm, Turtleman wrote:| Yikes – you're giving up without having even seen the code and running it! |
|
It's not a case of "giving up" but of avoiding further effort being expended when it can't succeed. It would be inappropriate for me to encourage you to carry on, since nothing you can do will make it run any faster than it is now.
What does puzzle me somewhat (although I must emphasise that it has nothing to do with speed) is why you are not populating the boxes in a loop. Whilst LB compatibility prevents you using a loop to create the boxes, there is no such limitation when it comes to populating them.
So whilst you will have no choice but to return to using LB to achieve the speed you seem to require, you could significantly reduce the size of the code by removing much of the repetition.
Thank you for your interest in LBB, I'm sorry it didn't work out in this case.
Richard.
|
|
Logged
|
|
|
|
Turtleman
New Member
member is offline


Gender: 
Posts: 29
|
 |
Re: Card graphics not sticking
« Reply #41 on: May 23rd, 2016, 9:32pm » |
|
Thanks Russell, though I'm disappointed that LBB won't provide a boost to my program, and even more disappointed that I don't have a clue why it loads differently in LB vs. LBB. (I'm also pretty sure it loaded faster before I went from Win 7 to Win 10, but that's another issue.) I really hate giving up the advantages of LBB, but it's still very useful in identifying coding flaws that LB doesn't care about. And you're right about reducing much of the code, but frankly, I'm not sure how to go about it!
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline


Gender: 
Posts: 210
|
 |
Re: Card graphics not sticking
« Reply #42 on: May 23rd, 2016, 9:46pm » |
|
I've put a bit of Code:print "Time taken ";time$("ms")-t0: t0=time$("ms") lines to see what's going on.
Basically LB shows window (on my old machine) at 200ms, while LBB at 560 Parts that take time: Code:creating controls / opening window
60 ms LB , 200 LBB
[InitGrid]
100 ms LB , 140 LBB
[title]
140 ms LB , 300 LBB I pretty sure nothing could be done at first part. [ InitGrid ] and [ title ] is basically bunch of drawing commands LBB is known might be slower in graphics - there are too much layers to emulate. It is shine in calculating (strings and math). So you still could have speed gain ;) Time shows things could be done at [ title ] Let's see You can move font from each box to main Code:
[title]
#main "font arial 12 bold" you can get rid of color (black by default), down (down by defualt in LBB) and flush. So I got about 200 ms out of 300 with parts like these Code:'REM 1
#main.gb22, "fill yellow; backcolor yellow;place 10 17"
#main.gb22, "\1"
(man you really should rewrite that part with a loop and handle variables).
BUT with Code:stylebits #main, 0, _WS_VISIBLE, 0, 0
...
#main "show"
window seems to came instantly anyway. So - create window once, then done, Code: , then need, Code: - instantly.
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline


Gender: 
Posts: 210
|
 |
Re: Card graphics not sticking
« Reply #43 on: May 23rd, 2016, 9:49pm » |
|
Quote:| And you're right about reducing much of the code, but frankly, I'm not sure how to go about it! |
|
Code:[title]
#main "font arial 12 bold"
for i = 22 to 31
handle$ = "#main.gb";i
#handle$, "fill yellow; backcolor yellow;place 10 17;\";i-21
next
'REM VERTICAL COLUMN LABELS ----------------------------------------------------------------------
for i = 1 to 14
handle$ = "#main.gb1";i
#handle$, "fill white; backcolor white; place 14 20;\";i
next
return
|
| « Last Edit: May 23rd, 2016, 9:54pm by tsh73 » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Card graphics not sticking
« Reply #44 on: May 23rd, 2016, 10:47pm » |
|
on May 23rd, 2016, 9:46pm, tsh73 wrote:BUT with Code:stylebits #main, 0, _WS_VISIBLE, 0, 0
...
#main "show" window seems to came instantly anyway. |
|
The OP has already said that he would not be satisfied with that approach: "While the display could be hidden until finished loading, the delay is still not desirable". You (and I) may consider it to be 'instant', but he evidently has a different opinion.
Richard.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Card graphics not sticking
« Reply #45 on: May 24th, 2016, 08:58am » |
|
Just to tidy up loose ends, I timed the code (with Anatoly's modifications, but with flush retained for LB compatibility) as follows on my laptop:
LBB 3.04: ~600 ms LB 4.5.0: ~300 ms
So, yes, LBB takes twice as long as LB to create and populate the window and all its controls. But both take significantly less than a second and I would not expect that to be greatly annoying to a user (especially if it can be done during initialisation, or when he is reading a prompt for example).
Here we have a case where the OP set an artificial requirement, that the code must not run any slower than in LB, and it's a requirement LBB simply cannot meet. Arguably it would have been better if he had looked at the 'bigger picture' rather than fixated on this one performance measure.
Right at the start of the thread (reply #3) I wrote: "If it's mostly plotting graphics [LBB] may run no faster at all, or even a little slower" so since much of the complained-about delay is indeed when plotting graphics the OP really had no reason to be unduly surprised.
I might perhaps have been more disposed to be helpful if he could have been bothered to get my name right! 
Richard.
|
|
Logged
|
|
|
|
Turtleman
New Member
member is offline


Gender: 
Posts: 29
|
 |
Re: Card graphics not sticking
« Reply #46 on: May 24th, 2016, 10:38am » |
|
Richard: I'm so sorry to have gotten your name wrong in what must have been a momentary bout of dyslexia. I don't have a clue how I could have done that. Please forgive me!
I never set an "artificial requirement," but was merely curious about the speed differences. I thought (hoped) I was doing something wrong. Yes, perhaps that window and others could be loaded earlier and kept minimized until needed. Unfortunately, another window is used for plotting data repeatedly where speed is much more critical than opening the example code. With hundreds or thousands of data points, even a small difference in speed adds up. I expect that could be a "deal breaker," but will experiment further before giving up.
With thanks to tsh73, the example code used only consecutive numbers in the vertical label column, but in the real application, various numbers and letters are used, which might make it more difficult to simplify the code. I'm sure it can be done, where the labels can be fetched as data, but I haven't gotten around to working on that yet.
My LBB expectations were obviously misplaced, but am glad I gave it a go. And again, if nothing else, LBB is proving helping in identifying LB coding boo-boos!
|
| « Last Edit: May 24th, 2016, 10:39am by Turtleman » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Card graphics not sticking
« Reply #47 on: May 24th, 2016, 12:39pm » |
|
on May 24th, 2016, 10:38am, Turtleman wrote:| Unfortunately, another window is used for plotting data repeatedly where speed is much more critical than opening the example code. With hundreds or thousands of data points, even a small difference in speed adds up. |
|
I wonder if you have read the Wiki article Speeding up graphics plotting. In the very specific example given there it was possible, by making the suggested changes, to go from LBB plotting graphics noticeably more slowly than LB to it actually plotting more quickly.
Quote:| in the real application, various numbers and letters are used, which might make it more difficult to simplify the code. |
|
If those "various numbers and letters" are constants, they could for example be read from a DATA statement. If they are variables, then I would have expected that they could either be stored in an array or calculated at run-time as the boxes are populated.
Incidentally what is the reason that the main 'grid' is a single large graphicbox, whereas the row and column 'labels' are individual controls? I'm probably missing something, but it's not obvious to me why the row of horizontal labels shouldn't be a single graphicbox, and similarly the column of vertical labels, or indeed why the whole caboodle couldn't be a single graphicbox.
Quote:| My LBB expectations were obviously misplaced, but am glad I gave it a go. |
|
It was to make sure that your expectations were not "misplaced" that I said so early on that you should not expect graphics plotting to be any faster. I don't know whether you somehow missed that, or hoped that it wasn't true, but your realisation that LBB is not a panacea shouldn't have been a recent one!
The background, for those who are interested, is that since both LB and LBB simply pass graphics commands onto the Windows API, fundamentally they should execute at virtually the same speed (if anything LB would be expected to be a little slower because it is both plotting to the screen and recording the commands to a metafile). The reason LBB tends to be slower in practice is the overhead of interpreted BBC BASIC, which decodes the command strings.
It would, in principle, be perfectly possible for the existing BBC BASIC code to be replaced by (say) C or assembler code, which would almost certainly guarantee that graphics plotting is always faster in LBB than LB. But the very reason for LBB's existence is as a demonstrator of the capabilities of BBC BASIC, so from that point of view replacing it with code in another language makes no sense.
Richard.
|
|
Logged
|
|
|
|
Turtleman
New Member
member is offline


Gender: 
Posts: 29
|
 |
Re: Card graphics not sticking
« Reply #48 on: May 26th, 2016, 4:37pm » |
|
This probably belongs in the Novice category on the LB board, but since it's already been suggested here to hide the window with "stylebits #main, 0, _WS_VISIBLE, 0, 0" and then "#main "show"" after loading, I have a related question.
If the "hidden" window is loaded at the start of the program, it can be made visible by manually issuing a "show" command when desired. That way the window appears to open immediately, which is highly desirable. QUESTION: How do you hide the window again once opened? The program crashes if issued a "#main "hide"" instruction, and simply closing the window takes me back to where I started. Perhaps relocating the window off-screen will work.
There are several windows (not all involving graphics) that can be toggled open or closed by the user, but I don't have enough experience to know how best to go about it. ANOTHER QUESTION: Is opening and closing the "normal" way of handling multiple windows or should they be loaded at the program's start and made visible or invisible as required? I hope that makes sense, and thanks to everyone for your patience.
Tsh73: Thanks to your help, a lot of unnecessary code has been eliminated.
|
|
Logged
|
|
|
|
Turtleman
New Member
member is offline


Gender: 
Posts: 29
|
 |
Re: Card graphics not sticking
« Reply #49 on: May 28th, 2016, 4:58pm » |
|
Richard: Thanks for your explanations. Not knowing any better, I initially designed the program to open selected windows on demand. I'm now changing that to launch all windows along with the rest of the program – they're just hidden until needed. That eliminates any lag in populating the displays and tremendously simplifies the coding. (I often have a tendency to overcomplicate things! ) So far, it looks like LBB might lend itself to running the program after all, but there're many more changes to make first.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Card graphics not sticking
« Reply #50 on: May 28th, 2016, 10:58pm » |
|
on May 28th, 2016, 4:58pm, Turtleman wrote:| Not knowing any better, I initially designed the program to open selected windows on demand. |
|
In the great majority of programs, it will make no noticeable difference which way you do it. Creating a window usually happens virtually 'instantaneously'; even in your own program it's not the window creation that takes a significant time but the window initialisation, i.e. filling all those graphicboxes and grid cells with a background color and text.
As I think I said previously, I've only once before encountered a program in which the window creation/initialisation took sufficiently longer in LBB than in LB to be important, so it's very unusual. On that occasion I could improve things somewhat, but not match the performance of LB.
I've suggested ways in which you could improve the performance of your program. To speed up window creation you could replace the horizontal set of column labels and the vertical set of row labels with single graphicboxes rather than many individual ones. To speed up the window initialisation you could concatenate the commands into one long string, as suggested in the Wiki article to which I linked.
But you never responded to either suggestion, which is why I concluded you weren't really motivated to get it working well in LBB. The code below incorporates both mods:
Code: 'Graphic boxes demo - May 23, 2016
nomainwin
start = time$("ms")
GridWidth = 40
GridHeight = 25
GridRows = 20
GridColumns = 10
MaxColors = 5
dim counters(GridColumns, GridRows), colors$(MaxColors-1)
restore [FieldValues]
for row = 1 to GridRows
for column = 1 to GridColumns
read n
counters(column, row) = n
next
next
restore [FieldColors]
for i = 0 to MaxColors-1
read color$
colors$(i) = color$
next
BoxWidth = GridColumns * GridWidth
BoxHeight = GridRows * GridHeight
WindowWidth = BoxWidth + 100
WindowHeight = BoxHeight + 100
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
graphicbox #main.gb2, 50, 10, BoxWidth, GridHeight
y = 15
graphicbox #main.gb1, 5, GridHeight + y, GridWidth, BoxHeight
graphicbox #main.gb, 50, 40, BoxWidth, BoxHeight
stylebits #main, 0, _WS_VISIBLE, 0, 0
open "Grid" for window as #main
#main, "trapclose [quit.main]"
#main.gb "down; font arial 10; size 1; color black"
#main.gb "when leftButtonUp [IncreaseCounter]"
#main.gb "when leftButtonDouble [IncreaseCounter]"
gosub [InitGrid]
gosub [title]
#main "show"
finish = time$("ms")
print finish-start
wait
[quit.main]
Close #main
END
[IncreaseCounter]
row = int( MouseY / GridHeight) + 1
column = int( MouseX / GridWidth) + 1
counters(column, row) = counters(column, row) + 1
if counters(column, row) > (MaxColors - 1) then counters(column, row) = 0
#main.gb "delsegment GridUpdate"
gosub [DrawField]
#main.gb "flush GridUpdate"
wait
[InitGrid]
for row = 1 to GridRows
for column = 1 to GridColumns
gosub [DrawField]
next
next
#main.gb "flush InitGrid"
return
[DrawField]
gb$ = "color black; backcolor "; colors$(counters(column, row)); ";"
gb$ = gb$ + "place "; (column-1)*GridWidth; " "; (row-1)*GridHeight; ";"
gb$ = gb$ + "boxfilled "; column*GridWidth; " "; row*GridHeight; ";"
gb$ = gb$ + "place "; (column-.6)*GridWidth; " "; (row-.4)*GridHeight; ";"
if instr(lower$(colors$(counters(column, row))), "dark") > 0 then gb$ = gb$ + "color white;"
gb$ = gb$ + "\"; counters(column, row)
#main.gb gb$
return
[FieldValues]
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
data 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
[FieldColors]
data "red" '0
data "darkgreen"'1
data "cyan" '2
data "yellow" '3
data "pink" '4
[title]
#main "font arial 12 bold"
#main "font arial 12 bold"
#main.gb2 "down; color black; backcolor yellow"
for i = 22 to 31
gb2$ = "place ";(i-22) * GridWidth; " 0;"
gb2$ = gb2$ + "boxfilled ";(i-21) * GridWidth; " "; GridHeight-2; ";"
gb2$ = gb2$ + "place ";(i-21.6) * GridWidth; " 17;\";i-21
#main.gb2 gb2$
next
#main.gb2 "flush"
'REM VERTICAL COLUMN LABELS ----------------------------------------------------------------------
#main.gb1 "down; color black; backcolor white"
for i = 1 to 20
gb1$ = "place 0 ";i * GridHeight; ";"
gb1$ = gb1$ + "boxfilled ";GridWidth-2; " "; (i-1) * GridHeight; ";"
gb1$ = gb1$ + "place 14 ";(i-0.4) * GridHeight; ";\"; i
#main.gb1 gb1$
next
#main.gb1 "flush"
return Richard.
|
|
Logged
|
|
|
|
|