Skip to content

Commit

Permalink
Add a new drawing function, DisplayFrame(), to unify most drawing of …
Browse files Browse the repository at this point in the history
…frames used by different setup dialogs.
  • Loading branch information
mywave82 committed Nov 9, 2024
1 parent 64dd72f commit 058b991
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 521 deletions.
32 changes: 32 additions & 0 deletions boot/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,37 @@ static void display_nprintf (uint16_t y, uint16_t x, uint8_t color, uint16_t wid
va_end(ap);
}

static void display_frame (uint16_t y, uint16_t x, uint16_t h, uint16_t w, uint8_t color, const char *title, uint16_t dot, uint16_t hbar1, uint16_t hbar2)
{
size_t len = strlen (title);
int left;
int right;

if (len > (w - 4))
{
len = w - 4;
}
left = (w - 4 - len) / 2;
right = w - 4 - len - left;

/* dot = 0, no dot, otherwize it says which line number after Y to place it at */
display_nprintf (y++, x, color, w, "\xda%*C\xc4 %*s %*C\xc4\xbf", left, len, title, right); h--; dot--; hbar1--; hbar2--;
while (h > 1)
{
if ((!hbar1) || (!hbar2))
{
display_nprintf (y++, x, color, w, "\xc3%*C\xc4\xb4", w - 2);
} else {
display_nprintf (y++, x, color, w, "\xb3%*C %c", w - 2, dot ? '\xb3': '\xdd');
}
h--;
dot--;
hbar1--;
hbar2--;
}
display_nprintf (y++, x, color, w, "\xc0%*C\xc4\xd9", w - 2); h--;
}

static void writenum (uint16_t *buf, uint16_t ofs, uint8_t attr, unsigned long num, uint8_t radix, uint16_t len, int clip0)
{
char convbuf[20];
Expand Down Expand Up @@ -733,6 +764,7 @@ struct console_t Console =
{
&dummyConsoleDriver,
display_nprintf,
display_frame,
writenum,
writestring,
writestringattr,
Expand Down
2 changes: 1 addition & 1 deletion dev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ deviwave.o: deviwave.c \
../stuff/err.h \
../stuff/imsrtns.h \
../stuff/poutput.h
$(CC) deviwave.c -c -o $@ -c
$(CC) deviwave.c -o $@ -c

mchasm.o: mchasm.c mchasm.h \
../config.h \
Expand Down
86 changes: 36 additions & 50 deletions dev/deviplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ static int deviplayLateInit (struct PluginInitAPI_t *API)
const char *def;
int i;


setup_devp = API->dev_file_create (
API->dmSetup->basedir,
"devp.dev",
Expand Down Expand Up @@ -372,7 +373,7 @@ static void deviplayLateClose (void)
plrDriverListNone = -1;
}

static void setup_devp_draw (const char *title, int dsel)
static void setup_devp_draw (const struct DevInterfaceAPI_t *API, const char *title, int dsel)
{
unsigned int mlHeight;
unsigned int mlTop;
Expand Down Expand Up @@ -402,39 +403,37 @@ static void setup_devp_draw (const char *title, int dsel)
if (plrDriverListEntries <= fit)
{ /* all entries can fit */
skip = 0;
dot = -1;
dot = 0;
} else if (dsel < half)
{ /* we are in the top part */
skip = 0;
dot = 0;
dot = 3;
} else if (dsel >= (plrDriverListEntries - half))
{ /* we are at the bottom part */
skip = plrDriverListEntries - fit;
dot = fit - 1;
dot = fit + 2;
} else {
skip = dsel - half;
dot = skip * (fit) / (plrDriverListEntries - (fit));
dot = skip * (fit) / (plrDriverListEntries - (fit)) + 3;
}

{
int CacheLen = strlen (title);
int Skip = (mlWidth - CacheLen - 2) / 2;
display_nprintf (mlTop, mlLeft, 0x09, mlWidth, "\xda%*C\xc4 %s %*C\xc4\xbf", Skip - 1, title, mlWidth - Skip - 3 - CacheLen); /* +----- title ------+ */
}
API->console->DisplayFrame (mlTop++, mlLeft++, mlHeight, mlWidth, DIALOG_COLOR_FRAME, title, dot, 2, mlHeight - 4);
mlWidth -= 2;
mlHeight -= 2;

display_nprintf (mlTop + 1, mlLeft, 0x09, mlWidth, "\xb3%0.7o Available audio drivers, and their priority in the autodection%*C %0.9o\xb3", mlWidth - 65);
API->console->DisplayPrintf (mlTop++, mlLeft, 0x07, mlWidth, " Available audio drivers, and their priority in the autodetection:");

display_nprintf (mlTop + 2, mlLeft, 0x09, mlWidth, "\xc3%*C\xc4\xb4", mlWidth - 2); /* | | */
mlTop++; // 2: horizontal bar

for (i = 3; i < (mlHeight-3); i++)
for (i = 2; i < (mlHeight-3); i++)
{
int index = i - 3 + skip;
int index = i - 2 + skip;
int color;
const char *msg;

if (index >= plrDriverListEntries)
{
display_nprintf (mlTop + i, mlLeft, 0x09, mlWidth, "\xb3%.*C \xb3", mlWidth - 2);
mlTop++;
continue;
}

Expand All @@ -459,65 +458,52 @@ static void setup_devp_draw (const char *title, int dsel)
msg = "";
}

display_nprintf (mlTop + i, mlLeft, 0x09, mlWidth, "\xb3%*.*o%-.3d %.*o%.8s: %s %.*o%.18s %0.9o%c",
(dsel == index)?7:0,
(dsel == index)?0:7,
API->console->DisplayPrintf (mlTop++, mlLeft,
(((dsel == index)?7:0) << 4) |
((dsel == index)?0:7),
mlWidth, "%-.3d %.*o%.8s: %s %.*o%.18s",
index + 1,
(dsel == index)?0:3,
plrDriverList[index].name,
dots(plrDriverList[index].driver?plrDriverList[index].driver->description:""),
color,
msg,
((i-3) == dot) ? '\xdd':'\xb3'
msg
);
}

display_nprintf (mlTop + mlHeight - 4, mlLeft, 0x09, mlWidth, "\xc3%*C\xc4\xb4", mlWidth - 2); /* +---------------+ */
display_nprintf (mlTop + mlHeight - 3, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<\x18>%0.7o/%0.15o<\x19>%0.7o: Navigate "
mlTop++; // Horizontal bar
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <\x18>%0.7o/%0.15o<\x19>%0.7o: Navigate "
"%0.15o<+>%0.7o/%0.15o<->%0.7o: Change priority "
"<ESC>%0.7o close dialog "
"%0.9o \xb3"
"%0.15o<ESC>%0.7o close dialog"
);

if ((dsel >= plrDriverListEntries) || (plrDriver && (plrDriverList[dsel].driver == plrDriver)))
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth, "\xb3%*C \xb3", mlWidth - 2); /* | | */
mlTop++;
} else if ((!plrDriverList[dsel].driver) && (!plrDriverList[dsel].disabled))
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<d>%0.7o: disable driver "
"%0.15o<DEL>%0.7o: delete entry "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <d>%0.7o: disable driver "
"%0.15o<DEL>%0.7o: delete entry"
);
} else if ((!plrDriverList[dsel].driver) && (plrDriverList[dsel].disabled))
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<e>%0.7o: enable driver "
"%0.15o<DEL>%0.7o: delete entry "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <e>%0.7o: enable driver "
"%0.15o<DEL>%0.7o: delete entry"
);
} else if (plrDriverList[dsel].disabled)
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<e>%0.7o: enable driver"
" "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <e>%0.7o: enable driver"
);
} else {
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<ENTER>%0.7o: activate driver "
"%0.15o<d>%0.7o: disable driver "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <ENTER>%0.7o: activate driver "
"%0.15o<d>%0.7o: disable driver"
);
}

