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

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

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

Post 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)
Last edited by Justin on Sun Dec 26, 2010 9:19 pm, edited 2 times in total.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

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

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 5897
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

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

Post by idle »

This looks really good thanks.
Windows 11, Manjaro, Raspberry Pi OS
Image
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

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

Post 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

Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

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

Post by Justin »

Version 0.1.2 adds
- accelerators
- command events
- keyboard interface for the top level window
Zach
Addict
Addict
Posts: 1676
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

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

Post by Zach »

What's an "accelerator" ?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post by ts-soft »

Zach wrote:What's an "accelerator" ?
the same as "AddKeyboardShortcut"

@Justin
thx, looks good :!:

greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Zach
Addict
Addict
Posts: 1676
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

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

Post 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.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

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

Post by electrochrisso »

Been having a bit of a play with your Framework and it is 8)
Thanks and Keep up the good work. :)
PureBasic! Purely the best 8)
Zach
Addict
Addict
Posts: 1676
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

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

Post 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 ?
Post Reply