Skip to content

Commit

Permalink
ofxDatGuiFont rebuilt and simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
braitsch committed Dec 30, 2015
1 parent 5583887 commit 2f6ad8e
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
8A8DBFA31C33A02B0022544D /* ofxDatGuiTheme.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A8DBFA11C33A02B0022544D /* ofxDatGuiTheme.cpp */; };
8AB357521BB2302E002AC802 /* ofxDatGuiComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8AB357471BB2302E002AC802 /* ofxDatGuiComponent.cpp */; };
8AB357531BB2302E002AC802 /* ofxDatGui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8AB3574D1BB2302E002AC802 /* ofxDatGui.cpp */; };
8AB35E491BDF1BB400A016A1 /* ofxDatGuiTheme.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8AB35E481BDF1BB400A016A1 /* ofxDatGuiTheme.cpp */; };
E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4328148138ABC890047C5CB /* openFrameworksDebug.a */; };
E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; };
E4B69E210A3A1BDC003C02F2 /* ofApp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1E0A3A1BDC003C02F2 /* ofApp.cpp */; };
Expand Down Expand Up @@ -46,6 +46,9 @@

/* Begin PBXFileReference section */
8A1D66EC1BC7570800D30189 /* ofxDatGuiTimeGraph.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiTimeGraph.h; sourceTree = "<group>"; };
8A8DBFA01C33A02B0022544D /* ofxDatGuiMyThemes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiMyThemes.h; sourceTree = "<group>"; };
8A8DBFA11C33A02B0022544D /* ofxDatGuiTheme.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ofxDatGuiTheme.cpp; sourceTree = "<group>"; };
8A8DBFA21C33A02B0022544D /* ofxDatGuiTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiTheme.h; sourceTree = "<group>"; };
8AB3573B1BB2302E002AC802 /* ofxDatGui2dPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGui2dPad.h; sourceTree = "<group>"; };
8AB3573C1BB2302E002AC802 /* ofxDatGuiButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiButton.h; sourceTree = "<group>"; };
8AB3573D1BB2302E002AC802 /* ofxDatGuiColorPicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiColorPicker.h; sourceTree = "<group>"; };
Expand All @@ -61,13 +64,9 @@
8AB357481BB2302E002AC802 /* ofxDatGuiComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiComponent.h; sourceTree = "<group>"; };
8AB357491BB2302E002AC802 /* ofxDatGuiConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiConstants.h; sourceTree = "<group>"; };
8AB3574A1BB2302E002AC802 /* ofxDatGuiEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiEvents.h; sourceTree = "<group>"; };
8AB3574B1BB2302E002AC802 /* ofxDatGuiFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiFont.h; sourceTree = "<group>"; };
8AB3574C1BB2302E002AC802 /* ofxDatGuiIntObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiIntObject.h; sourceTree = "<group>"; };
8AB3574D1BB2302E002AC802 /* ofxDatGui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxDatGui.cpp; path = ../src/ofxDatGui.cpp; sourceTree = "<group>"; };
8AB3574E1BB2302E002AC802 /* ofxDatGui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxDatGui.h; path = ../src/ofxDatGui.h; sourceTree = "<group>"; };
8AB357501BB2302E002AC802 /* ofxDatGuiTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxDatGuiTheme.h; path = ../themes/ofxDatGuiTheme.h; sourceTree = "<group>"; };
8AB357511BB2302E002AC802 /* ofxDatGuiMyThemes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxDatGuiMyThemes.h; path = ../themes/ofxDatGuiMyThemes.h; sourceTree = "<group>"; };
8AB35E481BDF1BB400A016A1 /* ofxDatGuiTheme.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxDatGuiTheme.cpp; path = ../themes/ofxDatGuiTheme.cpp; sourceTree = "<group>"; };
E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = openFrameworksLib.xcodeproj; path = ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj; sourceTree = SOURCE_ROOT; };
E4B69B5B0A3A1756003C02F2 /* example-AllComponentsGuiDebug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "example-AllComponentsGuiDebug.app"; sourceTree = BUILT_PRODUCTS_DIR; };
E4B69E1D0A3A1BDC003C02F2 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = src/main.cpp; sourceTree = SOURCE_ROOT; };
Expand All @@ -90,6 +89,17 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
8A8DBF9F1C33A02B0022544D /* themes */ = {
isa = PBXGroup;
children = (
8A8DBFA01C33A02B0022544D /* ofxDatGuiMyThemes.h */,
8A8DBFA11C33A02B0022544D /* ofxDatGuiTheme.cpp */,
8A8DBFA21C33A02B0022544D /* ofxDatGuiTheme.h */,
);
name = themes;
path = ../src/themes;
sourceTree = "<group>";
};
8AB3573A1BB2302E002AC802 /* components */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -117,24 +127,12 @@
8AB357481BB2302E002AC802 /* ofxDatGuiComponent.h */,
8AB357491BB2302E002AC802 /* ofxDatGuiConstants.h */,
8AB3574A1BB2302E002AC802 /* ofxDatGuiEvents.h */,
8AB3574B1BB2302E002AC802 /* ofxDatGuiFont.h */,
8AB3574C1BB2302E002AC802 /* ofxDatGuiIntObject.h */,
);
name = core;
path = ../src/core;
sourceTree = "<group>";
};
8AB3574F1BB2302E002AC802 /* themes */ = {
isa = PBXGroup;
children = (
8AB35E481BDF1BB400A016A1 /* ofxDatGuiTheme.cpp */,
8AB357501BB2302E002AC802 /* ofxDatGuiTheme.h */,
8AB357511BB2302E002AC802 /* ofxDatGuiMyThemes.h */,
);
name = themes;
path = ../src/templates;
sourceTree = "<group>";
};
BB4B014C10F69532006C3DED /* addons */ = {
isa = PBXGroup;
children = (
Expand All @@ -146,11 +144,11 @@
D8DD1043C333F6F63C8685E6 /* ofxDatGui */ = {
isa = PBXGroup;
children = (
8AB357461BB2302E002AC802 /* core */,
8AB3573A1BB2302E002AC802 /* components */,
8AB3574D1BB2302E002AC802 /* ofxDatGui.cpp */,
8AB3574E1BB2302E002AC802 /* ofxDatGui.h */,
8AB3574F1BB2302E002AC802 /* themes */,
8AB357461BB2302E002AC802 /* core */,
8AB3573A1BB2302E002AC802 /* components */,
8A8DBF9F1C33A02B0022544D /* themes */,
);
name = ofxDatGui;
sourceTree = "<group>";
Expand Down Expand Up @@ -285,7 +283,7 @@
8AB357531BB2302E002AC802 /* ofxDatGui.cpp in Sources */,
E4B69E210A3A1BDC003C02F2 /* ofApp.cpp in Sources */,
8AB357521BB2302E002AC802 /* ofxDatGuiComponent.cpp in Sources */,
8AB35E491BDF1BB400A016A1 /* ofxDatGuiTheme.cpp in Sources */,
8A8DBFA31C33A02B0022544D /* ofxDatGuiTheme.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion example-AllComponentsGui/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void ofApp::setup()
gui = new ofxDatGui( ofxDatGuiAnchor::TOP_RIGHT );

// uncomment this line to assign a custom theme //
// gui->setTheme(new ofxDatGuiExampleCustomTheme());
gui->setTheme(new ofxDatGuiExampleCustomTheme());

// add some components //
gui->addTextInput("message", "# open frameworks #");
Expand Down
2 changes: 1 addition & 1 deletion src/components/ofxDatGuiGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class ofxDatGuiDropdownOption : public ofxDatGuiButton {
{
ofxDatGuiButton::onThemeSet(tmplt);
mStyle.stripe.color = tmplt->stripe.dropdown;
mLabel.rect = mFont->getStringBoundingBox("* "+mLabel.text, 0, 0);
mLabel.rect = mFont.getRect("* "+mLabel.text);
}

};
Expand Down
1 change: 1 addition & 0 deletions src/components/ofxDatGuiLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ofxDatGuiBreak : public ofxDatGuiComponent{
} else {
mStyle.height = ofxDatGuiComponent::theme->layout.height * .1;
}
onThemeSet(ofxDatGuiComponent::theme.get());
}

void draw()
Expand Down
15 changes: 9 additions & 6 deletions src/components/ofxDatGuiMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ class ofxDatGuiMatrixButton : public ofxDatGuiInteractiveObject {

void draw(int x, int y)
{
mRect.x = x+origin.x;
mRect.y = y+origin.y;
mRect.x = x + origin.x;
mRect.y = y + origin.y;
ofPushStyle();
ofFill();
ofSetColor(mBkgdColor);
ofDrawRectangle(mRect);
if (mShowLabels) mFont->drawText(ofToString(mIndex+1), mLabelColor, mRect.x+mRect.width/2-mFontRect.width/2, mRect.y+mRect.height/2);
if (mShowLabels) {
ofSetColor(mLabelColor);
mFont.draw(ofToString(mIndex+1), mRect.x + mRect.width/2 - mFontRect.width/2, mRect.y + mRect.height/2 + mFontRect.height/2);
}
ofPopStyle();
}

Expand Down Expand Up @@ -100,8 +103,8 @@ class ofxDatGuiMatrixButton : public ofxDatGuiInteractiveObject {

void setTheme(const ofxDatGuiTheme* tmplt)
{
mFont = tmplt->font.ttf;
mFontRect = mFont->getStringBoundingBox(ofToString(mIndex+1), 0, 0);
mFont.ttf = &tmplt->font.ttf;
mFontRect = mFont.getRect(ofToString(mIndex+1));
mBkgdColor = tmplt->color.matrix.normal.button;
mLabelColor = tmplt->color.matrix.normal.label;
colors.normal.label = tmplt->color.matrix.normal.label;
Expand All @@ -123,7 +126,7 @@ class ofxDatGuiMatrixButton : public ofxDatGuiInteractiveObject {
bool mSelected;
bool mShowLabels;
ofRectangle mFontRect;
ofxDatGuiFont* mFont;
ofxDatGuiFont mFont;
struct {
struct{
ofColor label;
Expand Down
54 changes: 34 additions & 20 deletions src/components/ofxDatGuiTextInputField.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ofxDatGuiTextInputField : public ofxDatGuiInteractiveObject{

ofxDatGuiTextInputField(float height)
{
mRect.height = height;
mInputRect.height = height;
mFocused = false;
mTextChanged = false;
mHighlightText = false;
Expand All @@ -47,56 +47,69 @@ class ofxDatGuiTextInputField : public ofxDatGuiInteractiveObject{

void setWidth(int w)
{
mRect.width = w;
mInputRect.width = w;
}

void setOrigin(int x, int y)
{
mRect.x = x;
mRect.y = y;
mInputRect.x = x;
mInputRect.y = y;
}

void setTheme(const ofxDatGuiTheme* tmplt)
{
mFont = tmplt->font.ttf;
mFont.ttf = &tmplt->font.ttf;
color.active.background = tmplt->color.backgroundOnMouseOver;
color.inactive.background = tmplt->color.inputAreaBackground;
color.active.text = tmplt->color.label;
color.inactive.text = tmplt->color.textInput.text;
color.highlight = tmplt->color.textInput.highlight;
mUpperCaseText = tmplt->layout.textInput.forceUpperCase;
mHighlightPadding = tmplt->layout.textInput.highlightPadding;
}

void draw()
{
// center the text //
int tx = mRect.width / 2 - mTextRect.width / 2;
int tx = mInputRect.x + mInputRect.width / 2 - mTextRect.width / 2;
int ty = mInputRect.y + mInputRect.height / 2 - mTextRect.height / 2;
ofPushStyle();
// draw the input field background //
if (mFocused && mType != COLORPICKER){
ofSetColor(color.active.background);
} else {
ofSetColor(color.inactive.background);
}
ofDrawRectangle(mRect);
ofDrawRectangle(mInputRect);
// draw the highlight rectangle //
if (mHighlightText){
ofRectangle hRect;
hRect.x = tx - mHighlightPadding;
hRect.width = mTextRect.width + (mHighlightPadding * 2);
hRect.y = ty - mHighlightPadding;
hRect.height = mTextRect.height + (mHighlightPadding * 2);
ofSetColor(color.highlight);
ofDrawRectangle(hRect);
}
// draw the text //
ofColor tColor = mHighlightText ? color.active.text : color.inactive.text;
mFont->drawText(mType == COLORPICKER ? "#" + mText : mText, tColor, mRect.x + tx, mRect.y + mRect.height / 2, mHighlightText);
ofSetColor(tColor);
mFont.draw(mType == COLORPICKER ? "#" + mText : mText, tx, ty + mTextRect.height);
if (mFocused) {
// draw the cursor //
ofSetColor(tColor);
ofDrawLine(ofPoint(mRect.x + tx + mCursorX, mRect.getBottom()), ofPoint(mRect.x + tx + mCursorX, mRect.getTop()));
ofDrawLine(ofPoint(tx + mCursorX, mInputRect.getTop()), ofPoint(tx + mCursorX, mInputRect.getBottom()));
}
ofPopStyle();
}

int getWidth()
{
return mRect.width;
return mInputRect.width;
}

int getHeight()
{
return mRect.height;
return mInputRect.height;
}

bool hasFocus()
Expand All @@ -106,15 +119,15 @@ class ofxDatGuiTextInputField : public ofxDatGuiInteractiveObject{

bool hitTest(ofPoint m)
{
return (m.x>=mRect.x && m.x<=mRect.x+mRect.width && m.y>=mRect.y && m.y<=mRect.y+mRect.height);
return (m.x>=mInputRect.x && m.x<=mInputRect.x+mInputRect.width && m.y>=mInputRect.y && m.y<=mInputRect.y+mInputRect.height);
}

void setText(string text)
{
mText = text;
mTextChanged = true;
if (mUpperCaseText) mText = ofToUpper(mText);
mTextRect = mFont->getStringBoundingBox(mType==COLORPICKER ? "#"+mText : mText, 0, 0);
mTextRect = mFont.getRect(mType==COLORPICKER ? "#"+mText : mText);
}

string getText()
Expand Down Expand Up @@ -198,11 +211,11 @@ class ofxDatGuiTextInputField : public ofxDatGuiInteractiveObject{
void setCursorIndex(int index)
{
if (index == 0) {
mCursorX = mFont->getStringBoundingBox(mText.substr(0, index), 0, 0).getLeft();
mCursorX = mFont.getRect(mText.substr(0, index)).getLeft();
} else if (index > 0) {
mCursorX = mFont->getStringBoundingBox(mText.substr(0, index), 0, 0).getRight();
mCursorX = mFont.getRect(mText.substr(0, index)).getRight();
// if we're at a space append the width the font's 'p' character //
if (mText.at(index - 1) == ' ') mCursorX+=mFont->getStringBoundingBox("p", 0, 0).width;
if (mText.at(index - 1) == ' ') mCursorX += mFont.getRect("p").width;
}
mCursorIndex = index;
}
Expand Down Expand Up @@ -260,10 +273,11 @@ class ofxDatGuiTextInputField : public ofxDatGuiInteractiveObject{
bool mHighlightText;
bool mUpperCaseText;
float mCursorX;
ofRectangle mTextRect;
ofRectangle mInputRect;
unsigned int mCursorIndex;
unsigned int mMaxCharacters;
ofRectangle mRect;
ofRectangle mTextRect;
unsigned int mHighlightPadding;
struct{
struct {
ofColor text;
Expand All @@ -276,7 +290,7 @@ class ofxDatGuiTextInputField : public ofxDatGuiInteractiveObject{
ofColor cursor;
ofColor highlight;
} color;
ofxDatGuiFont* mFont;
ofxDatGuiFont mFont;
ofxDatGuiTextInputFieldType mType;
};

37 changes: 22 additions & 15 deletions src/core/ofxDatGuiComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ void ofxDatGuiComponent::setTheme(ofxDatGuiTheme* tmplt)
mStyle.height = tmplt->layout.height;
mStyle.padding = tmplt->layout.padding;
mStyle.vMargin = tmplt->layout.vMargin;
mStyle.labelArea = tmplt->layout.labelAreaPercentage;
mStyle.labelMargin = tmplt->layout.labelMarginPercentage;
mStyle.color.background = tmplt->color.background;
mStyle.color.inputArea = tmplt->color.inputAreaBackground;
mStyle.color.onMouseOver = tmplt->color.backgroundOnMouseOver;
Expand All @@ -116,8 +118,7 @@ void ofxDatGuiComponent::setTheme(ofxDatGuiTheme* tmplt)
mIcon.y = mStyle.height * .33;
mIcon.size = mRetinaEnabled ? 20 : 10;
mIcon.color = tmplt->color.icons;
mFont = tmplt->font.ttf;
mLabel.maxWidth = tmplt->layout.label.maxWidth;
mFont.ttf = &tmplt->font.ttf;
mLabel.forceUpperCase = tmplt->layout.label.forceUpperCase;
setLabel(mLabel.text);
setWidth(mStyle.width);
Expand All @@ -128,19 +129,22 @@ void ofxDatGuiComponent::setTheme(ofxDatGuiTheme* tmplt)
void ofxDatGuiComponent::setWidth(int w)
{
mStyle.width = w;
mLabel.width = mStyle.width * .35;
if (mLabel.width > mLabel.maxWidth) mLabel.width = mLabel.maxWidth;
mFont->labelX = (mStyle.width * .03) + 10;
mLabel.width = mStyle.width * mStyle.labelArea;
mLabel.marginLeft = mStyle.width * mStyle.labelMargin;
mLabel.marginRight = mStyle.width * mStyle.labelMargin;
mIcon.x = mStyle.width - (mStyle.width * .05) - 20;
if (mType == ofxDatGuiType::BUTTON || mType == ofxDatGuiType::TOGGLE ||
mType == ofxDatGuiType::DROPDOWN || mType == ofxDatGuiType::FOLDER){
mLabel.width = mStyle.width;
if (mType != ofxDatGuiType::BUTTON){
mLabel.marginRight = mStyle.width - mIcon.x + (mStyle.width * mStyle.labelMargin);
}
}
for (int i=0; i<children.size(); i++) children[i]->setWidth(w);
// onWidthSet(w);
}

// methods to be overridden in derived classes after component has been updated //
//void ofxDatGuiComponent::onWidthSet(int width) {}
void ofxDatGuiComponent::onThemeSet(const ofxDatGuiTheme* tmplt) {

}
void ofxDatGuiComponent::onThemeSet(const ofxDatGuiTheme* tmplt) {}

const ofxDatGuiTheme* ofxDatGuiComponent::getTheme()
{
Expand Down Expand Up @@ -248,7 +252,7 @@ void ofxDatGuiComponent::setLabel(string label)
{
if (mLabel.forceUpperCase) label = ofToUpper(label);
mLabel.text = label;
mLabel.rect = mFont->getStringBoundingBox(mLabel.text, 0, 0);
mLabel.rect = mFont.getRect(mLabel.text);
}

string ofxDatGuiComponent::getLabel()
Expand Down Expand Up @@ -374,15 +378,18 @@ void ofxDatGuiComponent::drawLabel()

void ofxDatGuiComponent::drawLabel(string label)
{
int lx;
float lx;
if (mLabel.alignment == ofxDatGuiAlignment::LEFT){
lx = mFont->labelX;
lx = mLabel.marginLeft;
} else if (mLabel.alignment == ofxDatGuiAlignment::CENTER){
lx = (mLabel.width / 2) - (mLabel.rect.width / 2);
} else if (mLabel.alignment == ofxDatGuiAlignment::RIGHT){
lx = mLabel.width - mLabel.rect.width - mFont->labelX - mLabel.marginRight;
lx = mLabel.width - mLabel.rect.width - mLabel.marginRight;
}
mFont->drawLabel(label, x+lx, y+mStyle.height/2-mLabel.rect.height/2);
ofPushStyle();
ofSetColor(mLabel.color);
mFont.draw(mLabel.text, x+lx, y+mStyle.height/2 + mLabel.rect.height/2);
ofPopStyle();
}

void ofxDatGuiComponent::drawStripe()
Expand Down
Loading

0 comments on commit 2f6ad8e

Please sign in to comment.