Skip to content

Commit

Permalink
replace some dynamic_cast<> with pCaller->As
Browse files Browse the repository at this point in the history
  • Loading branch information
olilarkin committed Nov 1, 2020
1 parent 608e95d commit 085e10b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/IGraphics.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
"prefix": "AttachIVSliderControl",
"body": [
"pGraphics->AttachControl(new IVSliderControl(b.GetCentredInside(30,100), [](IControl* pCaller){",
"\tdynamic_cast<IVSliderControl*>(pCaller)->SetColor(kX1, IColor::LinearInterpolateBetween(COLOR_RED, COLOR_ORANGE, pCaller->GetValue())); },",
"\tpCaller->As<IVSliderControl>()->SetColor(kX1, IColor::LinearInterpolateBetween(COLOR_RED, COLOR_ORANGE, pCaller->GetValue())); },",
"\t\"\", DEFAULT_STYLE, false, EDirection::Vertical, DEFAULT_GEARING, 0.f, 15.f));",
],
"description": "Attach an AttachIVSliderControl"
Expand Down
2 changes: 1 addition & 1 deletion Examples/IPlugControls/IPlugControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ IPlugControls::IPlugControls(const InstanceInfo& info)
pGraphics->ShowMessageBox("Message Title", "Message", kMB_YESNO, [&](EMsgBoxResult result) {
WDL_String str;
str.SetFormatted(32, "%s pressed", kMessageResultStrs[result]);
dynamic_cast<ITextControl*>(pGraphics->GetControlWithTag(kCtrlTagDialogResult))->SetStr(str.Get());
pGraphics->GetControlWithTag(kCtrlTagDialogResult)->As<ITextControl>()->SetStr(str.Get());
});
};

Expand Down
2 changes: 1 addition & 1 deletion Examples/IPlugDrumSynth/IPlugDrumSynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void IPlugDrumSynth::OnMidiMsgUI(const IMidiMsg& msg)

if(pitchClass < kNumDrums)
{
DrumPadControl* pPad = dynamic_cast<DrumPadControl*>(GetUI()->GetControlWithTag(pitchClass));
DrumPadControl* pPad = GetUI()->GetControlWithTag(pitchClass)->As<DrumPadControl>();
pPad->SetSplashPoint(pPad->GetRECT().MW(), pPad->GetRECT().MH());
pPad->TriggerAnimation();
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/IPlugInstrument/IPlugInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ IPlugInstrument::IPlugInstrument(const InstanceInfo& info)
#endif

pGraphics->SetQwertyMidiKeyHandlerFunc([pGraphics](const IMidiMsg& msg) {
dynamic_cast<IVKeyboardControl*>(pGraphics->GetControlWithTag(kCtrlTagKeyboard))->SetNoteFromMidi(msg.NoteNumber(), msg.StatusMsg() == IMidiMsg::kNoteOn);
pGraphics->GetControlWithTag(kCtrlTagKeyboard)->As<IVKeyboardControl>()->SetNoteFromMidi(msg.NoteNumber(), msg.StatusMsg() == IMidiMsg::kNoteOn);
});
};
#endif
Expand Down
2 changes: 1 addition & 1 deletion Examples/IPlugReaperExtension/IPlugReaperExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void IPlugReaperExtension::OnIdle()
mPrevTrackCount = tracks;

if(GetUI()) {
dynamic_cast<ITextControl*>(GetUI()->GetControlWithTag(kCtrlTagText))->SetStrFmt(64, "NumTracks: %i", tracks);
GetUI()->GetControlWithTag(kCtrlTagText)->As<ITextControl>()->SetStrFmt(64, "NumTracks: %i", tracks);
}
}
}
5 changes: 2 additions & 3 deletions IGraphics/IControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ void SplashAnimationFunc(IControl* pCaller)
return;
}

dynamic_cast<IVectorBase*>(pCaller)->SetSplashRadius((float) progress);

pCaller->As<IVectorBase>()->SetSplashRadius((float) progress);
pCaller->SetDirty(false);
};

Expand All @@ -49,7 +48,7 @@ void SplashClickActionFunc(IControl* pCaller)
{
float x, y;
pCaller->GetUI()->GetMouseDownPoint(x, y);
dynamic_cast<IVectorBase*>(pCaller)->SetSplashPoint(x, y);
pCaller->As<IVectorBase>()->SetSplashPoint(x, y);
pCaller->SetAnimation(SplashAnimationFunc, DEFAULT_ANIMATION_DURATION);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/IGraphicsStressTest/IGraphicsStressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void IGraphicsStressTest::LayoutUI(IGraphics* pGraphics)
break;
}

dynamic_cast<ITextControl*>(GetUI()->GetControlWithTag(kCtrlTagNumThings))->SetStrFmt(64, "Number of things = %i", mNumberOfThings);
dynamic_cast<ITextControl*>(GetUI()->GetControlWithTag(kCtrlTagTestNum))->SetStrFmt(64, "Test %i/%i", this->mKindOfThing, 32);
GetUI()->GetControlWithTag(kCtrlTagNumThings)->As<ITextControl>()->SetStrFmt(64, "Number of things = %i", mNumberOfThings);
GetUI()->GetControlWithTag(kCtrlTagTestNum))->As<ITextControl>()->SetStrFmt(64, "Test %i/%i", this->mKindOfThing, 32);
GetUI()->SetAllControlsDirty();
};

Expand Down
4 changes: 2 additions & 2 deletions Tests/IGraphicsTest/IGraphicsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ IGraphicsTest::IGraphicsTest(const InstanceInfo& info)
if(!isUp) {
switch (key.VK) {
case kVK_TAB:
dynamic_cast<IPanelControl*>(GetUI()->GetBackgroundControl())->SetPattern(IColor::GetRandomColor());
GetUI()->GetBackgroundControl()->As<IPanelControl>()->SetPattern(IColor::GetRandomColor());
break;

default:
Expand Down Expand Up @@ -146,7 +146,7 @@ IGraphicsTest::IGraphicsTest(const InstanceInfo& info)
[pGraphics, chooseTestControl](IControl* pCaller) {
pGraphics->RemoveControlWithTag(kCtrlTagTestControl);
SplashClickActionFunc(pCaller);
int selectedTest = dynamic_cast<IVRadioButtonControl*>(pCaller)->GetSelectedIdx();
int selectedTest = pCaller->As<IVRadioButtonControl>()->GetSelectedIdx();
chooseTestControl(selectedTest);
},
testNames
Expand Down

0 comments on commit 085e10b

Please sign in to comment.