void Buttons::setPosition(int xx, int yy) {
    x = xx;
    y = yy;
    positionElements();
    updateStaticTextPositions();

    static_text->setTextPosition(title_dx, x + 5, y + 2);
    flagChanged();
}
void Buttons::addElement(Element* el, const string& label) {
    el->setup();
    el->label = label;
    el->w = w;
    el->static_text = static_text;
    el->dynamic_text = dynamic_text;
    el->setColor(col_hue, col_sat, col_bright, col_alpha);
    el->needsRedraw();

    elements.push_back(el);
    positionElements();

    el->generateStaticText();
    el->generateDynamicText();

    // Add child elements
    vector<Element*> children;
    el->getChildElements(children);
    addChildElements(el, children);

}
Exemple #3
0
MenuView::MenuView(Vector2u & screensize, bool extended)
{
	//Musik
	m_pMS = MusikSampler::getInstance(); // singleton

	m_animating = true;
	m_extended = extended;
	backgroundanimation = 0;

	m_nextView = Views::NOCHANGE;
	m_background.setFillColor(MyColors.Transparent);
	m_background.setPosition(0,0);
	m_background.setSize(sf::Vector2f((float)screensize.x, (float)screensize.y));

	m_exitbutton = new StandardButton(Vector2f(0,0), Vector2f(MENU_WIDTH,50), "Exit", 0, false);
	m_exitbutton->Attach(this);
	m_DrawV.push_back(m_exitbutton);
	m_AnimateV.push_back(m_exitbutton);
	m_ClickV.push_back(m_exitbutton);

	m_continuebutton = new StandardButton(Vector2f(0,0), Vector2f(MENU_WIDTH,50), "Resume", 1, false);
	m_continuebutton->Attach(this);
	m_DrawV.push_back(m_continuebutton);
	m_AnimateV.push_back(m_continuebutton);
	m_ClickV.push_back(m_continuebutton);

	m_volumetext = new Textblock(Vector2f(0,0), Vector2f(MENU_WIDTH,50), "Hintergrundlautstärke", 20);
	m_volumetext->setFillColor(MyColors.Transparent);
	m_volumetext->setFontColor(MyColors.White);
	m_DrawV.push_back(m_volumetext);
																
	m_volumeslider = new Slider(true, Vector2f(MENU_WIDTH, 30), 1, Vector2f(0,0), 0);
	m_volumeslider->setValue(m_pMS->get_BGV() / 100);
	m_volumeslider->Attach(this);
	m_DrawV.push_back(m_volumeslider);
	m_ClickV.push_back(m_volumeslider);

	m_musictext = new Textblock(Vector2f(0,0), Vector2f(MENU_WIDTH, 50), "Effektlautstärke", 20);
	m_musictext->setFillColor(MyColors.Transparent);
	m_musictext->setFontColor(MyColors.White);
	m_DrawV.push_back(m_musictext);

	m_musicslider = new Slider(true, Vector2f(MENU_WIDTH, 30), 1, Vector2f(0,0), 1);
	m_musicslider->setValue(m_pMS->get_SOV() / 100);
	m_musicslider->Attach(this);
	m_DrawV.push_back(m_musicslider);
	m_ClickV.push_back(m_musicslider);

	m_pGraphics = new SpriteTex[3];

	Image img;
	if(!img.loadFromFile("Data/images/menu_top.png"))
		std::cout << "MenuView.cpp : load menu_top.png failed";
	m_pGraphics[0].t.loadFromImage(img);
	if(!img.loadFromFile("Data/images/menu_mid.png"))
		std::cout << "MenuView.cpp : load menu_mid.png failed";
	m_pGraphics[1].t.loadFromImage(img);
	if(!img.loadFromFile("Data/images/menu_bot.png"))
		std::cout << "MenuView.cpp : load menu_bot.png failed";
	m_pGraphics[2].t.loadFromImage(img);

	for(int i = 0; i < 3; i++)
	{
		m_pGraphics[i].t.setSmooth(false);
		m_pGraphics[i].t.setRepeated(true);
		m_pGraphics[i].s.setTexture(&m_pGraphics[i].t, true);
	}
	m_pGraphics[0].s.setSize(Vector2f(240,150));
	/*TEMP*/ m_pGraphics[1].s.setSize(Vector2f(240,230));			//TO CHANGE
	m_pGraphics[2].s.setSize(Vector2f(240,150));

	positionElements(screensize);
}
void Buttons::update() {
    if(!is_visible) {
        return;
    }

    h = 0;
    bool needs_redraw = false;
    bool needs_text_update = false;

    if(is_open) {
        vector<Element*>::iterator it = elements.begin();
        while(it != elements.end()) {
            Element& el = *(*it);
            el.update();

            if(el.is_child || !el.is_visible) {
                ++it;
                continue;
            }

            h += el.h;
            ++it;
        }

        // check if we need to update the vertices or if a value is changed.
        it = elements.begin();
        if(!is_changed) { // is this panel self changed.
            vector<Element*> value_changed_els;
            bool value_changed = false;
            while(it != elements.end()) {
                Element& el = **it;
                if(el.needs_redraw) {
                    needs_redraw = true;
                }
                if(el.needs_text_update) {
                    needs_text_update = true;
                }
                if(el.value_changed) {
                    if(el.is_child) {
                        el.parent->onChildValueChanged();
                    }
                    else {
                        value_changed_els.push_back(&el);
                    }
                    el.value_changed = false;
                }
                ++it;
            }
            // notify after all "parents" had their change to update (e..g onChildValueChanged above)
            it = value_changed_els.begin();
            while(it != value_changed_els.end()) {
                notifyListeners(BEVENT_VALUE_CHANGED, *it, (*it)->event_data);
                ++it;
            }
        }
        else {
            // when the gui itself is changed we always update!
            needs_redraw = true;
        }
    }

    if(needs_redraw || is_changed) {
        positionElements();
        updateDynamicTexts(); // need to update everything when a element i.e. get bigger
        updateStaticTextPositions();
        generateVertices();
        notifyListeners(BEVENT_BUTTONS_REDRAW, NULL, NULL);
    }
    if(needs_text_update) {
        updateDynamicTexts();
    }

    // do we need to grow our buffer?
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    eglGetError();
    size_t size_needed = vd.size() * sizeof(ButtonVertex);
    if(size_needed > allocated_bytes) {
        while(allocated_bytes < size_needed) {
            allocated_bytes = std::max<size_t>(allocated_bytes * 2, 256);
        }
        first_run = false; // we don't need this one anymore @todo cleanup
        glBufferData(GL_ARRAY_BUFFER, allocated_bytes, NULL, GL_STREAM_DRAW);
        eglGetError();
    }

    // And update the vbo.
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    eglGetError(); // roxlu
    glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ButtonVertex)*vd.size(), (GLvoid*)vd.getPtr());
    eglGetError();
}
Exemple #5
0
void MenuView::onResize(Vector2u & size)
{
	positionElements(size);
}