Hi Guys,
I have a Canvas subclass that will draw a grid with up to 512 “Cells” and will do various things like changing the cell color if a “Channel” (Name of each Cell) has changed. It works very well (it draws in 60ms in fullscreen). But… I need to call the invalidate(false) function using a timer at least every 200ms to have a relatively fluid view of the incoming “Channel Values” - which will be input via UDP at approx every 40ms… Now If I invalidate it every 200ms, it will actually take 30% of my MacBook Pros CPU, according to “Activity Manager”.
I am always refreshing the whole thing, since if I pass an area to only refresh this part, it is even slower… Any ideas welcome… Heres my code in the paint event:
[code] 'DrawGrid(g)
Dim i,j,k,l As Integer
//Now calculate the size of a box
//do it here in case canvas is resized
CellWidth = Self.Width \ ColumnCount
CellHeight = Self.Height \ rowCount
for k = 1 to ColumnCount
for l = 1 to RowCount
// Calc ChannelNumber depending on row and column
dim chNum as integer
chNum= (l-1)*mColumnCount+k
if chNum <= channelCount then
if displayHighlightChangedValues = false Then
// Set Background Rectangle Color
g.ForeColor=&c999999
else
if ChannelChanged(chNum-1) = true then //Gets this Value off of a Array of Bools with 511 length, so Channel 1 = index 0
// Set Background Rectangle Color
g.ForeColor=&c33FF33
else
// Set Background Rectangle Color
g.ForeColor=&c999999
end
end
// Draw Background Rectangle
g.FillRect (k*CellWidth -CellWidth, _
l*CellHeight-CellHeight, _
CellWidth-1, _
CellHeight-1)
// Draw ChannelNumber
g.ForeColor=&cCCCCCC
g.TextSize=CellHeight/4
g.DrawString(str(chNum), (k*CellWidth+2)-CellWidth ,l*CellHeight-CellHeight + g.TextSize+2,CellWidth)
/Get ChannelValue
dim chVal as string
chVal = str(ChannelValue(chNum-1))
If displayZeroIfZero = true then
// Draw Channel Value
g.ForeColor=&c000000
g.TextSize=CellHeight/3
g.DrawString(chVal, (k*CellWidth)-CellWidth/2 -Graphics.StringWidth(chVal)/2 ,l*CellHeight-CellHeight + CellHeight/2 + g.TextSize-CellHeight/25,CellWidth)
else
if ChannelValue(chNum-1) > 0 then
// Draw Channel Value
g.ForeColor=&c000000
g.TextSize=CellHeight/3
g.DrawString(chVal, (k*CellWidth)-CellWidth/2 -Graphics.StringWidth(chVal)/2 ,l*CellHeight-CellHeight + CellHeight/2 + g.TextSize-CellHeight/25,CellWidth)
end
end
end
next
next
[/code]