Skip to content

Commit 2fee938

Browse files
committed
move font3x5 to tobkit, add theme cols for fxkb, fix slow draw
1 parent 4dba0ad commit 2fee938

File tree

20 files changed

+189
-181
lines changed

20 files changed

+189
-181
lines changed

Makefile.arm9

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ INCLUDEDIRS :=
1616
GFXDIRS :=
1717
BINDIRS := arm9/data
1818
AUDIODIRS :=
19-
FONTSDIRS := arm9/fonts
19+
FONTSDIRS :=
2020
BITMAPSDIRS := arm9/bitmaps
2121
TOOLSDIR := tools
2222

@@ -90,10 +90,6 @@ ifneq ($(GFXDIRS),)
9090
SOURCES_PNG := $(shell find -L $(GFXDIRS) -name "*.png")
9191
INCLUDEDIRS += $(addprefix $(BUILDDIR)/,$(GFXDIRS))
9292
endif
93-
ifneq ($(FONTSDIRS),)
94-
SOURCES_FONTS := $(shell find -L $(FONTSDIRS) -name "*.png")
95-
INCLUDEDIRS += $(addprefix $(BUILDDIR)/,$(FONTSDIRS))
96-
endif
9793
ifneq ($(BITMAPSDIRS),)
9894
SOURCES_BITMAPS := $(shell find -L $(BITMAPSDIRS) -name "*.png")
9995
INCLUDEDIRS += $(addprefix $(BUILDDIR)/,$(BITMAPSDIRS))
@@ -231,13 +227,6 @@ $(BUILDDIR)/%.png.o $(BUILDDIR)/%.h : %.png %.grit
231227
$(V)$(CC) $(CFLAGS) -MMD -MP -c -o $(BUILDDIR)/$*.png.o $(BUILDDIR)/$*.c
232228
$(V)touch $(BUILDDIR)/$*.png.o $(BUILDDIR)/$*.h
233229

234-
$(BUILDDIR)/arm9/fonts/font_3x5.raw.o : arm9/fonts/font_3x5.png
235-
@echo $(notdir $<)
236-
@$(MKDIR) -p $(@D)
237-
$(V)python3 $(TOOLSDIR)/font_3x5_pack.py $< $(basename $(basename $@)).raw
238-
$(V)$(BLOCKSDS)/tools/bin2c/bin2c $(basename $(basename $@)).raw $(@D)
239-
$(V)$(CC) $(CFLAGS) -MMD -MP -c -o $(basename $(basename $@)).raw.o $(basename $(basename $@))_raw.c
240-
241230
$(BUILDDIR)/%.raw.o : %.png
242231
@echo $(notdir $<)
243232
@$(MKDIR) -p $(@D)

arm9/source/main.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ void setEffectParam(u16 eff_par, bool new_e_cmd, bool force_clear=false)
21082108
// ....OR if the cell has no parameter, use whatever E button they last pressed
21092109
// (otherwise 0)
21102110
} else {
2111-
ecmd_cmd = fxkb->getLastECmd() << 4;
2111+
ecmd_cmd = fxkb->getLastCmd() << 4;
21122112
ecmd_par = eff_par & 0x0F;
21132113
}
21142114
}
@@ -2314,15 +2314,11 @@ void handleToggleEffectsVisibility(bool on)
23142314
}
23152315

