Your Help with Win32Lib Program

new topic     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_01CF_01C2FE9A.12E39A80
	charset="iso-8859-1"

In anticipation of making my program x-plat (or at least UI customizable),
I've started creating a liaison function ("ccgcm()"), whereby the selected
UI will send user commands to the CCG_CardMaker program. I'm attaching the
program as it currently exists because I know my next few steps will be
critical and I don't want to screw anything up. I want to get all the base
functionality of the program first, then worry about developing a
standard/default interface (like, with the IDE or for FreeBSD).

As you can see from the files, I have CardMaker functions that are accessed
via the "ccgcm" function. So, the UI would do something like this:

    junk = ccgcm( "addCard" , { "Card Name" } }
    if junk[1] then -- success...
        output("Card added.")
    end if

or

    junk = ccgcm( "addAttribute" , { "New Attribute" } }
    if junk[1] then -- success...
        output("Attribute added.")
    end if

or

    list = ccgcm( "commandList" , {} )
    if junk[1] then -- success...
        output(junk[2])
    end if

and receive an errMsg in return (success or fail, with message).

This seems very cumbersome and bloated! But, for the sake of
modularity/customizability, I'm willing to suffer it. Maybe.

I'm building a command_list(), but I don't know that it's the most effecient
way to develop an API (having a function call other functions). And I
suspect that I should be using routine_id() for something! :)

If anybody has any suggestions, please speak up.

Thanks,
ck


------=_NextPart_000_01CF_01C2FE9A.12E39A80
Content-Type: application/octet-stream;
	name="ccg_cardmaker.exw"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ccg_cardmaker.exw"

--  code generated by Win32Lib IDE v0.16.0

=20
-- CCG Card List Creator
-- v0.1.0
-- by cklester

include Win32Lib.ew
without warning

-- this is intro code

include xControls.ew
include eugrid.ew
include ccg_dex.ew

object junk

-- end intro code

-------------------------------------------------------------------------=
-------
--  Window Window1
constant Window1 =3D createEx( Window, "CCG Simulator Deck Designer", 0, =
Default, Default, 475, 480, 0, 0 )
constant menu_file =3D createEx( Menu, "File", Window1, 0, 1, 0, 0, 0, 0 =
)
constant menu_filenewdeck =3D createEx( MenuItem, "New Deck", menu_file, =
0, 2, 0, 0, 0, 0 )
constant menu_fileopen =3D createEx( MenuItem, "Open Deck", menu_file, =
0, 3, 0, 0, 0, 0 )
constant menu_filesave =3D createEx( MenuItem, "Save Deck", menu_file, =
0, 4, 0, 0, 0, 0 )
constant menu_fileexit =3D createEx( MenuItem, "Exit", menu_file, 0, 5, =
0, 0, 0, 0 )
constant cardlist_popup =3D createEx( Popup, "Card List Popup", Window1, =
0, 1, 0, 0, 0, 0 )
constant cardlist_popupedit =3D createEx( MenuItem, "Edit", =
cardlist_popup, 0, 2, 0, 0, 0, 0 )
constant cardlist_popupdelete =3D createEx( MenuItem, "Delete", =
cardlist_popup, 0, 3, 0, 0, 0, 0 )
constant grp_attr =3D createEx( Group, "Card Attributes", Window1, 180, =
40, 276, 364, 0, 0 )
constant bttn_AddAttr =3D createEx( PushButton, "Add", grp_attr, 76, =
332, 60, 24, 0, 0 )
constant bttn_RemoveAttr =3D createEx( PushButton, "Remove", grp_attr, =
144, 332, 60, 24, 0, 0 )
constant grp_cards =3D createEx( Group, "Cards", Window1, 12, 40, 160, =
364, 0, 0 )
constant list_cards =3D createEx( List, "Card List", grp_cards, 8, 20, =
144, 304, 0, 0 )
constant bttn_AddCard =3D createEx( PushButton, "Add", grp_cards, 16, =
332, 60, 24, 0, 0 )
constant bttn_RemoveCard =3D createEx( PushButton, "Remove", grp_cards, =
84, 332, 60, 24, 0, 0 )
---------------------------------------------------------
-------------------------------------------------------------------------=
-------
------------------------
-- begin general code --
------------------------

