void CMultiLineEditUI::SetPos(RECT rc) { if( m_pCanvas != NULL ) { CRect rcEdit = rc; ::SetWindowPos(*m_pCanvas, HWND_TOP, rcEdit.left, rcEdit.top, rcEdit.GetWidth(), rcEdit.GetHeight(), SWP_NOOWNERZORDER); } if( m_pWindow != NULL ) { CRect rcEdit = rc; rcEdit.right += 20; ::SetWindowPos(*m_pWindow, HWND_TOP, 0, 0, rcEdit.GetWidth(), rcEdit.GetHeight(), SWP_NOACTIVATE); } CControlUI::SetPos(rc); }
void CEquationEditorWindow::ZoomDFS( float coef, std::shared_ptr<IBaseExprModel> node ) { for( auto child : node->GetChildren() ) { ZoomDFS( coef, child ); } CRect rect = node->GetRect(); int heightNew = ( int ) rect.GetHeight() * coef; int widthNew = ( int ) rect.GetWidth() * coef; rect.Set( rect.Left(), rect.Top(), rect.Left() + widthNew, rect.Top() + heightNew ); node->SetRect( rect ); std::wstring text = node->GetText(); if( text.length() > 0 ) { std::shared_ptr<CEditControlModel> eNode = std::dynamic_pointer_cast<CEditControlModel>(node); std::vector<int> symbolsWidthsNew; for( int i = 0; i < text.length(); i++ ) { int symbolWidth = GetSymbolWidth( text[i], heightNew ); symbolsWidthsNew.push_back( symbolWidth ); } eNode->UpdateSymbolsWidths( symbolsWidthsNew ); } }
void CHwndUI::SetPos(RECT rc) { CControlUI::SetPos(rc); CRect rcUI = m_rcItem; if (m_UIHwnd&&::IsWindow(m_UIHwnd)) { ::SetWindowPos(m_UIHwnd,NULL,rcUI.left,rcUI.top,rcUI.GetWidth(),rcUI.GetHeight(),SWP_NOZORDER); } }
void CMultiLineEditUI::SetPos(RECT rc) { if( m_pWindow != NULL ) { CRect rcEdit = rc; rcEdit.Deflate(3, 3); ::SetWindowPos(*m_pWindow, HWND_TOP, rcEdit.left, rcEdit.top, rcEdit.GetWidth(), rcEdit.GetHeight(), SWP_NOACTIVATE); } CControlUI::SetPos(rc); }
void CPaintEngineTool::DrawCursorInCanvas( CCanvas& inCanvas, CPoint& outHotSpot ) { inCanvas.BeginDrawing(); CRect box = inCanvas.GetRect(); CGraphicsState state; state.SetLineColor( GetPaintEngine()->GetLineColor() ); TCoordinate lineThickness = GetPaintEngine()->GetLineThickness(); if( lineThickness > (box.GetWidth() / 2) ) lineThickness = (box.GetWidth() / 2); state.SetLineThickness( lineThickness ); box.Offset( -0.5, -0.5 ); inCanvas.StrokeLineFromPointToPoint( CPoint(box.GetH(),box.GetVCenter()), CPoint(box.GetMaxH(),box.GetVCenter()), state ); inCanvas.StrokeLineFromPointToPoint( CPoint(box.GetHCenter(),box.GetV()), CPoint(box.GetHCenter(),box.GetMaxV()), state ); inCanvas.EndDrawing(); box = inCanvas.GetRect(); outHotSpot = CPoint( box.GetHCenter() -0.5, box.GetVCenter() -0.5 ); }
void CFracControlModel::PlaceChildren() { CRect newRect; int middle = (rect.Right() + rect.Left()) / 2; CRect oldRect = firstChild->GetRect( ); newRect.Top() = rect.Top(); newRect.Bottom() = rect.Top() + oldRect.GetHeight(); newRect.Left() = middle - oldRect.GetWidth() / 2; newRect.Right() = middle + oldRect.GetWidth() / 2; firstChild->SetRect( newRect ); oldRect = secondChild->GetRect( ); newRect.Bottom() = rect.Bottom(); newRect.Top() = rect.Bottom() - oldRect.GetHeight(); newRect.Left() = middle - oldRect.GetWidth() / 2; newRect.Right() = middle + oldRect.GetWidth() / 2; secondChild->SetRect( newRect ); updatePolygons(); }
void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor, const CPos &pos, const float &z, const CRect &clipping) { CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); tech->BeginPass(); bool isClipped = (clipping != CRect()); if (isClipped) { glEnable(GL_SCISSOR_TEST); glScissor(clipping.left, g_yres - clipping.bottom, clipping.GetWidth(), clipping.GetHeight()); } CTextRenderer textRenderer(tech->GetShader()); textRenderer.SetClippingRect(clipping); textRenderer.Translate(0.0f, 0.0f, z); for (std::vector<SGUIText::STextCall>::const_iterator it = Text.m_TextCalls.begin(); it != Text.m_TextCalls.end(); ++it) { // If this is just a placeholder for a sprite call, continue if (it->m_pSpriteCall) continue; CColor color = it->m_UseCustomColor ? it->m_Color : DefaultColor; textRenderer.Color(color); textRenderer.Font(it->m_Font); textRenderer.Put((float)(int)(pos.x+it->m_Pos.x), (float)(int)(pos.y+it->m_Pos.y), &it->m_String); } textRenderer.Render(); for (std::list<SGUIText::SSpriteCall>::iterator it=Text.m_SpriteCalls.begin(); it!=Text.m_SpriteCalls.end(); ++it) { DrawSprite(it->m_Sprite, it->m_CellID, z, it->m_Area + pos); } if (isClipped) glDisable(GL_SCISSOR_TEST); tech->EndPass(); }
void CSystemControlModel::PlaceChildren() { CRect newRect; int currentTop = rect.Top() + 5; for (int i = 0; i < children.size(); ++i) { CRect oldRect = children[i]->GetRect(); newRect.Top() = currentTop; currentTop += oldRect.GetHeight() + 5; newRect.Bottom() = newRect.Top() + oldRect.GetHeight(); newRect.Left() = rect.Left() + 15; newRect.Right() = newRect.Left() + oldRect.GetWidth(); children[i]->SetRect(newRect); } updatePolygons(); }
void CBalloonTip::UpdateWindow() { CRect rc; GetClientRect(GetHWND(),&rc); int nBorder = GetSystemMetrics(SM_CXFRAME); int nWidth = GetSystemMetrics(SM_CXMAXIMIZED)- 2*nBorder; int nHeight= GetSystemMetrics(SM_CYMAXIMIZED)- 2*nBorder; int nClientWidth = rc.GetWidth();// m_BKImageBig->GetWidth() ; int nClientHeight = rc.GetHeight();//m_BKImageBig->GetHeight() ; int bTopPos = (30*(255-m_nFade))/255; SetWindowPos(GetHWND(),NULL,nWidth-nClientWidth,nHeight-nClientHeight+bTopPos,nClientWidth,nClientHeight,SWP_NOZORDER|SWP_NOACTIVATE); SetLayeredWindowAttributes(GetHWND(), NULL, m_nFade, LWA_ALPHA); }
void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping) { CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); tech->BeginPass(); bool isClipped = (clipping != CRect()); if (isClipped) { glEnable(GL_SCISSOR_TEST); glScissor( clipping.left / g_GuiScale, g_yres - clipping.bottom / g_GuiScale, clipping.GetWidth() / g_GuiScale, clipping.GetHeight() / g_GuiScale); } CTextRenderer textRenderer(tech->GetShader()); textRenderer.SetClippingRect(clipping); textRenderer.Translate(0.0f, 0.0f, z); for (const SGUIText::STextCall& tc : Text.m_TextCalls) { // If this is just a placeholder for a sprite call, continue if (tc.m_pSpriteCall) continue; CColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor; textRenderer.Color(color); textRenderer.Font(tc.m_Font); textRenderer.Put((float)(int)(pos.x + tc.m_Pos.x), (float)(int)(pos.y + tc.m_Pos.y), &tc.m_String); } textRenderer.Render(); for (const SGUIText::SSpriteCall& sc : Text.m_SpriteCalls) DrawSprite(sc.m_Sprite, sc.m_CellID, z, sc.m_Area + pos); if (isClipped) glDisable(GL_SCISSOR_TEST); tech->EndPass(); }
void PopupMenu::Popup(CPoint point) { CListUI* menu_list = static_cast<CListUI*>(paint_manager_.FindControl(kMenuList)); if (menu_list != NULL) { CRect rc; rc.left = point.x; rc.top = point.y; rc.right = rc.left + kContextMenuWidth; rc.bottom = rc.top + menu_list->GetCount() * kContextMenuItemHeight + 2 * 8; int nWidth = rc.GetWidth(); int nHeight = rc.GetHeight(); //#if defined(WIN32) && !defined(UNDER_CE) // MONITORINFO oMonitor = {}; // oMonitor.cbSize = sizeof(oMonitor); // ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); // CRect rcWork = oMonitor.rcWork; //#else CRect rcWork; GetWindowRect(hosted_window_, &rcWork); //#endif if( rc.bottom > rcWork.bottom ) { if( nHeight >= rcWork.GetHeight() ) { rc.top = 0; rc.bottom = nHeight; } else { rc.bottom = point.y; rc.top = rc.bottom - nHeight; } } if (rc.right > rcWork.right) { if (nWidth >= rcWork.GetWidth()) { rc.left = 0; rc.right = nWidth; } else { rc.right = rcWork.right; rc.left = rc.right - nWidth; } } menu_list->SelectItem(0); MoveWindow(*this, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), TRUE); SetWindowPos(*this, NULL, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), SWP_FRAMECHANGED); HWND hWndParent = m_hWnd; while( ::GetParent(hWndParent) != NULL ) hWndParent = ::GetParent(hWndParent); ::ShowWindow(m_hWnd, SW_SHOW); #if defined(WIN32) && !defined(UNDER_CE) ::SendMessage(hWndParent, WM_NCACTIVATE, TRUE, 0L); #endif } }
LRESULT CMenuWnd::OnCreate( UINT uMag, WPARAM wParam, LPARAM lParam,BOOL& bHandled ) { if( m_pOwner != NULL) { LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); styleValue &= ~WS_CAPTION; ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); RECT rcClient; ::GetClientRect(*this, &rcClient); ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \ rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); m_pm.Init(m_hWnd); // The trick is to add the items to the new container. Their owner gets // reassigned by this operation - which is why it is important to reassign // the items back to the righfull owner/manager when the window closes. m_pLayout = new CMenuUI(); m_pm.UseParentResource(m_pOwner->GetManager()); m_pLayout->SetManager(&m_pm, NULL, true); LPCTSTR pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(kMenuUIInterfaceName); if( pDefaultAttributes ) { m_pLayout->ApplyAttributeList(pDefaultAttributes); } m_pLayout->SetBkColor(0xFFFFFFFF); m_pLayout->SetBorderColor(0xFF85E4FF); m_pLayout->SetBorderSize(0); m_pLayout->SetAutoDestroy(false); m_pLayout->EnableScrollBar(); for( int i = 0; i < m_pOwner->GetCount(); i++ ) { if(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ (static_cast<CMenuElementUI*>(m_pOwner->GetItemAt(i)))->SetOwner(m_pLayout); m_pLayout->Add(static_cast<CControlUI*>(m_pOwner->GetItemAt(i))); } } m_pm.AttachDialog(m_pLayout); // Position the popup window in absolute space RECT rcOwner = m_pOwner->GetPos(); RECT rc = rcOwner; int cxFixed = 0; int cyFixed = 0; #if defined(WIN32) && !defined(UNDER_CE) MONITORINFO oMonitor = {}; oMonitor.cbSize = sizeof(oMonitor); ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); CRect rcWork = oMonitor.rcWork; #else CRect rcWork; GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); #endif SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; for( int it = 0; it < m_pOwner->GetCount(); it++ ) { if(m_pOwner->GetItemAt(it)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ CControlUI* pControl = static_cast<CControlUI*>(m_pOwner->GetItemAt(it)); SIZE sz = pControl->EstimateSize(szAvailable); cyFixed += sz.cy; if( cxFixed < sz.cx ) cxFixed = sz.cx; } } cyFixed += 4; cxFixed += 4; RECT rcWindow; GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWindow); rc.top = rcOwner.top; rc.bottom = rc.top + cyFixed; ::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc); rc.left = rcWindow.right; rc.right = rc.left + cxFixed; rc.right += 2; bool bReachBottom = false; bool bReachRight = false; LONG chRightAlgin = 0; LONG chBottomAlgin = 0; RECT rcPreWindow = {0}; ContextMenuObserver::Iterator<BOOL, ContextMenuParam> iterator(s_context_menu_observer); ReceiverImplBase<BOOL, ContextMenuParam>* pReceiver = iterator.next(); while( pReceiver != NULL ) { CMenuWnd* pContextMenu = dynamic_cast<CMenuWnd*>(pReceiver); if( pContextMenu != NULL ) { GetWindowRect(pContextMenu->GetHWND(), &rcPreWindow); bReachRight = rcPreWindow.left >= rcWindow.right; bReachBottom = rcPreWindow.top >= rcWindow.bottom; if( pContextMenu->GetHWND() == m_pOwner->GetManager()->GetPaintWindow() || bReachBottom || bReachRight ) break; } pReceiver = iterator.next(); } if (bReachBottom) { rc.bottom = rcWindow.top; rc.top = rc.bottom - cyFixed; } if (bReachRight) { rc.right = rcWindow.left; rc.left = rc.right - cxFixed; } if( rc.bottom > rcWork.bottom ) { rc.bottom = rc.top; rc.top = rc.bottom - cyFixed; } if (rc.right > rcWork.right) { rc.right = rcWindow.left; rc.left = rc.right - cxFixed; rc.top = rcWindow.bottom; rc.bottom = rc.top + cyFixed; } if( rc.top < rcWork.top ) { rc.top = rcOwner.top; rc.bottom = rc.top + cyFixed; } if (rc.left < rcWork.left) { rc.left = rcWindow.right; rc.right = rc.left + cxFixed; } MoveWindow(m_hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); } else { m_pm.Init(m_hWnd); CDialogBuilder builder; CMenuBuilderCallback menuCallback; CControlUI* pRoot = builder.Create(m_xml, &menuCallback, &m_pm , NULL , m_sType.GetData()); m_pm.AttachDialog(pRoot); #if defined(WIN32) && !defined(UNDER_CE) MONITORINFO oMonitor = {}; oMonitor.cbSize = sizeof(oMonitor); ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); CRect rcWork = oMonitor.rcWork; #else CRect rcWork; /** 原来有bug m_pOwner为NULL,不能用m_pOwner->GetManager(),应为m_pm */ //GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); GetWindowRect(m_pm.GetPaintWindow(), &rcWork); #endif SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; szAvailable = pRoot->EstimateSize(szAvailable); m_pm.SetInitSize(szAvailable.cx, szAvailable.cy); DWORD dwAlignment = eMenuAlignment_Left | eMenuAlignment_Top; SIZE szInit = m_pm.GetInitSize(); CRect rc; CPoint point = m_BasedPoint; rc.left = point.x; rc.top = point.y; rc.right = rc.left + szInit.cx; rc.bottom = rc.top + szInit.cy; int nWidth = rc.GetWidth(); int nHeight = rc.GetHeight(); if (dwAlignment & eMenuAlignment_Right) { rc.right = point.x; rc.left = rc.right - nWidth; } if (dwAlignment & eMenuAlignment_Bottom) { rc.bottom = point.y; rc.top = rc.bottom - nHeight; } SetForegroundWindow(m_hWnd); MoveWindow(m_hWnd, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), FALSE); SetWindowPos(m_hWnd, HWND_TOPMOST, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), SWP_SHOWWINDOW); } return 0; }
void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*>& Sprites) { // This is called only when something has changed (like the size of the // sprite), so it doesn't need to be particularly efficient. // Clean up the old data Calls.clear(); // If this object has zero size, there's nothing to render. (This happens // with e.g. tooltips that have zero size before they're first drawn, so // it isn't necessarily an error.) if (Size.left == Size.right && Size.top == Size.bottom) return; std::map<CStr, CGUISprite*>::iterator it(Sprites.find(SpriteName)); if (it == Sprites.end()) { /* * Sprite not found. Check whether this a special sprite, * and if so create a new sprite: * "stretched:filename.ext" - stretched image * "stretched:grayscale:filename.ext" - stretched grayscale image. * "cropped:0.5, 0.25" - stretch this ratio (x,y) of the top left of the image * "color:r g b a" - solid color * > "textureAsMask" - when using color, use the (optional) texture alpha channel as mask. * These can be combined, but they must be separated by a ":" * so you can have a white overlay over an stretched grayscale image with: * "grayscale:color:255 255 255 100:stretched:filename.ext" */ // Check that this can be a special sprite. if (SpriteName.ReverseFind(":") == -1 && SpriteName.Find("color(") == -1) { LOGERROR("Trying to use a sprite that doesn't exist (\"%s\").", SpriteName.c_str()); return; } CGUISprite* Sprite = new CGUISprite; VfsPath TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.AfterLast(":")); if (SpriteName.Find("stretched:") != -1) { // TODO: Should check (nicely) that this is a valid file? SGUIImage* Image = new SGUIImage; Image->m_TextureName = TextureName; // Allow grayscale images for disabled portraits if (SpriteName.Find("grayscale:") != -1) { Image->m_Effects = new SGUIImageEffects; Image->m_Effects->m_Greyscale = true; } CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); Image->m_Size = ca; Image->m_TextureSize = ca; Sprite->AddImage(Image); Sprites[SpriteName] = Sprite; } else if (SpriteName.Find("cropped:") != -1) { // TODO: Should check (nicely) that this is a valid file? SGUIImage* Image = new SGUIImage; CStr info = SpriteName.AfterLast("cropped:").BeforeFirst(":"); double xRatio = info.BeforeFirst(",").ToDouble(); double yRatio = info.AfterLast(",").ToDouble(); Image->m_TextureName = TextureName; CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); CClientArea cb(CRect(0, 0, 0, 0), CRect(0, 0, 100/xRatio, 100/yRatio)); Image->m_Size = ca; Image->m_TextureSize = cb; Sprite->AddImage(Image); Sprites[SpriteName] = Sprite; } if (SpriteName.Find("color:") != -1) { CStrW value = wstring_from_utf8(SpriteName.AfterLast("color:").BeforeFirst(":")); CColor color; // Check color is valid if (!GUI<CColor>::ParseString(value, color)) { LOGERROR("GUI: Error parsing sprite 'color' (\"%s\")", utf8_from_wstring(value)); return; } SGUIImage* Image = new SGUIImage; // If we are using a mask, this is an effect. // Otherwise we can fallback to the "back color" attribute // TODO: we are assuming there is a filename here. if (SpriteName.Find("textureAsMask:") != -1) { Image->m_TextureName = TextureName; Image->m_Effects = new SGUIImageEffects; Image->m_Effects->m_SolidColor = color; } else Image->m_BackColor = color; CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); Image->m_Size = ca; Image->m_TextureSize = ca; Sprite->AddImage(Image); Sprites[SpriteName] = Sprite; } it = Sprites.find(SpriteName); // Otherwise, just complain and give up: if (it == Sprites.end()) { SAFE_DELETE(Sprite); LOGERROR("Trying to use a sprite that doesn't exist (\"%s\").", SpriteName.c_str()); return; } } Calls.reserve(it->second->m_Images.size()); // Iterate through all the sprite's images, loading the texture and // calculating the texture coordinates std::vector<SGUIImage*>::const_iterator cit; for (cit = it->second->m_Images.begin(); cit != it->second->m_Images.end(); ++cit) { SDrawCall Call(*cit); // pointers are safe since we never modify sprites/images after startup CRect ObjectSize = (*cit)->m_Size.GetClientArea(Size); if (ObjectSize.GetWidth() == 0.0 || ObjectSize.GetHeight() == 0.0) { // Zero sized object. Don't report as an error, since it's common for e.g. hitpoint bars. continue; // i.e. don't continue with this image } Call.m_Vertices = ObjectSize; if ((*cit)->m_RoundCoordinates) { // Round the vertex coordinates to integers, to avoid ugly filtering artifacts Call.m_Vertices.left = (int)(Call.m_Vertices.left + 0.5f); Call.m_Vertices.right = (int)(Call.m_Vertices.right + 0.5f); Call.m_Vertices.top = (int)(Call.m_Vertices.top + 0.5f); Call.m_Vertices.bottom = (int)(Call.m_Vertices.bottom + 0.5f); } if (!(*cit)->m_TextureName.empty()) { CTextureProperties textureProps(g_L10n.LocalizePath((*cit)->m_TextureName)); textureProps.SetWrap((*cit)->m_WrapMode); CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps); texture->Prefetch(); Call.m_HasTexture = true; Call.m_Texture = texture; Call.m_EnableBlending = false; // will be overridden if the texture has an alpha channel Call.m_ObjectSize = ObjectSize; Call.m_CellID = CellID; } else { Call.m_HasTexture = false; // Enable blending if it's transparent (allowing a little error in the calculations) Call.m_EnableBlending = !(fabs((*cit)->m_BackColor.a - 1.0f) < 0.0000001f); } Call.m_BackColor = (*cit)->m_BackColor; Call.m_BorderColor = (*cit)->m_Border ? (*cit)->m_BorderColor : CColor(); Call.m_DeltaZ = (*cit)->m_DeltaZ; if (!Call.m_HasTexture) { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid); } else if ((*cit)->m_Effects) { if ((*cit)->m_Effects->m_AddColor != CColor()) { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_add); Call.m_ShaderColorParameter = (*cit)->m_Effects->m_AddColor; // Always enable blending if something's being subtracted from // the alpha channel if ((*cit)->m_Effects->m_AddColor.a < 0.f) Call.m_EnableBlending = true; } else if ((*cit)->m_Effects->m_Greyscale) { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_grayscale); } else if ((*cit)->m_Effects->m_SolidColor != CColor()) { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid_mask); Call.m_ShaderColorParameter = (*cit)->m_Effects->m_SolidColor; Call.m_EnableBlending = !(fabs((*cit)->m_Effects->m_SolidColor.a - 1.0f) < 0.0000001f); } else /* Slight confusion - why no effects? */ { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_basic); } } else { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_basic); } Calls.push_back(Call); } }
CRect SDrawCall::ComputeTexCoords() const { float TexWidth = m_Texture->GetWidth(); float TexHeight = m_Texture->GetHeight(); if (!TexWidth || !TexHeight) return CRect(0, 0, 1, 1); // Textures are positioned by defining a rectangular block of the // texture (usually the whole texture), and a rectangular block on // the screen. The texture is positioned to make those blocks line up. // Get the screen's position/size for the block CRect BlockScreen = m_Image->m_TextureSize.GetClientArea(m_ObjectSize); if (m_Image->m_FixedHAspectRatio) BlockScreen.right = BlockScreen.left + BlockScreen.GetHeight() * m_Image->m_FixedHAspectRatio; // Get the texture's position/size for the block: CRect BlockTex; // "real_texture_placement" overrides everything if (m_Image->m_TexturePlacementInFile != CRect()) { BlockTex = m_Image->m_TexturePlacementInFile; } // Check whether this sprite has "cell_size" set (and non-zero) else if ((int)m_Image->m_CellSize.cx) { int cols = (int)TexWidth / (int)m_Image->m_CellSize.cx; if (cols == 0) cols = 1; // avoid divide-by-zero int col = m_CellID % cols; int row = m_CellID / cols; BlockTex = CRect(m_Image->m_CellSize.cx*col, m_Image->m_CellSize.cy*row, m_Image->m_CellSize.cx*(col+1), m_Image->m_CellSize.cy*(row+1)); } // Use the whole texture else BlockTex = CRect(0, 0, TexWidth, TexHeight); // When rendering, BlockTex will be transformed onto BlockScreen. // Also, TexCoords will be transformed onto ObjectSize (giving the // UV coords at each vertex of the object). We know everything // except for TexCoords, so calculate it: CPos translation (BlockTex.TopLeft()-BlockScreen.TopLeft()); float ScaleW = BlockTex.GetWidth()/BlockScreen.GetWidth(); float ScaleH = BlockTex.GetHeight()/BlockScreen.GetHeight(); CRect TexCoords ( // Resize (translating to/from the origin, so the // topleft corner stays in the same place) (m_ObjectSize-m_ObjectSize.TopLeft()) .Scale(ScaleW, ScaleH) + m_ObjectSize.TopLeft() // Translate from BlockTex to BlockScreen + translation ); // The tex coords need to be scaled so that (texwidth,texheight) is // mapped onto (1,1) TexCoords.left /= TexWidth; TexCoords.right /= TexWidth; TexCoords.top /= TexHeight; TexCoords.bottom /= TexHeight; return TexCoords; }
void CChart::Draw() { PROFILE3("render chart"); if (!GetGUI()) return; if (m_Series.empty()) return; const float bz = GetBufferedZ(); CRect rect = GetChartRect(); const float width = rect.GetWidth(); const float height = rect.GetHeight(); // Disable depth updates to prevent apparent z-fighting-related issues // with some drivers causing units to get drawn behind the texture. glDepthMask(0); // Setup the render state CMatrix3D transform = GetDefaultGuiMatrix(); CShaderDefines lineDefines; CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid, g_Renderer.GetSystemShaderDefines(), lineDefines); tech->BeginPass(); CShaderProgramPtr shader = tech->GetShader(); shader->Uniform(str_transform, transform); CVector2D leftBottom, rightTop; leftBottom = rightTop = m_Series[0].m_Points[0]; for (const CChartData& data : m_Series) for (const CVector2D& point : data.m_Points) { if (point.X < leftBottom.X) leftBottom.X = point.X; if (point.Y < leftBottom.Y) leftBottom.Y = point.Y; if (point.X > rightTop.X) rightTop.X = point.X; if (point.Y > rightTop.Y) rightTop.Y = point.Y; } CVector2D scale(width / (rightTop.X - leftBottom.X), height / (rightTop.Y - leftBottom.Y)); for (const CChartData& data : m_Series) { if (data.m_Points.empty()) continue; std::vector<float> vertices; vertices.reserve(data.m_Points.size() * 3); for (const CVector2D& point : data.m_Points) { vertices.push_back(rect.left + (point.X - leftBottom.X) * scale.X); vertices.push_back(rect.bottom - (point.Y - leftBottom.Y) * scale.Y); vertices.push_back(bz + 0.5f); } shader->Uniform(str_color, data.m_Color); shader->VertexPointer(3, GL_FLOAT, 0, &vertices[0]); shader->AssertPointersBound(); glEnable(GL_LINE_SMOOTH); glLineWidth(1.1f); if (!g_Renderer.m_SkipSubmit) glDrawArrays(GL_LINE_STRIP, 0, vertices.size() / 3); glLineWidth(1.0f); glDisable(GL_LINE_SMOOTH); } tech->EndPass(); // Reset depth mask glDepthMask(1); }
CSize::CSize(const CRect &rect) : cx(rect.GetWidth()), cy(rect.GetHeight()) { }
void CBalloonTip::InitControls() { CLabelUI * pLab = NULL; CButtonUI* pBtn = NULL; CTextUI * pText= NULL; SIZE sz;GetDrawTextSize(m_strInfo,sz); if (sz.cx<9999&&sz.cy<300) { SetWindowPos(GetHWND(),HWND_TOPMOST,0,0,MAX(sz.cx+60,260),sz.cy+((m_dwMsgStyle!=0)?90:50),SWP_NOMOVE); } CRect rc; GetClientRect(GetHWND(),&rc); int nWidth = rc.GetWidth(); int nHeight = rc.GetHeight(); m_pPM->AddFont(MSYH,16,FALSE,FALSE,FALSE); int s = m_pPM->GetFontIndex(MSYH,16,FALSE,FALSE,FALSE); pLab = RegiserLabel(ID_LAB_TITLE,CRect(15,8,200,25),m_strTitle); if (pLab) { pLab->SetTextColor(RGB(73,73,73)); pLab->SetText(m_strTitle); pLab->SetShowHtml(TRUE); } int nInfoStart = (nWidth - sz.cx)/2; pText = (CTextUI*)RegiserControl(CONTROL(CTextUI),ID_LAB_INFO,CRect(nInfoStart ,35,nWidth,40 + sz.cy)); if (pText) { pText->SetShowHtml(TRUE); pText->SetText(m_strInfo); pText->SetTextColor(RGB(73,73,73)); pText->SetTextStyle(DT_VCENTER|DT_LEFT); } pBtn = RegiserButton(ID_BTN_COSE,CRect(nWidth-31,2,nWidth-2,27)); if (pBtn) { pBtn->SetImage(m_nClose); } if (m_dwMsgStyle != 0) { if ((m_dwMsgStyle & 0X0000000F) == MB_YESNO) { CButtonUI* pBtn = RegiserButton(ID_BTN_YES, CRect(30,sz.cy+50,120,sz.cy+80), _T("yes")); if (pBtn) { pBtn->SetImage( CUIMessageBox::m_nLeftBtnImage); pBtn->SetCorner(CRect(5,5,5,5)); } pBtn = RegiserButton(ID_BTN_NO, CRect(nWidth - 120,sz.cy+50,nWidth - 30,sz.cy+80), _T("no")); if (pBtn) { pBtn->SetImage( CUIMessageBox::m_nLeftBtnImage); pBtn->SetCorner(CRect(5,5,5,5)); } } } }