Merge pull request #2803 from lioncash/fp
CheatSearchTab: Show floating point value equivalent
This commit is contained in:
commit
f79855ab46
|
@ -3,9 +3,10 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
#include <wx/button.h>
|
#include <wx/button.h>
|
||||||
#include <wx/choice.h>
|
#include <wx/choice.h>
|
||||||
#include <wx/listbox.h>
|
#include <wx/listctrl.h>
|
||||||
#include <wx/panel.h>
|
#include <wx/panel.h>
|
||||||
#include <wx/radiobox.h>
|
#include <wx/radiobox.h>
|
||||||
#include <wx/radiobut.h>
|
#include <wx/radiobut.h>
|
||||||
|
@ -44,11 +45,9 @@ CheatSearchTab::CheatSearchTab(wxWindow* const parent)
|
||||||
std::array<wxString, 3> data_size_names = { { _("8-bit"), _("16-bit"), _("32-bit") } };
|
std::array<wxString, 3> data_size_names = { { _("8-bit"), _("16-bit"), _("32-bit") } };
|
||||||
m_data_sizes = new wxRadioBox(this, wxID_ANY, _("Data Size"), wxDefaultPosition, wxDefaultSize, static_cast<int>(data_size_names.size()), data_size_names.data());
|
m_data_sizes = new wxRadioBox(this, wxID_ANY, _("Data Size"), wxDefaultPosition, wxDefaultSize, static_cast<int>(data_size_names.size()), data_size_names.data());
|
||||||
|
|
||||||
// Listbox for search results (shown in monospace font).
|
// ListView for search results
|
||||||
m_lbox_search_results = new wxListBox(this, wxID_ANY);
|
m_lview_search_results = new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
|
||||||
wxFont list_font = m_lbox_search_results->GetFont();
|
ResetListViewColumns();
|
||||||
list_font.SetFamily(wxFONTFAMILY_TELETYPE);
|
|
||||||
m_lbox_search_results->SetFont(list_font);
|
|
||||||
|
|
||||||
// Result count
|
// Result count
|
||||||
m_label_results_count = new wxStaticText(this, wxID_ANY, _("Count:"));
|
m_label_results_count = new wxStaticText(this, wxID_ANY, _("Count:"));
|
||||||
|
@ -60,7 +59,7 @@ CheatSearchTab::CheatSearchTab(wxWindow* const parent)
|
||||||
// results groupbox
|
// results groupbox
|
||||||
wxStaticBoxSizer* const sizer_cheat_search_results = new wxStaticBoxSizer(wxVERTICAL, this, _("Results"));
|
wxStaticBoxSizer* const sizer_cheat_search_results = new wxStaticBoxSizer(wxVERTICAL, this, _("Results"));
|
||||||
sizer_cheat_search_results->Add(m_label_results_count, 0, wxALIGN_LEFT | wxALL, 5);
|
sizer_cheat_search_results->Add(m_label_results_count, 0, wxALIGN_LEFT | wxALL, 5);
|
||||||
sizer_cheat_search_results->Add(m_lbox_search_results, 1, wxEXPAND | wxALL, 5);
|
sizer_cheat_search_results->Add(m_lview_search_results, 1, wxEXPAND | wxALL, 5);
|
||||||
sizer_cheat_search_results->Add(button_cheat_search_copy_address, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5);
|
sizer_cheat_search_results->Add(button_cheat_search_copy_address, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5);
|
||||||
|
|
||||||
// Search value radio buttons
|
// Search value radio buttons
|
||||||
|
@ -154,7 +153,6 @@ void CheatSearchTab::StartNewSearch(wxCommandEvent& WXUNUSED(event))
|
||||||
UpdateCheatSearchResultsList();
|
UpdateCheatSearchResultsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CheatSearchTab::FilterCheatSearchResults(wxCommandEvent&)
|
void CheatSearchTab::FilterCheatSearchResults(wxCommandEvent&)
|
||||||
{
|
{
|
||||||
const u8* const memptr = Memory::m_pRAM;
|
const u8* const memptr = Memory::m_pRAM;
|
||||||
|
@ -261,7 +259,8 @@ void CheatSearchTab::ApplyFocus(wxFocusEvent& ev)
|
||||||
|
|
||||||
void CheatSearchTab::UpdateCheatSearchResultsList()
|
void CheatSearchTab::UpdateCheatSearchResultsList()
|
||||||
{
|
{
|
||||||
m_lbox_search_results->Clear();
|
m_lview_search_results->ClearAll();
|
||||||
|
ResetListViewColumns();
|
||||||
|
|
||||||
wxString count_label = wxString::Format(_("Count: %lu"),
|
wxString count_label = wxString::Format(_("Count: %lu"),
|
||||||
(unsigned long)m_search_results.size());
|
(unsigned long)m_search_results.size());
|
||||||
|
@ -271,11 +270,12 @@ void CheatSearchTab::UpdateCheatSearchResultsList()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (const CheatSearchResult& result : m_search_results)
|
m_lview_search_results->Freeze();
|
||||||
{
|
|
||||||
u32 display_value = result.old_value;
|
for (size_t i = 0; i < m_search_results.size(); i++)
|
||||||
|
{
|
||||||
|
u32 display_value = m_search_results[i].old_value;
|
||||||
|
|
||||||
// #ifdef LIL_ENDIAN :p
|
|
||||||
switch (m_search_type_size)
|
switch (m_search_type_size)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -287,14 +287,27 @@ void CheatSearchTab::UpdateCheatSearchResultsList()
|
||||||
display_value = Common::swap32(display_value);
|
display_value = Common::swap32(display_value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// #elseif BIG_ENDIAN
|
|
||||||
// need to do some stuff in here (for 8 and 16bit) for bigendian
|
|
||||||
// #endif
|
|
||||||
std::string rowfmt = StringFromFormat("0x%%08X 0x%%0%uX %%u/%%i", m_search_type_size*2);
|
|
||||||
|
|
||||||
m_lbox_search_results->Append(
|
// Insert into the list control.
|
||||||
wxString::Format(rowfmt.c_str(), result.address, display_value, display_value, display_value));
|
wxString buf;
|
||||||
|
buf.Printf("0x%08X", m_search_results[i].address);
|
||||||
|
long index = m_lview_search_results->InsertItem(static_cast<long>(i), buf);
|
||||||
|
|
||||||
|
buf.Printf("0x%08X", display_value);
|
||||||
|
m_lview_search_results->SetItem(index, 1, buf);
|
||||||
|
|
||||||
|
float display_value_float = 0.0f;
|
||||||
|
std::memcpy(&display_value_float, &display_value, sizeof(u32));
|
||||||
|
buf.Printf("%e", display_value_float);
|
||||||
|
m_lview_search_results->SetItem(index, 2, buf);
|
||||||
|
|
||||||
|
double display_value_double = 0.0;
|
||||||
|
std::memcpy(&display_value_double, &display_value, sizeof(u32));
|
||||||
|
buf.Printf("%e", display_value_double);
|
||||||
|
m_lview_search_results->SetItem(index, 3, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_lview_search_results->Thaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_label_results_count->SetLabel(count_label);
|
m_label_results_count->SetLabel(count_label);
|
||||||
|
@ -302,13 +315,22 @@ void CheatSearchTab::UpdateCheatSearchResultsList()
|
||||||
|
|
||||||
void CheatSearchTab::CreateARCode(wxCommandEvent&)
|
void CheatSearchTab::CreateARCode(wxCommandEvent&)
|
||||||
{
|
{
|
||||||
const int sel = m_lbox_search_results->GetSelection();
|
long idx = m_lview_search_results->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||||
if (sel >= 0)
|
|
||||||
|
if (idx != wxNOT_FOUND)
|
||||||
{
|
{
|
||||||
const u32 address = m_search_results[sel].address | ((m_search_type_size & ~1) << 24);
|
const u32 address = m_search_results[idx].address | ((m_search_type_size & ~1) << 24);
|
||||||
|
|
||||||
CreateCodeDialog arcode_dlg(this, address, ActionReplay::GetARCodes());
|
CreateCodeDialog arcode_dlg(this, address, ActionReplay::GetARCodes());
|
||||||
arcode_dlg.SetExtraStyle(arcode_dlg.GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS);
|
arcode_dlg.SetExtraStyle(arcode_dlg.GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS);
|
||||||
arcode_dlg.ShowModal();
|
arcode_dlg.ShowModal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheatSearchTab::ResetListViewColumns()
|
||||||
|
{
|
||||||
|
m_lview_search_results->AppendColumn(_("Address"));
|
||||||
|
m_lview_search_results->AppendColumn(_("Value"));
|
||||||
|
m_lview_search_results->AppendColumn(_("Value (float)"));
|
||||||
|
m_lview_search_results->AppendColumn(_("Value (double)"));
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
class wxButton;
|
class wxButton;
|
||||||
class wxChoice;
|
class wxChoice;
|
||||||
class wxFocusEvent;
|
class wxFocusEvent;
|
||||||
class wxListBox;
|
class wxListView;
|
||||||
class wxRadioBox;
|
class wxRadioBox;
|
||||||
class wxRadioButton;
|
class wxRadioButton;
|
||||||
class wxStaticText;
|
class wxStaticText;
|
||||||
|
@ -31,11 +31,18 @@ private:
|
||||||
u32 old_value;
|
u32 old_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void UpdateCheatSearchResultsList();
|
||||||
|
void ResetListViewColumns();
|
||||||
|
void StartNewSearch(wxCommandEvent& event);
|
||||||
|
void FilterCheatSearchResults(wxCommandEvent& event);
|
||||||
|
void CreateARCode(wxCommandEvent&);
|
||||||
|
void ApplyFocus(wxFocusEvent&);
|
||||||
|
|
||||||
std::vector<CheatSearchResult> m_search_results;
|
std::vector<CheatSearchResult> m_search_results;
|
||||||
unsigned int m_search_type_size;
|
unsigned int m_search_type_size;
|
||||||
|
|
||||||
wxChoice* m_search_type;
|
wxChoice* m_search_type;
|
||||||
wxListBox* m_lbox_search_results;
|
wxListView* m_lview_search_results;
|
||||||
wxStaticText* m_label_results_count;
|
wxStaticText* m_label_results_count;
|
||||||
wxTextCtrl* m_textctrl_value_x;
|
wxTextCtrl* m_textctrl_value_x;
|
||||||
|
|
||||||
|
@ -49,10 +56,4 @@ private:
|
||||||
wxRadioButton* rad_oldvalue;
|
wxRadioButton* rad_oldvalue;
|
||||||
wxRadioButton* rad_uservalue;
|
wxRadioButton* rad_uservalue;
|
||||||
} m_value_x_radiobtn;
|
} m_value_x_radiobtn;
|
||||||
|
|
||||||
void UpdateCheatSearchResultsList();
|
|
||||||
void StartNewSearch(wxCommandEvent& event);
|
|
||||||
void FilterCheatSearchResults(wxCommandEvent& event);
|
|
||||||
void CreateARCode(wxCommandEvent&);
|
|
||||||
void ApplyFocus(wxFocusEvent&);
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue