Add FTGL dependency and text all the things
parent
35a44308d9
commit
2841c71f7f
|
@ -12,8 +12,8 @@ PTAPUISRC := ptapui.cpp
|
|||
PTAPUIOBJ := $(PTAPUISRC:.cpp=.o) ../pui/*.o
|
||||
PTAPUIO := ptapui.so
|
||||
|
||||
$(PTAPUIOBJ): CFLAGS += `pkg-config lv2core pugl-0 --cflags`
|
||||
$(PTAPUIO): LDFLAGS += `pkg-config lv2core pugl-0 --libs`
|
||||
$(PTAPUIOBJ): CFLAGS += `pkg-config lv2core ftgl pugl-0 --cflags`
|
||||
$(PTAPUIO): LDFLAGS += `pkg-config lv2core ftgl pugl-0 --libs`
|
||||
|
||||
CPP := g++
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ struct PTapUI : PUi {
|
|||
|
||||
void PTapUI::InitWidgets()
|
||||
{
|
||||
char tmp[128];
|
||||
|
||||
scale = 1.0f;
|
||||
|
||||
widget = new Container();
|
||||
|
@ -62,7 +64,15 @@ void PTapUI::InitWidgets()
|
|||
int padding = 4;
|
||||
|
||||
int c_w = (widget->w - padding * 3) * 0.5f;
|
||||
int c_h = (widget->h - padding * 5) * 0.25f;
|
||||
int c_h = (widget->h - 25 - padding * 5) * 0.25f;
|
||||
|
||||
Container *t = new Container();
|
||||
t->colour = Colour(0, 0, 0, .5f);
|
||||
t->x = 0;
|
||||
t->y = 0;
|
||||
t->w = widget->w;
|
||||
t->h = 25;
|
||||
this->widget->children.push_back(t);
|
||||
|
||||
int slide_w = 25;
|
||||
int slide_h = c_h - 25;
|
||||
|
@ -71,7 +81,7 @@ void PTapUI::InitWidgets()
|
|||
Container *c = new Container();
|
||||
if (i < TAPS) c->frame = Colour(0, 0, 0, .15f);
|
||||
c->x = (i & 1) * (c_w + padding) + padding;
|
||||
c->y = (i >> 1) * (c_h + padding) + padding;
|
||||
c->y = (i >> 1) * (c_h + padding) + padding + 25;
|
||||
c->w = c_w;
|
||||
c->h = c_h;
|
||||
/*
|
||||
|
@ -112,8 +122,16 @@ void PTapUI::InitWidgets()
|
|||
c4->h = slide_h;
|
||||
c->children.push_back(c4);
|
||||
|
||||
if (i < TAPS) {
|
||||
snprintf(tmp, sizeof tmp, "Tap %d", i + 1);
|
||||
} else {
|
||||
strncpy(tmp, i == TAPS ? "Left Out" : "Right Out", sizeof tmp);
|
||||
}
|
||||
|
||||
for (int j = 0; j < TAPS; j++) {
|
||||
Slider *slider = new VSlider();
|
||||
strncpy(slider->group, tmp, sizeof slider->group);
|
||||
snprintf(slider->label, sizeof slider->label, "Tap %d", j + 1);
|
||||
slider->big = false;
|
||||
if (i == j) {
|
||||
slider->colour = Colour(.5f, .7f, 1, 1);
|
||||
|
@ -133,6 +151,8 @@ void PTapUI::InitWidgets()
|
|||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
Slider *slider = new VSlider();
|
||||
strncpy(slider->group, tmp, sizeof slider->group);
|
||||
strncpy(slider->label, j == 0 ? "Left" : "Right", sizeof slider->label);
|
||||
slider->big = false;
|
||||
slider->x = c3->x + j * slide_w;//(j & 1) * slide_w;
|
||||
slider->y = c3->y;// + (j >> 1) * slide_h;
|
||||
|
@ -147,6 +167,8 @@ void PTapUI::InitWidgets()
|
|||
|
||||
for (int j = 0; j < 1; j++) {
|
||||
Slider *slider = new VSlider();
|
||||
strncpy(slider->group, tmp, sizeof slider->group);
|
||||
strncpy(slider->label, "Gain", sizeof slider->label);
|
||||
slider->big = i >= TAPS;
|
||||
slider->colour = Colour(1, .2f, .2f, 1);
|
||||
slider->x = c4->x + j * slide_w;//(j & 1) * slide_w;
|
||||
|
@ -169,6 +191,8 @@ void PTapUI::InitWidgets()
|
|||
c->children.push_back(c5);
|
||||
|
||||
Knob *k = new Knob();
|
||||
strncpy(k->group, tmp, sizeof k->group);
|
||||
strncpy(k->label, "Delay", sizeof k->label);
|
||||
k->x = c5->x;
|
||||
k->y = c5->y;
|
||||
k->w = c5->w;
|
||||
|
@ -182,6 +206,13 @@ void PTapUI::InitWidgets()
|
|||
|
||||
this->widget->children.push_back(c);
|
||||
}
|
||||
|
||||
tooltip = new Label();
|
||||
tooltip->x = widget->w * 0.5f;
|
||||
tooltip->y = 10;
|
||||
tooltip->colour = Colour(1, 1, 1, 1);
|
||||
tooltip->SetLabel("INIT");
|
||||
this->widget->children.push_back(tooltip);
|
||||
}
|
||||
|
||||
static void *ui_thread(void *ptr)
|
||||
|
@ -199,6 +230,10 @@ void PTapUI::ParameterChanged(const Widget *w)
|
|||
if (w->port == UINT_MAX) return;
|
||||
|
||||
this->write(this->controller, w->port, sizeof w->value, 0, &w->value);
|
||||
|
||||
char tmp[64];
|
||||
snprintf(tmp, sizeof tmp, "(%s) %s: %0.4f", w->group, w->label, w->value);
|
||||
tooltip->SetLabel(tmp);
|
||||
}
|
||||
|
||||
static LV2UI_Handle ptapui_instantiate(
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
CFLAGS := -Wall -O3 -g -D_GNU_SOURCE
|
||||
LDFLAGS := -lm
|
||||
|
||||
CFLAGS += `pkg-config pugl-0 --cflags`
|
||||
LDFLAGS += `pkg-config pugl-0 --libs`
|
||||
CFLAGS += `pkg-config ftgl pugl-0 --cflags`
|
||||
LDFLAGS += `pkg-config ftgl pugl-0 --libs`
|
||||
|
||||
PUISRC := container.cpp
|
||||
PUISRC += label.cpp
|
||||
PUISRC += knob.cpp
|
||||
PUISRC += pui.cpp
|
||||
PUISRC += slider.cpp
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#include <cstring>
|
||||
#include <FTGL/ftgl.h>
|
||||
#include <pugl/pugl.h>
|
||||
#include "pui.h"
|
||||
|
||||
void Label::OnPaint(const PUi *pui) const
|
||||
{
|
||||
// if (this->dirty) {
|
||||
/* Update bounding box */
|
||||
FTBBox box = pui->font->BBox(this->text);
|
||||
FTPoint p = box.Upper() - box.Lower();
|
||||
float cx = p.X();
|
||||
float cy = p.Y();
|
||||
// }
|
||||
|
||||
float ox = -.5f;
|
||||
float oy = 0;
|
||||
|
||||
glPushMatrix();
|
||||
glColor4f(colour.r, colour.g, colour.b, colour.a);
|
||||
glTranslatef(x + w * 0.5f, y + h * 0.5f + 10, 0);
|
||||
glScalef(.6f, -.6f, 1);
|
||||
glTranslatef(cx * ox, cy * oy, 0);
|
||||
pui->font->Render(this->text);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Label::SetLabel(const char *str)
|
||||
{
|
||||
if (strcmp(str, this->text)) {
|
||||
strncpy(this->text, str, sizeof this->text);
|
||||
this->dirty = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef LABEL_H
|
||||
#define LABEL_H
|
||||
|
||||
struct Label : Widget {
|
||||
Colour colour;
|
||||
char text[64];
|
||||
bool dirty;
|
||||
float cx;
|
||||
float cy;
|
||||
|
||||
/* virtual */ void OnPaint(const PUi *pui) const;
|
||||
|
||||
void SetLabel(const char *str);
|
||||
};
|
||||
|
||||
#endif /* LABEL_H */
|
|
@ -1,9 +1,12 @@
|
|||
#ifndef PUI_H
|
||||
#define PUI_H
|
||||
|
||||
#include <FTGL/ftgl.h>
|
||||
|
||||
#include "textures.h"
|
||||
#include "widget.h"
|
||||
#include "container.h"
|
||||
#include "label.h"
|
||||
#include "knob.h"
|
||||
#include "slider.h"
|
||||
|
||||
|
@ -11,6 +14,7 @@ struct PUi : PTextures {
|
|||
PuglView *view;
|
||||
Container *widget;
|
||||
|
||||
Label *tooltip;
|
||||
Widget *active;
|
||||
int mx, my, mb, mm;
|
||||
float scale;
|
||||
|
|
|
@ -209,6 +209,26 @@ void VSlider::OnPaint(const PUi *pui) const
|
|||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
char tmp[128];
|
||||
snprintf(tmp, sizeof tmp, "%s", this->label);
|
||||
|
||||
FTBBox box = pui->font->BBox(tmp);
|
||||
FTPoint p = box.Upper() - box.Lower();
|
||||
float cx = p.X();
|
||||
float cy = p.Y();
|
||||
|
||||
float ox = -.5f;
|
||||
float oy = 0;
|
||||
|
||||
glPushMatrix();
|
||||
// glColor4f(colour.r, colour.g, colour.b, colour.a);
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glTranslatef(x + w * 0.5f, y - 4, 0);
|
||||
glScalef(.5f, -.5f, 1);
|
||||
glTranslatef(cx * ox, -cy * oy, 0);
|
||||
pui->font->Render(tmp);
|
||||
glPopMatrix();
|
||||
|
||||
if (this->active) {
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glColor4f(1.f, 1.f, 1.0f, 0.25f);
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include "textures/trough2-vertical.c"
|
||||
#include "textures/knob4.c"
|
||||
|
||||
#include "textures/font.c"
|
||||
|
||||
void PTextures::BindTexture(int texture, int width, int height, const unsigned char *data, int format)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, tex[texture]);
|
||||
|
@ -87,4 +89,9 @@ void PTextures::InitTextures()
|
|||
knob4.width,
|
||||
knob4.height,
|
||||
knob4.pixel_data);
|
||||
|
||||
this->font = new FTTextureFont(font_data, font_data_len);
|
||||
// this->font = FTGL::ftglCreateTextureFont("/usr/share/fonts/truetype/droid/DroidSans.ttf");
|
||||
this->font->FaceSize(20);
|
||||
// FTGL::ftglSetFontFaceSize(this->font, 12, 12);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ struct PTextures {
|
|||
int w[TEX_END];
|
||||
int h[TEX_END];
|
||||
|
||||
FTFont *font;
|
||||
|
||||
void InitTextures();
|
||||
void BindTexture(int texture, int width, int height, const unsigned char *data, int format = GL_RGBA);
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,6 +10,8 @@ bool Widget::SetValue(float newvalue)
|
|||
/* Value is different? */
|
||||
if (newvalue == this->value) return false;
|
||||
|
||||
snprintf(this->text, sizeof this->text, "%s: %0.4f", this->label, newvalue);
|
||||
|
||||
this->value = newvalue;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@ struct Widget : Rect {
|
|||
float min;
|
||||
float max;
|
||||
float value;
|
||||
char group[128];
|
||||
char label[128];
|
||||
char text[128];
|
||||
|
||||
bool active;
|
||||
|
||||
|
|
Loading…
Reference in New Issue