void CutsceneGUI::renderGlobal(float dt) { if (m_fade_level > 0.0f) { GL32_draw2DRectangle( video::SColor((int)(m_fade_level*255), 0,0,0), core::rect<s32>(0, 0, UserConfigParams::m_width, UserConfigParams::m_height)); } if (m_subtitle.size() > 0) { core::rect<s32> r(0, UserConfigParams::m_height - GUIEngine::getFontHeight()*2, UserConfigParams::m_width, UserConfigParams::m_height); if (GUIEngine::getFont()->getDimension(m_subtitle.c_str()).Width > (unsigned int)UserConfigParams::m_width) { GUIEngine::getSmallFont()->draw(m_subtitle, r, video::SColor(255,255,255,255), true, true, NULL); } else { GUIEngine::getFont()->draw(m_subtitle, r, video::SColor(255,255,255,255), true, true, NULL); } } }
void CutsceneGUI::renderGlobal(float dt) { core::dimension2d<u32> screen_size = irr_driver->getActualScreenSize(); if (m_fade_level > 0.0f) { GL32_draw2DRectangle( video::SColor((int)(m_fade_level*255), 0,0,0), core::rect<s32>(0, 0, screen_size.Width, screen_size.Height)); } if (m_subtitle.size() > 0) { core::rect<s32> r(0, screen_size.Height - GUIEngine::getFontHeight()*2, screen_size.Width, screen_size.Height); if (GUIEngine::getFont()->getDimension(m_subtitle.c_str()).Width > screen_size.Width) { GUIEngine::getSmallFont()->draw(m_subtitle, r, video::SColor(255,255,255,255), true, true, NULL); } else { GUIEngine::getFont()->draw(m_subtitle, r, video::SColor(255,255,255,255), true, true, NULL); } } }
//----------------------------------------------------------------------------- /// Helper to draw a white background void Profiler::drawBackground() { video::IVideoDriver* driver = irr_driver->getVideoDriver(); const core::dimension2d<u32>& screen_size = driver->getScreenSize(); core::rect<s32>background_rect((int)(MARGIN_X * screen_size.Width), (int)((MARGIN_Y + 0.25f) * screen_size.Height), (int)((1.0-MARGIN_X) * screen_size.Width), (int)((MARGIN_Y + 1.75f*LINE_HEIGHT) * screen_size.Height)); video::SColor color(0x88, 0xFF, 0xFF, 0xFF); GL32_draw2DRectangle(color, background_rect); }
//----------------------------------------------------------------------------- /// Draw the markers void Profiler::draw() { PROFILER_PUSH_CPU_MARKER("ProfilerDraw", 0xFF, 0xFF, 0x00); video::IVideoDriver* driver = irr_driver->getVideoDriver(); std::stack<Marker> hovered_markers; drawBackground(); // Force to show the pointer irr_driver->showPointer(); int read_id = !m_write_id; // Compute some values for drawing (unit: pixels, but we keep floats for reducing errors accumulation) core::dimension2d<u32> screen_size = driver->getScreenSize(); const double profiler_width = (1.0 - 2.0*MARGIN_X) * screen_size.Width; const double x_offset = MARGIN_X*screen_size.Width; const double y_offset = (MARGIN_Y + LINE_HEIGHT)*screen_size.Height; const double line_height = LINE_HEIGHT*screen_size.Height; size_t nb_thread_infos = m_thread_infos.size(); double start = -1.0f; double end = -1.0f; for (size_t i = 0; i < nb_thread_infos; i++) { MarkerList& markers = m_thread_infos[i].markers_done[read_id]; MarkerList::const_iterator it_end = markers.end(); for (MarkerList::const_iterator it = markers.begin(); it != it_end; it++) { const Marker& m = *it; if (start < 0.0) start = m.start; else start = std::min(start, m.start); if (end < 0.0) end = m.end; else end = std::max(end, m.end); } } const double duration = end - start; const double factor = profiler_width / duration; // Get the mouse pos core::vector2di mouse_pos = GUIEngine::EventHandler::get()->getMousePos(); // For each thread: for (size_t i = 0; i < nb_thread_infos; i++) { // Draw all markers MarkerList& markers = m_thread_infos[i].markers_done[read_id]; if (markers.empty()) continue; if (m_capture_report) { if (m_first_capture_sweep) m_capture_report_buffer->getStdStream() << "\"Thread\";"; else m_capture_report_buffer->getStdStream() << i << ";"; } MarkerList::const_iterator it_end = markers.end(); for (MarkerList::const_iterator it = markers.begin(); it != it_end; it++) { const Marker& m = *it; assert(m.end >= 0.0); if (m_capture_report) { if (m_first_capture_sweep) m_capture_report_buffer->getStdStream() << "\"" << m.name << "\";"; else m_capture_report_buffer->getStdStream() << (int)round((m.end - m.start) * 1000) << ";"; } core::rect<s32> pos((s32)( x_offset + factor*m.start ), (s32)( y_offset + i*line_height ), (s32)( x_offset + factor*m.end ), (s32)( y_offset + (i+1)*line_height )); // Reduce vertically the size of the markers according to their layer pos.UpperLeftCorner.Y += m.layer*2; pos.LowerRightCorner.Y -= m.layer*2; GL32_draw2DRectangle(m.color, pos); // If the mouse cursor is over the marker, get its information if(pos.isPointInside(mouse_pos)) hovered_markers.push(m); } if (m_capture_report) { m_capture_report_buffer->getStdStream() << "\n"; m_first_capture_sweep = false; } } // GPU profiler QueryPerf hovered_gpu_marker = Q_LAST; long hovered_gpu_marker_elapsed = 0; int gpu_y = int(y_offset + nb_thread_infos*line_height + line_height/2); float total = 0; unsigned int gpu_timers[Q_LAST]; for (unsigned i = 0; i < Q_LAST; i++) { gpu_timers[i] = irr_driver->getGPUTimer(i).elapsedTimeus(); total += gpu_timers[i]; } static video::SColor colors[] = { video::SColor(255, 255, 0, 0), video::SColor(255, 0, 255, 0), video::SColor(255, 0, 0, 255), video::SColor(255, 255, 255, 0), video::SColor(255, 255, 0, 255), video::SColor(255, 0, 255, 255) }; if (hovered_markers.size() == 0) { float curr_val = 0; for (unsigned i = 0; i < Q_LAST; i++) { //Log::info("GPU Perf", "Phase %d : %d us\n", i, irr_driver->getGPUTimer(i).elapsedTimeus()); float elapsed = float(gpu_timers[i]); core::rect<s32> pos((s32)(x_offset + (curr_val / total)*profiler_width), (s32)(y_offset + gpu_y), (s32)(x_offset + ((curr_val + elapsed) / total)*profiler_width), (s32)(y_offset + gpu_y + line_height)); curr_val += elapsed; GL32_draw2DRectangle(colors[i % 6], pos); if (pos.isPointInside(mouse_pos)) { hovered_gpu_marker = (QueryPerf)i; hovered_gpu_marker_elapsed = gpu_timers[i]; } if (m_capture_report) { if (m_first_gpu_capture_sweep) m_gpu_capture_report_buffer->getStdStream() << GPU_Phase[i] << ";"; else m_gpu_capture_report_buffer->getStdStream() << elapsed << ";"; } } if (m_capture_report) { m_gpu_capture_report_buffer->getStdStream() << "\n"; m_first_gpu_capture_sweep = false; } } // Draw the end of the frame { s32 x_sync = (s32)(x_offset + factor*m_time_between_sync); s32 y_up_sync = (s32)(MARGIN_Y*screen_size.Height); s32 y_down_sync = (s32)( (MARGIN_Y + (2+nb_thread_infos)*LINE_HEIGHT)*screen_size.Height ); driver->draw2DLine(core::vector2di(x_sync, y_up_sync), core::vector2di(x_sync, y_down_sync), video::SColor(0xFF, 0x00, 0x00, 0x00)); } // Draw the hovered markers' names gui::ScalableFont* font = GUIEngine::getFont(); if (font) { core::stringw text; while(!hovered_markers.empty()) { Marker& m = hovered_markers.top(); std::ostringstream oss; oss.precision(4); oss << m.name << " [" << (m.end - m.start) << " ms / "; oss.precision(3); oss << (m.end - m.start)*100.0 / duration << "%]" << std::endl; text += oss.str().c_str(); hovered_markers.pop(); } font->draw(text, MARKERS_NAMES_POS, video::SColor(0xFF, 0xFF, 0x00, 0x00)); if (hovered_gpu_marker != Q_LAST) { std::ostringstream oss; oss << GPU_Phase[hovered_gpu_marker] << " : " << hovered_gpu_marker_elapsed << " us"; font->draw(oss.str().c_str(), GPU_MARKERS_NAMES_POS, video::SColor(0xFF, 0xFF, 0x00, 0x00)); } } if (m_capture_report) { font->draw("Capturing profiler report...", MARKERS_NAMES_POS, video::SColor(0xFF, 0x00, 0x90, 0x00)); } PROFILER_POP_CPU_MARKER(); }
//! draws the element and its children void CGUIEditBox::draw() { #ifndef SERVER_ONLY if (!IsVisible) return; const bool focus = Environment->hasFocus(this); IGUISkin* skin = Environment->getSkin(); if (!skin) return; FrameRect = AbsoluteRect; // draw the border if (Border) { EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE; if ( isEnabled() ) col = focus ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE; skin->draw3DSunkenPane(this, skin->getColor(col), false, true, FrameRect, &AbsoluteClippingRect); FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1; FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1; FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; } core::rect<s32> localClipRect = FrameRect; localClipRect.clipAgainst(AbsoluteClippingRect); // draw the text IGUIFont* font = OverrideFont; if (!OverrideFont) font = skin->getFont(); s32 cursorLine = 0; s32 charcursorpos = 0; if (font) { if (LastBreakFont != font) { breakText(); } // calculate cursor pos core::stringw *txtLine = &Text; s32 startPos = 0; core::stringw s, s2; // get mark position const bool ml = (!PasswordBox && (WordWrap || MultiLine)); const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0; const s32 hlineCount = ml ? getLineFromPos(realmend) - hlineStart + 1 : 1; const s32 lineCount = ml ? BrokenText.size() : 1; // Save the override color information. // Then, alter it if the edit box is disabled. const bool prevOver = OverrideColorEnabled; const video::SColor prevColor = OverrideColor; if (Text.size()) { if (!isEnabled() && !OverrideColorEnabled) { OverrideColorEnabled = true; OverrideColor = skin->getColor(EGDC_GRAY_TEXT); } for (s32 i=0; i < lineCount; ++i) { setTextRect(i); // clipping test - don't draw anything outside the visible area core::rect<s32> c = localClipRect; c.clipAgainst(CurrentTextRect); if (!c.isValid()) continue; // get current line if (PasswordBox) { if (BrokenText.size() != 1) { BrokenText.clear(); BrokenText.push_back(core::stringw()); } if (BrokenText[0].size() != Text.size()) { BrokenText[0] = Text; for (u32 q = 0; q < Text.size(); ++q) { BrokenText[0] [q] = PasswordChar; } } txtLine = &BrokenText[0]; startPos = 0; } else { txtLine = ml ? &BrokenText[i] : &Text; startPos = ml ? BrokenTextPositions[i] : 0; } font->draw(translations->fribidize(txtLine->c_str()), CurrentTextRect, OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), false, true, &localClipRect); // draw with fribidize no matter what language, because in fribidize function, // it will return the input pointer if (this->isRTLLanguage()) from Translations::isRTLText // is false // draw mark and marked text if (focus && MarkBegin != MarkEnd && i >= hlineStart && i < hlineStart + hlineCount) { s32 mbegin = 0, mend = 0; s32 lineStartPos = 0, lineEndPos = txtLine->size(); if (i == hlineStart) { // highlight start is on this line s = txtLine->subString(0, realmbgn - startPos); mbegin = font->getDimension(s.c_str()).Width; // deal with kerning mbegin += font->getKerningWidth( &((*txtLine)[realmbgn - startPos]), realmbgn - startPos > 0 ? &((*txtLine)[realmbgn - startPos - 1]) : 0); lineStartPos = realmbgn - startPos; } if (i == hlineStart + hlineCount - 1) { // highlight end is on this line s2 = txtLine->subString(0, realmend - startPos); mend = font->getDimension(s2.c_str()).Width; lineEndPos = (s32)s2.size(); } else mend = font->getDimension(txtLine->c_str()).Width; CurrentTextRect.UpperLeftCorner.X += mbegin; CurrentTextRect.LowerRightCorner.X = CurrentTextRect.UpperLeftCorner.X + mend - mbegin; // draw mark skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), CurrentTextRect, &localClipRect); // draw marked text s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos); if (s.size()) font->draw(s.c_str(), CurrentTextRect, OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT), false, true, &localClipRect); } } // Return the override color information to its previous settings. OverrideColorEnabled = prevOver; OverrideColor = prevColor; } // draw cursor if (WordWrap || MultiLine) { cursorLine = getLineFromPos(CursorPos); txtLine = &BrokenText[cursorLine]; startPos = BrokenTextPositions[cursorLine]; } s = txtLine->subString(0,CursorPos-startPos); charcursorpos = font->getDimension(s.c_str()).Width ; // + font->getKerningWidth(L"_", CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0); if (focus && (getTime() - BlinkStartTime) % 2 == 0 && !m_rtl) { //setTextRect(cursorLine); //CurrentTextRect.UpperLeftCorner.X += charcursorpos; setTextRect(0); core::rect< s32 > caret_rect = CurrentTextRect; caret_rect.UpperLeftCorner.X += charcursorpos - 1; caret_rect.LowerRightCorner.X = caret_rect.UpperLeftCorner.X + 2; GL32_draw2DRectangle( video::SColor(255,0,0,0), caret_rect ); /* font->draw(L"_", CurrentTextRect, OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), false, true, &localClipRect); */ } } // draw children IGUIElement::draw(); #endif }