Example #1
0
/* InputPrefsPanel::onBtnDefaults
 * Called when the 'Reset to Default' button is clicked
 *******************************************************************/
void InputPrefsPanel::onBtnDefaults(wxCommandEvent& e)
{
	// Get selected item
	wxTreeListItem item = list_binds->GetSelection();
	BindListItemData* bind = ((BindListItemData*)list_binds->GetItemData(item));

	// Do nothing if it's not a primary keybind
	if (!bind || !(bind->bind))
		return;

	// Remove all child items
	wxTreeListItem child = list_binds->GetFirstChild(item);
	while (child.IsOk())
	{
		list_binds->DeleteItem(child);
		child = list_binds->GetFirstChild(item);
	}

	// Reset primary key to default
	bind->key.key = "";
	if (bind->bind->nDefaults() > 0)
		bind->key = bind->bind->getDefault(0);

	// Go through default keys for the bind
	for (int a = 1; a < bind->bind->nDefaults(); a++)
		wxTreeListItem n = list_binds->AppendItem(item, "", -1, -1, new BindListItemData(bind->bind->getDefault(a)));

	// Refresh list
	updateBindsList();
}
Example #2
0
/* InputPrefsPanel::removeKey
 * Removes the keybind key at [item]
 *******************************************************************/
void InputPrefsPanel::removeKey(wxTreeListItem item)
{
	// Get item keybind info
	BindListItemData* bind = ((BindListItemData*)list_binds->GetItemData(item));

	// Do nothing if item is a group
	if (!bind)
		return;

	// Remove the item if it's not a primary bind
	if (!(bind->bind))
	{
		list_binds->DeleteItem(item);
		return;
	}

	// Clear the primary bind and move all subsequent keys back 1
	bind->key.key = "";
	wxTreeListItem child = list_binds->GetFirstChild(item);
	wxTreeListItem last_child;
	while (child.IsOk())
	{
		last_child = child;
		bind->key = ((BindListItemData*)list_binds->GetItemData(child))->key;
		child = list_binds->GetNextSibling(child);
	}

	// Remove last key if any existed
	if (last_child.IsOk())
		list_binds->DeleteItem(last_child);

	// Refresh list
	updateBindsList();
}
Example #3
0
/* InputPrefsPanel::init
 * Initialises panel controls
 *******************************************************************/
void InputPrefsPanel::init()
{
	updateBindsList();

	// Update list column sizes
	int width = list_binds->GetSize().x / 3;
	list_binds->SetColumnWidth(1, width);
	list_binds->SetColumnWidth(0, width * 1.8);
}
Example #4
0
/* InputPrefsPanel::InputPrefsPanel
 * InputPrefsPanel class constructor
 *******************************************************************/
InputPrefsPanel::InputPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent)
{
	// Create sizer
	wxBoxSizer* psizer = new wxBoxSizer(wxVERTICAL);
	SetSizer(psizer);

	// Create frame+sizer
	wxStaticBox* frame = new wxStaticBox(this, -1, "Input Preferences");
	wxStaticBoxSizer* sizer = new wxStaticBoxSizer(frame, wxVERTICAL);
	psizer->Add(sizer, 1, wxEXPAND|wxALL, 4);

	// Keybinds list
	list_binds = new wxTreeListCtrl(this, -1);
	sizer->Add(list_binds, 1, wxEXPAND|wxALL, 4);

	// Change keybind button
	wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
	psizer->Add(hbox, 0, wxEXPAND|wxALL, 4);
	btn_change = new wxButton(this, -1, "Set Key");
	hbox->Add(btn_change, 0, wxEXPAND|wxRIGHT, 4);
	btn_change->Enable(false);

	// Add keybind button
	btn_add = new wxButton(this, -1, "Add Key");
	hbox->Add(btn_add, 0, wxEXPAND|wxRIGHT, 4);
	btn_add->Enable(false);

	// Remove keybind button
	btn_remove = new wxButton(this, -1, "Remove Key");
	hbox->Add(btn_remove, 0, wxEXPAND|wxRIGHT, 4);
	btn_remove->Enable(false);

	// Default button
	btn_defaults = new wxButton(this, -1, "Reset to Default");
	hbox->Add(btn_defaults, 0, wxEXPAND);
	btn_defaults->Enable(false);

	// Bind events
	//Bind(wxEVT_SIZE, &InputPrefsPanel::onSize, this);
	list_binds->Bind(wxEVT_TREELIST_SELECTION_CHANGED, &InputPrefsPanel::onListSelectionChanged, this);
	list_binds->Bind(wxEVT_TREELIST_ITEM_ACTIVATED, &InputPrefsPanel::onListItemActivated, this);
	//list_binds->Bind(wxEVT_KEY_DOWN, &InputPrefsPanel::onListKeyDown, this);
	btn_change->Bind(wxEVT_BUTTON, &InputPrefsPanel::onBtnChangeKey, this);
	btn_add->Bind(wxEVT_BUTTON, &InputPrefsPanel::onBtnAddKey, this);
	btn_remove->Bind(wxEVT_BUTTON, &InputPrefsPanel::onBtnRemoveKey, this);
	btn_defaults->Bind(wxEVT_BUTTON, &InputPrefsPanel::onBtnDefaults, this);

	Layout();
	initBindsList();
	updateBindsList();
}
/* InputPrefsPanel::init
 * Initialises panel controls
 *******************************************************************/
void InputPrefsPanel::init()
{
	updateBindsList();
}