Skip to content

Commit ccd51b9

Browse files
committed
working on arduino gui
1 parent b9b6489 commit ccd51b9

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

arduino/hwtest/hwtest2_guitest/SynthUI.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class SynthUI {
4141
}
4242

4343

44-
void print_text(int x, int y, const char* str, const GFXfont *fnt = NULL) {
45-
if(fnt!=NULL) { display->setFont(fnt); }
44+
void print_text(int x, int y, const char* str, const GFXfont* fnt = NULL) {
45+
if (fnt != NULL) { display->setFont(fnt); }
4646
display->setTextColor(WHITE, 0);
4747
display->setCursor(x, y);
4848
display->print(str);
@@ -52,11 +52,22 @@ class SynthUI {
5252
* Draw vertical slider with a "thumb" position identifying value
5353
* thumpos ranges 0.0-1.0
5454
*/
55-
void draw_vertical_slider(int x, int y, float thumbpos, int w = 5, int h = 63, int thumbw = 5, int thumbh = 10) {
55+
void draw_vertical_slider(int x, int y, float thumbpos, int w = 5, int h = 63, int thumbw = 0, int thumbh = 10) {
5656
int ypos = thumbpos * h;
57+
thumbw = (thumbw==0) ? w : thumbw; // make thumbw same width as slider if not specified
5758
display->drawRect(x, y, w, h, WHITE); // right side scroll bar
5859
display->fillRect(x, y + ypos, thumbw, thumbh, WHITE); // FIXME
5960
}
61+
/**
62+
* Draw horizontal slider with a "thumb" position identifying value
63+
* thumpos ranges 0.0-1.0
64+
*/
65+
void draw_horizontal_slider(int x, int y, float thumbpos, int w = 127, int h = 5, int thumbw = 10, int thumbh = 0) {
66+
int xpos = thumbpos * (w - thumbw);
67+
thumbh = (thumbh==0) ? h : thumbh; // make thumbh same height as slider if not specified
68+
display->drawRect(x, y - h, w, h, WHITE); // right side scroll bar
69+
display->fillRect(x + xpos, y - h, thumbw, thumbh, WHITE); // FIXME
70+
}
6071

6172

6273
Adafruit_GFX* display;

arduino/hwtest/hwtest2_guitest/hwtest2_guitest.ino

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,12 @@ void updateInputs() {
120120
}
121121
}
122122

123-
124-
/**
125-
* Draw vertical slider with a "thumb" position identifying value
126-
* thumpos ranges 0.0-1.0
127-
*/
128-
void draw_vertical_slider(int x, int y, float thumbpos, int w=5, int h=63, int thumbw=5, int thumbh=10 ) {
129-
int ypos = thumbpos * h;
130-
display.drawRect( x, y, w, h, WHITE ); // right side scroll bar
131-
display.fillRect( x, y + ypos, thumbw, thumbh, WHITE ); // FIXME
132-
}
133-
/**
134-
* Draw horizontal slider with a "thumb" position identifying value
135-
* thumpos ranges 0.0-1.0
136-
*/
137-
void draw_horizontal_slider(int x, int y, float thumbpos, int w=127, int h=5, int thumbw=10, int thumbh=5) {
138-
int xpos = thumbpos * (w-thumbw);
139-
display.drawRect( x, y-h, w, h, WHITE ); // right side scroll bar
140-
display.fillRect( x+xpos, y-h, thumbw, thumbh, WHITE ); // FIXME
141-
}
142-
143123
/**
144124
*
145125
*/
146126
void updateDisplay() {
147127
// delay(50);
148-
char buf[20];
128+
char buf1[20], buf2[20];
149129
float xpos, ypos;
150130
int hp = hilite_param + param_offset;
151131

@@ -164,23 +144,19 @@ void updateDisplay() {
164144
display.setFont(&myfont);
165145
display.setTextColor(WHITE, 0);
166146

167-
draw_vertical_slider( 122, 0, (float)param_offset / (num_params-num_disp_params+1));
147+
synthui.draw_vertical_slider( 122, 0, (float)param_offset / (num_params-num_disp_params+1));
168148

169149
for (int i = 0; i < num_disp_params; i++) {
170-
display.setFont( i==hilite_param ? &myfontB : &myfont);
150+
//display.setFont( );
171151
int io = i + param_offset;
172152
int loff = line_offset + i * line_spacing;
173153
if (io < num_params) {
174-
snprintf(buf, 20, "%s", params[io].name);
175-
display.setCursor(5, loff); // param name
176-
display.print(buf);
177-
display.setFont(&myfontSM);
178-
snprintf(buf, 20, params[io].fmt, params[io].val); // param value
179-
// display.setFont( i==hilite_param ? &myfontB : &myfont);
180-
display.setCursor(45, loff);
181-
display.print(": ");
182-
display.print(buf);
183-
draw_horizontal_slider( 80, loff, params[io].percent(), 30, 5 );
154+
snprintf(buf1, 20, "%s", params[io].name);
155+
snprintf(buf2, 20, params[io].fmt, params[io].val); // param value
156+
synthui.print_text(5, loff, buf1, i==hilite_param ? &myfontB : &myfont);
157+
synthui.print_text(45, loff, ":", &myfontSM);
158+
synthui.print_text(50, loff, buf2);
159+
synthui.draw_horizontal_slider( 80, loff, params[io].percent(), 35, 7,7 );
184160
}
185161
}
186162

0 commit comments

Comments
 (0)