void utils::beginInfoBox( float x, float y, float fontSize, float width, int numRows, const char *title, H3DRes fontMaterialRes, H3DRes boxMaterialRes ) { float barHeight = fontSize + 0.01f; float bodyHeight = numRows * 0.035f + 0.005f; infoBox.fontMatRes = fontMaterialRes; infoBox.x = x; infoBox.y_row0 = y + barHeight + 0.005f; infoBox.width = width; infoBox.row = 0; // Title bar float ovTitleVerts[] = { x, y, 0, 1, x, y + barHeight, 0, 0, x + width, y + barHeight, 1, 0, x + width, y, 1, 1 }; h3dShowOverlays( ovTitleVerts, 4, 0.15f, 0.23f, 0.31f, 0.8f, boxMaterialRes, 0 ); // Title text h3dutShowText( title, x + 0.005f, y + 0.005f, fontSize, 0.7f, 0.85f, 0.95f, fontMaterialRes ); // Body float yy = y + barHeight; float ovBodyVerts[] = { x, yy, 0, 1, x, yy + bodyHeight, 0, 0, x + width, yy + bodyHeight, 1, 0, x + width, yy, 1, 1 }; h3dShowOverlays( ovBodyVerts, 4, 0.12f, 0.12f, 0.12f, 0.5f, boxMaterialRes, 0 ); }
void VideoComponent::render() { if (m_playing && m_isOverlay) { // Render the overlay const float ww = (float)h3dGetNodeParamI( m_camId, H3DCamera::ViewportWidthI ) / (float)h3dGetNodeParamI( m_camId, H3DCamera::ViewportHeightI ); //take the aspectRation into account for the x pos float x = m_x*ww; float w = m_w; if(m_stretchToAspect) { // and for the width if this is wanted w *= ww; } const float coords[] = { x, m_y, 0, 1.0f, x, m_y+m_h, 0, 0, x+w, m_y+m_h, 1.0f, 0, x+w, m_y, 1.0f, 1.0f }; h3dShowOverlays(coords, sizeof(coords) / 4, 1.0f,1.0f,1.0f,1.0f, m_material, 0); } }
void Cursor::updateView(float mouseData[2]){ if (visible == true) { float posX = mouseData[0]; float posY = mouseData[1]; float vals[] = { posX, posY, 0, 1, posX, posY+height, 0, 0, posX+width, posY+height, 1, 0, posX+width, posY, 1, 1 }; h3dShowOverlays(vals, 4,1, 1, 1, 1,getActualTex(), 0 ); } }
void Application::mainLoop( float timeSinceLastFrame ) { keyHandler( timeSinceLastFrame ); // Set camera parameters h3dSetNodeTransform( _cam, _x, _y, _z, _rx ,_ry, 0, 1, 1, 1 ); _lightTimer += timeSinceLastFrame; // Has it gone a second since the light changed color? if( _lightTimer >= 1.0f ) { // Set a random light color switch( rand() % 6 ) { case 0: // Red h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 1: // Green h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 2: // Blue h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; case 3: // Yellow h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 4: // Purple h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; case 5: // Cyan h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; } // Reset the timer _lightTimer = 0.0f; } // Show stats h3dutShowFrameStats( _fontMatRes, _panelMatRes, _statMode ); if( _statMode > 0 ) { displaySoundInfo(); } // Show logo const float ww = (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportWidthI ) / (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportHeightI ); const float ovLogo[] = { ww-0.4f, 0.8f, 0, 1, ww-0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; h3dShowOverlays( ovLogo, 4, 1.f, 1.f, 1.f, 1.f, _logoMatRes, 0 ); // Render scene h3dRender( _cam ); // Finish rendering of frame h3dFinalizeFrame(); // Remove all overlays h3dClearOverlays(); // Write all mesages to log file h3dutDumpMessages(); }
void Slider::updateView(float mouseData[2], int clickType, wchar_t keyChar, vector<string> eventCompList) { if (getVisible()) { float transparency = getTransparency(); if ((getFocusEffect() == true) && (getMouseOverContainer() == true)) transparency = 1.0f; if (!getMouseOverContainer()) slide = false; if (!getEnabled()) { setActualTex(getDisabledTex()); } else { if ((slide || isMouseOver(mouseData) || button->isMouseOver(mouseData))&&getMouseOverContainer()) setActualTex(getHighlightTex()); else { setActualTex(getNormalTex()); //slide = false; } } if (clickType == 1 && (isMouseOver(mouseData) || button->isMouseOver(mouseData))) { slide = true; } if ((clickType == -1) && (slide)) { slide = false; } if (slide) { if (horizontal) { float step = getWidth()/((getMaxValue()-getMinValue())/getValueStep()); if (mouseData[0] >= button->getPosX()+step) { if (setPosition(getPosition()+getValueStep())) sendNewValue(getPosition(), eventCompList); } if (mouseData[0] <= button->getPosX()-step) { if (setPosition(getPosition()-getValueStep())) sendNewValue(getPosition(), eventCompList); } } else { float step = getHeight()/((getMaxValue()-getMinValue())/getValueStep()); if (mouseData[1] <= button->getPosY()-step) { if (setPosition(getPosition()+getValueStep())) sendNewValue(getPosition(), eventCompList); } if (mouseData[1] >= button->getPosY()+step) { if (setPosition(getPosition()-getValueStep())) sendNewValue(getPosition(), eventCompList); } } } float posX = getPosX(); float posY = getPosY(); float height = getHeight(); float width = getWidth(); float vals[] = {posX, posY, 0, 1, posX, posY+height, 0, 0, posX+width, posY+height, 1, 0, posX+width, posY, 1, 1 }; h3dShowOverlays(vals, 4,1, 1, 1, transparency,getActualTex(), 0 ); if (slide) { button->setMouseOverIsTrue(true); button->updateView(mouseData,1,keyChar,eventCompList); } else { button->setMouseOverIsTrue(false); button->updateView(mouseData,clickType,keyChar,eventCompList); } } }
void Button::updateView(float mouseData[2], int clickType, wchar_t keyChar, vector<string> eventCompList) { if (getVisible() == true) { sentClickEvent = false; float posX = getPosX(); float posY = getPosY(); float height = getHeight(); float width = getWidth(); float transparency = getTransparency(); if ((getFocusEffect() == true) && (getMouseOverContainer() == true)) transparency = 1.0f; if (getEnabled() == false) setActualTex(getDisabledTex()); else { if ((isMouseOver(mouseData) == true) && (getMouseOverContainer())) { if (getFocusEffect() == true) transparency = 1.0f; if (clickType == 0) { if (hintCounter < 1.0f) hintCounter += 1/GameEngine::FPS(); if (getActualTex() != getPressedTex()) { setActualTex(getHighlightTex()); if (wasLeft) sendOnce = false; if ((sendOnce == false) && (wasLeft == true)) { sendOnce = true; wasOver = true; wasLeft = false; GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSEOVER,this->getName())); sendEvents(O_COMP_MOUSEOVER, eventCompList); } if (hintCounter >= 1.0f) { if (!hint->getVisible() ) { //needed for aspect ratio (maximum width) int m_camID = GameEngine::entityWorldID("camera"); int x,y, width, height; H3DNode camID = GameEngine::entitySceneGraphID( m_camID ); x = h3dGetNodeParamI( camID, H3DCamera::ViewportXI); y = h3dGetNodeParamI( camID, H3DCamera::ViewportYI); width = h3dGetNodeParamI( camID, H3DCamera::ViewportWidthI); height = h3dGetNodeParamI( camID, H3DCamera::ViewportHeightI); float aspect = (float)width/(float)height; hint->setText(getHintText()); float posX = mouseData[0]+0.03f; if (posX+ hint->getWidth() > aspect) posX = aspect - hint->getWidth() - 0.01f; hint->setPosX(posX); float posY = mouseData[1]+0.06f; if (posY+ hint->getHeight() > 1.0f) posY = mouseData[1] - hint->getHeight() - 0.06f; hint->setPosY(posY); hint->setVisible(true); } } } } if (clickType == 1) { setActualTex(getPressedTex()); clickWasOver = true; } if ((clickType == -1) && (clickWasOver)) { setActualTex(getHighlightTex()); if (wasLeft) sendOnce = false; if ((sendOnce == false) && (wasLeft == true)) { sendOnce = true; wasOver = true; wasLeft = false; GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSEOVER,this->getName())); sendEvents(O_COMP_MOUSEOVER, eventCompList); } //prevent sending the same event multiple times if (oldClickType != clickType) { //send event to all listed components sendEvents(O_BUTTON_CLICKED, eventCompList); //send to GUI for sound GUIEventData::sendToGUI(new GUIEventData(O_BUTTON_CLICKED,this->getName())); sentClickEvent = true; } } } else { clickWasOver = false; setActualTex(getNormalTex()); if (wasOver) sendOnce = false; if ((sendOnce == false) && (wasOver == true)) { sendOnce = true; wasOver = false; wasLeft = true; GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSELEFT,this->getName())); sendEvents(O_COMP_MOUSELEFT, eventCompList); hint->setVisible(false); hintCounter = 0.0f; } } } oldClickType = clickType; float vals[] = { posX, posY, 0, 1, posX, posY+height, 0, 0, posX+width, posY+height, 1, 0, posX+width, posY, 1, 1 }; h3dShowOverlays(vals, 4,1, 1, 1, transparency,getActualTex(), 0 ); } else if (!wasLeft) { //if a mouseleft event wasn't sent it's done here GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSELEFT,this->getName())); wasLeft = true; } }