void CEx_DrawView::OnDraw(CDC* pDC) { // TODO: add draw code for native data here CEx_DrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); m_bufferDC.BitBlt(0, 0, m_size.cx, m_size.cy, pDC, 0, 0, WHITENESS); DrawGraphic(&m_bufferDC); if (pDoc->m_sel != -1) { ASSERT(pDoc->m_sel >= 0 && pDoc->m_sel < pDoc->m_obArray.GetSize()); CGraphic* P = Convert_To_Graphic(pDoc->m_obArray[pDoc->m_sel]); ASSERT_VALID(P); P->Draw(&m_bufferDC); m_bufferDC.SelectObject(GetStockObject(WHITE_BRUSH)); P->DrawSelectedEdge(&m_bufferDC); if (pDoc->m_bShowTab) { CString str; int bkMode = m_bufferDC.SetBkMode(TRANSPARENT); str.Format(_T("%d"), pDoc->m_sel); m_bufferDC.SelectObject(&m_tabFont); m_bufferDC.TextOut(P->m_pt1.x, P->m_pt1.y, str); } } pDC->BitBlt(0, 0, m_size.cx, m_size.cy, &m_bufferDC, 0, 0, SRCCOPY); }
////////////////////////////////////////////////////////////////////////// //From CControl ////////////////////////////////////////////////////////////////////////// void CGradeDialog::Draw(CGraphic& gc)const { gc.SetPenColor(TRgb(0,0,0)); gc.SetPenStyle(CBitmapContext::ESolidPen); gc.SetBrushStyle(CBitmapContext::ENullBrush); gc.BitBlt(iStartPoint,iDialogBmp); gc.DrawText(iStartPoint+TPoint(iIconPoint.iX,iScreenLayout.FontHeight()/3),iTitle); for(TInt i=0;i<5;i++) { if(i<iGradeNum/2) { iBitmapFactory.DrawGradeBmpByID(gc,iStartPoint+iIconPoint+TPoint((iIconSize.iWidth+iIconPoint.iX)*i,0),0); } else { if((iGradeNum-i*2)==1) { iBitmapFactory.DrawGradeBmpByID(gc,iStartPoint+iIconPoint+TPoint((iIconSize.iWidth+iIconPoint.iX)*i,0),1); } else { iBitmapFactory.DrawGradeBmpByID(gc,iStartPoint+iIconPoint+TPoint((iIconSize.iWidth+iIconPoint.iX)*i,0),2); } } } }
/** ** Draw a sprite with is like a bar (several stages) ** ** @param x X screen pixel position ** @param y Y screen pixel position ** @param unit Unit pointer ** @todo fix sprite configuration. */ void CDecoVarSpriteBar::Draw(int x, int y, const CUnitType *, const CVariable &Variable) const { int n; // frame of the sprite to show. CGraphic *sprite; // the sprite to show. Decoration *decosprite; // Info on the sprite. Assert(Variable.Max); Assert(this->NSprite != -1); decosprite = &DecoSprite.SpriteArray[(int)this->NSprite]; sprite = decosprite->Sprite; x += decosprite->HotX; // in addition of OffsetX... Usefull ? y += decosprite->HotY; // in addition of OffsetY... Usefull ? n = sprite->NumFrames - 1; n -= (n * Variable.Value) / Variable.Max; if (this->IsCenteredInX) { x -= sprite->Width / 2; } if (this->IsCenteredInY) { y -= sprite->Height / 2; } sprite->DrawFrameClip(n, x, y); }
bool sqr_tools::CEditModel::AddPieceGroup( const char* szFileName ) { CPieceGroup* pPieceGroup = NULL; CGraphic* pGraphic = CGraphic::GetInst(); if ( pGraphic->CreatePieceGroup(szFileName, &pPieceGroup) == -1 ) { string log = szFileName; log = log + "模型没有找到,可能该文件不存在"; MessageBox(NULL, log.c_str(), "错误", MB_OK); return false; } size_t nPieceClassNum = pPieceGroup->GetPieceClassNum(); for ( size_t i = 0; i < nPieceClassNum; i++) { this->AddMeshPiece(pPieceGroup, pPieceGroup->GetPieceClassName(i), 0); } pPieceGroup->Release(); m_strModelName = szFileName; return true; }
void CWndAreaRendere::RenderSelWndList() { if( !m_renderWndList || m_renderWndList->size() <= 1 ) return; CGraphic* pGraphic = CGraphic::GetInst(); vector<SQRWnd*>::iterator it = m_renderWndList->begin(); vector<SQRWnd*>::iterator eit = m_renderWndList->end(); while(it != eit) { SQRWnd* pwnd = *it; if (pwnd) { CFRect rt; pwnd->GetWndRect(rt); VerColor2D v[5]= { VerColor2D( (float)rt.left, (float)rt.top, 0, 0xffff00ff ), VerColor2D( (float)rt.right, (float)rt.top, 0, 0xffff00ff ), VerColor2D( (float)rt.right, (float)rt.bottom, 0, 0xffff00ff ), VerColor2D( (float)rt.left, (float)rt.bottom, 0, 0xffff00ff ), VerColor2D( (float)rt.left, (float)rt.top, 0, 0xffff00ff ), }; VerColor2D* pVB; RenderState * pRS; pGraphic->GetRenderStack( RS_FONT, NULL, NULL, PT_LINESTRIP, 5, 4, VerColor2D::Format, sizeof(VerColor2D), (void**)&pVB, NULL, (void**)&pRS ); pRS->m_ZTestEnable = false; pRS->m_ZTestFun = CMP_ALWAYS; memcpy( pVB, v, sizeof( VerColor2D )*5 ); } ++it; } }
void CEx_Ctrl::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { // TODO: Add your specialized code here and/or call the base class if (lHint == 0x2000) { m_sel_graph.SetCurSel(GetDocument()->m_GM.m_DrawType); OnSelGraph(); } else if (lHint == 0x4000) { CObArray& arr = GetDocument()->m_obArray; CString str; CGraphic* P = NULL; m_lists.ResetContent(); for (int i = 0; i < arr.GetSize(); i++) { P = Convert_To_Graphic(arr[i]); str.Format(_T("%d - %s - %s"), i, P->GetName(), P->m_lpszName); m_lists.InsertString(0, str); } } else if (lHint == 0x4001) { int sel = GetDocument()->m_sel; if (sel != -1) { m_lists.SetCurSel(m_lists.GetCount() - sel - 1); } } }
void CFlashRender::Render() { CGraphic* pGraphic = CGraphic::GetInst(); pGraphic->ClearStack(); CMainWindowTarget::GetInst()->Clear(); if(m_pText) { VerText2D* pVB; RenderState* pRS; CMatrix* Matrix = pGraphic->GetRenderStack( RS_GUI, m_pText, NULL, PT_TRIANGLESTRIP, 4, 2, VerText2D::Format, sizeof(VerText2D), (void**)&pVB, NULL, (void**)&pRS ); pRS->m_Cull = 1; pRS->m_AlphaBlendEnable = m_bAlphaBlend; pRS->m_AlphaTestEnable = m_bAlphaTest; pRS->m_ZTestEnable = FALSE; Matrix->Identity(); pVB[0].x = m_fOffX; pVB[0].y = m_fOffY; pVB[0].z = 1.0f; pVB[1].x = float(m_Width)+ m_fOffX; pVB[1].y = m_fOffY; pVB[1].z = 1.0f; pVB[2].x = m_fOffX; pVB[2].y = float(m_Height) + m_fOffY; pVB[2].z = 1.0f; pVB[3].x = float(m_Width)+ m_fOffX; pVB[3].y = float(m_Height) + m_fOffY; pVB[3].z = 1.0f; pVB[0].w = 1.0; pVB[0].tu = 0.0; pVB[0].tv = 0.0; pVB[1].w = 1.0; pVB[1].tu = 1.0; pVB[1].tv = 0.0; pVB[2].w = 1.0; pVB[2].tu = 0.0; pVB[2].tv = 1.0; pVB[3].w = 1.0; pVB[3].tu = 1.0; pVB[3].tv = 1.0; if(m_bShowRect) { VerColor2D* pVBRenct; RenderState* pLRS; Matrix = pGraphic->GetRenderStack( RS_GUI, NULL, NULL, PT_TRIANGLESTRIP, 4, 2, VerColor2D::Format, sizeof(VerColor2D), (void**)&pVBRenct, NULL, (void**)&pLRS ); Matrix->Identity(); pLRS->m_Cull = 1; pLRS->m_AlpOP_S1 = TOP_SELECTARG1; pLRS->m_AlpArg1_S1 = TA_DIFFUSE; pLRS->m_TexOP_S1 = TOP_BLENDDIFFUSEALPHA; pLRS->m_TexArg1_S1 = TA_CURRENT; pLRS->m_TexArg2_S1 = TA_DIFFUSE; pLRS->m_AlphaBlendEnable = TRUE; pLRS->m_AlphaTestEnable = FALSE; pLRS->m_ZTestEnable = FALSE; pVBRenct[0].x = m_fOffX + m_fRect.left; pVBRenct[0].y = m_fOffY + m_fRect.top; pVBRenct[0].z = 1.0f; pVBRenct[1].x = m_fOffX + m_fRect.right; pVBRenct[1].y = m_fOffY + m_fRect.top; pVBRenct[1].z = 1.0f; pVBRenct[2].x = m_fOffX + m_fRect.left; pVBRenct[2].y = m_fOffY + m_fRect.bottom; pVBRenct[2].z = 1.0f; pVBRenct[3].x = m_fOffX + m_fRect.right; pVBRenct[3].y = m_fOffY + m_fRect.bottom; pVBRenct[3].z = 1.0f; pVBRenct[0].w = 1.0f; pVBRenct[1].w = 1.0f; pVBRenct[2].w = 1.0f; pVBRenct[3].w = 1.0f; pVBRenct[0].diffuse = pVBRenct[1].diffuse = pVBRenct[2].diffuse = pVBRenct[3].diffuse = 0x800000FF; } } }
void CWndAreaRendere::Render() { // first render the root rect RenderRootRect(); // then render the wnd rect selected if( !m_bRender ) return; CGraphic* pGraphic = CGraphic::GetInst(); VerColor2D v[5]= { VerColor2D( (float)m_curRect.left, (float)m_curRect.top, 0, 0xff0000ff ), VerColor2D( (float)m_curRect.right, (float)m_curRect.top, 0, 0xff0000ff ), VerColor2D( (float)m_curRect.right, (float)m_curRect.bottom, 0, 0xff0000ff ), VerColor2D( (float)m_curRect.left, (float)m_curRect.bottom, 0, 0xff0000ff ), VerColor2D( (float)m_curRect.left, (float)m_curRect.top, 0, 0xff0000ff ), }; VerColor2D* pVB; RenderState * pRS; pGraphic->GetRenderStack( RS_FONT, NULL, NULL, PT_LINESTRIP, 5, 4, VerColor2D::Format, sizeof(VerColor2D), (void**)&pVB, NULL, (void**)&pRS ); pRS->m_ZTestEnable = false; pRS->m_ZTestFun = CMP_ALWAYS; memcpy( pVB, v, sizeof( VerColor2D )*5 ); // render wnd list RenderSelWndList(); }
void CCurThreeListBoxItem::Draw(CGraphic& aGraphic,TPoint& aPoint) const { TPoint point = aPoint; ASSERT(iSlideText); TRect rect; if(iActive) { TSize size = iItemSize; size.iHeight *= 3; rect = size; rect.Move(point); aGraphic.SetPenColor(KTextColor); aGraphic.SetPenStyle(CGraphicsContext::ESolidPen); aGraphic.SetBrushColor(KListSelectedColor); aGraphic.SetBrushStyle(CGraphicsContext::ESolidBrush); aGraphic.DrawRect(rect); aGraphic.SetBrushStyle(CGraphicsContext::ENullBrush); } if(iIcon) { ASSERT(iIconMask); aGraphic.BitBltMasked(point,iIcon,iIconMask); } rect = iItemSize; if(iIcon) { rect.iTl.iX += iIcon->SizeInPixels().iWidth; } rect.Move(point); iSlideText->SetClientRect(rect); iSlideText->Draw(aGraphic); if(iActive) { aGraphic.SetPenColor(iTextColor); rect.Move(0,iItemSize.iHeight); if(iSecondText) { aGraphic.DrawText(*iSecondText,rect); } rect.Move(0,iItemSize.iHeight); if(iThirdText) { aGraphic.DrawText(*iThirdText,rect); } aPoint.iY += iItemSize.iHeight*3; } else { aPoint.iY += iItemSize.iHeight; } }
void CEx_DrawView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CEx_DrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); UINT type = pDoc->m_GM.m_DrawType; if (nChar == VK_SHIFT && type != SELECT) { m_bShiftDown = TRUE; CPoint pt; GetCursorPos(&pt); ScreenToClient(&pt); OnMouseMove(0, pt); } else if (nChar == VK_CONTROL && type == SELECT) { m_bCtrlDown = TRUE; } else if (nChar == VK_DELETE && type == SELECT) { int sel = pDoc->m_sel; if (sel != -1) { GraphicDeleteById(sel); pDoc->m_sel = -1; } } else if (nChar >= VK_LEFT && nChar <= VK_DOWN) { int sel = pDoc->m_sel; if (sel != -1) { CGraphic* P = Convert_To_Graphic(pDoc->m_obArray[pDoc->m_sel]); switch (nChar) { case VK_LEFT: P->m_pt1.x--; P->m_pt2.x--; break; case VK_RIGHT: P->m_pt1.x++; P->m_pt2.x++; break; case VK_DOWN: P->m_pt1.y++; P->m_pt2.y++; break; case VK_UP: P->m_pt1.y--; P->m_pt2.y--; break; } CRect rt; P->GetRect(rt); P->m_modifiedTime = CTime::GetCurrentTime(); rt.OffsetRect(-GetScrollPosition()); InvalidateRect(&rt, FALSE); } } CScrollView::OnKeyDown(nChar, nRepCnt, nFlags); }
BOOL CEx_DrawView::OnCommand(WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class CEx_DrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (wParam == 0x200) { GraphicDeleteById(pDoc->m_sel); pDoc->m_sel = -1; return TRUE; } if (wParam == 0x201) { ASSERT(pDoc->m_sel >= 0); ConfigDlg dlg; CGraphic* P = Convert_To_Graphic(pDoc->m_obArray[pDoc->m_sel]); ASSERT_VALID(P); CRect rt; P->GetRect(rt); P->UpdateData(&dlg.m_GM, FALSE); CGraphic* pSave = CGraphic::CreateGraphic(&dlg.m_GM); pSave->m_modifiedTime = dlg.m_GM.m_modifiedTime; dlg.m_typeName = P->GetName(); if (dlg.DoModal() == IDOK) { if (dlg.m_GM.m_bHidden) pDoc->m_sel = -1; P->UpdateData(&dlg.m_GM); pDoc->WriteLog(CGraphicLog::GOS_UPDATE, pSave, pDoc->m_sel); pDoc->UpdateAllViews(NULL, 0x4000); pDoc->UpdateAllViews(NULL, 0x4001); Invalidate(); } else { delete pSave; } return TRUE; } if (wParam == 0x202) { GraphicDeleteById(pDoc->m_sel); pDoc->m_sel = -1; return TRUE; } return CScrollView::OnCommand(wParam, lParam); }
////////////////////////////////////////////////////////////////////////// //From CControl ////////////////////////////////////////////////////////////////////////// void CContentInfoDialog::Draw(CGraphic& gc)const { gc.SetPenColor(TRgb(255,255,255)); gc.SetBrushColor(TRgb(64,61,90)); gc.SetPenStyle(CBitmapContext::ESolidPen); gc.SetBrushStyle(CBitmapContext::ESolidBrush); gc.DrawRoundRect(iBackRect); TPoint point=iStartPoint; if(iBool&&iShowBmp==NULL) { gc.DrawRoundRect(TRect(iStartPoint-TPoint(2,2),TSize(iIconSize.iWidth+4,iIconSize.iHeight+4))); gc.DrawText(iMainEngine.GetDesById(ECoCoTextRes_GetImage),TRect(point,iIconSize),CGraphicsContext::ELeft); point.iY=point.iY+iIconSize.iHeight; } if(iShowBmp) { /*TPoint iconPoint(0,0); TSize iconSize=iIconSize; if(iSelectIndex<iAllLine) { iconPoint.iY=iconPoint.iY+iTextSize.iHeight*iSelectIndex; iconSize.iHeight=iIconSize.iHeight-iTextSize.iHeight*iSelectIndex; if(iconPoint.iY>=0&&iconSize.iHeight>0) gc.BitBlt(point,iShowBmp,TRect(iconPoint,iconSize)); }*/ gc.BitBlt(point,iShowBmp); point.iY=point.iY+iIconSize.iHeight; } TInt index=0; for(TInt i=0;i<iMaxLine;i++) { index=i+iFirstIndex; if(index>=iDesArray->Count()) break; gc.DrawText((*iDesArray)[index],TRect(point+TPoint(0,i*iTextSize.iHeight),iTextSize),CGraphicsContext::ELeft); } gc.SetBrushStyle(CGraphicsContext::ENullBrush); if(iScrollbar) iScrollbar->Draw(gc); }
void CEx_DrawView::GraphicDeleteById( int id ) { CEx_DrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); int size = pDoc->m_obArray.GetSize(); ASSERT(id >= 0 && id < size); CRect rt; CGraphic* pDelete = Convert_To_Graphic(pDoc->m_obArray[id]); pDelete->GetRect(rt); pDoc->WriteLog(CGraphicLog::GOS_DELETE, pDelete, id); pDelete = NULL; pDoc->UpdateAllViews(NULL, 0x4000); rt.OffsetRect(-GetScrollPosition()); InvalidateRect(&rt, TRUE); }
/** ** Draw a static sprite. ** ** @param x X screen pixel position ** @param y Y screen pixel position ** @param unit Unit pointer ** ** @todo fix sprite configuration configuration. */ void CDecoVarStaticSprite::Draw(int x, int y, const CUnit *unit) const { CGraphic *sprite; // the sprite to show. Decoration *decosprite; // Info on the sprite. decosprite = &DecoSprite.SpriteArray[(int)this->NSprite]; sprite = decosprite->Sprite; x += decosprite->HotX; // in addition of OffsetX... Usefull ? y += decosprite->HotY; // in addition of OffsetY... Usefull ? if (this->IsCenteredInX) { x -= sprite->Width / 2; } if (this->IsCenteredInY) { y -= sprite->Height / 2; } sprite->DrawFrameClip(this->n, x, y); }
void CToolMainPlayer::SetMainPlayerModel(string & str) { if ( str == "" || m_pMainPlayer == NULL ) return; if( m_strMainPlayerModel != str ) m_pMainPlayer->DelFramework(); m_strMainPlayerModel = str; m_pMainPlayer->ClearMeshPiece(); CPieceGroup *pPieceGroup = NULL; CGraphic * pCoreGraphic = CGraphic::GetInst(); SQR_TRY { if ( pCoreGraphic->CreatePieceGroup(str.c_str(), &pPieceGroup) == INVALID ) { string log = str; log = log + "主角模型文件没有找到"; MessageBox(NULL, log.c_str(), "错误", MB_OK); return; } } SQR_CATCH(exp) { MessageBox(NULL, exp.ErrorMsg(), "错误", MB_OK); return; } SQR_TRY_END; for ( size_t i = 0; i < pPieceGroup->GetPieceClassNum(); i++) { m_pMainPlayer->AddMeshPiece(pPieceGroup,pPieceGroup->GetPieceClassName(i),0); } m_bLoadMainPlayer = true; pPieceGroup->Release(); }
////////////////////////////////////////////////////////////////////////// //From CControl ////////////////////////////////////////////////////////////////////////// void CSelectGroup::Draw(CGraphic& gc)const { TInt index=0; for(TInt i=0; i<iMaxLinePerPage; i++) { index=i+iFirstIndex; if(index>=iSelectArray.Count()) break; if(index==iSelectedIndex) { TRect rect(iStartPoint+TPoint(0,i*iLineHeight),iItemSize); gc.SetPenColor(KPopMenuRectColor); gc.SetPenStyle(CGraphicsContext::ESolidPen); gc.SetBrushColor(KNaviPaneSelectedItemColor); gc.SetBrushStyle(CGraphicsContext::ESolidBrush); gc.DrawRect(rect); gc.SetBrushStyle(CGraphicsContext::ENullBrush); gc.SetPenColor(KRgbWhite); } iSelectArray[index]->DrawItem(gc,TRect(iStartPoint+TPoint(0,i*iLineHeight),iItemSize)); } if(iScrollbar) iScrollbar->Draw(gc); }
void CNormalListBoxItem::Draw(CGraphic& aGraphic,TPoint& aPoint) const { UtilityTools::WriteLogsL(_L("CNormalListBoxItem::Draw")); ASSERT(iSlideText); TRect rect(iItemSize); rect.Move(aPoint); if(iActive) { aGraphic.SetPenColor(KTextColor); aGraphic.SetPenStyle(CGraphicsContext::ESolidPen); aGraphic.SetBrushColor(KListSelectedColor); aGraphic.SetBrushStyle(CGraphicsContext::ESolidBrush); aGraphic.DrawRect(rect); aGraphic.SetBrushStyle(CGraphicsContext::ENullBrush); } if(iIcon) { rect.iTl.iX += iIcon->SizeInPixels().iWidth; } if(iIcon) { ASSERT(iIconMask); aGraphic.BitBltMasked(aPoint,iIcon,iIconMask); } iSlideText->SetClientRect(rect); iSlideText->Draw(aGraphic); aPoint.iY += iItemSize.iHeight; UtilityTools::WriteLogsL(_L("CNormalListBoxItem::Draw End")); }
void CEx_DrawView::DrawGraphic( CDC* pDC, int skip /*= -1*/ ) { CEx_DrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CString str; BOOL bShowHidden = pDoc->m_bShowHidden; for (int i = 0; i < pDoc->m_obArray.GetSize(); i++) { CGraphic* p = Convert_To_Graphic(pDoc->m_obArray[i]); if (i == skip || (!bShowHidden && p->m_bHidden)) { continue; } p->Draw(pDC); if (pDoc->m_bShowTab) GraphicDrawTab(pDC, p, i); } }
BOOL CEx_DrawView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default BOOL bResult = FALSE; GraphicHitTest(m_ptCursor, bResult, m_iTrackID); if ((bResult || (m_bLButtonDown && m_pMoveTarget != NULL)) && GetDocument()->m_GM.m_DrawType == SELECT && !m_bContextMenu) { BOOL bRet = FALSE; CGraphic* P = Convert_To_Graphic(GetDocument()->m_obArray[m_iTrackID]); ASSERT_VALID(P); LPCTSTR cursor = P->HitSizingTest(m_ptCursor, bRet); if (bRet) { SetCursor(AfxGetApp()->LoadStandardCursor(cursor)); return TRUE; } SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL)); return TRUE; } return CScrollView::OnSetCursor(pWnd, nHitTest, message); }
/** ** Load all fonts. */ void LoadFonts() { for (FontFamiliesType::iterator iter = FontFamilies.begin(); iter != FontFamilies.end(); ++iter) { CFontFamily *fontFamily = iter->second; CGraphic *g = fontFamily->G; if (g) { ShowLoadProgress("Fonts %s", g->File.c_str()); g->Load(); fontFamily->MeasureWidths(); if (UseOpenGL) { fontFamily->MakeFontColorGraphics(); } } } // TODO: remove this SmallFont = CFont::Get("small"); GameFont = CFont::Get("game"); LargeFont = CFont::Get("large"); }
void CEx_DrawView::GraphicHitTest( CPoint& pt, BOOL& bResult, int& sel ) { CEx_DrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); BOOL bShowHidden = pDoc->m_bShowHidden; if (pDoc->m_sel != -1) // 已选中者优先 { if (pDoc->m_sel == pDoc->m_obArray.GetSize()) pDoc->m_sel--; CGraphic* P = Convert_To_Graphic(pDoc->m_obArray[pDoc->m_sel]); P->HitTest(pt, bResult); if ( bResult && (bShowHidden || (!bShowHidden && !P->m_bHidden)) ) return; bResult = FALSE; } for (int i = pDoc->m_obArray.GetSize() - 1; i >= 0; i--) { CGraphic* P = Convert_To_Graphic(pDoc->m_obArray[i]); P->HitTest(pt, bResult); if ( bResult && (bShowHidden || (!bShowHidden && !P->m_bHidden)) ) { sel = i; return; } bResult = FALSE; } }
/** ** Draw character with current color. ** ** @param g Pointer to object ** @param gx X offset into object ** @param gy Y offset into object ** @param w width to display ** @param h height to display ** @param x X screen position ** @param y Y screen position */ static void VideoDrawChar(const CGraphic &g, int gx, int gy, int w, int h, int x, int y, const CFontColor &fc) { if (!UseOpenGL) { SDL_Rect srect = {gx, gy, w, h}; SDL_Rect drect = {x, y, 0, 0}; std::vector<SDL_Color> sdlColors(fc.Colors, fc.Colors + MaxFontColors); SDL_SetColors(g.Surface, &sdlColors[0], 0, MaxFontColors); SDL_BlitSurface(g.Surface, &srect, TheScreen, &drect); } else { g.DrawSub(gx, gy, w, h, x, y); } }
void CWndAreaRendere::RenderRootRect() { if( !m_bRootRender ) return; CGraphic* pGraphic = CGraphic::GetInst(); VerColor2D v[5]= { VerColor2D( (float)m_rootRect.left, (float)m_rootRect.top, 0, 0xffff0000 ), VerColor2D( (float)m_rootRect.right, (float)m_rootRect.top, 0, 0xffff0000 ), VerColor2D( (float)m_rootRect.right, (float)m_rootRect.bottom, 0, 0xffff0000 ), VerColor2D( (float)m_rootRect.left, (float)m_rootRect.bottom, 0, 0xffff0000 ), VerColor2D( (float)m_rootRect.left, (float)m_rootRect.top, 0, 0xffff0000 ), }; VerColor2D* pVB; RenderState * pRS; pGraphic->GetRenderStack( RS_FONT, NULL, NULL, PT_LINESTRIP, 5, 4, VerColor2D::Format, sizeof(VerColor2D), (void**)&pVB, NULL, (void**)&pRS ); pRS->m_ZTestEnable = false; pRS->m_ZTestFun = CMP_ALWAYS; memcpy( pVB, v, sizeof( VerColor2D )*5 ); }
/** ** Show a title image */ void TitleScreen::ShowTitleImage() { const EventCallback *old_callbacks = GetCallbacks(); EventCallback callbacks; WaitNoEvent = true; callbacks.ButtonPressed = WaitCallbackButtonPressed; callbacks.ButtonReleased = WaitCallbackButtonReleased; callbacks.MouseMoved = WaitCallbackMouse; callbacks.MouseExit = WaitCallbackExit; callbacks.KeyPressed = WaitCallbackKeyPressed; callbacks.KeyReleased = WaitCallbackKeyReleased; callbacks.KeyRepeated = WaitCallbackKeyRepeated; //callbacks.NetworkEvent = NetworkEvent; callbacks.NetworkEvent = nullptr; SetCallbacks(&callbacks); CGraphic *g = CGraphic::New(this->File); g->Load(); if (this->StretchImage) { g->Resize(Video.Width, Video.Height); } int timeout = this->Timeout ? this->Timeout * CYCLES_PER_SECOND : -1; while (timeout-- && WaitNoEvent) { g->DrawClip((Video.Width - g->Width) / 2, (Video.Height - g->Height) / 2); this->ShowLabels(); Invalidate(); RealizeVideoMemory(); WaitEventsOneFrame(); } SetCallbacks(old_callbacks); CGraphic::Free(g); }
void CMiniCADView::OnDraw(CDC* pDC) { CMiniCADDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here //v1.1 //char info[100] = "F1-Line F2-Rect F3-Circle F4-Ellipse F5-PencilPath"; //pDC->TextOut(0, 0, info); CBrush brsn; brsn.CreateStockObject(NULL_BRUSH); CBrush *oldBrsh = pDC->SelectObject(&brsn); for (int i = 0; i < m_Graphic.GetSize(); ++i) { CGraphic *aGraphic = (CGraphic *)m_Graphic[i]; aGraphic->drawGraphic(pDC); } brsn.DeleteObject(); pDC->SelectObject(oldBrsh); }
void CWindow::DrawButton(CGraphic& aGraphic)const { ASSERT(NULL != iControlPaneBmp); TSize screenSize = UtilityTools::ScreenSize(); //temp code TSize size = iControlPaneBmp->SizeInPixels(); TPoint point(0,0); point.iY += screenSize.iHeight; point.iY -= size.iHeight; aGraphic.BitBlt(point,iControlPaneBmp); aGraphic.SetPenColor(KTextColor); TRect controlPaneRect = iMainEngine.ScreenLayout().GetControlPaneRect(); TInt margin = iMainEngine.ScreenLayout().InnerMargin(); TPtrC leftButtonPtr; TPtrC rightButtonPtr; leftButtonPtr.Set(iLeftButtonText); rightButtonPtr.Set(iRightButtonText); if(iControlArray.Count() > 0) { for(TInt controlIndex = iControlArray.Count() - 1 ; controlIndex >= 0 ; controlIndex--) { CControl* lastControl = iControlArray[controlIndex]; if(lastControl->HasButton()) { leftButtonPtr.Set(lastControl->LeftButton()); rightButtonPtr.Set(lastControl->RightButton()); break; } } } aGraphic.DrawText(leftButtonPtr,controlPaneRect,CGraphicsContext::ELeft,margin); aGraphic.DrawText(rightButtonPtr,controlPaneRect,CGraphicsContext::ERight,margin); }
/** ** Draw character with current color. ** ** @param g Pointer to object ** @param gx X offset into object ** @param gy Y offset into object ** @param w width to display ** @param h height to display ** @param x X screen position ** @param y Y screen position */ static void VideoDrawChar(const CGraphic &g, int gx, int gy, int w, int h, int x, int y, const CFontColor &fc) { #if defined(USE_OPENGL) || defined(USE_GLES) if (UseOpenGL) { g.DrawSub(gx, gy, w, h, x, y); } else #endif { SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)}; SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0}; std::vector<SDL_Color> sdlColors(fc.Colors, fc.Colors + MaxFontColors); SDL_SetColors(g.Surface, &sdlColors[0], 0, MaxFontColors); SDL_BlitSurface(g.Surface, &srect, TheScreen, &drect); } }
////////////////////////////////////////////////////////////////////////// //From CControl ////////////////////////////////////////////////////////////////////////// void CInputDialog::Draw(CGraphic& gc)const { gc.SetPenColor(TRgb(0,0,0)); gc.SetPenStyle(CBitmapContext::ESolidPen); gc.SetBrushStyle(CBitmapContext::ENullBrush); gc.BitBlt(iStartPoint,iDialogBmp); //画标题 gc.DrawText(iStartPoint+TPoint(iMargin,iScreenLayout.FontHeight()/3),*iTitle); iBitmapFactory.DrawInputIconBmpByID(gc,iStartPoint+iIconPoint,iMainEngine.GetInputType()-1); //gc.BitBltMasked(iStartPoint+iIconPoint,iInputTypeIcon,iInputTypeIconMask); //画提示信息 gc.DrawTextWithBlueUnderline(iStartPoint+TPoint(iMargin,(iScreenLayout.FontHeight()+iScreenLayout.FontHeight()/2)*2+iScreenLayout.FontHeight()/3),*iInfo); }
/** ** Initialize the video part for SDL. */ void InitVideoSdl() { Uint32 flags = 0; if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { #ifndef USE_WIN32 // Fix tablet input in full-screen mode SDL_putenv(strdup("SDL_MOUSE_RELATIVE=0")); #endif int res = SDL_Init( #ifdef DEBUG SDL_INIT_NOPARACHUTE | #endif SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_TIMER); if (res < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } // Clean up on exit atexit(SDL_Quit); #ifdef USE_MAEMO maemo_init(); #endif // If debug is enabled, Stratagus disable SDL Parachute. // So we need gracefully handle segfaults and aborts. #if defined(DEBUG) && !defined(USE_WIN32) signal(SIGSEGV, CleanExit); signal(SIGABRT, CleanExit); #endif // Set WindowManager Title if (!FullGameName.empty()) { SDL_WM_SetCaption(FullGameName.c_str(), FullGameName.c_str()); } else if (!Parameters::Instance.applicationName.empty()) { SDL_WM_SetCaption(Parameters::Instance.applicationName.c_str(), Parameters::Instance.applicationName.c_str()); } else { SDL_WM_SetCaption("Stratagus", "Stratagus"); } #if ! defined(USE_WIN32) && ! defined(USE_MAEMO) #if defined(USE_OPENGL) || defined(USE_GLES) // Make sure, that we not create OpenGL textures (and do not call OpenGL functions), when creating icon surface bool UseOpenGL_orig = UseOpenGL; UseOpenGL = false; #endif SDL_Surface *icon = NULL; CGraphic *g = NULL; struct stat st; std::string FullGameNameL = FullGameName; for (size_t i = 0; i < FullGameNameL.size(); ++i) { FullGameNameL[i] = tolower(FullGameNameL[i]); } std::string ApplicationName = Parameters::Instance.applicationName; std::string ApplicationNameL = ApplicationName; for (size_t i = 0; i < ApplicationNameL.size(); ++i) { ApplicationNameL[i] = tolower(ApplicationNameL[i]); } std::vector <std::string> pixmaps; pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameName + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameNameL + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameName + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameNameL + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationName + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationNameL + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationName + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationNameL + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + "Stratagus" + ".png"); pixmaps.push_back(std::string() + PIXMAPS + "/" + "stratagus" + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "Stratagus" + ".png"); pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "stratagus" + ".png"); for (size_t i = 0; i < pixmaps.size(); ++i) { if (stat(pixmaps[i].c_str(), &st) == 0) { if (g) { CGraphic::Free(g); } g = CGraphic::New(pixmaps[i].c_str()); g->Load(); icon = g->Surface; if (icon) { break; } } } if (icon) { SDL_WM_SetIcon(icon, 0); } if (g) { CGraphic::Free(g); } #if defined(USE_OPENGL) || defined(USE_GLES) UseOpenGL = UseOpenGL_orig; #endif #endif #ifdef USE_WIN32 HWND hwnd = NULL; HICON hicon = NULL; SDL_SysWMinfo info; SDL_VERSION(&info.version); if (SDL_GetWMInfo(&info)) { hwnd = info.window; } if (hwnd) { hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0); } if (hicon) { SendMessage(hwnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hicon); SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon); } #endif } // Initialize the display #ifdef USE_MAEMO // TODO: Support window mode and portrait mode resolution on Maemo - Nokia N900 Video.FullScreen = 1; Video.Width = 800; Video.Height = 480; #endif #if !defined(USE_OPENGL) && !defined(USE_GLES) flags = SDL_HWSURFACE | SDL_HWPALETTE; #endif // Sam said: better for windows. /* SDL_HWSURFACE|SDL_HWPALETTE | */ if (Video.FullScreen) { flags |= SDL_FULLSCREEN; } #if defined(USE_OPENGL) || defined(USE_GLES) if (UseOpenGL) { #ifdef USE_GLES_NATIVE flags |= SDL_OPENGLES; #endif #ifdef USE_GLES_MAEMO if (SDL_GLES_Init(SDL_GLES_VERSION_1_1) < 0) { fprintf(stderr, "Couldn't initialize SDL_GLES: %s\n", SDL_GetError()); exit(1); } // Clean up GLES on exit atexit(SDL_GLES_Quit); flags |= SDL_SWSURFACE; #endif #ifdef USE_OPENGL flags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER; #endif } #endif if (!Video.Width || !Video.Height) { Video.Width = 640; Video.Height = 480; } if (!Video.Depth) { Video.Depth = 32; } #if defined(USE_OPENGL) || defined(USE_GLES) if (!Video.ViewportWidth || !Video.ViewportHeight) { Video.ViewportWidth = Video.Width; Video.ViewportHeight = Video.Height; } TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, flags); #else TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, Video.Depth, flags); #endif if (TheScreen && (TheScreen->format->BitsPerPixel != 16 && TheScreen->format->BitsPerPixel != 32)) { // Only support 16 and 32 bpp, default to 16 #if defined(USE_OPENGL) || defined(USE_GLES) TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, 16, flags); #else TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, 16, flags); #endif } if (TheScreen == NULL) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", Video.Width, Video.Height, Video.Depth, SDL_GetError()); exit(1); } Video.FullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0; Video.Depth = TheScreen->format->BitsPerPixel; #if defined(USE_TOUCHSCREEN) && defined(USE_WIN32) // Must not allow SDL to switch to relative mouse coordinates // with touchscreen when going fullscreen. So we don't hide the // cursor, but instead set a transparent 1px cursor Uint8 emptyCursor[] = {'\0'}; Video.blankCursor = SDL_CreateCursor(emptyCursor, emptyCursor, 1, 1, 0, 0); SDL_SetCursor(Video.blankCursor); #else // Turn cursor off, we use our own. SDL_ShowCursor(SDL_DISABLE); #endif // Make default character translation easier SDL_EnableUNICODE(1); #if defined(USE_OPENGL) || defined(USE_GLES) if (UseOpenGL) { #ifdef USE_GLES_MAEMO SDL_GLES_Context *context = SDL_GLES_CreateContext(); if (!context) { fprintf(stderr, "Couldn't initialize SDL_GLES_CreateContext: %s\n", SDL_GetError()); exit(1); } if (SDL_GLES_MakeCurrent(context) < 0) { fprintf(stderr, "Couldn't initialize SDL_GLES_MakeCurrent: %s\n", SDL_GetError()); exit(1); } // atexit(GLES_DeleteContext(context)); #endif #ifdef USE_GLES_EGL // Get the SDL window handle SDL_SysWMinfo sysInfo; //Will hold our Window information SDL_VERSION(&sysInfo.version); //Set SDL version if (SDL_GetWMInfo(&sysInfo) <= 0) { fprintf(stderr, "Unable to get window handle\n"); exit(1); } eglDisplay = eglGetDisplay((EGLNativeDisplayType)sysInfo.info.x11.display); if (!eglDisplay) { fprintf(stderr, "Couldn't open EGL Display\n"); exit(1); } if (!eglInitialize(eglDisplay, NULL, NULL)) { fprintf(stderr, "Couldn't initialize EGL Display\n"); exit(1); } // Find a matching config EGLint configAttribs[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE}; EGLint numConfigsOut = 0; EGLConfig eglConfig; if (eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &numConfigsOut) != EGL_TRUE || numConfigsOut == 0) { fprintf(stderr, "Unable to find appropriate EGL config\n"); exit(1); } eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)sysInfo.info.x11.window, 0); if (eglSurface == EGL_NO_SURFACE) { fprintf(stderr, "Unable to create EGL surface\n"); exit(1); } // Bind GLES and create the context eglBindAPI(EGL_OPENGL_ES_API); EGLint contextParams[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE}; EGLContext eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL); if (eglContext == EGL_NO_CONTEXT) { fprintf(stderr, "Unable to create GLES context\n"); exit(1); } if (eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) == EGL_FALSE) { fprintf(stderr, "Unable to make GLES context current\n"); exit(1); } #endif InitOpenGL(); } #endif InitKey2Str(); ColorBlack = Video.MapRGB(TheScreen->format, 0, 0, 0); ColorDarkGreen = Video.MapRGB(TheScreen->format, 48, 100, 4); ColorLightBlue = Video.MapRGB(TheScreen->format, 52, 113, 166); ColorBlue = Video.MapRGB(TheScreen->format, 0, 0, 252); ColorOrange = Video.MapRGB(TheScreen->format, 248, 140, 20); ColorWhite = Video.MapRGB(TheScreen->format, 252, 248, 240); ColorLightGray = Video.MapRGB(TheScreen->format, 192, 192, 192); ColorGray = Video.MapRGB(TheScreen->format, 128, 128, 128); ColorDarkGray = Video.MapRGB(TheScreen->format, 64, 64, 64); ColorRed = Video.MapRGB(TheScreen->format, 252, 0, 0); ColorGreen = Video.MapRGB(TheScreen->format, 0, 252, 0); ColorYellow = Video.MapRGB(TheScreen->format, 252, 252, 0); UI.MouseWarpPos.x = UI.MouseWarpPos.y = -1; }
////////////////////////////////////////////////////////////////////////// //private ////////////////////////////////////////////////////////////////////////// void CWindow::DrawBackground(CGraphic& aGraphic)const { ASSERT(NULL != iBackgroundBmp); aGraphic.BitBlt(TPoint(0,0),iBackgroundBmp); }