

Anything better than camvas? I am not a good painter!Josh wrote:I think the best way will be painting all on a canvas gadget
Does anyone know how can I do it in PB?Τ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.
The canvas gadget is very useful for that thing.doctorized wrote:Anything better than camvas? I am not a good painter!
That's very nice STARGÅTESTARGÅTE wrote:The canvas gadget is very useful for that thing.doctorized wrote:Anything better than camvas? I am not a good painter!
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
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.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.
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
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
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
Lovely doneSTARGÅTE wrote:Here is a small example with the CanvasGadget:
BinaryGadget(#Gadget, X, Y, Height, *Memory) ; shows the *Memory in the Gadget