Skip to content

EmuBitfield

Michael edited this page Jul 3, 2021 · 2 revisions

A bitfield is a series of on / off switches, each of which affect a different bit in an integer value. These are commonly used to visually represent a flag such as a collision mask, although in many cases a series of checkboxes would work just as well.

Note: I recommend having a strong understanding of binary numbers and bit fields ("flags") before manually creating and manipulating Emu's bitfield-related elements.

Constructor

Inheritance: EmuCore / EmuCallback

EmuBitfield(x, y, width, height, value, callback)
Parameter Type Description
x real The x coordinate where the bitfield will be created
y real The y coordinate where the bitfield will be created
w real The width of the bitfield
h real The height of the bitfield
value real The initial value of the bitfield
callback function The callback that will be invoked when the value of the bitfield is changed

Relevant Methods

EmuBitfield::SetOrientation(orientation)

Returns: N/A

Parameter Type Description
orientation E_BitfieldOrientations Whether you want the bitfield to be oriented horizontally or vertically

Use this to set the orientation of the bitfield. Bitfields may be oriented horizontally (columns) or vertically (rows).

By default, bitfields are oriented horizontally.

EmuBitfield::AddOptions(elements)

Returns: self

Parameter Type Description
elements string or EmuBitfieldOption The elements you wish to add to the bitfield

As with EmuCore::AddContents, there are several ways you may add options to a bitfield. If you provide a single string or EmuBitfieldOption, it will be added by itself whereas an array of strings, EmuBitfieldOptions or a combination of the two will add each option in a row.

If you specify one or more EmuBitfieldOptions, they will be added on their own. If you specify one or more strings, they will be automatically turned into EmuBitfieldOptions.

EmuBitfield::SetFixedSpacing(spacing)

Returns: self

Parameter Type Description
spacing real The fixed spacing for each of the field buttons in the bitfield

Use this to define fixed spacing for each of the field buttons in the bitfield. If fixed spacing is enabled, each of the field buttons will be the same size and the width or height (depending on the orientation) of the bitfield will expand to accommodate, outside the bounds of the element if necessary.

EmuBitfield::SetAutoSpacing()

Returns: self

Use this to define automatic spacing for each of the field buttons in the bitfield. If automatic spacing is enabled, the width or height of the field buttons (depending on the orientation) will expand or contract to fill the bounds of the element.

Example

var bitfield = new EmuBitfield(352, 16, 256, 256, 41, function() {
});
bitfield.SetFixedSpacing(32);
bitfield.AddOptions([
    "My", "Very", "Earnest", "Mother", "Just", "Served", "Us", "Nine",
    new EmuBitfieldOption("all", 0xffffffff, emu_bitfield_option_all_callback, emu_bitfield_option_all_eval),
    new EmuBitfieldOption("none", 0, emu_bitfield_option_none_callback, emu_bitfield_option_none_eval),
]);
bitfield.SetOrientation(E_BitfieldOrientations.VERTICAL);

container.AddContent(bitfield);

This will create an EmuBitfield element and adds it to a previously defined container.

Clone this wiki locally