
GUI_BUTTON_CLASS db GUI_BUTTON_CLASS_NAME, 0
GUI_BUTTON_PROC equ GUI.Button.Proc

;; GUI.Button widget procedure
; @param e is one of CORE.Event family objects
; @returns 0 or error code
;;
proc GUI.Button.Proc obj:DWORD, e:DWORD
	push	ebx
	mov	ebx, [e]
	mov	eax, [ebx + CORE.Event.type]
	cmp	eax, CORE_EVENT_PAINT
	je	.paint_event
	xor	eax, eax
	inc	eax

  .exit:
	pop	ebx
	ret

  .paint_event:
	mov	ebx, [ebx + CORE.Event.Paint.gc]
	invoke	gfx_pen_color, ebx, 0x000000
	invoke	gfx_brush_color, ebx, 0xffffff
	mov	eax, [obj]
	invoke	gfx_rectangle, ebx, 0, 0, [eax + CORE.Widget.rect.width], [eax + CORE.Widget.rect.height]
	mov	eax, [obj]
	mov	eax, [eax + GUI.Button.text]
	invoke	gfx_text, ebx, [eax + CORE.String.text], [eax + CORE.String.length], 2, 2
	xor	eax, eax
	jmp	.exit
endp

proc GUI.Button.Create width:DWORD, height:DWORD, text:DWORD
	invoke	mem_alloc, sizeof.GUI.Button
	stdcall GUI.Button.Init, eax, [width], [height], [text]
	ret
endp

proc GUI.Button.Init obj:DWORD, width:DWORD, height:DWORD, text:DWORD
	push	ebx
	mov	ebx, [obj]
	push	[width]
	pop	[ebx + CORE.Widget.rect.width]
	push	[height]
	pop	[ebx + CORE.Widget.rect.height]
	stdcall CORE.String.Create, [text]
	mov	[ebx + GUI.Button.text], eax
	mov	eax, ebx
	pop	ebx
	ret
endp

proc GUI.Button.Destroy obj:DWORD
	mov	eax, [obj]
	stdcall CORE.String.Destroy, [eax + GUI.Button.text]
	invoke	mem_free, [obj]
	ret
endp

proc GUI.Button.GetText obj:DWORD, text:DWORD
	ret
endp

proc GUI.Button.SetText obj:DWORD, text:DWORD
	ret
endp
