Microsoft Small Basic

Program Listing: TGS200-0
' SmallBasic Version 1.2
' Program: DataView-ColorMatrix
' Changelog:
' Author: Pappa Lapub
' Website: https://social.msdn.microsoft.com/Forums/en-US/2ad180a9-e5a0-42f4-a61c-02a9bc893f26/about-dataview-control
' ImportURL: http://smallbasic.com/program/?TGS200-0
' SBOnline: http://smallbasic-publicwebsite-dev.azurewebsites.net/Program/view.aspx?
' Extension: LitDev
' Comment:
'
' Variables:
' ToDo:
' ==============================================================================
'pic = "image path here"
pic = "https://pngimg.com/uploads/butterfly/butterfly_PNG1041.png"
img = ImageList.LoadImage(pic)
LDImage.To32bitARGB(img)
orig = LDImage.Copy(img)
nRow = 5

Identity()
rowCols = LDText.Split("Red,Lime,Blue,White,Gray", ",")

GraphicsWindow.Top = 0
LDGraphicsWindow.BackgroundBrush(LDShapes.BrushGradient("1=Black;2=#D2D3D4;","V"))
GraphicsWindow.FontBold = ""
GraphicsWindow.FontSize = 11

dv = LDControls.AddDataView(214,135, LDText.Split("R,G,B,A,W", ","))
LDControls.DataViewAllowUserEntry(dv, "") ' NO bottom row
LDControls.DataViewAllowSort(dv, "") ' NO col sorting
LDControls.DataViewColumnWidths(dv, LDText.Split("30,30,30,30,30", ","))

SetData()
For r = 1 To nRow
LDControls.DataViewRowColours(dv, r, rowCols[r],"Black")
EndFor

shp = Shapes.AddImage(img)
Shapes.Move(shp, 220,10)


LDControls.DataViewCellValueChanged = OnDataChange


' ////////// SUBs \\\\\\\\\\
Sub Identity
cm[1] = LDText.Split("1,0,0,0,0", ",")
cm[2] = LDText.Split("0,1,0,0,0", ",")
cm[3] = LDText.Split("0,0,1,0,0", ",")
cm[4] = LDText.Split("0,0,0,1,0", ",")
cm[5] = LDText.Split("0,0,0,0,1", ",")
EndSub

Sub SetData
For r = 1 To nRow
LDControls.DataViewSetRow(dv, r, cm[r])
EndFor
EndSub


' ////////// EVENTs \\\\\\\\\\
Sub OnDataChange
cell = LDControls.LastDataViewCellValueChanged
cm[cell[1]][cell[2]] = cell[3]
img = LDImage.Copy(orig)
LDImage.ColorMatrix(img, cm)
LDShapes.SetImage(shp, img)
EndSub