

#Include "crt/stdlib.bi"
#Include "crt/stdio.bi"
#Include "inc/iup.bi"
#include "inc/iupcontrols.bi"
#Include "inc/iupcd.bi"


Function nlines_cb Cdecl(h As Ihandle Ptr )  as integer
	return 8
End Function

Function ncols_cb Cdecl(h As Ihandle Ptr ) as integer
	return 8
End Function

Function height_cb Cdecl(h As Ihandle Ptr ,i as Integer )  as integer
	return 50
End Function

Function width_cb Cdecl(h As Ihandle Ptr ,j As Integer )  as integer
	Return 50
End Function


Function draw_cb CDECL(h As Ihandle ptr, i As integer, j As integer, xmin As integer, xmax As integer,ymin As integer ,  ymax as integer , canvas As cdCanvas Ptr ) As Integer

	if (((i Mod 2) and (j Mod 2)) or (((i+1) Mod 2) and ((j+1) Mod 2))) Then
		cdCanvasForeground(canvas, CD_WHITE)
	else
		cdCanvasForeground(canvas, CD_BLACK)
	EndIf
	cdCanvasBox(canvas, xmin, xmax, ymin, ymax)

	return IUP_DEFAULT
End Function

Function create() as Ihandle ptr

	Dim As Ihandle Ptr cells = IupCells()

	IupSetCallback(cells, "DRAW_CB", cast(Icallback,@draw_cb))
	IupSetCallback(cells, "WIDTH_CB", cast(Icallback,@width_cb))
	IupSetCallback(cells, "HEIGHT_CB", cast(Icallback,@height_cb))
	IupSetCallback(cells, "NLINES_CB", cast(Icallback,@nlines_cb))
	IupSetCallback(cells, "NCOLS_CB", cast(Icallback,@ncols_cb))

	return cells
End Function


Dim As Ihandle Ptr dlg
Dim As Ihandle Ptr cells

IupOpen(0, 0)
IupControlsOpen()

cells = create()
dlg = IupDialog(cells)

IupSetAttribute(dlg,"RASTERSIZE","440x480")
IupSetAttribute(dlg,"TITLE","IupCells")

IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
IupMainLoop()
IupClose()


