Page 1 of 2

GUI question

Posted: Mon Aug 26, 2013 3:19 pm
by doctorized
Is there any simple and fast way to create an array to accept byte data, something like these in the images?
Image
Image

Re: GUI question

Posted: Mon Aug 26, 2013 4:15 pm
by Josh
I think the best way will be painting all on a canvas gadget

Re: GUI question

Posted: Tue Aug 27, 2013 1:51 am
by Nubcake
Slightly offtopic but that's the Hex Editor I use :D. Back to the original question I don't know for sure but it looks like that toolbar/rebar is ownerdrawn.

Nubcake

Re: GUI question

Posted: Tue Aug 27, 2013 2:15 pm
by doctorized
Josh wrote:I think the best way will be painting all on a canvas gadget
Anything better than camvas? I am not a good painter! :(

Re: GUI question

Posted: Wed Aug 28, 2013 9:34 am
by doctorized
I sent a mail to the creator of XVI32 and he told me this:
Τhe main part of my editor is a grid, or more precisely a string grid.
A string grid component should be available in every modern object
oriented programming language (I use Delphi).
One "problem" is that - in contrast to an edit field where you can simply
set a text property - you have to fill a grid programmatically.
Does anyone know how can I do it in PB?

Re: GUI question

Posted: Wed Aug 28, 2013 10:22 am
by said
You can search for a grid ... or use

http://www.purebasic.fr/english/viewtop ... 12&t=54022

it can handle this

Re: GUI question

Posted: Wed Aug 28, 2013 11:17 am
by STARGÅTE
doctorized wrote:Anything better than camvas? I am not a good painter! :(
The canvas gadget is very useful for that thing.

You can convert your byte data direct to an output with DrawText.
canvas events you can use for edit or selection.

I've also written a BinaryGadget for my project: Oandone - Editor for binary files and functions

Re: GUI question

Posted: Wed Aug 28, 2013 11:41 am
by said
STARGÅTE wrote:
doctorized wrote:Anything better than camvas? I am not a good painter! :(
The canvas gadget is very useful for that thing.

You can convert your byte data direct to an output with DrawText.
canvas events you can use for edit or selection.

I've also written a BinaryGadget for my project: Oandone - Editor for binary files and functions
That's very nice STARGÅTE :)

Are you sharing the source code as well ? I dont understand German, couldn't figure out ... just noticed a link and clicked on it to get the program


Edit: Forget about my question! I used Google translator ...

Re: GUI question

Posted: Wed Aug 28, 2013 12:28 pm
by STARGÅTE
Not from the whole project!

I could share the code of the gadget,
but the gadget use many other Includes to work with big binary files (binary streaming) and undo redo.

But I look for a previous version of the gadget, which you can use as a template, but takes 1 to 2 days, I'm not at home.

Re: GUI question

Posted: Wed Aug 28, 2013 2:38 pm
by doctorized
STARGÅTE wrote:I could share the code of the gadget,
but the gadget use many other Includes to work with big binary files (binary streaming) and undo redo.
Your gadget is what I need!! I only need the gadget code! No undo-redo, no nothing. I just want to display some data, nothing more.

Re: GUI question

Posted: Wed Aug 28, 2013 3:33 pm
by RASHAD
Hi
Next will fulfill your needs ,use it as a start

# 1 :

Code: Select all

Structure NMLVSCROLL
    hdr.NMHDR
    dx.l
    dy.l
EndStructure

Procedure FillLI(Parameter)
  ReadFile(0,"g:\girl.bmp")
  While Not Eof(0)
     AddGadgetItem(2, -1,""+Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+ Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+ Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+"")
     For x = 0 To 15
        hexn = ReadByte(0)
        SetGadgetItemText(2,item,RSet(Hex(hexn),2,"0"),x)
        ;Text$ = Text$ + Chr(hexn)
     Next
     AddGadgetItem(1,-1,RSet(Hex(r),8,"0"))
     r+16
     x = 0
     item+1
  Wend
  CloseFile(0)  
EndProcedure

Procedure WindowCallback(hWnd,uMsg,wParam,lParam)

   Select uMsg
      Case #WM_NOTIFY
      Protected *pnmh.NMHDR = lParam   
      
      If *pnmh\hwndFrom = GadgetID(2)
         If *pnmh\code = #LVN_ENDSCROLL
            Protected *pnms.NMLVSCROLL = lParam
            Protected LVTI = SendMessage_(GadgetID(2),#LVM_GETTOPINDEX,0,0)
            Protected LVCP = SendMessage_(GadgetID(2),#LVM_GETCOUNTPERPAGE,0,0)
            
            If *pnms\dy < 0
               SendMessage_(GadgetID(1),#LVM_ENSUREVISIBLE,LVTI,0)
            ElseIf *pnms\dy > 0
               SendMessage_(GadgetID(1),#LVM_ENSUREVISIBLE,LVTI +  LVCP - 1,0)
            EndIf
         EndIf
      EndIf
      
      Case #WM_KEYDOWN ,#WM_MENUSELECT
        If wParam=#VK_UP
          SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_LINEUP,0)
          SendMessage_(GadgetID(2),#WM_VSCROLL,#SB_LINEUP,0)
        ElseIf wParam=#VK_DOWN
          SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_LINEDOWN,0)
          SendMessage_(GadgetID(2),#WM_VSCROLL,#SB_LINEDOWN,0)
        EndIf             
   EndSelect
   
   ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
  
LoadFont(0,"Arial",10)
OpenWindow(0, 0, 0, 840, 390, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,#Black)
  If CreateMenu(0, WindowID(0))
  MenuTitle("File")
    MenuItem( 1, "&Load...")
    MenuItem( 2, "Save")
    MenuItem( 3, "Save As...")
    MenuBar()
    OpenSubMenu("Recents")
      MenuItem( 5, "Pure.png")
      MenuItem( 6, "Basic.jpg")
      OpenSubMenu("Even more !")
        MenuItem( 12, "Yeah")
      CloseSubMenu()
      MenuItem( 13, "Rocks.tga")
    CloseSubMenu()
    MenuBar()
    MenuItem( 7, "&Quit")

  MenuTitle("Edition")
    MenuItem( 8, "Cut")
    MenuItem( 9, "Copy")
    MenuItem(10, "Paste")
    
  MenuTitle("?")
    MenuItem(11, "About")

EndIf

ContainerGadget(0,10,34,74,324)
    ListIconGadget(1,  -1, -26, 120, 356, "", 90)
CloseGadgetList()

SetGadgetFont(1,FontID(0))


SetGadgetColor(1, #PB_Gadget_FrontColor,#Black)
SetGadgetColor(1, #PB_Gadget_BackColor,#White)

ListIconGadget(2,  90,  10, 502, 348, "00", 30,#PB_ListIcon_MultiSelect )
;SendMessage_(GadgetID(1),#LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)
SetGadgetFont(2,FontID(0))

For c = 1 To 15
    AddGadgetColumn(2, c, "0"+Hex(c,#PB_Byte) , 30)
Next
SetGadgetColor(2, #PB_Gadget_FrontColor,#Gray)
SetGadgetColor(2, #PB_Gadget_BackColor,#Black)

EditorGadget(3,598,10,235,348)
SetGadgetFont(3,FontID(0))
AddGadgetItem(3,0,"TEST")

Thread =  CreateThread(@FillLI(), 1)

SetWindowCallback(@WindowCallback())  
 

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow


# 2 :
Better scroll

Code: Select all

Global oldCallback

Procedure FillLI(Parameter)
  ReadFile(0,"g:\girl.bmp")
  While Not Eof(0)
     AddGadgetItem(2, -1,""+Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+ Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+""+Chr(10)+ ""+Chr(10)+""+Chr(10)+""+Chr(10)+"")
     For x = 0 To 15
        hexn = ReadByte(0)
        SetGadgetItemText(2,item,RSet(Hex(hexn),2,"0"),x)
        Text$ = Text$ + Chr(hexn)
     Next
     AddGadgetItem(1,-1,RSet(Hex(r),8,"0"))
     AddGadgetItem(5,-1,Text$)
     r+16
     x = 0
     item+1
     Text$ = ""
  Wend
  CloseFile(0)  
EndProcedure

Procedure LIcallback(hwnd, msg, wparam, lparam)
  result = CallWindowProc_(oldCallback, hwnd, msg, wparam, lparam)  
  
  Select msg
       
    Case #WM_VSCROLL
          Item_Sp = SendMessage_(GadgetID(2), #LVM_GETITEMSPACING, #True, 0) >> 16 
          SelItem = GetScrollPos_(GadgetID(2),#SB_VERT) - GetScrollPos_(GadgetID(1),#SB_VERT)  
          SendMessage_(GadgetID(1), #LVM_SCROLL, 0, SelItem * Item_Sp)
          SendMessage_(GadgetID(5), #LVM_SCROLL, 0, SelItem * Item_Sp)          
          ;UpdateWindow_(GadgetID(1))

            
    Case #WM_KEYDOWN ,#WM_MENUSELECT
          If wParam=#VK_NEXT                       
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_PAGEDOWN,0)
            SendMessage_(GadgetID(5),#WM_VSCROLL,#SB_PAGEDOWN,0)
          ElseIf wParam=#VK_PRIOR
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_PAGEUP,0)
            SendMessage_(GadgetID(5),#WM_VSCROLL,#SB_PAGEUP,0)
          ElseIf wParam=#VK_UP
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_LINEUP,0)
            SendMessage_(GadgetID(2),#WM_VSCROLL,#SB_LINEUP,0)
            SendMessage_(GadgetID(5),#WM_VSCROLL,#SB_LINEUP,0)
          ElseIf wParam=#VK_DOWN
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_LINEDOWN,0)
            SendMessage_(GadgetID(2),#WM_VSCROLL,#SB_LINEDOWN,0)
            SendMessage_(GadgetID(5),#WM_VSCROLL,#SB_LINEDOWN,0)
          ElseIf wParam=#VK_HOME
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_TOP,0)
            SendMessage_(GadgetID(5),#WM_VSCROLL,#SB_TOP,0)
          ElseIf wParam=#VK_END
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_BOTTOM,0)
            SendMessage_(GadgetID(5),#WM_VSCROLL,#SB_BOTTOM,0)
          EndIf

   EndSelect

  ProcedureReturn result
EndProcedure


LoadFont(0,"Arial",10)
OpenWindow(0, 0, 0, 840, 390, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,#Black)
  If CreateMenu(0, WindowID(0))
  MenuTitle("File")
    MenuItem( 1, "&Load...")
    MenuItem( 2, "Save")
    MenuItem( 3, "Save As...")
    MenuBar()
    OpenSubMenu("Recents")
      MenuItem( 5, "Pure.png")
      MenuItem( 6, "Basic.jpg")
      OpenSubMenu("Even more !")
        MenuItem( 12, "Yeah")
      CloseSubMenu()
      MenuItem( 13, "Rocks.tga")
    CloseSubMenu()
    MenuBar()
    MenuItem( 7, "&Quit")

  MenuTitle("Edition")
    MenuItem( 8, "Cut")
    MenuItem( 9, "Copy")
    MenuItem(10, "Paste")
    
  MenuTitle("?")
    MenuItem(11, "About")

EndIf

ContainerGadget(0,10,34,74,324)
    ListIconGadget(1,  -1, -26, 120, 356, "", 90)
CloseGadgetList()

SetGadgetFont(1,FontID(0))


SetGadgetColor(1, #PB_Gadget_FrontColor,#White)
SetGadgetColor(1, #PB_Gadget_BackColor,#Black)

ListIconGadget(2,  90,  34, 502, 324, "00", 30,#PB_ListIcon_MultiSelect |#PB_ListIcon_FullRowSelect|#LVS_NOCOLUMNHEADER)
oldCallback = SetWindowLongPtr_(GadgetID(2), #GWL_WNDPROC, @LIcallback())
;SendMessage_(GadgetID(1),#LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)
SetGadgetFont(2,FontID(0))

For c = 1 To 15
    AddGadgetColumn(2, c, "0"+Hex(c,#PB_Byte) , 30)
Next
SetGadgetColor(2, #PB_Gadget_FrontColor,#Gray)
SetGadgetColor(2, #PB_Gadget_BackColor,#Black)

TextGadget(3,90,10,502,22,"  00    01    02    03    04    05    06    07    08    09   0A    0B    0C   0D    0E    0F")
SetGadgetFont(3,FontID(0))
SetGadgetColor(3, #PB_Gadget_FrontColor,#White)
SetGadgetColor(3, #PB_Gadget_BackColor,#Black)

ContainerGadget(4,602,34,230,324)
  ListIconGadget(5, -1,-1,260,330,"", 220,#PB_ListIcon_MultiSelect |#PB_ListIcon_FullRowSelect|#LVS_NOCOLUMNHEADER)
CloseGadgetList()
SetGadgetFont(5,FontID(0))

SetGadgetColor(5, #PB_Gadget_FrontColor,#Blue)
SetGadgetColor(5, #PB_Gadget_BackColor,$DFFEFD)

Thread =  CreateThread(@FillLI(), 1)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Edit : # 2 Modified once more

Re: GUI question

Posted: Wed Aug 28, 2013 11:37 pm
by STARGÅTE
Here is a small example with the CanvasGadget:

BinaryGadget(#Gadget, X, Y, Height, *Memory) ; shows the *Memory in the Gadget

Code: Select all


Structure AsciiArray
	a.a[0]
EndStructure

Structure BinaryGadgetInclude
	FontID.i
	BackgroundColor.i
EndStructure

Structure BinaryGadget
	Canvas.i
	ScrollBar.i
	*Memory
EndStructure

Global BinaryGadgetInclude.BinaryGadgetInclude

Procedure UpdateBinaryGadget(*BinaryGadget.BinaryGadget, Event.i=#Null)
	
	Protected *Memory.AsciiArray = *BinaryGadget\Memory
	Protected Column.i, Row.i, Rows.i, LastIndex.i, Offset.i
	
	If *Memory
		Rows = MemorySize(*Memory)/16+1
		SetGadgetAttribute(*BinaryGadget\ScrollBar, #PB_ScrollBar_Maximum, Rows-GadgetHeight(*BinaryGadget\Canvas)/20+1)
		Offset = GetGadgetState(*BinaryGadget\ScrollBar)
		Rows - Offset
		LastIndex = MemorySize(*Memory)-1 - Offset*16
	EndIf
	
	Select Event
		Case #PB_EventType_MouseWheel
			SetGadgetState(*BinaryGadget\ScrollBar, Offset - GetGadgetAttribute(EventGadget(), #PB_Canvas_WheelDelta))
			Offset = GetGadgetState(*BinaryGadget\ScrollBar)
	EndSelect
	
	If StartDrawing(CanvasOutput(*BinaryGadget\Canvas))
		DrawingMode(#PB_2DDrawing_Transparent)
		DrawingFont(BinaryGadgetInclude\FontID)
		Box(0, 0, OutputWidth(), OutputHeight(), BinaryGadgetInclude\BackgroundColor)
		For Column = 0 To 15
			DrawText(60+Column*22+3, 0, RSet(Hex(Column),2,"0"), $808080)
		Next
		For Row = 0 To Rows-1
			DrawText(0, 20+Row*20+2, RSet(Hex((Offset+Row)*16),6,"0"), $808080)
		Next
		Box(60, 20, 16*22, Rows*20, $FFFFFF)
		For Index = 0 To LastIndex
			DrawText(60+(Index%16)*22+3, 20+Int(Index/16)*20+2, RSet(Hex(*Memory\a[Offset*16+Index]),2,"0"), $000000)
		Next
		StopDrawing()
	EndIf
	
EndProcedure

Procedure UpdateBinaryGadgetCallback()
	UpdateBinaryGadget(GetGadgetData(EventGadget()), EventType())
EndProcedure


Procedure BinaryGadget(Gadget, X.i, Y.i, Height.i, *Memory)
	
	Protected *BinaryGadget.BinaryGadget = AllocateMemory(SizeOf(BinaryGadget))
	
	If Gadget = #PB_Any
		Gadget = CanvasGadget(#PB_Any, X, Y, 60+16*22, Height, #PB_Canvas_Keyboard)
	Else
		CanvasGadget(Gadget, X, Y, 60+16*22, Height, #PB_Canvas_Keyboard)
	EndIf
	
	With *BinaryGadget
		\Canvas = Gadget
		\ScrollBar = ScrollBarGadget(#PB_Any, X+GadgetWidth(Gadget), Y, 16, Height, 0, 10, 10, #PB_ScrollBar_Vertical)
		\Memory = *Memory
		SetGadgetData(Gadget, *BinaryGadget)
		SetGadgetData(\ScrollBar, *BinaryGadget)
		UpdateBinaryGadget(*BinaryGadget)
		BindGadgetEvent(Gadget, @UpdateBinaryGadgetCallback())
		BindGadgetEvent(\ScrollBar, @UpdateBinaryGadgetCallback())
	EndWith
	
EndProcedure



With BinaryGadgetInclude
	\FontID = FontID(LoadFont(#PB_Any, "Courier New", 10))
	\BackgroundColor = GetSysColor_(#COLOR_3DFACE)
EndWith

Enumeration
	#Window
	#Gadget
	#ScrollBar
EndEnumeration


Define *Memory = AllocateMemory(2048)
RandomData(*Memory, MemorySize(*Memory))

OpenWindow(#Window, 0, 0, 800, 600, "WindowTitle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
BinaryGadget(#Gadget, 10, 10, 580, *Memory)


Repeat
	
	Select WaitWindowEvent()
			
		Case #PB_Event_CloseWindow
			End
			
	EndSelect
	
ForEver

Re: GUI question

Posted: Thu Aug 29, 2013 6:30 am
by davido
@STARGÅTE

Excellent demonstration of Canvas Gadget!
Thank you for sharing. :D

Re: GUI question

Posted: Thu Aug 29, 2013 10:02 am
by doctorized
Thanx a lot both of you!! That's what I needed!!

Re: GUI question

Posted: Fri Aug 30, 2013 12:52 am
by said
STARGÅTE wrote:Here is a small example with the CanvasGadget:

BinaryGadget(#Gadget, X, Y, Height, *Memory) ; shows the *Memory in the Gadget

Lovely done :) thanks for sharing