Skip to content

Commit

Permalink
configurable bar color! no more vomit yellow bar
Browse files Browse the repository at this point in the history
  • Loading branch information
khang06 committed Dec 7, 2021
1 parent ded8055 commit 22c81e2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
33 changes: 24 additions & 9 deletions PianoFromAbove/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void VizSettings::LoadDefaultValues() {
this->sSplashMIDI = L"";
this->bVisualizePitchBends = false;
this->bDumpFrames = false;
this->iBarColor = 0x00FF0080;
}

void AudioSettings::LoadMIDIDevices()
Expand Down Expand Up @@ -354,26 +355,34 @@ void ViewSettings::LoadConfigValues( TiXmlElement *txRoot )
}

void VizSettings::LoadConfigValues(TiXmlElement* txRoot) {
TiXmlElement* txView = txRoot->FirstChildElement("Viz");
if (!txView)
TiXmlElement* txViz = txRoot->FirstChildElement("Viz");
if (!txViz)
return;

int iAttrVal;
if (txView->QueryIntAttribute("TickBased", &iAttrVal) == TIXML_SUCCESS)
if (txViz->QueryIntAttribute("TickBased", &iAttrVal) == TIXML_SUCCESS)
bTickBased = (iAttrVal != 0);
if (txView->QueryIntAttribute("ShowMarkers", &iAttrVal) == TIXML_SUCCESS)
if (txViz->QueryIntAttribute("ShowMarkers", &iAttrVal) == TIXML_SUCCESS)
bShowMarkers = (iAttrVal != 0);
if (txView->QueryIntAttribute("NerdStats", &iAttrVal) == TIXML_SUCCESS)
if (txViz->QueryIntAttribute("NerdStats", &iAttrVal) == TIXML_SUCCESS)
bNerdStats = (iAttrVal != 0);
if (txView->QueryIntAttribute("VisualizePitchBends", &iAttrVal) == TIXML_SUCCESS)
if (txViz->QueryIntAttribute("VisualizePitchBends", &iAttrVal) == TIXML_SUCCESS)
bVisualizePitchBends = (iAttrVal != 0);
if (txView->QueryIntAttribute("DumpFrames", &iAttrVal) == TIXML_SUCCESS)
if (txViz->QueryIntAttribute("DumpFrames", &iAttrVal) == TIXML_SUCCESS)
bDumpFrames = (iAttrVal != 0);
std::string sTempStr;
txView->QueryStringAttribute("SplashMIDI", &sTempStr);
txViz->QueryStringAttribute("SplashMIDI", &sTempStr);
sSplashMIDI = Util::StringToWstring(sTempStr);
txView->QueryIntAttribute("MarkerEncoding", (int*)&eMarkerEncoding);
txViz->QueryIntAttribute("MarkerEncoding", (int*)&eMarkerEncoding);
eMarkerEncoding = min(MarkerEncoding::CP1252, max(eMarkerEncoding, MarkerEncoding::UTF8));

int r, g, b = 0;
TiXmlElement* txBarColor = txViz->FirstChildElement("BarColor");
if (txBarColor)
if (txBarColor->QueryIntAttribute("R", &r) == TIXML_SUCCESS &&
txBarColor->QueryIntAttribute("G", &g) == TIXML_SUCCESS &&
txBarColor->QueryIntAttribute("B", &b) == TIXML_SUCCESS)
iBarColor = ((r & 0xFF) << 0) | ((g & 0xFF) << 8) | ((b & 0xFF) << 16);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -479,5 +488,11 @@ bool VizSettings::SaveConfigValues(TiXmlElement* txRoot) {
txViz->SetAttribute("SplashMIDI", Util::WstringToString(sSplashMIDI));
txViz->SetAttribute("VisualizePitchBends", bVisualizePitchBends);
txViz->SetAttribute("DumpFrames", bDumpFrames);

TiXmlElement* txBarColor = new TiXmlElement("BarColor");
txViz->LinkEndChild(txBarColor);
txBarColor->SetAttribute("R", (iBarColor >> 0) & 0xFF);
txBarColor->SetAttribute("G", (iBarColor >> 8) & 0xFF);
txBarColor->SetAttribute("B", (iBarColor >> 16) & 0xFF);
return true;
}
3 changes: 2 additions & 1 deletion PianoFromAbove/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ struct VizSettings : public ISettings {
std::wstring sSplashMIDI;
bool bVisualizePitchBends;
bool bDumpFrames;
int iBarColor;
};

class Config : public ISettings
Expand All @@ -203,7 +204,7 @@ class Config : public ISettings
const ControlsSettings& GetControlsSettings() const { return m_ControlsSettings; }
PlaybackSettings& GetPlaybackSettings() { return m_PlaybackSettings; }
ViewSettings& GetViewSettings() { return m_ViewSettings; }
const VizSettings& GetVizSettings() const { return m_VizSettings; }
VizSettings& GetVizSettings() { return m_VizSettings; }

void SetVisualSettings(const VisualSettings &VisualSettings) { m_VisualSettings = VisualSettings; }
void SetAudioSettings(const AudioSettings &audioSettings) { m_AudioSettings = audioSettings; }
Expand Down
15 changes: 11 additions & 4 deletions PianoFromAbove/ConfigProcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ INT_PTR WINAPI VisualProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )

