Add FTGL dependency and text all the things

This commit is contained in:
2013-02-04 07:31:26 +00:00
parent 35a44308d9
commit 2841c71f7f
12 changed files with 6496 additions and 6 deletions

View File

@@ -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

34
pui/label.cpp Normal file
View File

@@ -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;
}
}

16
pui/label.h Normal file
View File

@@ -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 */

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
};

6366
pui/textures/font.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -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;
}

View File

@@ -32,6 +32,9 @@ struct Widget : Rect {
float min;
float max;
float value;
char group[128];
char label[128];
char text[128];
bool active;