Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openframeworks/openFrameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
arturoc committed May 27, 2020
2 parents 7cc5d21 + 8946a08 commit 5078acf
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 184 deletions.
32 changes: 26 additions & 6 deletions addons/ofxGui/src/ofxBaseGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ofxGuiDisableHiResDisplay(){


ofColor
ofxBaseGui::headerBackgroundColor(64),
ofxBaseGui::headerBackgroundColor(80),
ofxBaseGui::backgroundColor(0),
ofxBaseGui::borderColor(120, 100),
ofxBaseGui::textColor(255),
Expand Down Expand Up @@ -138,8 +138,19 @@ void ofxBaseGui::unregisterMouseEvents(){
ofUnregisterMouseEvents(this, defaultEventsPriority);
bRegisteredForMouseEvents = false;
}

void ofxBaseGui::setEvents(ofCoreEvents & _events){
if(&_events != events){
bool wasMouseInputEnabled = bRegisteredForMouseEvents;// || !events;
unregisterMouseEvents();
events = &_events;
if (wasMouseInputEnabled) {
// note: this will set bMouseInputEnabled to true as a side-effect.
registerMouseEvents();
}
}
}
void ofxBaseGui::draw(){
setEvents(ofEvents());
if(needsRedraw){
generateDraw();
needsRedraw = false;
Expand Down Expand Up @@ -202,15 +213,17 @@ ofRectangle ofxBaseGui::getTextBoundingBox(const string & text, float x, float y
}
}
float ofxBaseGui::getTextVCenteredInRect(const ofRectangle& container){

if(useTTF){
return container.getCenter().y + font.getAscenderHeight()*0.5;
return container.getCenter().y + (font.getAscenderHeight() + font.getDescenderHeight()) *0.5;
}else{
// The bitmap font does not provide a getAscenderHeight() method.
// However,it can be found by calling `getTextBoundingBox(" ",0,0)`
// which returns the ascender value in the rectangle's Y as a negative value.
// It does not matter which string is passed to it, the value will be always the same.
return container.getCenter().y - getTextBoundingBox(" ",0,0).y *0.5;

// Fix. It centers the text properly with `getTextBoundingBox(" ",0,0)` as it takes into account the screen pixel scaling.
auto bb = getTextBoundingBox(" ",0,0);
return container.getCenter().y - bb.height*0.5 - bb.y;
}
}

Expand Down Expand Up @@ -284,7 +297,14 @@ void ofxBaseGui::setShape(float x, float y, float w, float h){
b.set(x, y, w, h);
sizeChangedCB();
}

void ofxBaseGui::setShapeNoNotification(const ofRectangle& r){
b = r;
setNeedsRedraw();
}
void ofxBaseGui::setShapeNoNotification(float x, float y, float w, float h){
b.set(x, y, w, h);
setNeedsRedraw();
}
glm::vec3 ofxBaseGui::getPosition() const {
return glm::vec3(b.x, b.y, 0);
}
Expand Down
13 changes: 10 additions & 3 deletions addons/ofxGui/src/ofxBaseGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class ofxBaseGui {
virtual void setShape(ofRectangle r);
virtual void setShape(float x, float y, float w, float h);

/// sets the shape but does not notify its parent.
/// This is mostly used internally to avoid infinite loops
void setShapeNoNotification(const ofRectangle& r);
void setShapeNoNotification(float x, float y, float w, float h);

glm::vec3 getPosition() const;
ofRectangle getShape() const;
float getWidth() const;
Expand Down Expand Up @@ -71,8 +76,8 @@ class ofxBaseGui {
static void loadFont(const ofTrueTypeFontSettings & fontSettings);
static void setUseTTF(bool bUseTTF);

void registerMouseEvents();
void unregisterMouseEvents();
virtual void registerMouseEvents();
virtual void unregisterMouseEvents();

virtual void sizeChangedCB();
virtual void setParent(ofxBaseGui * parent);
Expand All @@ -89,6 +94,7 @@ class ofxBaseGui {
virtual void mouseExited(ofMouseEventArgs &){
}

void setEvents(ofCoreEvents & events);
protected:
virtual void render() = 0;
virtual bool setValue(float mx, float my, bool bCheckBounds) = 0;
Expand Down Expand Up @@ -135,10 +141,11 @@ class ofxBaseGui {
static void loadStencilFromHex(ofImage & img, unsigned char * data);

void setNeedsRedraw();

ofCoreEvents * events = nullptr;
private:
bool needsRedraw;
unsigned long currentFrame;
bool bRegisteredForMouseEvents;

//std::vector<ofEventListener> coreListeners;
};
Loading

0 comments on commit 5078acf

Please sign in to comment.