-- EuGrid controls
constant
	grid1 =3D EGW_CreateGrid( grp_attr, 10, 30, 275, 295, True ),
	grid1col1 =3D EGW_AddColumn(grid1, "Name", 100, EGW_LAST, EGW_EDIT, 1 =
),
	grid1col2 =3D EGW_AddColumn(grid1, "Value", 100, EGW_LAST, EGW_EDIT, 2 =
)
=09
	junk =3D EGW_SetGridProperty(grid1, EGW_ROW_HEADER_WIDTH, 0)
	junk =3D EGW_SetColumnProperty(grid1, grid1col1, EGW_COL_DATATYPE, =
EGW_CHAR )
	junk =3D EGW_SetColumnProperty(grid1, grid1col2, EGW_COL_DATATYPE, =
EGW_CHAR )

-- xControls assignments
constant
--	LSID =3D xControl( LimitSize, "", Window1, 475, 480, 640, 480, 0, 0 =
),
	LSID =3D xControl( LimitSize, "", Window1, 475, 480, 640, 768, 0, 0 ),
	GMID =3D xControl( Geometry, "", Window1, 0, 0, 0, 0, 0, 0 )

	manage( GMID , grp_cards , {0,0}, {0,40}, {0,160}, {1,-5} )
	manage( GMID , bttn_AddCard , {0,5}, {grp_cards,-75} , {bttn_AddCard, =
60}, {bttn_AddCard,24} )
	manage( GMID , bttn_RemoveCard , {bttn_AddCard,15}, =
{grp_cards,-75},{bttn_RemoveCard,60},{bttn_RemoveCard,24} )
	manage( GMID , list_cards , {0,5}, {0,45}, {0,150}, {bttn_AddCard,-5} )
=09
	manage( GMID , grp_attr , {grp_cards,5}, {0,40}, {1,-5}, {1,-5} )
	manage( GMID , bttn_AddAttr , {0,5}, {grp_attr,-75} , {bttn_AddAttr, =
60}, {bttn_AddAttr,24} )
	manage( GMID , bttn_RemoveAttr , {bttn_AddAttr,15} , =
{grp_attr,-75},{bttn_RemoveAttr,60},{bttn_RemoveAttr,24} )
	manage( GMID , grid1 , {0,5}, {0,45}, {1,-180}, {bttn_AddAttr,-5} )

	manage_now( LSID )
	manage_now( GMID )

-- end xControls assignments

-- Other Control event procedures

procedure grid1_w32HResize (integer self, integer event, sequence =
params)--params is ()
sequence gridrect
atom gridwidth, col1

	col1 =3D 0.30
	gridrect =3D getClientRect( grid1 )
	gridwidth =3D gridrect[3] - gridrect[1]
--	junk =3D message_box( sprintf("%d",{gridwidth}) , "Grid Size" , =
MB_OK)
	col1 =3D floor(col1 * gridwidth)
	junk =3D EGW_SetColumnProperty( grid1 , grid1col1 , EGW_COL_WIDTH, col1 =
)
	junk =3D EGW_SetColumnProperty( grid1 , grid1col2 , EGW_COL_WIDTH, =
gridwidth - col1 )
	repaintWindow( grid1 )
end procedure
setHandler( grid1, w32HResize, routine_id("grid1_w32HResize"))

-- end Other Control event procedures

procedure show_card_attributes( object cardnum )
sequence data
sequence card_attr
integer num_cards
	-- show the attributes for card number OR card named
	junk =3D ccgcm({"card_count",""})
	if junk[1] then
		if junk[2] > 0 and getIndex( list_cards ) !=3D 0 then
			if atom(cardnum) then
				-- it's a card number
				card_attr =3D ccgcm({"card", cardnum })
			else
				-- it's a card name
				-- find the name
				-- set card_attr =3D cards[ cardfound ]
			end if