// Config to fill out the form
Config &config = Config::GetConfig();
SetVisualProc( hWnd, config.GetVisualSettings() );
SetVisualProc( hWnd, config.GetVisualSettings(), config.GetVizSettings() );
return TRUE;
}
// Draws the colored buttons
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT pdis = (LPDRAWITEMSTRUCT)lParam;
if ( ( pdis->CtlID < IDC_COLOR1 || pdis->CtlID > IDC_COLOR6 ) && pdis->CtlID != IDC_BKGCOLOR )
if ( ( pdis->CtlID < IDC_COLOR1 || pdis->CtlID > IDC_COLOR6 ) && pdis->CtlID != IDC_BKGCOLOR && pdis->CtlID != IDC_BARCOLOR )
return FALSE;

SetDCBrushColor( pdis->hDC, (COLORREF)GetWindowLongPtr( pdis->hwndItem, GWLP_USERDATA ) );
Expand All @@ -111,6 +111,7 @@ INT_PTR WINAPI VisualProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
case IDC_COLOR1: case IDC_COLOR2: case IDC_COLOR3:
case IDC_COLOR4: case IDC_COLOR5: case IDC_COLOR6:
case IDC_BKGCOLOR:
case IDC_BARCOLOR:
{
static COLORREF acrCustClr[16] = { 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF,
0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF };
Expand All @@ -135,8 +136,11 @@ INT_PTR WINAPI VisualProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
VisualSettings cVisualSettings;
cVisualSettings.LoadDefaultValues();

VizSettings cVizSettings;
cVizSettings.LoadDefaultValues();

SendMessage( hWnd, WM_SETREDRAW, FALSE, 0 );
SetVisualProc( hWnd, cVisualSettings );
SetVisualProc( hWnd, cVisualSettings, cVizSettings );
SendMessage( hWnd, WM_SETREDRAW, TRUE, 0 );
InvalidateRect( hWnd, NULL, FALSE );
return TRUE;
Expand All @@ -156,6 +160,7 @@ INT_PTR WINAPI VisualProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
Config &config = Config::GetConfig();
VisualSettings cVisual = config.GetVisualSettings();
ViewSettings &cView = config.GetViewSettings();
VizSettings &cViz = config.GetVizSettings();

// VisualSettings struct
bool bAlwaysShowControls = cVisual.bAlwaysShowControls;
Expand All @@ -170,6 +175,7 @@ INT_PTR WINAPI VisualProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
for ( int i = 0; i < IDC_COLOR6 - IDC_COLOR1 + 1; i++ )
cVisual.colors[i] = (int)GetWindowLongPtr( GetDlgItem( hWnd, IDC_COLOR1 + i ), GWLP_USERDATA );
cVisual.iBkgColor = (int)GetWindowLongPtr( GetDlgItem( hWnd, IDC_BKGCOLOR ), GWLP_USERDATA );
cViz.iBarColor = (int)GetWindowLongPtr(GetDlgItem(hWnd, IDC_BARCOLOR), GWLP_USERDATA);

// Report success and return
config.SetVisualSettings( cVisual );
Expand All @@ -187,7 +193,7 @@ INT_PTR WINAPI VisualProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
}

