Page 1 of 1

WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Wed Dec 22, 2010 10:46 pm
by Justin
Altough the PB gadget stuff is good for basic things it has some limitations so i started this framework to put some funcionality i need. It can be used with PB windows, to create pure api windows or combined.
Version 0.1.2 freatures:
- control anchoring
- mouse enter / leave events
- command events (control, menu, accelerator)
- accelerators
- easy way of subclassing
- easy api window creation
- modal/modeless dialogs

My goals are keep it compatible with PB, easy to use, flexible and procedural based.

EDIT:
I set up a sourceforge project, the framework is removed from here, it will get too big, i only leave the examples.

Version 0.1.2 adds
- accelerators
- command events

DOWNLOAD:
http://sourceforge.net/projects/wfxframework/files/
The download contains all the examples.

Examples:

Code: Select all

XIncludeFile "wfx.pbi"

;Anchoring and mouse enter/leave demo

enableexplicit

procedure eventcallback(hwid.i, code.i, p1.i, p2.i, param.i)
	select code
		case #WFX_NM_MOUSEENTER
			if hwid=0
				debug "container mouse enter"
			elseif hwid=1
				debug "button 1 mouse enter"
			endif 

		case #WFX_NM_MOUSELEAVE
			if hwid=0
				debug "container mouse leave"
			elseif hwid=1
				debug "button 1 mouse leave"
			endif 
	endselect 
endprocedure 

;- CODE
define.i EventID, state
define.i but, hwpbbut, hwbut, win