=09
			-- updates the attributes list
			data =3D ccgcm({"get_attribute", 1 })
			if data[1] then
				junk =3D EGW_LoadData( grid1, { { data[2] } }, EGW_REPLACE )			=09
			end if
			for t=3D2 to ccgcm({"attribute_count",""}) do
				junk =3D EGW_LoadData( grid1, { { ccgcm({"get_attribute", t}) } } , =
EGW_LAST )
			end for
		end if	=09
	end if
	repaintWindow( grid1 )
end procedure

procedure update_card_list()
	-- rebuild the card list from the cards sequence
	eraseItems( list_cards )
	junk =3D ccgcm({"card_count",""})
	if junk[1] then
		for t=3D1 to junk[2] do
			addItem( list_cards , ccgcm({"card_data", {t,CARDNAME} } ) )
		end for	=09
	end if
end procedure

------------------------
--  end general code  --
------------------------
-------------------------------------------------------------------------=
-------
procedure menu_filenewdeck_onClick (integer self, integer event, =
sequence params)--params is ()
	junk =3D ccgcm({"delete_all_cards",""})
	junk =3D ccgcm({"delete_all_attributes",""})
	update_card_list()
end procedure
setHandler( menu_filenewdeck, w32HClick, =
routine_id("menu_filenewdeck_onClick"))
-------------------------------------------------------------------------=
-------
procedure menu_filesave_onClick (integer self, integer event, sequence =
params)--params is ()
	-- save this to a EUPH database
end procedure
setHandler( menu_filesave, w32HClick, =
routine_id("menu_filesave_onClick"))
-------------------------------------------------------------------------=
-------
procedure menu_fileexit_onClick (integer self, integer event, sequence =
params)--params is ()
-- make sure everything's saved 'n' all...
	closeWindow ( Window1 )
end procedure
setHandler( menu_fileexit, w32HClick, =
routine_id("menu_fileexit_onClick"))
-------------------------------------------------------------------------=
-------
procedure grp_attr_onClick (integer self, integer event, sequence =
params)--params is ()
=09
end procedure
setHandler( grp_attr, w32HClick, routine_id("grp_attr_onClick"))
-------------------------------------------------------------------------=
-------
procedure list_cards_onClick (integer self, integer event, sequence =
params)--params is ()
	junk =3D ccgcm({"card_count",""})
	if junk[1] then
		if junk[2] > 0 then
			show_card_attributes( getIndex( list_cards ) )	=09
		end if
	end if
end procedure
setHandler( list_cards, w32HClick, routine_id("list_cards_onClick"))
-------------------------------------------------------------------------=
-------
procedure bttn_AddCard_onClick (integer self, integer event, sequence =
params)--params is ()
	junk =3D ccgcm({"addCard","Unnamed Card"})
	update_card_list()
end procedure
setHandler( bttn_AddCard, w32HClick, routine_id("bttn_AddCard_onClick"))
-------------------------------------------------------------------------=
-------
procedure bttn_RemoveCard_onClick (integer self, integer event, sequence =
params)--params is ()
	junk =3D ccgcm({"removeCard",getIndex(list_cards)})
	update_card_list()
	show_card_attributes( 1 )
end procedure
setHandler( bttn_RemoveCard, w32HClick, =
routine_id("bttn_RemoveCard_onClick"))
-------------------------------------------------------------------------=
-------
procedure bttn_AddAttr_onClick (integer self, integer event, sequence =
params)--params is ()
	junk =3D ccgcm({"addAttribute","Unnamed"})
	show_card_attributes( getIndex( list_cards ) )
end procedure
setHandler( bttn_AddAttr, w32HClick, routine_id("bttn_AddAttr_onClick"))
-------------------------------------------------------------------------=
-------
procedure bttn_RemoveAttr_onClick (integer self, integer event, sequence =
params)--params is ()
	junk =3D EGW_GetCurrentCell ( grid1 )
	junk =3D ccgcm({"removeAttribute", junk[1]})
	update_card_list()
	-- select card #1
	setFocus( list_cards )
	show_card_attributes( 1 )
end procedure
setHandler( bttn_RemoveAttr, w32HClick, =
routine_id("bttn_RemoveAttr_onClick"))


WinMain( Window1,Normal )

------=_NextPart_000_01CF_01C2FE9A.12E39A80
Content-Type: application/octet-stream;
	name="ccg_dex.ew"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ccg_dex.ew"

