void draw() { // clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // render the HUD hud(); // draw the camera long cur_time = glutGet(GLUT_ELAPSED_TIME); camera_draw(camera, cur_time - last_draw); last_draw = cur_time; // set light position shit GLfloat lpos[] = { 56.0f, 30.0f, 56.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_POSITION, lpos); // draw the ground for (int x = 0; x < 56; x++) for (int z = 0; z < 0x39; z++) draw_ground(x, z, t2ground[x].column[z]); // swap buffers glutSwapBuffers(); }
void Player::drawHud(sf::RenderWindow& rw) const { static bool firstRun = true; static sf::Font font; if(firstRun) { firstRun = false; font.LoadFromFile("silesiana.otf", 50, L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��XxVvQq0123456789~!@#$%^&*()_-[]\\;',./{}:\"<>?=-+ "); } sf::Sprite hud(hudimg, sf::Vector2f(0, 350)); rw.Draw(hud); int hbarheight= health * hbarimg.GetHeight(); sf::Sprite hbar(hbarimg, sf::Vector2f(42, 376 + hbarimg.GetHeight() - hbarheight)); hbar.SetSubRect(sf::IntRect(0, hbarimg.GetHeight() - hbarheight, hbarimg.GetWidth(), hbarimg.GetHeight())); rw.Draw(hbar); std::wstring str; for(int i=0;i<4;i++) { if(i<msgList.size()) str += msgList[i] + L"\n"; } sf::String msgs(str, font, 30); msgs.SetColor(sf::Color(120, 10, 10)); msgs.SetPosition(200, 450); rw.Draw(msgs); }
QImage AudioSpectrum::renderHUD(uint) { QTime start = QTime::currentTime(); if (m_innerScopeRect.height() > 0 && m_innerScopeRect.width() > 0) { // May be below 0 if widget is too small // Minimum distance between two lines const uint minDistY = 30; const uint minDistX = 40; const uint textDistX = 10; const uint textDistY = 25; const uint topDist = m_innerScopeRect.top() - m_scopeRect.top(); const uint leftDist = m_innerScopeRect.left() - m_scopeRect.left(); const uint dbDiff = ceil((float)minDistY/m_innerScopeRect.height() * (m_dBmax-m_dBmin)); const int mouseX = m_mousePos.x() - m_innerScopeRect.left(); const int mouseY = m_mousePos.y() - m_innerScopeRect.top(); QImage hud(m_scopeRect.size(), QImage::Format_ARGB32); hud.fill(qRgba(0,0,0,0)); QPainter davinci(&hud); davinci.setPen(AbstractScopeWidget::penLight); int y; for (int db = -dbDiff; db > m_dBmin; db -= dbDiff) { y = topDist + m_innerScopeRect.height() * ((float)db)/(m_dBmin - m_dBmax); if (y-topDist > m_innerScopeRect.height()-minDistY+10) { // Abort here, there is still a line left for min dB to paint which needs some room. break; } davinci.drawLine(leftDist, y, leftDist + m_innerScopeRect.width()-1, y); davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, y + 6, i18n("%1 dB", m_dBmax + db)); } davinci.drawLine(leftDist, topDist, leftDist + m_innerScopeRect.width()-1, topDist); davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+6, i18n("%1 dB", m_dBmax)); davinci.drawLine(leftDist, topDist+m_innerScopeRect.height()-1, leftDist + m_innerScopeRect.width()-1, topDist+m_innerScopeRect.height()-1); davinci.drawText(leftDist + m_innerScopeRect.width() + textDistX, topDist+m_innerScopeRect.height()+6, i18n("%1 dB", m_dBmin)); const uint hzDiff = ceil( ((float)minDistX)/m_innerScopeRect.width() * m_freqMax / 1000 ) * 1000; int x = 0; const int rightBorder = leftDist + m_innerScopeRect.width()-1; y = topDist + m_innerScopeRect.height() + textDistY; for (int hz = 0; x <= rightBorder; hz += hzDiff) { davinci.setPen(AbstractScopeWidget::penLighter); x = leftDist + m_innerScopeRect.width() * ((float)hz)/m_freqMax; if (x <= rightBorder) { davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6); } if (hz < m_freqMax && x+textDistY < leftDist + m_innerScopeRect.width()) { davinci.drawText(x-4, y, QVariant(hz/1000).toString()); } else { x = leftDist + m_innerScopeRect.width(); davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()+6); davinci.drawText(x-10, y, i18n("%1 kHz", QString("%1").arg((double)m_freqMax/1000, 0, 'f', 1))); } if (hz > 0) { // Draw finer lines between the main lines davinci.setPen(AbstractScopeWidget::penLightDots); for (uint dHz = 3; dHz > 0; dHz--) { x = leftDist + m_innerScopeRect.width() * ((float)hz - dHz * hzDiff/4.0f)/m_freqMax; if (x > rightBorder) { break; } davinci.drawLine(x, topDist, x, topDist + m_innerScopeRect.height()-1); } } } if (m_aTrackMouse->isChecked() && m_mouseWithinWidget && mouseX < m_innerScopeRect.width()-1) { davinci.setPen(AbstractScopeWidget::penThin); x = leftDist + mouseX; float db = 0; float freq = ((float) mouseX)/(m_innerScopeRect.width()-1) * m_freqMax; bool drawDb = false; m_lastFFTLock.acquire(); // We need to test whether the mouse is inside the widget // because the position could already have changed in the meantime (-> crash) if (m_lastFFT.size() > 0 && mouseX >= 0 && mouseX < m_innerScopeRect.width()) { uint right = ((float) m_freqMax)/(m_freq/2) * (m_lastFFT.size() - 1); QVector<float> dbMap = FFTTools::interpolatePeakPreserving(m_lastFFT, m_innerScopeRect.width(), 0, right, -120); db = dbMap[mouseX]; y = topDist + m_innerScopeRect.height()-1 - (dbMap[mouseX] - m_dBmin) / (m_dBmax-m_dBmin) * (m_innerScopeRect.height()-1); if (y < (int)topDist + m_innerScopeRect.height()-1) { drawDb = true; davinci.drawLine(x, y, leftDist + m_innerScopeRect.width()-1, y); } } else { y = topDist + mouseY; } m_lastFFTLock.release(); if (y > (int)topDist + mouseY) { y = topDist+ mouseY; } davinci.drawLine(x, y, x, topDist + m_innerScopeRect.height()-1); if (drawDb) { QPoint dist(20, -20); QRect rect( leftDist + mouseX + dist.x(), topDist + mouseY + dist.y(), 100, 40 ); if (rect.right() > (int)leftDist + m_innerScopeRect.width()-1) { // Mirror the rectangle at the y axis to keep it inside the widget rect = QRect( rect.topLeft() - QPoint(rect.width() + 2*dist.x(), 0), rect.size()); } QRect textRect( rect.topLeft() + QPoint(12, 4), rect.size() ); davinci.fillRect(rect, AbstractScopeWidget::penBackground.brush()); davinci.setPen(AbstractScopeWidget::penLighter); davinci.drawRect(rect); davinci.drawText(textRect, QString( i18n("%1 dB", QString("%1").arg(db, 0, 'f', 2)) + '\n' + i18n("%1 kHz", QString("%1").arg(freq/1000, 0, 'f', 2)))); } } emit signalHUDRenderingFinished(start.elapsed(), 1); return hud; } else { #ifdef DEBUG_AUDIOSPEC qDebug() << "Widget is too small for painting inside. Size of inner scope rect is " << m_innerScopeRect.width() << "x" << m_innerScopeRect.height() <<"."; #endif emit signalHUDRenderingFinished(0, 1); return QImage(); } }
QImage Waveform::renderHUD(uint) { QImage hud(m_scopeRect.size(), QImage::Format_ARGB32); hud.fill(qRgba(0,0,0,0)); QPainter davinci(&hud); davinci.setPen(penLight); QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(KdenliveSettings::current_profile()); // qDebug() << values.value("width"); const int rightX = scopeRect().width()-m_textWidth.width()+3; const int x = m_mousePos.x() - scopeRect().x(); const int y = m_mousePos.y() - scopeRect().y(); if (scopeRect().height() > 0 && m_mouseWithinWidget) { int val = 255*(1-(float)y/scopeRect().height()); if (val >= 0 && val <= 255) { // Draw a horizontal line through the current mouse position // and show the value of the waveform there davinci.drawLine(0, y, scopeRect().size().width()-m_textWidth.width(), y); // Make the value stick to the line unless it is at the top/bottom of the scope int valY = y+5; const int top = 30; const int bottom = 20; if (valY < top) { valY = top; } else if (valY > scopeRect().height()-bottom) { valY = scopeRect().height()-bottom; } davinci.drawText(rightX, valY, QVariant(val).toString()); } if (scopeRect().width() > 0) { // Draw a vertical line and the x position of the source clip bool ok; const int profileWidth = values.value("width").toInt(&ok); if (ok) { const int clipX = (float)x/(scopeRect().width()-m_textWidth.width()-1)*(profileWidth-1); if (clipX >= 0 && clipX <= profileWidth) { int valX = x-15; if (valX < 0) { valX = 0; } if (valX > scopeRect().width()-55-m_textWidth.width()) { valX = scopeRect().width()-55-m_textWidth.width(); } davinci.drawLine(x, y, x, scopeRect().height()-m_paddingBottom); davinci.drawText(valX, scopeRect().height()-5, QVariant(clipX).toString() + " px"); } } } } davinci.drawText(rightX, scopeRect().height()-m_paddingBottom, "0"); davinci.drawText(rightX, 10, "255"); emit signalHUDRenderingFinished(0, 1); return hud; }
void Game_Manager::draw() { int Id; static sf::Clock render_clock; render_clock.restart(); m_app->clear(); background.draw(0, 0 - tile_size); for (size_t x = 0; x < 5; x++) { for (size_t y = 0; y < 10; y++) { sprites[my_map[y][x].getId()].draw(tile_size * x, tile_size * y); my_map[y][x].draw_tile(); } } for (int i = 0; i < citizen_max; i++) { if (citizen_state[i]) { character1[i].draw(); } } for (int i = 0; i < monster_max; i++) { if (monster_state[i]) { monster1[i].draw(); } } goal_border.draw(selected_tile.goal_x* tile_size, selected_tile.goal_y * tile_size);///////////////////////////////////////////////////// selection_border.draw(selected_tile.clicked_x * tile_size, selected_tile.clicked_y * tile_size); buttons[0].draw(); buttons[1].draw(); buttons[2].draw(); buttons[3].draw(); int compteur = 0; for (int i = 0; i < character1.size(); i++) { if ((character1[i].getX() == selected_tile.clicked_x) && (character1[i].getY() == selected_tile.clicked_y) && (character1[i].isIdle())) { compteur++; } } if (cinematic_on) { cinematic_draw(); } if (info) { info_sprite.draw(0, 0 - tile_size); } if (glissor_on) { glissor1[0].update(selected_tile.goal_x* tile_size, selected_tile.goal_y * tile_size, compteur); glissor1[0].draw(character1.size()); } //pause handling if (!pause) { hud(); } if (pause && !cinematic_on) { pause_sprite.draw(tile_size, 0); }// Update the window m_app->display(); }