[Gambas-user] Help with DrawingArea and class design

Caveat Gambas at ...1950...
Thu Jan 17 11:25:04 CET 2013


As a kind of getting started hint (not sure how far you got already), I 
have some code I wrote a while back to draw hex values as binary using 
little red boxes to represent the 1 bits...in the good old days, you'd 
often get custom sprites or characters defined with a bunch of DATA 
statements and binary values...

Public Sub Form_Open()
   Dim draw As New DrawingArea(Me)
   Dim values As String[]
   Dim hexValues As String = "01 0F 1C FF 00 01 02 03 04 05 06 07 08 09 
10 11"
   values = Split(hexValues, " ")
   addBoxes(draw, 20, values)
End

Public Sub addBoxes(draw As DrawingArea, size As Integer, values As 
String[])

   Dim idx, idy As Integer
   Dim drawc As DrawingArea
   Dim aBinValue As String
   For idy = 1 To values.Count
     aBinValue = hexToBinary(values[idy - 1])
     For idx = 1 To Len(aBinValue)
       drawc = New DrawingArea(draw)
       drawc.H = size
       drawc.W = size
       drawc.X = idx * size
       drawc.Y = idy * size
       If Mid(aBinValue, idx, 1) = "1" Then
         drawc.Background = Color.Red
       Else
         drawc.Background = Color.White
       End If
     Next
   Next

End

Private Function hexToBinary(hexValue As String) As String

   Dim idx As Integer
   Dim result As String = ""
   For idx = 1 To Len(hexValue)
     result &= hexDigitToBinary(Mid(hexValue, idx, 1))
   Next
   Return result

End


Private Function hexDigitToBinary(hexDigit As String) As String

   Dim idx, idy As Integer
   Dim conversions As String[][] = [
       ["0", "0000"], ["1", "0001"], ["2", "0010"], ["3", "0011"],
       ["4", "0100"], ["5", "0101"], ["6", "0110"], ["7", "0111"],
       ["8", "1000"], ["9", "1001"], ["A", "1010"], ["B", "1011"],
       ["C", "1010"], ["D", "1011"], ["E", "1110"], ["F", "1111"]]
   For idx = 0 To conversions.Count - 1
     If conversions[idx][0] = hexDigit Then
       Return conversions[idx][1]
     Endif
   Next
   Return "*"
End

Hope this helps,
Caveat

On 17/01/13 10:18, Ulrich Hartmann wrote:
> Hi all,
>
> I'm trying to create a class which can draw a pixel-font character on screen and would let me edit the pixels (this is for my graphic lcd connected to an arduino project). So I started playing around with the Paint class in Gambas3.
>
> So here are my questions:
>
> If I wanted to create my own class in which I would need to draw stuff like boxes which represent the characters pixels and make them clickable to activate or deactivate pixels (eg. draw characters), which class would I use to inherit from (DrawAerea?)?
>
> Also how would I be able to draw form within my new class when it seems to be only possible to draw in the _Draw event of the DrawingArea (can I hijack the _Draw event insde the new class inherited from DrawigArea to do the drawing)?
>
> I guess what I want is more like my own component to display and edit a pixel character.
>
> Tips and help would be highly appreciated!
>
> Uli
>
>
>
>
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122712
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>





More information about the User mailing list