Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheatSearchTab: Show floating point value equivalent #2803

Merged
merged 2 commits into from
Aug 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 43 additions & 21 deletions Source/Core/DolphinWX/Cheats/CheatSearchTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// Refer to the license.txt file included.

#include <array>
#include <cstring>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/listbox.h>
#include <wx/listctrl.h>
#include <wx/panel.h>
#include <wx/radiobox.h>
#include <wx/radiobut.h>
Expand Down Expand Up @@ -44,11 +45,9 @@ CheatSearchTab::CheatSearchTab(wxWindow* const parent)
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());

// Listbox for search results (shown in monospace font).
m_lbox_search_results = new wxListBox(this, wxID_ANY);
wxFont list_font = m_lbox_search_results->GetFont();
list_font.SetFamily(wxFONTFAMILY_TELETYPE);
m_lbox_search_results->SetFont(list_font);
// ListView for search results
m_lview_search_results = new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
ResetListViewColumns();

// Result count
m_label_results_count = new wxStaticText(this, wxID_ANY, _("Count:"));
Expand All @@ -60,7 +59,7 @@ CheatSearchTab::CheatSearchTab(wxWindow* const parent)
// results groupbox
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_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);

// Search value radio buttons
Expand Down Expand Up @@ -154,7 +153,6 @@ void CheatSearchTab::StartNewSearch(wxCommandEvent& WXUNUSED(event))
UpdateCheatSearchResultsList();
}


void CheatSearchTab::FilterCheatSearchResults(wxCommandEvent&)
{
const u8* const memptr = Memory::m_pRAM;
Expand Down Expand Up @@ -261,7 +259,8 @@ void CheatSearchTab::ApplyFocus(wxFocusEvent& ev)

void CheatSearchTab::UpdateCheatSearchResultsList()
{
m_lbox_search_results->Clear();
m_lview_search_results->ClearAll();
ResetListViewColumns();

wxString count_label = wxString::Format(_("Count: %lu"),
(unsigned long)m_search_results.size());
Expand All @@ -271,11 +270,12 @@ void CheatSearchTab::UpdateCheatSearchResultsList()
}
else
{
for (const CheatSearchResult& result : m_search_results)
m_lview_search_results->Freeze();

for (size_t i = 0; i < m_search_results.size(); i++)
{
u32 display_value = result.old_value;
u32 display_value = m_search_results[i].old_value;

// #ifdef LIL_ENDIAN :p
switch (m_search_type_size)
{
case 1:
Expand All @@ -287,28 +287,50 @@ void CheatSearchTab::UpdateCheatSearchResultsList()
display_value = Common::swap32(display_value);
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(
wxString::Format(rowfmt.c_str(), result.address, display_value, display_value, display_value));
// Insert into the list control.
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);
}

void CheatSearchTab::CreateARCode(wxCommandEvent&)
{
const int sel = m_lbox_search_results->GetSelection();
if (sel >= 0)
long idx = m_lview_search_results->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);

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());
arcode_dlg.SetExtraStyle(arcode_dlg.GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS);
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)"));
}
17 changes: 9 additions & 8 deletions Source/Core/DolphinWX/Cheats/CheatSearchTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class wxButton;
class wxChoice;
class wxFocusEvent;
class wxListBox;
class wxListView;
class wxRadioBox;
class wxRadioButton;
class wxStaticText;
Expand All @@ -31,11 +31,18 @@ class CheatSearchTab final : public wxPanel
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;
unsigned int m_search_type_size;

wxChoice* m_search_type;
wxListBox* m_lbox_search_results;
wxListView* m_lview_search_results;
wxStaticText* m_label_results_count;
wxTextCtrl* m_textctrl_value_x;

Expand All @@ -49,10 +56,4 @@ class CheatSearchTab final : public wxPanel
wxRadioButton* rad_oldvalue;
wxRadioButton* rad_uservalue;
} m_value_x_radiobtn;

void UpdateCheatSearchResultsList();
void StartNewSearch(wxCommandEvent& event);
void FilterCheatSearchResults(wxCommandEvent& event);
void CreateARCode(wxCommandEvent&);
void ApplyFocus(wxFocusEvent&);
};