win = OpenWindow(#pb_any, 100, 200, 300, 300, "WFX Anchoring", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
wfx_SetUpPBWindow(win)

ContainerGadget(0, 20,20,260,260, #PB_Container_Raised)
wfx_PutFlag(0, #WFX_TRACKMOUSEEVENTS)
wfx_SetAnchor(0, #WFX_ANCHORALL)
wfx_SetCallback(0, @eventcallback())

ButtonGadget(1,0,0,100,30, "Mouse Hover", #WS_CLIPSIBLINGS)
wfx_PutFlag(1, #WFX_TRACKMOUSEEVENTS)
wfx_SetAnchor(1, #WFX_ANCHORLEFT | #WFX_ANCHORTOP)
wfx_SetCallback(1, @eventcallback())

ButtonGadget(2,160 - 6,0,100,30, "Button 2", #WS_CLIPSIBLINGS)
wfx_SetAnchor(2, #WFX_ANCHORRIGHT | #WFX_ANCHORTOP)

ButtonGadget(3, 0,230 - 6,100,30, "Button 3", #WS_CLIPSIBLINGS)
wfx_SetAnchor(3, #WFX_ANCHORLEFT | #WFX_ANCHORBOTTOM)

ButtonGadget(4, 160 - 6,230 - 6,100,30, "Button 3", #WS_CLIPSIBLINGS)
wfx_SetAnchor(4, #WFX_ANCHORRIGHT | #WFX_ANCHORBOTTOM)

Repeat
 	EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow

Another example:

Code: Select all

xincludefile "wfx.pbi"

;WFX API window that uses PB gadgets

enableexplicit

procedure wndproc(hwnd.i, msg.i, wparam.i, lparam.i, param.i)
	define.RECT rc
	define.i but

	select msg
		case #WM_CREATE
			GetClientRect_(hwnd, @rc)
			usegadgetlist(hwnd)
			but = buttongadget(#pb_any, 0, rc\bottom - 20, 80, 20, "Button")
			wfx_SetAnchor(but, #WFX_ANCHORBOTTOM)
			procedurereturn 0

		case #WM_DESTROY
			PostQuitMessage_(0)
			procedurereturn 0

		default : procedurereturn DefWindowProc_(hwnd, msg, wparam, lparam)
	endselect 
endprocedure 

;- CODE
define.i param

param = 10

wfx__OpenWindow(0, "WFX API Window", #WS_OVERLAPPEDWINDOW|#WS_VISIBLE, 10, 10, 300, 200, @wndproc(), param)

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Wed Dec 22, 2010 10:50 pm
by Justin
And the following example shows how to integrate a custom control in the framework,
is basically a one function call:

Code: Select all

xincludefile "wfx.pbi"

structure WFX_BUTTON extends WFX_BASE
	test.i
endstructure 

procedure wfx__Button(exstyle.l, text.s, style.l, x.i, y.i, width.i, height.i, hwparent.i, id.i=0)
	define.i hwnd
	define.WFX_BUTTON *this

	hwnd = CreateWindowEx_(exstyle, "BUTTON", text, style, x, y, width, height, hwparent, id, GetModuleHandle_(0), 0)
	if hwnd
		wfx__SetDefaultFont(hwnd)
		*this = wfx__ExtendWindowObject(hwnd, sizeof(WFX_BUTTON))
		*this\test = 10

		procedurereturn hwnd
	endif
endprocedure 
The button is ready to be used and will support the wfx features.
Now i'll start to make some special controls i need.

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Fri Dec 24, 2010 9:46 pm
by idle
This looks really good thanks.

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Sat Dec 25, 2010 5:21 pm
by Justin
Version 0.1.1 introduces modal/modeless dialogs, it creates empty dialogs and you have to create the controls in the WM_INITDIALOG message, dialogs supports the same wfx features.
Two simple functions:
wfx_DlgOpenModal()
wfx_DlgOpenModeless()

Download link is in the first post.

You still have to use the api procedure to handle control events, i'll add some basic events to make it more PB friendly.
Modal / modeless Example using gadgets:

Code: Select all

;dialogs example

includepath "..\"
includefile "wfxframework.pbi"

enableexplicit

structure MY_APP 
	modelessDlg.i
endstructure

procedure modalDlgProc(hwnd.i, msg.i, wparam.i, lparam.i, *app.MY_APP)
	define.i but3

	select msg
		case #WM_INITDIALOG
			UseGadgetList(hwnd)
			ButtonGadget(3, 0, 10, 100, 30, "Button 3")
			procedurereturn #true

		case #WM_COMMAND
			if wfx__HwndToPbGadgetId(lparam)=3
				debug "button 3 click"
			endif 
			procedurereturn #true

		case #WM_CLOSE
			EndDialog_(hwnd, 1)
			procedurereturn #true

		default : procedurereturn #false
	endselect
endprocedure 

procedure modelessDlgProc(hwnd.i, msg.i, wparam.i, lparam.i, *app.MY_APP)
	select msg
		case #WM_INITDIALOG
			UseGadgetList(hwnd)
			ButtonGadget(4, 0, 10, 100, 30, "Button 4")
			procedurereturn #true

		case #WM_COMMAND
			if wfx__HwndToPbGadgetId(lparam)=4
				debug "button 4 click"
			endif 
			procedurereturn #true

		case #WM_CLOSE
			DestroyWindow_(hwnd)
			*app\modelessDlg = 0
			procedurereturn #true

		default : procedurereturn #false
	endselect
endprocedure 

;- CODE

define.i EventID
define.MY_APP app

OpenWindow(0, 100, 200, 300, 200, "Dialogs", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
wfx_SetUpPBWindow(0)

ButtonGadget(1, 0, 10, 100, 30, "Modal Dialog")
ButtonGadget(2, 200, 10, 100, 30, "Modeless Dialog")

Repeat
 	EventID = WaitWindowEvent()
	select eventid
		Case #PB_Event_Gadget
			Select EventGadget()
				case 1
					wfx_DlgOpenModal(0, #DS_CENTER|#WS_CAPTION|#WS_BORDER|#WS_SYSMENU, 10, 10, 200, 100, "Modal dialog", @modalDlgProc(), @app)

				case 2
					if app\modelessDlg=0 ;Show modeless dialog only if is not already shown
						app\modelessDlg = wfx_DlgOpenModeless(0, #DS_CENTER|#WS_CAPTION|#WS_BORDER|#WS_SYSMENU|#WS_VISIBLE, 10, 10, 200, 100, "Modeless dialog", @modelessDlgProc(), @app)
					endif 
			endselect
	endselect 
Until EventID = #PB_Event_CloseWindow


Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Sun Dec 26, 2010 9:25 pm
by Justin
Version 0.1.2 adds
- accelerators
- command events
- keyboard interface for the top level window

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Sun Dec 26, 2010 11:07 pm
by Zach
What's an "accelerator" ?

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Sun Dec 26, 2010 11:55 pm
by ts-soft
Zach wrote:What's an "accelerator" ?
the same as "AddKeyboardShortcut"

@Justin
thx, looks good :!:

greetings - Thomas

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Mon Dec 27, 2010 1:17 am
by Zach
Oh.. so it basically ties a Hotkey to a GUI control, then? Like hitting ALT + F to bring up a file menu or whatever.

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Mon Dec 27, 2010 6:28 am
by electrochrisso
Been having a bit of a play with your Framework and it is 8)
Thanks and Keep up the good work. :)

Re: WFX - A Flat GUI Framework (anchoring, events.. WIN)

Posted: Sat Jan 01, 2011 10:57 pm
by Zach
Been having this question bug me for the past few days..

Google wasn't much help for some reason, but I'm wondering what a "Flat GUI" is, as compared to other GUI's ?