mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-11-22 13:47:11 +00:00
Plugin API: ComboEx and ItemDeactivatedAfterEdit (#1275)
* Plugin API: ComboEx and ItemDeactivatedAfterEdit Two widget functions appended to the end of OptiPluginApi. The API version stays 1 and no field moves. - ComboEx: Combo with greyed out items, bit i of disabledItems disables items[i]. Lets a plugin keep an option in the list while it's not available instead of hiding it. Combo now calls it with no items disabled. - ItemDeactivatedAfterEdit: true on the frame the previous widget stopped being edited, a slider was released for example, so a plugin can apply a value once instead of on every frame of a drag. The sample uses both: Ultra quality is greyed out below 8 samples and the strength is logged once when its slider is released. A plain Combo picks the counter's log level, so the sample still calls every function. * Plugin API: 64 bit ComboEx mask, sample steps Ultra down ComboEx takes a uint64_t disabledItemsMask, so the first 64 items can be greyed out. In the sample, lowering Samples below 8 while Ultra is selected moves Quality to High.
This commit is contained in:
1 parent
e6a4c3e84e
commit
9302028ebe
4 files changed
+61
-5
No files matched your search
@@ -19,6 +19,13 @@ OptiPlugin* self = nullptr;
|
||||
const char* const qualityNames[] = { "Low", "Medium", "High", "Ultra" };
|
||||
constexpr int32_t qualityCount = sizeof(qualityNames) / sizeof(qualityNames[0]);
|
||||
|
||||
// Ultra needs at least this many samples
|
||||
constexpr int32_t ultraQuality = 3;
|
||||
constexpr int32_t ultraMinSamples = 8;
|
||||
|
||||
const char* const logLevelNames[] = { "Debug", "Info", "Warn", "Error" };
|
||||
constexpr int32_t logLevelCount = sizeof(logLevelNames) / sizeof(logLevelNames[0]);
|
||||
|
||||
struct Settings
|
||||
{
|
||||
bool enabled = true;
|
||||
@@ -32,6 +39,7 @@ struct Settings
|
||||
Settings settings;
|
||||
bool unsaved = false;
|
||||
int32_t clickCount = 0;
|
||||
int32_t clickLogLevel = OptiLog_Debug;
|
||||
|
||||
void LoadSettings()
|
||||
{
|
||||
@@ -90,13 +98,32 @@ void DrawMainTab(void* /*userData*/)
|
||||
}
|
||||
api->ItemTooltip("0.0 - no effect\n1.0 - full effect");
|
||||
|
||||
// Logged once when the slider is released, not on every frame of the drag
|
||||
if (api->ItemDeactivatedAfterEdit())
|
||||
{
|
||||
char text[64];
|
||||
snprintf(text, sizeof(text), "Strength set to %.2f", settings.strength);
|
||||
api->Log(self, OptiLog_Debug, text);
|
||||
}
|
||||
|
||||
if (api->SliderInt("Samples", &settings.samples, 1, 16, nullptr))
|
||||
{
|
||||
api->SetInt(self, "Samples", settings.samples);
|
||||
|
||||
// Too few samples for Ultra, step down to High
|
||||
if (settings.samples < ultraMinSamples && settings.quality == ultraQuality)
|
||||
{
|
||||
settings.quality = ultraQuality - 1;
|
||||
api->SetInt(self, "Quality", settings.quality);
|
||||
}
|
||||
|
||||
unsaved = true;
|
||||
}
|
||||
|
||||
if (api->Combo("Quality", &settings.quality, qualityNames, qualityCount))
|
||||
// With too few samples Ultra stays in the list but can't be picked
|
||||
const uint64_t disabledQualities = settings.samples < ultraMinSamples ? 1ull << ultraQuality : 0;
|
||||
|
||||
if (api->ComboEx("Quality", &settings.quality, qualityNames, qualityCount, disabledQualities))
|
||||
{
|
||||
api->SetInt(self, "Quality", settings.quality);
|
||||
unsaved = true;
|
||||
@@ -178,13 +205,16 @@ void DrawInfoTab(void* userData)
|
||||
|
||||
api->Section("Counter");
|
||||
|
||||
// Not kept in the ini, only for this session
|
||||
api->Combo("Log clicks as", &clickLogLevel, logLevelNames, logLevelCount);
|
||||
|
||||
// userData given to RegisterTab comes back here
|
||||
if (api->Button("Click me"))
|
||||
{
|
||||
(*counter)++;
|
||||
|
||||
snprintf(text, sizeof(text), "Button clicked %d times", *counter);
|
||||
api->Log(self, OptiLog_Debug, text);
|
||||
api->Log(self, static_cast<OptiLogLevel>(clickLogLevel), text);
|
||||
}
|
||||
|
||||
api->SameLine();
|
||||
@@ -197,7 +227,7 @@ void DrawInfoTab(void* userData)
|
||||
extern "C" __declspec(dllexport) bool OptiPluginInit(const OptiPluginApi* optiApi, OptiPlugin* plugin)
|
||||
{
|
||||
// An older OptiScaler doesn't have everything this plugin uses
|
||||
if (!OPTI_API_HAS(optiApi, Log))
|
||||
if (!OPTI_API_HAS(optiApi, ItemDeactivatedAfterEdit))
|
||||
return false;
|
||||
|
||||
api = optiApi;
|
||||
|
||||
Reference in new issue
Block a user