void MenuWindow::Draw() { if (_initialized == false) { IF_PRINT_WARNING(VIDEO_DEBUG) << "the menu window was not initialized:\n" << _initialization_errors << endl; return; } if (_window_state == VIDEO_MENU_STATE_HIDDEN) return; VideoManager->PushState(); VideoManager->SetDrawFlags(_xalign, _yalign, VIDEO_BLEND, 0); if (_is_scissored) { ScreenRect rect = _scissor_rect; if (VideoManager->IsScissoringEnabled()) { rect.Intersect(VideoManager->GetScissorRect()); } else { VideoManager->EnableScissoring(); } VideoManager->SetScissorRect(rect); } VideoManager->Move(_x_position, _y_position); _menu_image.Draw(Color::white); if (GUIManager->DEBUG_DrawOutlines() == true) { _DEBUG_DrawOutline(); } VideoManager->PopState(); return; } // void MenuWindow::Draw()
void Font::BitmapCharacter(float x, float y, float w, float h, int character) { WorldRect dstRect(x, y, w, h); ScreenRect* psrcRect; psrcRect = &atlas->sourceRectangles[character]; glBegin(GL_QUADS); { glTexCoord2d(psrcRect->fLeft(), psrcRect->fTop()); glVertex2f(dstRect.iLeft(), dstRect.iBottom()); glTexCoord2d(psrcRect->fRight(), psrcRect->fTop()); glVertex2f(dstRect.iRight(), dstRect.iBottom()); glTexCoord2d(psrcRect->fRight(), psrcRect->fBottom()); glVertex2f(dstRect.iRight(), dstRect.iTop()); glTexCoord2d(psrcRect->fLeft(), psrcRect->fBottom()); glVertex2f(dstRect.iLeft(), dstRect.iTop()); } glEnd(); }
static LayoutDeviceRect TransformCompositionBounds(const ParentLayerRect& aCompositionBounds, const CSSToParentLayerScale& aZoom, const ScreenPoint& aScrollOffset, const CSSToScreenScale& aResolution, const gfx3DMatrix& aTransformScreenToLayout) { // Transform the current composition bounds into transformed layout device // space by compensating for the difference in resolution and subtracting the // old composition bounds origin. ScreenRect offsetViewportRect = (aCompositionBounds / aZoom) * aResolution; offsetViewportRect.MoveBy(-aScrollOffset); gfxRect transformedViewport = aTransformScreenToLayout.TransformBounds( gfxRect(offsetViewportRect.x, offsetViewportRect.y, offsetViewportRect.width, offsetViewportRect.height)); return LayoutDeviceRect(transformedViewport.x, transformedViewport.y, transformedViewport.width, transformedViewport.height); }
void AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer, const LayoutDeviceToLayerScale& aResolution) { LayerComposite* layerComposite = aLayer->AsLayerComposite(); ContainerLayer* container = aLayer->AsContainerLayer(); const FrameMetrics& metrics = container->GetFrameMetrics(); // We must apply the resolution scale before a pan/zoom transform, so we call // GetTransform here. const gfx3DMatrix& currentTransform = aLayer->GetTransform(); gfx3DMatrix oldTransform = currentTransform; gfx3DMatrix treeTransform; CSSToLayerScale geckoZoom = metrics.mDevPixelsPerCSSPixel * aResolution; LayerIntPoint scrollOffsetLayerPixels = RoundedToInt(metrics.mScrollOffset * geckoZoom); if (mIsFirstPaint) { mContentRect = metrics.mScrollableRect; SetFirstPaintViewport(scrollOffsetLayerPixels, geckoZoom, mContentRect); mIsFirstPaint = false; } else if (!metrics.mScrollableRect.IsEqualEdges(mContentRect)) { mContentRect = metrics.mScrollableRect; SetPageRect(mContentRect); } // We synchronise the viewport information with Java after sending the above // notifications, so that Java can take these into account in its response. // Calculate the absolute display port to send to Java LayerIntRect displayPort = RoundedToInt( (metrics.mCriticalDisplayPort.IsEmpty() ? metrics.mDisplayPort : metrics.mCriticalDisplayPort ) * geckoZoom); displayPort += scrollOffsetLayerPixels; LayerMargin fixedLayerMargins(0, 0, 0, 0); ScreenPoint offset(0, 0); // Ideally we would initialize userZoom to AsyncPanZoomController::CalculateResolution(metrics) // but this causes a reftest-ipc test to fail (see bug 883646 comment 27). The reason for this // appears to be that metrics.mZoom is poorly initialized in some scenarios. In these scenarios, // however, we can assume there is no async zooming in progress and so the following statement // works fine. CSSToScreenScale userZoom(metrics.mDevPixelsPerCSSPixel.scale * metrics.mResolution.scale); ScreenPoint userScroll = metrics.mScrollOffset * userZoom; SyncViewportInfo(displayPort, geckoZoom, mLayersUpdated, userScroll, userZoom, fixedLayerMargins, offset); mLayersUpdated = false; // Apply the render offset mLayerManager->GetCompositor()->SetScreenRenderOffset(offset); // Handle transformations for asynchronous panning and zooming. We determine the // zoom used by Gecko from the transformation set on the root layer, and we // determine the scroll offset used by Gecko from the frame metrics of the // primary scrollable layer. We compare this to the user zoom and scroll // offset in the view transform we obtained from Java in order to compute the // transformation we need to apply. LayerToScreenScale zoomAdjust = userZoom / geckoZoom; LayerIntPoint geckoScroll(0, 0); if (metrics.IsScrollable()) { geckoScroll = scrollOffsetLayerPixels; } LayerPoint translation = (userScroll / zoomAdjust) - geckoScroll; treeTransform = gfx3DMatrix(ViewTransform(-translation, userZoom / metrics.mDevPixelsPerCSSPixel)); // The transform already takes the resolution scale into account. Since we // will apply the resolution scale again when computing the effective // transform, we must apply the inverse resolution scale here. gfx3DMatrix computedTransform = treeTransform * currentTransform; computedTransform.Scale(1.0f/container->GetPreXScale(), 1.0f/container->GetPreYScale(), 1); computedTransform.ScalePost(1.0f/container->GetPostXScale(), 1.0f/container->GetPostYScale(), 1); layerComposite->SetShadowTransform(computedTransform); NS_ASSERTION(!layerComposite->GetShadowTransformSetByAnimation(), "overwriting animated transform!"); // Apply resolution scaling to the old transform - the layer tree as it is // doesn't have the necessary transform to display correctly. oldTransform.Scale(aResolution.scale, aResolution.scale, 1); // Make sure that overscroll and under-zoom are represented in the old // transform so that fixed position content moves and scales accordingly. // These calculations will effectively scale and offset fixed position layers // in screen space when the compensatory transform is performed in // AlignFixedLayersForAnchorPoint. ScreenRect contentScreenRect = mContentRect * userZoom; gfxPoint3D overscrollTranslation; if (userScroll.x < contentScreenRect.x) { overscrollTranslation.x = contentScreenRect.x - userScroll.x; } else if (userScroll.x + metrics.mCompositionBounds.width > contentScreenRect.XMost()) { overscrollTranslation.x = contentScreenRect.XMost() - (userScroll.x + metrics.mCompositionBounds.width); } if (userScroll.y < contentScreenRect.y) { overscrollTranslation.y = contentScreenRect.y - userScroll.y; } else if (userScroll.y + metrics.mCompositionBounds.height > contentScreenRect.YMost()) { overscrollTranslation.y = contentScreenRect.YMost() - (userScroll.y + metrics.mCompositionBounds.height); } oldTransform.Translate(overscrollTranslation); gfxSize underZoomScale(1.0f, 1.0f); if (mContentRect.width * userZoom.scale < metrics.mCompositionBounds.width) { underZoomScale.width = (mContentRect.width * userZoom.scale) / metrics.mCompositionBounds.width; } if (mContentRect.height * userZoom.scale < metrics.mCompositionBounds.height) { underZoomScale.height = (mContentRect.height * userZoom.scale) / metrics.mCompositionBounds.height; } oldTransform.Scale(underZoomScale.width, underZoomScale.height, 1); // Make sure fixed position layers don't move away from their anchor points // when we're asynchronously panning or zooming AlignFixedLayersForAnchorPoint(aLayer, aLayer, oldTransform, fixedLayerMargins); }
void DrawLeftPanel() { float x,y,w,h; float border = 2.0f; x = lmenuRect.x + border; y = lmenuRect.y + border - 1; w = lmenuRect.w - 2*border; h = lmenuRect.h - 2*border + 1; glDisable(GL_TEXTURE_2D); glColor4f(0.5882f, 0.5882f, 0.5882f, 1.0f); glBegin(GL_QUADS); { glVertex2f(x, y); glVertex2f(x + w, y); glVertex2f(x + w, y + h); glVertex2f(x, y + h); } glEnd(); glEnable(GL_TEXTURE_2D); ScreenRect srcRect,dstRect; float top = 210; float dx = 32; float dw = 120; float dh = 128; w = tilethumbsize.x*2; h = tilethumbsize.y*2; x = lmenuRect.x + border + dx; y = lmenuRect.y + border - 1 + top; glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, *(atlas_tile.texture)); glBegin(GL_QUADS); { //brush srcRect = atlas_tile.sourceRectangles[selectedBrush]; dstRect = ScreenRect(x,y,w,h); glTexCoord2d(srcRect.fLeft(), srcRect.fTop()); glVertex2f(dstRect.fLeft(), dstRect.fTop()); glTexCoord2d(srcRect.fRight(), srcRect.fTop()); glVertex2f(dstRect.fRight(), dstRect.fTop()); glTexCoord2d(srcRect.fRight(), srcRect.fBottom()); glVertex2f(dstRect.fRight(), dstRect.fBottom()); glTexCoord2d(srcRect.fLeft(), srcRect.fBottom()); glVertex2f(dstRect.fLeft(), dstRect.fBottom()); } glEnd(); //cbrush glBindTexture(GL_TEXTURE_2D, *(atlas_collision.texture)); glBegin(GL_QUADS); { srcRect = atlas_collision.sourceRectangles[selectedCBrush]; dstRect = ScreenRect(x + dw, y ,w,h); glTexCoord2d(srcRect.fLeft(), srcRect.fTop()); glVertex2f(dstRect.fLeft(), dstRect.fTop()); glTexCoord2d(srcRect.fRight(), srcRect.fTop()); glVertex2f(dstRect.fRight(), dstRect.fTop()); glTexCoord2d(srcRect.fRight(), srcRect.fBottom()); glVertex2f(dstRect.fRight(), dstRect.fBottom()); glTexCoord2d(srcRect.fLeft(), srcRect.fBottom()); glVertex2f(dstRect.fLeft(), dstRect.fBottom()); } glEnd(); float lw = 4.0f; glDisable(GL_TEXTURE_2D); x += -8.0f; w += 16.0f; y += -8.0f; h += 16.0f; //tile outline glColor4f(0.0f, 0.4f, 0.9f, 1.0f); R_DrawHorizontalLine(x - lw, y, w + 2*lw,lw); R_DrawVerticalLine(x, y , h, lw); R_DrawHorizontalLine(x - lw, y + h, w + 2*lw, lw); R_DrawVerticalLine(x + w, y + h, -h, lw); //brush outline glColor4f(0.0f, 0.9f, 0.4f, 1.0f); x += dw; R_DrawHorizontalLine(x - lw, y, w + 2*lw,lw); R_DrawVerticalLine(x, y , h, lw); R_DrawHorizontalLine(x - lw, y + h, w + 2*lw, lw); R_DrawVerticalLine(x + w, y + h, -h, lw); x -= dw; glEnable(GL_TEXTURE_2D); char buffer[128]; Vector4 color; int ty = lmenuRect.y + border - 1 + top - 32; int dy = smallfont.charsXYWH.h * smallfont.scaleValue; color = Vector4(0.0f,0.0f,0.0f,1.0f); sprintf (buffer, "%s", "Image Brush"); smallfont.displayScreenTextSpacing(x - 16,ty,color.x,color.y,color.z,buffer); sprintf (buffer, "index = %d", selectedBrush); smallfont.displayScreenTextSpacing(x - 16,ty +dy,color.x,color.y,color.z,buffer); sprintf (buffer, "%s", "Collision Brush"); smallfont.displayScreenTextSpacing(x - 16 + dw, ty,color.x,color.y,color.z,buffer); sprintf (buffer, "index = %d", selectedCBrush); smallfont.displayScreenTextSpacing(x - 16 + dw, ty + dy,color.x,color.y,color.z,buffer); //CBrush icons glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, *(atlas_collision.texture)); w = 48.0f; h = 48.0f; x = lmenuRect.x + border + 8.0f; y = lmenuRect.y + border - 1 + top + dh; ScreenRect hl_dstRect,sel_dstRect; for(int i=0;i<atlas_collision.totalFrames;) { glBegin(GL_QUADS); { srcRect = atlas_collision.sourceRectangles[i]; dstRect = ScreenRect(x,y,w,h); glTexCoord2d(srcRect.fLeft(), srcRect.fTop()); glVertex2f(dstRect.fLeft(), dstRect.fTop()); glTexCoord2d(srcRect.fRight(), srcRect.fTop()); glVertex2f(dstRect.fRight(), dstRect.fTop()); glTexCoord2d(srcRect.fRight(), srcRect.fBottom()); glVertex2f(dstRect.fRight(), dstRect.fBottom()); glTexCoord2d(srcRect.fLeft(), srcRect.fBottom()); glVertex2f(dstRect.fLeft(), dstRect.fBottom()); } glEnd(); if(i == highlightedCBrush) hl_dstRect = dstRect; if(i == selectedCBrush) sel_dstRect = dstRect; x += w + 8.0f; i++; if(!fmod(i,4)) { x = lmenuRect.x + border + 8.0f; y += h + 8.0f; } } //highlightedCBrush lw = 1.0f; glDisable(GL_TEXTURE_2D); //selected glColor4f(0.5f, 1.0f, 0.5f, 1.0f); R_DrawHorizontalLine(sel_dstRect.x - lw, sel_dstRect.y, sel_dstRect.w + 2*lw, lw); R_DrawVerticalLine(sel_dstRect.x, sel_dstRect.y , sel_dstRect.h, lw); R_DrawHorizontalLine(sel_dstRect.x - lw, sel_dstRect.y + sel_dstRect.h, sel_dstRect.w + 2*lw, lw); R_DrawVerticalLine(sel_dstRect.x + sel_dstRect.w, sel_dstRect.y + sel_dstRect.h, -sel_dstRect.h, lw); if(PointinRect(Point(input.mouse.lX,input.mouse.lY),lmenuRect)) { x = lmenuRect.x + border + 8.0f; y = lmenuRect.y + border - 1 + top + dh; Point cursor(CLAMP(input.mouse.lX,0,lmenuRect.fRight()),input.mouse.lY); cursor.x -= x; cursor.y -= y; highlightedCBrush = ((int)(cursor.x/(w + 8.0f)) + 4*((int)((cursor.y)/(h + 8.0f)))); highlightedCBrush = CLAMP(highlightedCBrush,0,atlas_collision.totalFrames-1); glColor4f(1.0f, 1.0f, 0.0f, 1.0f); R_DrawHorizontalLine(hl_dstRect.x - lw, hl_dstRect.y, hl_dstRect.w + 2*lw, lw); R_DrawVerticalLine(hl_dstRect.x, hl_dstRect.y , hl_dstRect.h, lw); R_DrawHorizontalLine(hl_dstRect.x - lw, hl_dstRect.y + hl_dstRect.h, hl_dstRect.w + 2*lw, lw); R_DrawVerticalLine(hl_dstRect.x + hl_dstRect.w, hl_dstRect.y + hl_dstRect.h, -hl_dstRect.h, lw); } glEnable(GL_TEXTURE_2D); R_drawScreenDebug(); }
bool PointinRect(Point p, ScreenRect r) { return p.x >= r.fLeft() && p.x <= r.fRight() && p.y<=r.fBottom() && p.y >= r.fTop(); }
void TextBox::_DrawTextLines(float text_x, float text_y, ScreenRect scissor_rect) { int32 num_chars_drawn = 0; // Calculate the fraction of the text to display float percent_complete; if(_finished) percent_complete = 1.0f; else percent_complete = static_cast<float>(_current_time) / static_cast<float>(_end_time); // Iterate through the loop for every line of text and draw it for(int32 line = 0; line < static_cast<int32>(_text.size()); ++line) { // (1): Calculate the x draw offset for this line and move to that position float line_width = static_cast<float>(TextManager->CalculateTextWidth(_text_style.font, _text[line])); int32 x_align = VideoManager->_ConvertXAlign(_text_xalign); float x_offset = text_x + ((x_align + 1) * line_width) * 0.5f * VideoManager->_current_context.coordinate_system.GetHorizontalDirection(); VideoManager->MoveRelative(x_offset, 0.0f); int32 line_size = static_cast<int32>(_text[line].size()); // (2): Draw the text depending on the display mode and whether or not the gradual display is finished if(_finished || _mode == VIDEO_TEXT_INSTANT) { TextManager->Draw(_text[line], _text_style); } else if(_mode == VIDEO_TEXT_CHAR) { // Determine which character is currently being rendered int32 cur_char = static_cast<int32>(percent_complete * _num_chars); // If the current character to draw is after this line, render the entire line if(num_chars_drawn + line_size < cur_char) { TextManager->Draw(_text[line], _text_style); } // The current character to draw is on this line: figure out which characters on this line should be drawn else { int32 num_completed_chars = cur_char - num_chars_drawn; if(num_completed_chars > 0) { ustring substring = _text[line].substr(0, num_completed_chars); TextManager->Draw(substring); } } } // else if (_mode == VIDEO_TEXT_CHAR) else if(_mode == VIDEO_TEXT_FADECHAR) { // Figure out which character is currently being rendered float fade_cur_char = percent_complete * _num_chars; int32 cur_char = static_cast<int32>(fade_cur_char); float cur_percent = fade_cur_char - cur_char; // If the current character to draw is after this line, draw the whole line if(num_chars_drawn + line_size <= cur_char) { TextManager->Draw(_text[line], _text_style); } // The current character is on this line: draw any previous characters on this line as well as the current character else { int32 num_completed_chars = cur_char - num_chars_drawn; // Continue only if this line has at least one character that should be drawn if(num_completed_chars >= 0) { ustring substring; // Draw any fully completed characters at full opacity if(num_completed_chars > 0) { substring = _text[line].substr(0, num_completed_chars); TextManager->Draw(substring, _text_style); } // Draw the current character that is being faded in at the appropriate alpha level Color old_color = _text_style.color; _text_style.color[3] *= cur_percent; VideoManager->MoveRelative(static_cast<float>(TextManager->CalculateTextWidth(_text_style.font, substring)), 0.0f); TextManager->Draw(_text[line].substr(num_completed_chars, 1), _text_style); _text_style.color = old_color; } } } // else if (_mode == VIDEO_TEXT_FADECHAR) else if(_mode == VIDEO_TEXT_FADELINE) { // Deteremine which line is currently being rendered float fade_lines = percent_complete * _text.size(); int32 lines = static_cast<int32>(fade_lines); float cur_percent = fade_lines - lines; // If this line comes before the line being rendered, simply draw the line and be done with it if(line < lines) { TextManager->Draw(_text[line], _text_style); } // Otherwise if this is the line being rendered, determine the amount of alpha for the line being faded in and draw it else if(line == lines) { Color old_color = _text_style.color; _text_style.color[3] *= cur_percent; TextManager->Draw(_text[line], _text_style); _text_style.color = old_color; } } // else if (_mode == VIDEO_TEXT_FADELINE) else if(_mode == VIDEO_TEXT_REVEAL) { // Determine which character is currently being rendered float fade_cur_char = percent_complete * _num_chars; int32 cur_char = static_cast<int32>(fade_cur_char); float cur_percent = fade_cur_char - cur_char; int32 num_completed_chars = cur_char - num_chars_drawn; // If the current character comes after this line, simply render the entire line if(num_chars_drawn + line_size <= cur_char) { TextManager->Draw(_text[line], _text_style); } // If the line contains the current character, draw all previous characters as well as the current one else if(num_completed_chars >= 0) { ustring substring; // If there are already completed characters on this line, draw them in full if(num_completed_chars > 0) { substring = _text[line].substr(0, num_completed_chars); TextManager->Draw(substring, _text_style); } // Now draw the current character from the line, partially scissored according to the amount that is complete ustring cur_char_string = _text[line].substr(num_completed_chars, 1); // Create a rectangle for the current character, in window coordinates int32 char_x, char_y, char_w, char_h; char_x = static_cast<int32>(x_offset + VideoManager->_current_context.coordinate_system.GetHorizontalDirection() * TextManager->CalculateTextWidth(_text_style.font, substring)); char_y = static_cast<int32>(text_y - VideoManager->_current_context.coordinate_system.GetVerticalDirection() * (_font_properties->height + _font_properties->descent)); if(VideoManager->_current_context.coordinate_system.GetHorizontalDirection() < 0.0f) char_y = static_cast<int32>(VideoManager->_current_context.coordinate_system.GetBottom()) - char_y; if(VideoManager->_current_context.coordinate_system.GetVerticalDirection() < 0.0f) char_x = static_cast<int32>(VideoManager->_current_context.coordinate_system.GetLeft()) - char_x; char_w = TextManager->CalculateTextWidth(_text_style.font, cur_char_string); char_h = _font_properties->height; // Multiply the width by percentage done to determine the scissoring dimensions char_w = static_cast<int32>(cur_percent * char_w); VideoManager->MoveRelative(VideoManager->_current_context.coordinate_system.GetHorizontalDirection() * TextManager->CalculateTextWidth(_text_style.font, substring), 0.0f); // Construct the scissor rectangle using the character dimensions and draw the revealing character VideoManager->PushState(); ScreenRect char_scissor_rect(char_x, char_y, char_w, char_h); scissor_rect.Intersect(char_scissor_rect); VideoManager->EnableScissoring(); VideoManager->SetScissorRect(scissor_rect); TextManager->Draw(cur_char_string, _text_style); VideoManager->PopState(); } // In the else case, the current character is before the line, so we don't draw anything for this line at all } // else if (_mode == VIDEO_TEXT_REVEAL) else { // Invalid display mode: just render the text instantly TextManager->Draw(_text[line]); IF_PRINT_WARNING(VIDEO_DEBUG) << "an unknown/unsupported text display mode was active: " << _mode << std::endl; } // (3): Prepare to draw the next line and move the draw cursor appropriately num_chars_drawn += line_size; // VideoManager->MoveRelative(-xOffset, _font_properties.line_skip * -cs._vertical_direction); text_y += _font_properties->line_skip * -VideoManager->_current_context.coordinate_system.GetVerticalDirection(); VideoManager->Move(0.0f, text_y); } // for (int32 line = 0; line < static_cast<int32>(_text.size()); ++line) } // void TextBox::_DrawLines(float text_x, float text_y, ScreenRect scissor_rect)