iup example cleanup
This commit is contained in:
parent
94e212df3e
commit
cb9117cdf6
|
@ -1,9 +1,49 @@
|
||||||
require('auxlib');
|
-- super mario bros 1 hitbox script
|
||||||
|
-- iup example
|
||||||
|
-- this shows a test window with all kinds of idle dialogs
|
||||||
|
|
||||||
|
-- we need iup, so include it here
|
||||||
|
local iuplua_open = package.loadlib("iuplua51.dll", "iuplua_open");
|
||||||
|
iuplua_open();
|
||||||
|
-- we also need the "special controls" of iup (dont change the order though)
|
||||||
|
local iupcontrolslua_open = package.loadlib("iupluacontrols51.dll", "iupcontrolslua_open");
|
||||||
|
iupcontrolslua_open();
|
||||||
|
|
||||||
|
-- callback function to clean up our mess
|
||||||
|
-- this is called when the script exits (forced or natural)
|
||||||
|
-- you need to close all the open dialogs here or FCEUX crashes
|
||||||
|
function emu.OnClose.iuplua()
|
||||||
|
-- gui.popup("OnClose!");
|
||||||
|
if(emu and emu.OnCloseIup ~= nil) then
|
||||||
|
emu.OnCloseIup();
|
||||||
|
end
|
||||||
|
iup.Close(); -- close the iup system
|
||||||
|
end
|
||||||
|
|
||||||
|
-- this system allows you to open a number of dialogs without
|
||||||
|
-- having to bother about cleanup when the script exits
|
||||||
|
local handles = {}; -- this table should hold the handle to all dialogs created in lua
|
||||||
|
local dialogs = 0; -- should be incremented PRIOR to creating a new dialog
|
||||||
|
-- called by the onclose event (above)
|
||||||
|
function emu.OnCloseIup()
|
||||||
|
if (handles) then -- just in case the user was "smart" enough to clear this
|
||||||
|
local i = 1;
|
||||||
|
while (handles[i] ~= nil) do -- cycle through all handles, false handles are skipped, nil denotes the end
|
||||||
|
if (handles[i] and handles[i].destroy) then -- check for the existence of what we need
|
||||||
|
handles[i]:destroy(); -- close this dialog (close() just hides it)
|
||||||
|
handles[i] = nil;
|
||||||
|
end;
|
||||||
|
i = i + 1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
-- Note that in the following example, parentheses are optional if you
|
||||||
|
-- are specifying tables with curly braces! Might look a little confusing.
|
||||||
function testiup()
|
function testiup()
|
||||||
|
local img1 =
|
||||||
img1 = iup.image
|
iup.image{
|
||||||
{
|
|
||||||
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
|
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
|
||||||
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1},
|
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1},
|
||||||
{1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1},
|
{1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1},
|
||||||
|
@ -35,17 +75,17 @@ function testiup()
|
||||||
{1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
|
{1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
|
||||||
{1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
|
{1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
|
||||||
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
|
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
|
||||||
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
|
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; -- note that this ; is NOT the end of the command but a mere seperator, equivalent to a comma (,)
|
||||||
colors =
|
colors =
|
||||||
{
|
{
|
||||||
"BGCOLOR", -- 1
|
"BGCOLOR", -- 1
|
||||||
"255 0 0", -- 2
|
"255 0 0", -- 2
|
||||||
"0 0 0" -- 3 (changed because of Lua index starts at 1)
|
"0 0 0" -- 3 (changed because of Lua index starts at 1)
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
img2 = iup.image
|
local img2 =
|
||||||
{
|
iup.image{
|
||||||
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2},
|
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2},
|
||||||
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2},
|
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2},
|
||||||
{2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2},
|
{2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2},
|
||||||
|
@ -77,7 +117,7 @@ function testiup()
|
||||||
{2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
|
{2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
|
||||||
{2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
|
{2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
|
||||||
{2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
|
{2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
|
||||||
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};
|
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}; -- note that this ; is NOT the end of the command but a mere seperator, equivalent to a comma (,)
|
||||||
colors =
|
colors =
|
||||||
{
|
{
|
||||||
"0 255 0", -- 1
|
"0 255 0", -- 1
|
||||||
|
@ -85,105 +125,100 @@ function testiup()
|
||||||
"255 0 0", -- 3
|
"255 0 0", -- 3
|
||||||
"0 0 0" -- 4
|
"0 0 0" -- 4
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
mnu = iup.menu
|
mnu = iup.menu{
|
||||||
{
|
iup.submenu{
|
||||||
iup.submenu
|
title="IupSubMenu 1",
|
||||||
{
|
iup.menu {
|
||||||
iup.menu
|
|
||||||
{
|
|
||||||
iup.item{title="IupItem 1 Checked",value="ON"},
|
iup.item{title="IupItem 1 Checked",value="ON"},
|
||||||
iup.separator{},
|
iup.separator{},
|
||||||
iup.item{title="IupItem 2 Disabled",active="NO"}
|
iup.item{title="IupItem 2 Disabled",active="NO"}
|
||||||
}
|
}
|
||||||
;title="IupSubMenu 1"
|
|
||||||
},
|
},
|
||||||
iup.item{title="IupItem 3"},
|
iup.item{title="IupItem 3"},
|
||||||
iup.item{title="IupItem 4"}
|
iup.item{title="IupItem 4"}
|
||||||
}
|
};
|
||||||
|
|
||||||
dlg = iup.dialog
|
btn = iup.button{title="Press me!"};
|
||||||
{
|
-- set the callback function, action
|
||||||
iup.vbox
|
-- when the user clicks on the button, this function is executed
|
||||||
{
|
-- and in this case, it fires a silly popup message
|
||||||
iup.hbox
|
btn.action =
|
||||||
{
|
function (self)
|
||||||
iup.frame
|
iup.Message("Why","Why oh why did you press me?");
|
||||||
{
|
end;
|
||||||
iup.vbox
|
|
||||||
{
|
dialogs = dialogs + 1; -- there is no ++ in Lua
|
||||||
iup.button{title="Button Text"},
|
handles[dialogs] =
|
||||||
|
iup.dialog{
|
||||||
|
title="IupDialog Title",
|
||||||
|
menu=mnu, -- add the menu in the table
|
||||||
|
iup.vbox{
|
||||||
|
iup.hbox{
|
||||||
|
iup.frame{
|
||||||
|
title="IupButton",
|
||||||
|
iup.vbox{
|
||||||
|
btn, -- add the button
|
||||||
iup.button{title="",image=img1},
|
iup.button{title="",image=img1},
|
||||||
iup.button{title="",image=img1,impress=img2}
|
iup.button{title="",image=img1,impress=img2}
|
||||||
}
|
}
|
||||||
;title="IupButton"
|
|
||||||
},
|
},
|
||||||
iup.frame
|
iup.frame{
|
||||||
{
|
title="IupLabel",
|
||||||
iup.vbox
|
iup.vbox{
|
||||||
{
|
|
||||||
iup.label{title="Label Text"},
|
iup.label{title="Label Text"},
|
||||||
iup.label{title="",separator="HORIZONTAL"},
|
iup.label{title="",separator="HORIZONTAL"},
|
||||||
iup.label{title="",image=img1}
|
iup.label{title="",image=img1}
|
||||||
}
|
}
|
||||||
;title="IupLabel"
|
|
||||||
},
|
},
|
||||||
iup.frame
|
iup.frame{
|
||||||
{
|
title="IupToggle",
|
||||||
iup.vbox
|
iup.vbox{
|
||||||
{
|
|
||||||
iup.toggle{title="Toggle Text", value="ON"},
|
iup.toggle{title="Toggle Text", value="ON"},
|
||||||
iup.toggle{title="",image=img1,impress=img2},
|
iup.toggle{title="",image=img1,impress=img2},
|
||||||
iup.frame
|
iup.frame{
|
||||||
{
|
title="IupRadio",
|
||||||
iup.radio
|
iup.radio{
|
||||||
{
|
iup.vbox{
|
||||||
iup.vbox
|
|
||||||
{
|
|
||||||
iup.toggle{title="Toggle Text"},
|
iup.toggle{title="Toggle Text"},
|
||||||
iup.toggle{title="Toggle Text"}
|
iup.toggle{title="Toggle Text"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;title="IupRadio"
|
} -- /frame
|
||||||
}
|
} -- /vbox
|
||||||
}
|
|
||||||
;title="IupToggle"
|
|
||||||
},
|
},
|
||||||
iup.frame
|
iup.frame{
|
||||||
{
|
title="IupText/IupMultiline",
|
||||||
iup.vbox
|
iup.vbox{
|
||||||
{
|
|
||||||
iup.text{size="80x",value="IupText Text"},
|
iup.text{size="80x",value="IupText Text"},
|
||||||
iup.multiline{size="80x60",expand="YES",value="IupMultiline Text\nSecond Line\nThird Line"}
|
iup.multiline{size="80x60",
|
||||||
|
expand="YES",
|
||||||
|
value="IupMultiline Text\nSecond Line\nThird Line"}
|
||||||
}
|
}
|
||||||
;title="IupText/IupMultiline"
|
|
||||||
},
|
},
|
||||||
iup.frame
|
iup.frame{
|
||||||
{
|
title="IupList",
|
||||||
iup.vbox
|
iup.vbox{
|
||||||
{
|
|
||||||
iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; expand="YES",value="1"},
|
iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; expand="YES",value="1"},
|
||||||
iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; dropdown="YES",expand="YES",value="2"},
|
iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; dropdown="YES",expand="YES",value="2"},
|
||||||
iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; editbox="YES",expand="YES",value="3"}
|
iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; editbox="YES",expand="YES",value="3"}
|
||||||
}
|
}
|
||||||
;title="IupList"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
iup.canvas{bgcolor="128 255 0"}
|
|
||||||
;gap="5",alignment="ARIGHT",margin="5x5"
|
|
||||||
}
|
|
||||||
;title="IupDialog Title", menu=mnu
|
|
||||||
}
|
}
|
||||||
|
}, -- /hbox
|
||||||
|
iup.canvas{bgcolor="128 255 0"},
|
||||||
|
gap="5",
|
||||||
|
alignment="ARIGHT",
|
||||||
|
margin="5x5"
|
||||||
|
} -- /vbox
|
||||||
|
};
|
||||||
|
|
||||||
dlg:show()
|
handles[dialogs]:show(); -- this actually shows you the dialog. Note that this is equivalent to calling handles[dialogs].show(handles[dialogs]); just shorter.
|
||||||
|
end;
|
||||||
end
|
|
||||||
|
testiup(); -- note that this is NOT called from WITHIN the loop!
|
||||||
testiup();
|
|
||||||
|
-- once the loop quits, the script exits and all dialogs are automatically destroyed by the onclose event
|
||||||
while (true) do
|
while (true) do
|
||||||
|
FCEU.frameadvance();
|
||||||
FCEU.frameadvance();
|
|
||||||
|
|
||||||
end;
|
end;
|
Loading…
Reference in New Issue