// We expect polarization values to be between 0 and 1, so this is // tuned for that. // miny:maxy describes the extent of polarization values (i.e. // the data-plotting area - not the data themselves) // Return the location of the axis // Input params: // total width of subfigure, total height of sub-figure // xoff of left of subfigure // yoff of top of subfigure // yoff of top of y-axis in subfigure // height of y-ruler drawing space // min y value at bottom of y-ruler // max y value at top of y-ruler // scale translating y-value to pixel value int drawPolarizationRuler(int width, int height, int xoff, int yoff, int yoff_ruler, int height_ruler, float minPolarizationRange, float maxPolarizationRange, float polarizationScale) { XSetForeground( curDisplay, curGC, 0x00000000 ); // black int rwidth = DEFAULT_RWIDTH; if (minPolarization < 0.0 || maxPolarization > 1.0) { printf("Polarization values outside of expected range - using silly ruler\n"); return drawSillyYRuler(width, height, xoff, yoff, yoff_ruler, height_ruler, minPolarizationRange, maxPolarizationRange, polarizationScale, minPolarization, maxPolarization); } // dermine how wide the ruler needs to be float values[] = {0.0, 0.25, 0.5, 0.75, 1.0}; int numValues = sizeof(values)/sizeof(float); char label[100]; int i, len, strw, stra, strd; for (i=0; i<numValues; i++) { createCleanLabel(values[i], label, &len); getStringBoundingBox(label,len,&strw,&stra,&strd); if (strw+2*STRPAD > rwidth) rwidth = strw + 2*STRPAD; } // draw the axis XDrawLine( curDisplay, curWindow, curGC, xoff+rwidth, yoff_ruler, xoff+rwidth, yoff_ruler+height_ruler ); // draw ticks and labels int xp, yp; for (i=0; i < numValues; i++) { createCleanLabel(values[i], label, &len); getStringBoundingBox(label,len,&strw,&stra,&strd); xp = xoff+rwidth-strw-STRPAD; yp = yoff_ruler+ (int)((maxPolarizationRange-values[i])*polarizationScale); XDrawString(curDisplay, curWindow, curGC, xp, yp+stra/2, label, len); XDrawLine( curDisplay, curWindow, curGC, xoff+rwidth, yp, xoff+rwidth+TICK_LEN, yp ); } return rwidth; } // end drawPolarizationRuler
ofRectangle CheckBox::getLabelBoundingBox(void) { ofRectangle tempRect(_labelLocation.x, _labelLocation.y, 0, 0); if (_label != "") { tempRect = getStringBoundingBox(_label, _labelLocation.x, _labelLocation.y); } return tempRect; }
// We expect elongation values to be between 0.5 and 2.5, so this is // tuned for that. // miny:maxy describes the extent of elongation values (i.e. // the data-plotting area - not the data themselves) // Return the location of the axis // Input params: // total width of subfigure, total height of sub-figure // xoff of left of subfigure // yoff of top of subfigure // yoff of top of y-axis in subfigure // height of y-ruler drawing space // min y value at bottom of y-ruler // max y value at top of y-ruler // scale translating y-value to pixel value int drawElongationRuler(int width, int height, int xoff, int yoff, int yoff_ruler, int height_ruler, float minElongationRange, float maxElongationRange, float elongationScale) { XSetForeground( curDisplay, curGC, 0x00000000 ); // black int rwidth = DEFAULT_RWIDTH; if (maxElongationRange - minElongationRange < 0.5) { return drawSillyYRuler(width, height, xoff, yoff, yoff_ruler, height_ruler, minElongationRange, maxElongationRange, elongationScale, minElongation, maxElongation); } // dermine how wide the ruler needs to be char label[100]; int len, strw, stra, strd; float value; for (value=minElongationRange; value<=maxElongationRange; value+=0.5) { createCleanLabel(value, label, &len); getStringBoundingBox(label,len,&strw,&stra,&strd); if (strw+2*STRPAD > rwidth) rwidth = strw + 2*STRPAD; } // draw the axis XDrawLine( curDisplay, curWindow, curGC, xoff+rwidth, yoff_ruler, xoff+rwidth, yoff_ruler+height_ruler ); // draw ticks and labels int xp, yp; for (value=minElongationRange; value<=maxElongationRange; value+=0.5) { createCleanLabel(value, label, &len); getStringBoundingBox(label,len,&strw,&stra,&strd); xp = xoff+rwidth-strw-STRPAD; yp = yoff_ruler+ (int)((maxElongationRange-value)*elongationScale); XDrawString(curDisplay, curWindow, curGC, xp, yp+stra/2, label, len); XDrawLine( curDisplay, curWindow, curGC, xoff+rwidth, yp, xoff+rwidth+TICK_LEN, yp ); } return rwidth; } // end drawElongationRuler
/*! This function does not change the current selection, it just changes what text is current shown. */ void Dropdown::setDisplayedText(string text) { _displayedText = text; if (textFont->isLoaded()) { while (getStringBoundingBox(_displayedText).width > boundingBox.width) { _displayedText = _displayedText.substr(0, _displayedText.size() - 1); } } notifyControlNeedsRedraw(); }
float ofxFTGLFont::stringWidth(const string& c) { if (c.compare(" ") == 0) { // FTGL won't measure a space width properly, so we // have to use this hack to get that value. return (stringWidth("A A") - stringWidth("AA")); } else { ofRectangle rect = getStringBoundingBox(c, 0,0); return rect.width; } }
void FreeTypeFont::drawString(int x, int y, const std::string &text) { glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushMatrix(); //glTranslatef(x,y + ftfont->measure(text.c_str()).y_max_ ,0); glTranslatef(static_cast<GLfloat>(x),static_cast<GLfloat>(y + getStringBoundingBox(text).height) ,0); glScalef(1,-1,1); ftfont->draw(text.c_str()); glPopMatrix(); glDisable(GL_TEXTURE_2D); }
// Input params: // total width of subfigure, total height of sub-figure // xoff of left of subfigure // yoff of top of subfigure // yoff of top of y-axis in subfigure // height of y-ruler drawing space // min y value at bottom of y-ruler // max y value at top of y-ruler // scale translating y-value to pixel value // min y data value // max y data value int drawSillyYRuler(int width, int height, int xoff, int yoff, int yoff_ruler, int height_ruler, float miny_range, float maxy_range, float yscale, float miny, float maxy) { XSetForeground( curDisplay, curGC, 0x00000000 ); // black int rwidth = DEFAULT_RWIDTH; char label1[100], label2[100]; int len1, len2, w1, w2, a1, a2, d1, d2; len1 = sprintf(label1,"%1.3f",miny); len2 = sprintf(label2,"%1.3f",maxy); getStringBoundingBox(label1,len1,&w1,&a1,&d1); getStringBoundingBox(label2,len2,&w2,&a2,&d2); int labelw = (w2 > w1)? w2 : w1; if (labelw+2*STRPAD > rwidth) rwidth = labelw+2*STRPAD; XDrawString( curDisplay, curWindow, curGC, xoff+rwidth-w1-STRPAD, yoff_ruler+(int)((maxy_range-miny)*yscale)+a1/2, label1, len1); XDrawLine( curDisplay, curWindow, curGC, xoff+rwidth, yoff_ruler+(int)((maxy_range-miny)*yscale), xoff+rwidth+TICK_LEN, yoff_ruler+(int)((maxy_range-miny)*yscale)); XDrawString( curDisplay, curWindow, curGC, xoff+rwidth-w2-STRPAD, yoff_ruler+(int)((maxy_range-maxy)*yscale)+a2/2, label2, len2); XDrawLine( curDisplay, curWindow, curGC, xoff+rwidth, yoff_ruler+(int)((maxy_range-maxy)*yscale), xoff+rwidth+TICK_LEN, yoff_ruler+(int)((maxy_range-maxy)*yscale)); XDrawLine( curDisplay, curWindow, curGC, xoff+rwidth, yoff_ruler+(int)((maxy_range-miny_range)*yscale), xoff+rwidth, yoff_ruler+(int)((maxy_range-maxy_range)*yscale) ); return rwidth; } // end drawSillyYRuler
void Dropdown::setSelectedOption(int index) { if (index < 0 || index >= _selectionOptions.size()) { _currentSelectionIndex = NOTHING_SELECTED; _displayedText = _noSelectionText; return; } if (index == _currentSelectionIndex) { return; } _currentSelectionIndex = index; _displayedText = _selectionOptions.at(index).label; if (textFont->isLoaded()) { while (getStringBoundingBox(_displayedText).width > boundingBox.width) { _displayedText = _displayedText.substr(0, _displayedText.size() - 1); } } notifyControlNeedsRedraw(); }
//-------------------------------------------------------------- int ofxFreeType2::getStringWidth(string s) { ofRectangle boundingBox = getStringBoundingBox(s, 0, 0); return boundingBox.width; }
//------------------------------------------------------------------------ float ofxTrueTypeFontFS::stringWidth(string s){ ofRectangle bb = getStringBoundingBox( s, 0, 0 ); return -bb.x + bb.width; }
float ofxFTGLFont::stringHeight(const string& c) { ofRectangle rect = getStringBoundingBox(c, 0,0); return rect.height; }
//-------------------------------------------------------------- int ofxFreeType2::getStringHeight(string s) { ofRectangle boundingBox = getStringBoundingBox(s, 0, 0); return boundingBox.height; }
float ofxFontStash::stringWidth(const string& s){ ofRectangle rect = getStringBoundingBox(s, 0,0); return rect.width; }
float ofxFontStash::stringHeight(const string& s){ ofRectangle rect = getStringBoundingBox(s, 0,0); return rect.height; }
//------------------------------------------------------------------------ float ofxTrueTypeFontFS::stringHeight(string s){ ofRectangle bb = getStringBoundingBox( s, 0, 0); return -bb.y + bb.height; }
//----------------------------------------------------------- float ofTrueTypeFont::stringHeight(string c) { ofRectangle rect = getStringBoundingBox(c, 0,0); return rect.height; }
// Draw the axis, ticks, and labels for r in the given // drawing area. // Input params: // total width of subfigure, total height of sub-figure // xoff of left of subfigure // yoff of top of subfigure // xoff of left of x-axis in subfigure // yoff of top of x-ruler in subfigure // width of x-ruler drawing space // height of x-ruler drawing space // min x value at left of x-ruler // max x value at right of x-ruler // scale translating y-value to pixel value void drawRRuler(int width, int height, int xoff, int yoff, int xoff_ruler, int yoff_ruler, int width_ruler, int height_ruler, float minRRange, float maxRRange, float rscale ){ XSetForeground( curDisplay, curGC, 0x00000000 ); // black // Place labels for first and last data points, then // fill in remaining points as they fit. // Just us a greedy algorithm. int lbnd, rbnd; int strw, stra, strd; getStringBoundingBox("0.12356789",11,&strw,&stra,&strd); int yp = yoff_ruler + STRPAD + stra; char label[100]; int len; // axis XDrawLine( curDisplay, curWindow, curGC, xoff_ruler, yoff_ruler, xoff_ruler+width_ruler, yoff_ruler ); // first label createCleanLabel(minr, label, &len); getStringBoundingBox(label,len,&strw,&stra,&strd); int xp = xoff_ruler + (int)((minr-minRRange)*rscale) - strw/2; if (xp < xoff_ruler) xp = xoff_ruler; XDrawString( curDisplay, curWindow, curGC, xp, yp, label, len); XDrawLine( curDisplay, curWindow, curGC, xoff_ruler+(int)((minr-minRRange)*rscale), yoff_ruler, xoff_ruler+(int)((minr-minRRange)*rscale), yoff_ruler-TICK_LEN ); lbnd = xp+strw; // last label createCleanLabel(maxr, label, &len); getStringBoundingBox(label,len,&strw,&stra,&strd); xp = xoff_ruler + (int)((maxr-minRRange)*rscale) - strw/2; if (xp+strw > xoff_ruler+width_ruler) xp = xoff_ruler + width_ruler - strw; XDrawString( curDisplay, curWindow, curGC, xp, yp, label, len); XDrawLine( curDisplay, curWindow, curGC, xoff_ruler+(int)((maxr-minRRange)*rscale), yoff_ruler, xoff_ruler+(int)((maxr-minRRange)*rscale), yoff_ruler-TICK_LEN ); rbnd = xp; // Fill in remaining ticks (assuming r is sorted in ascending order) int i; for (i=1; i<numR-1; i++) { createCleanLabel(r[i], label, &len); getStringBoundingBox(label,len,&strw,&stra,&strd); xp = xoff_ruler + (int)((r[i]-minRRange)*rscale); if (xp > lbnd+STRPAD && xp+strw < rbnd-STRPAD) { XDrawString(curDisplay, curWindow, curGC, xp-strw/2, yp, label, len); XDrawLine( curDisplay, curWindow, curGC, xp, yoff_ruler, xp, yoff_ruler-TICK_LEN ); lbnd = xp+strw; } else { // draw unlabeled ticks gray XSetForeground( curDisplay, curGC, 0x00AAAAAA ); // gray XDrawLine( curDisplay, curWindow, curGC, xp, yoff_ruler, xp, yoff_ruler-TICK_LEN ); XSetForeground( curDisplay, curGC, 0x00000000 ); // black } } // axis-label ("r") len = sprintf(label,"r"); getStringBoundingBox(label,len,&strw,&stra,&strd); XDrawString( curDisplay, curWindow, curGC, xoff_ruler+width_ruler/2-strw/2, yp+STRPAD, label, len ); } // end drawRRuler
void drawFigure() { XSetWindowBackground( curDisplay, curWindow, 0x00FFFFFF ); XClearWindow( curDisplay, curWindow ); // Determine how large the window is Window root; int x_ret, y_ret; unsigned int width, height, bw, dr; XGetGeometry(curDisplay, curWindow, &root, &x_ret, &y_ret, &width, &height, &bw, &dr ); int xoff = 0; int yoff = 0; // make the min and max positions extend beyond the data float rd = maxr-minr; float ed = maxElongation-minElongation; float pd = maxPolarization-minPolarization; float minRRange = minr - 0.1*rd; float maxRRange = maxr + 0.1*rd; float minPolarizationRange = minPolarization - 0.1*pd; if (minPolarizationRange > 0.0) minPolarizationRange = 0.0; float maxPolarizationRange = maxPolarization + 0.1*pd; if (maxPolarizationRange < 1.1) maxPolarizationRange = 1.1; // We want to align the elongation range so that it makes // sense to use steps of size 0.5 float minElongationRange; float maxElongationRange; if (maxElongation-minElongation < 0.5) { minElongationRange = minElongation - 0.1*ed; maxElongationRange = maxElongation + 0.1*ed; } else { float cnt = floor(minElongation/0.5); minElongationRange = cnt*0.5; cnt = ceil(maxElongation/0.5); maxElongationRange = cnt*0.5; } // determine height of r-ruler area int stra, strd, strw; getStringBoundingBox("0.123r",5,&strw,&stra,&strd); // from top to bottom: tick, space, label, space, "r", space int rHeight = 2*(stra+strd) + 2*STRPAD + TICK_LEN; getStringBoundingBox("PolarizationElongation",22,&strw,&stra,&strd); int tHeight = stra+strd+2*STRPAD; // title height int eHeight = (height-yoff)/2; int pHeight = (height-yoff)/2; float elongationScale = (float)(eHeight-rHeight-tHeight)/ (maxElongationRange-minElongationRange); float polarizationScale = (float)(pHeight-rHeight-tHeight)/ (maxPolarizationRange-minPolarizationRange); // total width of subfigure, total height of sub-figure // xoff of left of subfigure // yoff of top of subfigure // yoff of top of y-axis in subfigure // height of y-ruler drawing space // min y value at bottom of y-ruler // max y value at top of y-ruler // scale translating y-value to pixel value int erw = drawElongationRuler(width-xoff, eHeight, xoff, yoff, yoff+tHeight, eHeight-rHeight-tHeight, minElongationRange, maxElongationRange, elongationScale); float rscale = (float)(width-xoff-erw) / (maxRRange-minRRange); // total width of subfigure, total height of sub-figure // xoff of left of subfigure // yoff of top of subfigure // xoff of left of x-axis in subfigure // yoff of top of x-ruler in subfigure // width of x-ruler drawing space // height of x-ruler drawing space // min x value at left of x-ruler // max x value at right of x-ruler // scale translating y-value to pixel value drawRRuler(width-xoff, eHeight, xoff, yoff, xoff+erw, yoff+eHeight-rHeight, width-xoff-erw, rHeight, minRRange, maxRRange, rscale ); drawData(width-xoff-erw, eHeight-rHeight-tHeight, xoff+erw, yoff+tHeight, numR, r, mean_elongation, minRRange, maxRRange, minElongationRange, maxElongationRange, rscale, elongationScale); char title[100]; int tlen = sprintf(title,"Elongation"); getStringBoundingBox(title,tlen,&strw,&stra,&strd); XDrawString( curDisplay, curWindow, curGC, xoff+erw+(width-xoff-erw)/2-strw/2, // middle of data area yoff+tHeight-STRPAD, title, tlen ); int prw = drawPolarizationRuler(width-xoff, pHeight, xoff, yoff+eHeight, yoff+eHeight+tHeight, pHeight-rHeight-tHeight, minPolarizationRange, maxPolarizationRange, polarizationScale); rscale = (float)(width-xoff-prw) / (maxRRange-minRRange); drawRRuler(width-xoff, eHeight, xoff, yoff+eHeight, xoff+prw, yoff+eHeight+pHeight-rHeight, width-xoff-prw, rHeight, minRRange, maxRRange, rscale ); drawData(width-xoff-prw, pHeight-rHeight-tHeight, xoff+prw, yoff+eHeight+tHeight, numR, r, mean_polarization, minRRange, maxRRange, minPolarizationRange, maxPolarizationRange, rscale, polarizationScale); tlen = sprintf(title,"Polarization"); getStringBoundingBox(title,tlen,&strw,&stra,&strd); XDrawString( curDisplay, curWindow, curGC, xoff+erw+(width-xoff-erw)/2-strw/2, // middle of data area yoff+eHeight+tHeight-STRPAD, title, tlen ); // draw separator bar // set the drawing color to gray 00rrggbb XSetForeground( curDisplay, curGC, 0x00AAAAAA ); XDrawLine( curDisplay, curWindow, curGC, 0, eHeight, width, eHeight ); } // end drawFigure
//----------------------------------------------------------- float ofTrueTypeFont::stringWidth(const std::string& c) const{ ofRectangle rect = getStringBoundingBox(c, 0,0); return rect.width; }
//----------------------------------------------------------- float ofTrueTypeFont::stringWidth(string c) { ofRectangle rect = getStringBoundingBox(c, 0,0); return rect.width; }
//----------------------------------------------------------- float ofTrueTypeFont::stringHeight(const std::string& c) const{ ofRectangle rect = getStringBoundingBox(c, 0,0); return rect.height; }