23162316
void onFxKeyPressed(u8 val, bool key_enabled)
2317-
{
2318-
fxkb->updateFxCaption(val); // show label even for disabled commands
2319-
2317+
{
23202318
if (!key_enabled || !state->recording) return;
2321-
23222319
// for E effects, the button's val is the E sub-command, rather than just 'E'
23232320
if (fxkb->getCategory() == FX_CATEGORY_E) {
23242321
setEffectCommand(0xE);
2325-
fxkb->setLastECmd(val);
23262322
setEffectParam((val << 4) | (fxkb->getParam() & 0x0f), true);
23272323
} else {
23282324
setEffectCommand(val);
@@ -2336,6 +2332,7 @@ void onFxKeyPressed(u8 val, bool key_enabled)
23362332
// box arrows or pen slide
23372333
void handleEffectParamChanged(u8 eff_par)
23382334
{
2335+
if (!state->recording) return;
23392336
setEffectParam(eff_par, false);
23402337
}
23412338

@@ -3359,7 +3356,7 @@ void setupGUI(bool dldi_enabled)
33593356
kb->registerNoteCallback(handleNoteStroke);
33603357
kb->registerReleaseCallback(handleNoteRelease);
33613358

3362-
fxkb = new FXKeyboard(0, 152, &sub_vram, onFxKeyPressed, handleEffectParamChanged, handleSetEffectParam, handleClearFx, true);
3359+
fxkb = new FXKeyboard(0, 152, &sub_vram, onFxKeyPressed, handleEffectParamChanged, handleSetEffectParam, handleClearFx, false);
33633360
gui->registerWidget(fxkb, 0, SUB_SCREEN);
33643361

33653362
pixmaplogo = new GradientIcon(98, 1, 80, 17,

arm9/source/tobkit/fxbutton.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ void FXButton::pleaseDraw(void) {
5151
// Event calls
5252
void FXButton::penDown(u8 x, u8 y)
5353
{
54+
parent->useDarkTitle(!is_enabled());
55+
parent->updateFxCaption(value);
5456
if (!enabled) return;
5557
penIsDown = true;
5658
draw(1);
5759
}
5860

5961
void FXButton::penUp(u8 x, u8 y)
6062
{
61-
if (parent) parent->useDarkTitle(!is_enabled());
62-
6363
if(onPush) {
6464
onPush(value, is_enabled());
65-
if (category == FX_CATEGORY_E) parent->setLastECmd(value);
65+
parent->setLastCmd(value);
6666
}
6767
if (!enabled) return;
6868
penIsDown = false;
@@ -87,14 +87,20 @@ void FXButton::setCaption(const char *_caption) {
8787
}
8888

8989
void FXButton::setSmallCaption(const char *_small_caption) {
90-
if (small_caption) ntxm_free(small_caption);
90+
if (small_caption) {
91+
ntxm_free(small_caption);
92+
small_caption = NULL;
93+
}
94+
95+
if (_small_caption == NULL)
96+
return;
97+
9198
small_caption = (char*)ntxm_cmalloc(strlen(_small_caption)+1);
9299
strcpy(small_caption, _small_caption);
93100
}
94101

95102
void FXButton::setCategory(u8 newcat)
96103
{
97-
setIsECommand(newcat == FX_CATEGORY_E);
98104
category = newcat;
99105
draw(penIsDown);
100106
}
@@ -111,7 +117,21 @@ u8 FXButton::getValue(void)
111117

112118
void FXButton::hide(void)
113119
{
114-
Widget::hide();
120+
if(isExposed())
121+
FXButton::overdraw();
122+
visible = false;
123+
}
124+
125+
bool FXButton::set_visible(bool value)
126+
{
127+
bool changed = value != visible;
128+
if (value) show(); else hide();
129+
return changed;
130+
}
131+
132+
void FXButton::overdraw(void)
133+
{
134+
drawFullBox(1, 0, width+1, height, bgcolor);
115135
}
116136

117137
void FXButton::setParent(FXKeyboard *parent_keyboard)
@@ -123,24 +143,25 @@ void FXButton::setParent(FXKeyboard *parent_keyboard)
123143

124144
void FXButton::draw(u8 down) {
125145
if (!caption || !isExposed()) return;
126-
146+
127147
if (enabled) {
128148
if (down)
129-
drawVerticalGradient(theme->col_piano_full_col1, theme->col_piano_full_col2, 1, 1, width - 2, height - 2);
149+
drawVerticalGradient(theme->col_fxkeyboard_col1, theme->col_fxkeyboard_col2, 1, 1, width - 2, height - 2);
130150
else
131-
drawVerticalGradient(theme->col_piano_full_col2, theme->col_piano_full_col1, 1, 1, width - 2, height - 2);
151+
drawVerticalGradient(theme->col_fxkeyboard_col2, theme->col_fxkeyboard_col1, 1, 1, width - 2, height - 2);
132152

133-
drawBox(1, 1, width-2, height-2, theme->col_piano_full_col2);
153+
drawBox(1, 1, width-2, height-2, theme->col_fxkeyboard_col2);
134154

135155
} else {
136-
drawVerticalGradient(theme->col_dark_ctrl_disabled, theme->col_light_ctrl_disabled, 1, 1, width - 2, height - 2);
137-
drawBox(1, 1, width-2, height-2, theme->col_dark_ctrl_disabled);
156+
drawVerticalGradient(theme->col_fxkeyboard_col2_disabled, theme->col_fxkeyboard_col1_disabled, 1, 1, width - 2, height - 2);
157+
drawBox(1, 1, width-2, height-2, theme->col_fxkeyboard_col2_disabled);
138158
}
139159

140160
drawBorder(theme->col_outline);
141161

142-
drawString(caption, (width-getStringWidth(caption))/2, height/2-7, (theme->col_piano_label | BIT(15)));
162+
drawString(caption, caption[0] == 'f' ? 4 : 3, height/2-7, (theme->col_fxkeyboard_btn_label | BIT(15)));
143163

144-
drawChar(GLYPH_3X5(small_caption[0]), 3, 16, theme->col_pv_notes);
145-
drawChar(GLYPH_3X5(small_caption[1]), 7, 16, small_caption[1] == 'Y' ? theme->col_pv_effect : theme->col_pv_notes);
164+
if (small_caption == NULL) return;
165+
drawChar(GLYPH_3X5(small_caption[0]), 3, 16, theme->col_fxkeyboard_minilabel_x);
166+
drawChar(GLYPH_3X5(small_caption[1]), 7, 16, small_caption[1] == 'Y' ? theme->col_fxkeyboard_minilabel_y : theme->col_fxkeyboard_minilabel_x);
146167
}

arm9/source/tobkit/fxbutton.h

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ limitations under the License.
1717
#ifndef FXBUTTON_H
1818
#define FXBUTTON_H
1919

20-
#define GLYPH_3X5_COUNT 47
21-
#define GLYPH_3X5(c) (c == ':') ? 40 : ((c < 58 && c > 47) ? (c - 48) : (c - 55))
22-
#define GLYPH_3X5_WIDTH 4
20+
2321

2422

2523
#define FX_CATEGORY_NORMAL 0
2624
#define FX_CATEGORY_E 1
2725
#define FX_CATEGORY_FT 2
2826
#define FX_CATEGORY_VOL 3
2927

30-
#include "../../arm9/fonts/font_3x5_raw.h"
3128
#include "tobkit/widget.h"
3229
namespace tobkit {
3330

@@ -55,38 +52,23 @@ class FXButton: public Widget {
5552
void buttonPress(u16 button);
5653
void setCategory(u8 newcat);
5754
void setValue(u8 newval);
58-
void hide(void);
5955
u8 getValue(void);
60-
void setIsECommand(bool e_cmd) { is_e_cmd = e_cmd; }
61-
bool getIsECommand(bool e_cmd) { return is_e_cmd; }
6256
inline bool isPenDown(void) const { return penIsDown; }
6357
void setCaption(const char *caption);
6458
void setSmallCaption(const char *small_caption);
6559
void setParent(FXKeyboard *parent_kb);
60+
bool set_visible(bool value);
61+
void hide(void);
6662
private:
6763
char *caption;
6864
char *small_caption;
6965
u8 category, value;
7066

7167
FXKeyboard *parent;
72-
bool is_e_cmd;
7368
void (*onPush)(u8 val, bool disabled);
74-
bool penIsDown;
69+
bool penIsDown, visible;
7570
void draw(u8 down);
76-
77-
inline void drawChar(u8 c, u8 cx, u8 cy, u16 col)
78-
{
79-
u8 i,j;
80-
for(j=0;j<5;++j) {
81-
for(i=0;i<3;++i) {
82-
u16 pixelidx = 3*GLYPH_3X5_COUNT*j+3*c+i;
83-
if(font_3x5_raw[pixelidx/8]&BIT(pixelidx%8)) {
84-
//*(*vram+SCREEN_WIDTH*(2+cy*8+j)+1+cx*4+i) = col;
85-
*(*vram+SCREEN_WIDTH*(y+cy+j)+x+cx+i) = col;
86-
}
87-
}
88-
}
89-
}
71+
void overdraw(void);
9072

9173
};
9274

arm9/source/tobkit/fxkeyboard.cpp

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@ FXKeyboard::FXKeyboard(u8 _x, u8 _y, uint16** _vram, void (*_onFxKeypress)(u8 pr
2929
void (*_onParamSet)(void), void (*_onFxClear)(void), bool _visible)
3030
: Widget(_x, _y, FXKEYBOARD_WIDTH, FXKEYBOARD_HEIGHT, _vram, _visible),
3131
caption(0), darken_title(false), onFxKeypress(_onFxKeypress), onParamChange(_onParamChange),
32-
onParamSet(_onParamSet), onFxClear(_onFxClear), last_e_cmd(0)
32+
onParamSet(_onParamSet), onFxClear(_onFxClear), last_cmd(0)
3333
{
34-
for (int i = 0; i < NUM_FXKEYS; ++i)
35-
{
36-
fxbuttons[i] = new FXButton(x + FXKEYBOARD_LMARGIN + ((FXBUTTON_WIDTH - 1) * i), y + FXKEYBOARD_YMARGIN, _vram, true);
37-
fxbuttons[i]->registerPushCallback(onFxKeypress);
38-
fxbuttons[i]->setParent(this);
39-
gui.registerWidget(fxbuttons[i]);
40-
}
34+
4135

4236
effectpar = new DigitBox(186, 164, 35, 17, _vram, 0, 0, 255, 2);
4337
effectpar->registerChangeCallback(onParamChange);
@@ -57,6 +51,14 @@ FXKeyboard::FXKeyboard(u8 _x, u8 _y, uint16** _vram, void (*_onFxKeypress)(u8 pr
5751

5852
gui.registerWidget(buttonseteffectpar);
5953

54+
for (int i = 0; i < NUM_FXKEYS; ++i)
55+
{
56+
fxbuttons[i] = new FXButton(x + FXKEYBOARD_LMARGIN + ((FXBUTTON_WIDTH - 1) * i), y + FXKEYBOARD_YMARGIN, _vram, true);
57+
fxbuttons[i]->registerPushCallback(onFxKeypress);
58+
fxbuttons[i]->setParent(this);
59+
gui.registerWidget(fxbuttons[i]);
60+
}
61+
6062
setCategory(0);
6163
}
6264

@@ -104,14 +106,14 @@ void FXKeyboard::setParam(u8 val)
104106
effectpar->setValue(val);
105107
}
106108

107-
u8 FXKeyboard::getLastECmd(void)
109+
u8 FXKeyboard::getLastCmd(void)
108110
{
109-
return last_e_cmd;
111+
return last_cmd;
110112
}
111113

112-
void FXKeyboard::setLastECmd(u8 _last_e_cmd)
114+
void FXKeyboard::setLastCmd(u8 _last_e_cmd)
113115
{
114-
last_e_cmd = _last_e_cmd;
116+
last_cmd = _last_e_cmd;
115117
}
116118

117119
void FXKeyboard::useDarkTitle(bool _darken_title)
@@ -125,6 +127,7 @@ void FXKeyboard::updateFxCaption(u8 val)
125127
setCaption(captions[val]);
126128
else if (category == FX_CATEGORY_E)
127129
setCaption(E_captions[val]);
130+
drawCaption();
128131
}
129132

130133
void FXKeyboard::setCategory(u8 newcat) {
@@ -136,31 +139,35 @@ void FXKeyboard::setCategory(u8 newcat) {
136139

137140
if (bt == 0) continue;
138141

139-
bt->enable();
140-
bt->show();
142+
bool hidden = false, disabled = false;
141143

142144
if (newcat == FX_CATEGORY_NORMAL) {
143-
if (i >= 5 && i <= 7) bt->disable();
145+
if (i >= 5 && i <= 7) disabled = true;
144146

145-
fxbuttons[i]->setSmallCaption(((xy_magicnum >> i) & 0x1) ? "XY" : "XX");
147+
bt->setSmallCaption(((xy_magicnum >> i) & 0x1) ? "XY" : "XX");
146148
} else if (newcat == FX_CATEGORY_E) {
147-
if (i == 0 || (i > 6 && i < 0xC)) bt->disable();
149+
if (i == 0 || (i > 6 && i < 0xC)) disabled = false;
148150

149151
char lbl[3];
150152
snprintf(lbl, 3, "%1XX", i);
151-
fxbuttons[i]->setSmallCaption(lbl);
153+
bt->setSmallCaption(lbl);
152154
} else {
153155
if ((newcat == FX_CATEGORY_FT && i >= 7) || (newcat == FX_CATEGORY_VOL && i >= 9)) {
154-
bt->hide();
156+
hidden = true;
155157
}
156-
157-
bt->disable();
158+
bt->setSmallCaption(NULL);
159+
disabled = true;
158160
}
159161

160-
const char lbl[2] = { fxlabels[i][newcat], '\0' };
161-
bt->setCaption(lbl);
162-
bt->setCategory(newcat); // calls draw()
163-
bt->setValue(i);
162+
if (!hidden) {
163+
const char lbl[2] = { fxlabels[i][newcat], '\0' };
164+
bt->setCaption(lbl);
165+
bt->setCategory(newcat);
166+
bt->setValue(i);
167+
bt->set_enabled(!disabled);
168+
}
169+
170+
bt->set_visible(!hidden);
164171
effectpar->setSingleDigit(newcat == FX_CATEGORY_E);
165172
}
166173

@@ -187,9 +194,7 @@ void FXKeyboard::setCategory(u8 newcat) {
187194
useDarkTitle(true);
188195
break;
189196
}
190-
191-
192-
draw();
197+
drawCaption();
193198
}
194199

195200

@@ -204,18 +209,24 @@ void FXKeyboard::setCaption(const char* _caption) {
204209
if (caption) ntxm_free(caption);
205210
caption = (char*)ntxm_cmalloc(strlen(_caption) + 1);
206211
strcpy(caption, _caption);
207-
draw();
208212
}
209213

210214
/* ===================== PRIVATE ===================== */
211215

216+
void FXKeyboard::drawCaption(void) {
217+
if (!isExposed()) return;
218+
219+
drawFullBox(1, 4, width-45, 8, bgcolor);
220+
u16 capcol = darken_title ? theme->col_fxkeyboard_cmd_label_disabled : theme->col_fxkeyboard_cmd_label;
221+
drawSmallString(caption, ((NUM_FXKEYS * FXBUTTON_WIDTH) / 2) - (2 * strlen(caption)), 4, capcol); // width=(3px char+1px space) / 2
222+
}
223+
212224
void FXKeyboard::draw(void) {
213225
if (!isExposed()) return;
214226

215227
drawFullBox(0, 0, width, height, theme->col_bg); // hide the piano
216228

217-
u16 capcol = darken_title ? theme->col_dark_ctrl_disabled : theme->col_text_light;
218-
drawSmallString(caption, ((NUM_FXKEYS * FXBUTTON_WIDTH) / 2) - (2 * strlen(caption)), 4, capcol);
229+
drawCaption();
219230
gui.revealAll();
220231
gui.draw();
221232
}

0 commit comments

Comments
 (0)