display_nprintf (mlTop + mlHeight - 1, mlLeft, 0x09, mlWidth, "\xc0%*C\xc4\xd9", mlWidth - 2); /* +---------------+ */
}

static void devp_save_devices (const struct DevInterfaceAPI_t *API)
Expand Down Expand Up @@ -551,7 +537,7 @@ static void setup_devp_run (void **token, const struct DevInterfaceAPI_t *API)
while (1)
{
API->fsDraw();
setup_devp_draw("Playback plugins", dsel);
setup_devp_draw (API, "Playback plugins", dsel);
while (API->console->KeyboardHit())
{
int key = API->console->KeyboardGetChar();
Expand Down
85 changes: 35 additions & 50 deletions dev/deviwave.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static void deviwaveLateClose (void)
mcpDriverListNone = -1;
}

static void setup_devw_draw (const char *title, int dsel)
static void setup_devw_draw (const struct DevInterfaceAPI_t *API, const char *title, int dsel)
{
unsigned int mlHeight;
unsigned int mlTop;
Expand Down Expand Up @@ -422,39 +422,37 @@ static void setup_devw_draw (const char *title, int dsel)
if (mcpDriverListEntries <= fit)
{ /* all entries can fit */
skip = 0;
dot = -1;
dot = 0;
} else if (dsel < half)
{ /* we are in the top part */
skip = 0;
dot = 0;
dot = 3;
} else if (dsel >= (mcpDriverListEntries - half))
{ /* we are at the bottom part */
skip = mcpDriverListEntries - fit;
dot = fit - 1;
dot = fit + 2;
} else {
skip = dsel - half;
dot = skip * (fit) / (mcpDriverListEntries - (fit));
dot = skip * (fit) / (mcpDriverListEntries - (fit)) + 3;
}

{
int CacheLen = strlen (title);
int Skip = (mlWidth - CacheLen - 2) / 2;
display_nprintf (mlTop, mlLeft, 0x09, mlWidth, "\xda%*C\xc4 %s %*C\xc4\xbf", Skip - 1, title, mlWidth - Skip - 3 - CacheLen); /* +----- title ------+ */
}
API->console->DisplayFrame (mlTop++, mlLeft++, mlHeight, mlWidth, DIALOG_COLOR_FRAME, title, dot, 2, mlHeight - 4);
mlWidth -= 2;
mlHeight -= 2;

display_nprintf (mlTop + 1, mlLeft, 0x09, mlWidth, "\xb3%0.7o Available audio drivers, and their priority in the autodection%*C %0.9o\xb3", mlWidth - 65);
API->console->DisplayPrintf (mlTop++, mlLeft, 0x07, mlWidth, " Available wavetable drivers, and their priority in the autodection:");

display_nprintf (mlTop + 2, mlLeft, 0x09, mlWidth, "\xc3%*C\xc4\xb4", mlWidth - 2); /* | | */
mlTop++; // 2: horizontal bar

for (i = 3; i < (mlHeight-3); i++)
for (i = 2; i < (mlHeight-3); i++)
{
int index = i - 3 + skip;
int index = i - 2 + skip;
int color;
const char *msg;

if (index >= mcpDriverListEntries)
{
display_nprintf (mlTop + i, mlLeft, 0x09, mlWidth, "\xb3%.*C \xb3", mlWidth - 2);
mlTop++;
continue;
}

Expand All @@ -479,65 +477,52 @@ static void setup_devw_draw (const char *title, int dsel)
msg = "";
}

display_nprintf (mlTop + i, mlLeft, 0x09, mlWidth, "\xb3%*.*o%-.3d %.*o%.8s: %s %.*o%.18s %0.9o%c",
(dsel == index)?7:0,
(dsel == index)?0:7,
API->console->DisplayPrintf (mlTop++, mlLeft,
(((dsel == index)?7:0) << 4) |
((dsel == index)?0:7),
mlWidth, "%-.3d %.*o%.8s: %s %.*o%.18s",
index + 1,
(dsel == index)?0:3,
mcpDriverList[index].name,
dots(mcpDriverList[index].driver?mcpDriverList[index].driver->description:""),
color,
msg,
((i-3) == dot) ? '\xdd':'\xb3'
msg
);
}

display_nprintf (mlTop + mlHeight - 4, mlLeft, 0x09, mlWidth, "\xc3%*C\xc4\xb4", mlWidth - 2); /* +---------------+ */
display_nprintf (mlTop + mlHeight - 3, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<\x18>%0.7o/%0.15o<\x19>%0.7o: Navigate "
mlTop++; // Horizontal bar
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <\x18>%0.7o/%0.15o<\x19>%0.7o: Navigate "
"%0.15o<+>%0.7o/%0.15o<->%0.7o: Change priority "
"<ESC>%0.7o close dialog "
"%0.9o \xb3"
"%0.15o<ESC>%0.7o close dialog"
);

if ((dsel >= mcpDriverListEntries) || (mcpDriver && (mcpDriverList[dsel].driver == mcpDriver)))
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth, "\xb3%*C \xb3", mlWidth - 2); /* | | */
mlTop++;
} else if ((!mcpDriverList[dsel].driver) && (!mcpDriverList[dsel].disabled))
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<d>%0.7o: disable driver "
"%0.15o<DEL>%0.7o: delete entry "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <d>%0.7o: disable driver "
"%0.15o<DEL>%0.7o: delete entry"
);
} else if ((!mcpDriverList[dsel].driver) && (mcpDriverList[dsel].disabled))
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<e>%0.7o: enable driver "
"%0.15o<DEL>%0.7o: delete entry "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <e>%0.7o: enable driver "
"%0.15o<DEL>%0.7o: delete entry"
);
} else if (mcpDriverList[dsel].disabled)
{
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<e>%0.7o: enable driver"
" "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <e>%0.7o: enable driver"
);
} else {
display_nprintf (mlTop + mlHeight - 2, mlLeft, 0x09, mlWidth,
"\xb3%0.7o "
"%0.15o<ENTER>%0.7o: activate driver "
"%0.15o<d>%0.7o: disable driver "
"%0.9o \xb3"
API->console->DisplayPrintf (mlTop++, mlLeft, 0x0f, mlWidth,
" <ENTER>%0.7o: activate driver "
"%0.15o<d>%0.7o: disable driver"
);
}

display_nprintf (mlTop + mlHeight - 1, mlLeft, 0x09, mlWidth, "\xc0%*C\xc4\xd9", mlWidth - 2); /* +---------------+ */
}

static void devw_save_devices (const struct DevInterfaceAPI_t *API)
Expand Down Expand Up @@ -571,7 +556,7 @@ static void setup_devw_run (void **token, const struct DevInterfaceAPI_t *API)
while (1)
{
API->fsDraw();
setup_devw_draw("Wavetable plugins", dsel);
setup_devw_draw (API, "Wavetable plugins", dsel);
while (API->console->KeyboardHit())
{
int key = API->console->KeyboardGetChar();
Expand Down
Loading

0 comments on commit 058b991

Please sign in to comment.