Beispiel #1
0
void MantaController::setMouseResponders()
{
    float sliderSizeX = 0.65 * getDrawWidth();
    float sliderSizeY = 0.05 * getDrawHeight();
    float buttonSize = 1.5 * 0.02 * getDrawWidth();
    
    ofRectangle sliderPosition0(x + 0.08 * getDrawWidth(), y + 0.05 * getDrawHeight(), sliderSizeX, sliderSizeY);
    ofRectangle sliderPosition1(x + 0.05 * getDrawWidth(), y + 0.13 * getDrawHeight(), sliderSizeX, sliderSizeY);
    ofRectangle buttonPosition0(x + 0.8 * getDrawWidth() - 0.5 * buttonSize, y + 0.075 * getDrawHeight() - 0.5 * buttonSize, buttonSize, buttonSize);
    ofRectangle buttonPosition1(x + 0.9 * getDrawWidth() - 0.5 * buttonSize, y + 0.075 * getDrawHeight() - 0.5 * buttonSize, buttonSize, buttonSize);
    ofRectangle buttonPosition2(x + 0.85 * getDrawWidth() - 0.5 * buttonSize, y + 0.155 * getDrawHeight() - 0.5 * buttonSize, buttonSize, buttonSize);
    ofRectangle buttonPosition3(x + 0.95 * getDrawWidth() - 0.5 * buttonSize, y + 0.155 * getDrawHeight() - 0.5 * buttonSize, buttonSize, buttonSize);
    
    sliderPositions[0] = sliderPosition0;
    sliderPositions[1] = sliderPosition1;
    buttonPositions[0] = buttonPosition0;
    buttonPositions[1] = buttonPosition1;
    buttonPositions[2] = buttonPosition2;
    buttonPositions[3] = buttonPosition3;
    
    for (int row=0; row<6; row++)
    {
        for (int col=0; col<8; col++)
        {
            int rx = x + ofMap(col + 0.5, 0, 8, 0.01 * getDrawWidth(), 0.94 * getDrawWidth());
            int ry = y + ofMap(row + 0.5, 6, 0, 0.24 * getDrawHeight(), 0.97 * getDrawHeight());
            int size = getDrawWidth() / 11.0;
            if (row %2 != 0)  rx += 0.93 * getDrawWidth() / 16.0;
            ofRectangle padPosition(rx - 0.5 * size, ry - 0.5*size, size, size);
            padPositions[row * 8 + col] = padPosition;
        }
    }
}
void ofxTextAlign::draw(string str, float x, float y, unsigned int flags)
{
	const char *ptr = str.c_str();
	float cursor_y = y+getOffsetY(ptr, flags, false);
	int line_count = getLineCount(ptr);
	float y_interval = line_count>1?(getDrawHeight(ptr, false)-getLineHeight())/(float)(line_count-1):0;
	while(*ptr != '\0') {
		float cursor_x = x+getOffsetX(ptr, flags, true);
		ptr = drawLine(ptr, cursor_x, cursor_y);
		cursor_y += y_interval;
	}
}
float ofxTextAlign::getOffsetY(const char *str, unsigned int flags, bool single_line)
{
	unsigned int flag = flags&VERTICAL_ALIGN_MASK;
	if(VERTICAL_ALIGN_TOP == flag) {
		return getAscenderHeight();
	}
	else if(!single_line && getLineCount(str) < 2) {
		float height = getLineHeight();
		switch(flag) {
			case VERTICAL_ALIGN_MIDDLE:	return getAscenderHeight()-height/2.f;
			case VERTICAL_ALIGN_BOTTOM:	return getAscenderHeight()-height;
		}
	}
	else {
		float height = getDrawHeight(str, single_line);
		switch(flag) {
			case VERTICAL_ALIGN_MIDDLE:	return getAscenderHeight()-height/2.f;
			case VERTICAL_ALIGN_BOTTOM:	return getAscenderHeight()-height;
		}
	}
	return 0;
}