-- ccg_dex.ew
-- Collectible Card Game Deck Maker

sequence cards -- the big list of cards, with CARDNAME as first element
sequence attributes -- attribute names
					-- will serve as a card template for now
sequence command_list -- all available commands

global constant CARDNAME =3D 1

cards =3D {}
attributes =3D {}
command_list =3D {}

--------------------------------------
-- CCG Cardmaker ---------------------
--------------------------------------

procedure add_command( sequence newcommand )
	command_list &=3D newcommand
end procedure

function delete_all_cards()
	cards =3D {}
	return {1,""}
end function

function delete_all_attributes()
	attributes =3D {}
	return {1,""}
end function

function removeCard( atom which )
	cards =3D cards[1..which-1] & cards[which+1..length(cards)]
	return {1,""}
end function
add_command("removeCard")

function addCard( sequence cardname )
sequence newCard
	-- add new record to cards db
	for t=3D1 to length( cards ) do
		if equal( cards[t][CARDNAME] , cardname ) then
			cardname &=3D "1"
		end if
	end for
	--cards =3D append( cards , { { cardname } } )
	newCard =3D repeat({},length(attributes))
	newCard[1] =3D cardname
	cards &=3D { newCard }
	return {1,""}
end function
add_command("addCard")

function addAttribute( sequence attrname )
	attributes =3D append( attributes , attrname )
	-- add this field to all cards
	for t=3D1 to length(cards) do
		cards[t] =3D append( cards[t], "unknown" )
	end for
	return {1,""}
end function
add_command("addAttribute")

function removeAttribute( integer which )
sequence errMsg
	errMsg =3D {1,""}
-- remove attribute #which from list and from cards
	if which > 0 and which <=3D length(attributes) then
		attributes =3D attributes[1..which-1] & =
attributes[which+1..length(attributes)]
		for t=3D1 to length(cards) do
			cards[t] =3D cards[t][1..which-1] & =
cards[t][which+1..length(cards[t])]
		end for
	else
		errMsg =3D {0,"Attribute number out of range for removeAttr()"}
	end if
	return errMsg
end function
add_command("removeAttribute")

function get_all_cards()
	return cards
end function
add_command("get_all_cards")

function card_exists( sequence cardname )
atom ce
	ce =3D (1=3D2)
-- does the cardname already exist?
-- loop through each card
	for t=3D1 to length(cards) do
		if equal(cardname, cards[CARDNAME]) then
			ce =3D (1=3D1)
		end if
	end for
	return ce
end function
add_command("card_exists")

function get_commands()
	return command_list
end function
add_command("get_commands")

function card_count()
	return length(cards)
end function
add_command("card_count")

function attribute_count()
	return length(attributes)
end function
add_command("attribute_count")

function card_data( integer cardnum, integer index )
	if index =3D 0 then
		return cards[cardnum]
	else
		return cards[cardnum][index]
	end if
end function

global function ccgcm( object order )
-- ccgcm is the global function through which all commands are processed
-- sequence order is made of two sequence elements: command, parameters
sequence command, params, errCode

	-- set errCode
	errCode =3D { 0 , "" }
	if not sequence( order ) then
		errCode =3D { 0 , "Order must be a SEQUENCE of two sequences" }
	else
		if length(order) !=3D 2 then
			errCode =3D { 0 , "Order must be sequence of TWO sequences" }
		else
			if not sequence(order[1]) or not sequence(order[2]) then
				errCode =3D { 0 , "Order must be sequence of two SEQUENCES" }
			else
				if find( order[1] , command_list ) =3D 0 then
					errCode =3D { 0 , "Unrecognized command '" & order[1] & "'" }
				end if
			end if
		end if
	end if
=09
	if errCode[1] =3D 1 then -- order is properly formatted
		command =3D order[1]
		params =3D order[2]
		-- verify params are appropriate for command?
		-- process command!
		if 1=3D2 then
			-- if the command is processed, return its errCode
			errCode =3D { 1 , "" }
		end if
	end if
	return errCode
end function

------=_NextPart_000_01CF_01C2FE9A.12E39A80--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu