0

I'm trying to make a refreshing counter... Take for example - Let's use the position of the mouse (within the window).

I've tried just clearing and redrawing everything but it always bugs out when there are many elements to draw.

a = 1
While(a = 1)
  Program.Delay(10)
  GraphicsWindow.Clear()
  GraphicsWindow.DrawText(10,10,Mouse.MouseX)
  GraphicsWindow.DrawText(10,20,Mouse.MouseY)
EndWhile  

Which works... Except that it flashes because it is refreshing too fast... If I was to increase the delay, it would not work correctly, especially when doing something like a stopwatch. The thing is that it also cannot support something with a large amount of commands... Like:

a = 1
While(a = 1)
  Program.Delay(10)
  GraphicsWindow.Clear()
  GraphicsWindow.DrawText(10,10,Mouse.MouseX)
  GraphicsWindow.DrawText(10,20,Mouse.MouseY)
  GraphicsWindow.DrawText(100,100,"Text")
  GraphicsWindow.BrushColor = "#FF0000"
  GraphicsWindow.DrawText(100,200,"Text")
  GraphicsWindow.BrushColor = "#00FF00"
  GraphicsWindow.DrawText(100,300,"Text")
  GraphicsWindow.BrushColor = "#0000FF"
  GraphicsWindow.DrawText(100,400,"Text")
  GraphicsWindow.BrushColor = "#000FF0"
  GraphicsWindow.DrawText(200,100,"Text")
  GraphicsWindow.BrushColor = "#FF0000"
  GraphicsWindow.DrawText(200,200,"Text")
  GraphicsWindow.BrushColor = "#0FF000"
  GraphicsWindow.DrawText(200,300,"Text")
  GraphicsWindow.BrushColor = "Black"
EndWhile

Which just makes a big flashing mess... And scrapping the GraphicsWindow.clear() isn't an option either because it makes a overwritten mess...

a = 1
While(a = 1)
  Program.Delay(10)
  GraphicsWindow.DrawText(10,10,Mouse.MouseX)
  GraphicsWindow.DrawText(10,20,Mouse.MouseY)
EndWhile  

Or something like this: https://i.stack.imgur.com/4sfSS.png


So, my question:
Is there any way to make a counter that can refresh smoothly without flashing that can have lots of extra things drawn in the background; elsewhere in the window? Something like the below, but also moves.
https://i.stack.imgur.com/aZQ5T.png

Sorry for the mess of links: Not enough reputation to post pictures...
Timothy
  • 364
  • 1
  • 12
  • 24

2 Answers2

1

That is not a very good way of doing it.

to do it a lot simpler, and without any extensions, try this:

GraphicsWindow.Show()
Text = Shapes.AddText("")
Shapes.Move(Text,100,100)

While 1 = 1
Program.Delay(5)
Shapes.SetText(Text,Clock.Second)
EndWhile

You are adding a text shape, then simply setting the text to a variable whenever you want.

Zock77
  • 951
  • 8
  • 26
0

You can reduce the flashing effect by rewriting elements that you have just cleared. For example, "delete" the text by drawing a rectangle (which is faster than GraphicsWindow.Clear()) and then DrawText immediately after it.

But this way of refreshing will always produce flashes. Better alternative is to use Fremy's FC extension, which feature a way to add "changable" text element (called a Label) to the GW. Fremy's extension has a load of extra functions to SB and it makes the language usable to create actual programs. It is something like JQuery to JavaScript. I highly recommend to use it, all you have to, is to download a *.dll library. More on this SB Wiki thread.

Syntax:

FCControls.AddLabel(Width [px], Height [px], Text)

Example:

mylabel = FCControls.AddLabel(100, 30, "loading...")
FCControls.Move(mylabel,10,10)

While "true"
...
FCControls.SetText(mylabel,value)
EndWhile

This allows you to refresh text without any flashing.

Extra hint: you can use While "true" to create infinite loops.

Vitexikora
  • 308
  • 2
  • 10
  • Just got another question: I've installed the extension.. However when I try to run (or compile), it says that it is not an object... Even though it registers as a command. – Timothy Jun 10 '14 at 08:31
  • What version of SmallBasic do you have? It is possible, that you have an older version of FC running. Because in version 0.9, SmallBasic added its own Controls, and FC was forced to rename it to FCControls. I will give you a link to my libraries, that are fully compatible with SB 1.0, there are several extensions, with loads of functions, but if you don't want them, keep just FC.dll and FC.xml, copy it to Lib/ directory in the smallbasic directory. Link here: [link](http://vitek.sikora.cz/files/SB1_extensions.zip) – Vitexikora Jun 10 '14 at 21:19