// Sets the values in the playback settings dialog. Used at init and restoring defaults
VOID SetVisualProc( HWND hWnd, const VisualSettings &cVisual )
VOID SetVisualProc( HWND hWnd, const VisualSettings &cVisual, const VizSettings& cViz )
{
HWND hWndFirstKey = GetDlgItem( hWnd, IDC_FIRSTKEY );
HWND hWndLastKey = GetDlgItem( hWnd, IDC_LASTKEY );
Expand All @@ -204,6 +210,7 @@ VOID SetVisualProc( HWND hWnd, const VisualSettings &cVisual )
for ( int i = 0; i < IDC_COLOR6 - IDC_COLOR1 + 1; i++ )
SetWindowLongPtr( GetDlgItem( hWnd, IDC_COLOR1 + i ), GWLP_USERDATA, cVisual.colors[i] );
SetWindowLongPtr( GetDlgItem( hWnd, IDC_BKGCOLOR ), GWLP_USERDATA, cVisual.iBkgColor );
SetWindowLongPtr( GetDlgItem( hWnd, IDC_BARCOLOR ), GWLP_USERDATA, cViz.iBarColor );
}

INT_PTR WINAPI AudioProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
Expand Down
2 changes: 1 addition & 1 deletion PianoFromAbove/ConfigProcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ VOID DoPreferences( HWND hWndOwner );
VOID Changed( HWND hWnd );

INT_PTR WINAPI VisualProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
VOID SetVisualProc( HWND hWnd, const VisualSettings &cVisual );
VOID SetVisualProc( HWND hWnd, const VisualSettings &cVisual, const VizSettings& cViz );

INT_PTR WINAPI NoteSpanProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
void MIDIInProc( unsigned char cStatus, unsigned char cParam1, unsigned char cParam2, int iMilliSecs, void *pUserData );
Expand Down
8 changes: 7 additions & 1 deletion PianoFromAbove/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,12 @@ void MainScreen::InitNoteMap( const vector< MIDIEvent* > &vEvents )
// Display colors
void MainScreen::InitColors()
{
static Config& config = Config::GetConfig();
static const VizSettings& cViz = config.GetVizSettings();

m_csBackground.SetColor( 0x00464646, 0.7f, 1.3f );
m_csKBBackground.SetColor( 0x00999999, 0.4f, 0.0f );
m_csKBRed.SetColor( 0x0000E6E6, 0.5f ); // "red"
m_csKBRed.SetColor(cViz.iBarColor, 0.5f);
m_csKBWhite.SetColor( 0x00FFFFFF, 0.8f, 0.6f );
m_csKBSharp.SetColor( 0x00404040, 0.5f, 0.0f );
}
Expand Down Expand Up @@ -961,6 +964,9 @@ GameState::GameError MainScreen::Logic( void )
static const VizSettings &cViz = config.GetVizSettings();
const MIDI::MIDIInfo &mInfo = m_MIDI.GetInfo();

// people are probably going to yell at me if you can't change the bar color during playback
m_csKBRed.SetColor(cViz.iBarColor, 0.5f);

// Detect changes in state
bool bPaused = cPlayback.GetPaused();
double dSpeed = cPlayback.GetSpeed();
Expand Down
Binary file modified PianoFromAbove/PianoFromAbove.rc
Binary file not shown.
4 changes: 3 additions & 1 deletion PianoFromAbove/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#define IDC_COLOR5 1010
#define IDC_COLOR6 1011
#define IDC_BKGCOLOR 1012
#define IDC_COLOR7 1013
#define IDC_BARCOLOR 1013
#define IDC_SHOWALLKEYS 1020
#define IDC_SHOWSONGKEYS 1021
#define IDC_SHOWCUSTOMKEYS 1022
Expand Down Expand Up @@ -199,7 +201,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 157
#define _APS_NEXT_RESOURCE_VALUE 158
#define _APS_NEXT_COMMAND_VALUE 40173
#define _APS_NEXT_CONTROL_VALUE 1108
#define _APS_NEXT_SYMED_VALUE 102
Expand Down

0 comments on commit 22c81e2

Please sign in to comment.