void Demo4Main::SetupBackgroundBuffer() { // NEW SWITCH switch( m_state ) { case stateInit: // Reload the level data FillBackground( 0xffff00 ); { char* data[] = { "bbbbbbbbbbbbbbb", "baeaeadadaeaeab", "babcbcbcbcbibeb", "badadgdadhdadhb", "bgbcbcbcbibcbeb", "badadadadadadab", "bfbcbibcbcbcbeb", "bahadadhdadadab", "bfbcbcbibcbibeb", "badadadadadadab", "bbbbbbbbbbbbbbb" }; // Specify how many tiles wide and high m_oTiles.SetSize( 15, 11 ); // Set up the tiles for ( int x = 0 ; x < 15 ; x++ ) for ( int y = 0 ; y < 11 ; y++ ) m_oTiles.SetValue( x, y, data[y][x]-'a' ); for ( int y = 0 ; y < 11 ; y++ ) { for ( int x = 0 ; x < 15 ; x++ ) printf("%d ", m_oTiles.GetValue(x,y) ); printf("\n" ); } // Specify the screen x,y of top left corner m_oTiles.SetBaseTilesPositionOnScreen( 25, 40 ); } return; case stateMain: FillBackground( 0 ); // Tell it to draw tiles from x1,y1 to x2,y2 in tile array, // to the background of this screen m_oTiles.DrawAllTiles( this, this->GetBackground(), 0, 0, 14, 10 ); break; // Drop out to the complicated stuff case statePaused: FillBackground( 0 ); m_oTiles.DrawAllTiles( this, this->GetBackground(), 0, 0, 14, 10 ); break; } // End switch }
void CXTPSkinObjectTab::FillClient(CDC* pDC, CRect rc) { FillBackground(pDC, rc); if (GetStyle() & TCS_BUTTONS) return; CXTPSkinManagerClass* pClass = GetSkinClass(); CRect rcClient(rc); CRect rcHeader = GetHeaderRect(); DWORD dwStyle = GetStyle(); if (IsRight(dwStyle)) { rcClient.right = rcHeader.left; } else if (IsLeft(dwStyle)) { rcClient.left = rcHeader.right; } else if (IsBottom(dwStyle)) { rcClient.bottom = rcHeader.top; } else { rcClient.top = rcHeader.bottom; } pClass->DrawThemeBackground(pDC, TABP_PANE, 0, &rcClient); }
// resize buffer first if necessary, then compose onto buffer, // wrapping if specified, finally update the screen. //void CScrollerCtrl::OnPaint() LRESULT CScrollerCtrl::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { CPaintDC dc(m_hWnd); CDC dcBackBuffer; dcBackBuffer.CreateCompatibleDC(dc); // resize buffer if neccessary, calculate content size. RecalcLayout(&dc); CBitmap pOldBmp = (HBITMAP)SelectObject(dcBackBuffer.m_hDC, m_bmpBackBuffer); FillBackground(&dcBackBuffer); int nOffset = nMARGIN + m_nScrollOffset; do { nOffset += DrawLogo(&dcBackBuffer, nOffset) + nMARGIN; nOffset += DrawBodyText(&dcBackBuffer, nOffset) + nMARGIN*2; } while ( nOffset < m_sizeBuffer.cy && m_bWrap ); dc.BitBlt(0,0,m_sizeBuffer.cx,m_sizeBuffer.cy,dcBackBuffer,0,0,SRCCOPY); // cleanup SelectObject(dcBackBuffer, pOldBmp); return TRUE; }
void JohnHeadCheat (int bVerbose) { gameStates.app.cheats.bJohnHeadOn = !gameStates.app.cheats.bJohnHeadOn; LoadBackgroundBitmap (); FillBackground (); if (bVerbose) HUDInitMessage (gameStates.app.cheats.bJohnHeadOn? TXT_HI_JOHN : TXT_BYE_JOHN); }
void EdgeCenterMarkFill(const Polygon& py, int color) { std::vector<EDGE3> et; InitScanLineEdgesTable(et, py);//初始化边表 FillBackground(A - color); //对整个填充区域背景颜色取补 for_each(et.begin(), et.end(), EdgeScanMarkColor);//依次处理每一条边 }
void EdgeFenceMarkFill(const Polygon& py, int fence, int color) { std::vector<EDGE3> et; InitScanLineEdgesTable(et, py);//初始化边表 FillBackground(A - color); //对整个填充区域背景颜色取补 for_each(et.begin(), et.end(), std::bind2nd(std::ptr_fun(FenceScanMarkColor), fence));//依次处理每一条边 }
int main(int argc, char *argv[]) { Uint32 flags; SDL_Surface *screen, *image; int i, depth, done; SDL_Event event; /* Check command line usage */ if ( ! argv[1] ) { fprintf(stderr, "Usage: %s <image_file>\n", argv[0]); return(1); } /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); return(1); } /* Set video mode */ // printf("START SDL_SetVideoMode(1920, 1080, 32, SDL_SWSURFACE)) \n"); if ( (screen = SDL_SetVideoMode(1024, 768, 32, SDL_HWSURFACE)) == NULL ) { // if ( (screen = SDL_SetVideoMode(1920, 1080, 32, SDL_SWSURFACE)) == NULL ) { // if ( (screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE)) == NULL ) { exit(2); } printf("START FillBackground\n"); FillBackground(screen); image = IMG_Load(argv[1]); if ( image == NULL ) { printf("Couldn't load %s: %s\n\n\n\n\n", argv[i], SDL_GetError()); exit(2); } // SDL_Surface *converted = SDL_DisplayFormat(image); // SDL_FreeSurface(image); // image= converted; // SDL_Rect r={100,100,900,900}; // SDL_Rect r1={0,0,800,600}; printf("START SDL_BlitSurface\n"); SDL_StretchBlit(image, NULL, screen, NULL); printf("start SDL_UpdateRect\n"); SDL_UpdateRect(screen, 0, 0, 0, 0); printf("END SDL_BlitSurface\n"); SDL_Delay(6000); SDL_FreeSurface(image); SDL_Quit(); return(0); }
/* Do any setup of back buffer prior to locking the screen buffer Basically do the drawing of the background in here and it'll be copied to the screen for you as needed */ void MyProjectMain::SetupBackgroundBuffer() { FillBackground( 0x000000 ); for ( int iX = 0 ; iX < GetScreenWidth() ; iX++ ) for ( int iY = 0 ; iY < this->GetScreenHeight() ; iY++ ) switch( rand()%100 ) { case 0: SetBackgroundPixel( iX, iY, 0xFF0000 ); break; case 1: SetBackgroundPixel( iX, iY, 0x00FF00 ); break; case 2: SetBackgroundPixel( iX, iY, 0x0000FF ); break; case 3: SetBackgroundPixel( iX, iY, 0xFFFF00 ); break; case 4: SetBackgroundPixel( iX, iY, 0x00FFFF ); break; case 5: SetBackgroundPixel( iX, iY, 0xFF00FF ); break; } }
void Demo2Main::SetupBackgroundBuffer() { FillBackground( 0 ); /* // Specify how many tiles wide and high m_oTiles.SetSize( 15, 11 ); // Set up the tiles for ( int x = 0 ; x < 15 ; x++ ) for ( int y = 0 ; y < 11 ; y++ ) m_oTiles.SetValue( x, y, rand()%31 ); // Specify the screen x,y of top left corner m_oTiles.SetBaseTilesPositionOnScreen( 25, 40 ); // Tell it to draw tiles from x1,y1 to x2,y2 in tile array, // to the background of this screen m_oTiles.DrawAllTiles( this, this->GetBackground(), 0, 0, 14, 10 ); */ }
void Demo3Main::SetupBackgroundBuffer() { FillBackground( 0 ); char* data[] = { "bbbbbbbbbbbbbbb", "baeaeadadaeaeab", "babcbcbcbcbibeb", "badadgdadhdadhb", "bgbcbcbcbibcbeb", "badadadadadadab", "bfbcbibcbcbcbeb", "bahadadhdadadab", "bfbcbcbibcbibeb", "badadadadadadab", "bbbbbbbbbbbbbbb" }; // Specify how many tiles wide and high m_oTiles.SetSize( 15, 11 ); // Set up the tiles for ( int x = 0 ; x < 15 ; x++ ) for ( int y = 0 ; y < 11 ; y++ ) m_oTiles.SetValue( x, y, data[y][x]-'a' ); // m_oTiles.SetValue( x, y, rand()%10 ); for ( int y = 0 ; y < 11 ; y++ ) { for ( int x = 0 ; x < 15 ; x++ ) printf("%d ", m_oTiles.GetValue(x,y) ); printf("\n" ); } // Specify the screen x,y of top left corner m_oTiles.SetBaseTilesPositionOnScreen( 25, 40 ); // m_oTiles.SetBaseTilesPositionOnScreen( 10, 10 ); // Tell it to draw tiles from x1,y1 to x2,y2 in tile array, // to the background of this screen m_oTiles.DrawAllTiles( this, this->GetBackground(), 0, 0, 14, 10 ); }
FX_BOOL CFWL_CheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { if (!pParams) return FALSE; switch (pParams->m_iPart) { case FWL_PART_CKB_Border: { DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); break; } case FWL_PART_CKB_Edge: { DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix); break; } case FWL_PART_CKB_Background: { FillBackground(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); if (pParams->m_dwStates & FWL_PARTSTATE_CKB_Focused) { pParams->m_rtPart = *(CFX_RectF*)pParams->m_pData; DrawFocus(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); } break; } case FWL_PART_CKB_CheckBox: { DrawBoxBk(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart, pParams->m_dwStates, &pParams->m_matrix); if (((pParams->m_dwStates & FWL_PARTSTATE_CKB_Mask2) == FWL_PARTSTATE_CKB_Checked) | ((pParams->m_dwStates & FWL_PARTSTATE_CKB_Mask2) == FWL_PARTSTATE_CKB_Neutral)) { DrawSign(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart, pParams->m_dwStates, &pParams->m_matrix); } FX_BOOL bDisable = (pParams->m_dwStates & FWL_PARTSTATE_CKB_Mask1) == FWL_PARTSTATE_CKB_Disabled; DrawSignBorder(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart, bDisable, &pParams->m_matrix); break; } default: { return FALSE; } } return TRUE; }
void NodeSurface::Update( TopologyNode* pNode, bool selected ) { if ( pNode == NULL ) { return; } // Store the PGRGuid so we can handle device information on clicks m_guid = pNode->GetGuid(); m_deviceId = pNode->GetDeviceId(); // Create a context for the surface Cairo::RefPtr<Cairo::Context> refCairo = Cairo::Context::create( m_surface ); int width = m_surface->get_width(); int height= m_surface->get_height(); int radius = 10; double red, green, blue; TopologyNode::NodeType nodeType = pNode->GetNodeType(); GetNodeTypeColor( nodeType, red, green, blue ); FillBackground( refCairo, 1.0, 1.0, 1.0 ); DrawRoundedRectangle( refCairo, 10, 10, width-20, height-20, radius, red, green, blue, selected ); DrawNodeText( refCairo, pNode, width/2, height/2 ); //DrawIcon( refCairo, m_iconSurface, m_iconPixBuf, width/2, height/2 ); DrawPorts( refCairo, pNode ); }
FX_BOOL CFWL_BarcodeTP::DrawBackground(CFWL_ThemeBackground* pParams) { if (!pParams) return FALSE; switch (pParams->m_iPart) { case CFWL_Part::Border: { DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); break; } case CFWL_Part::Edge: { DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix); break; } case CFWL_Part::Background: { FillBackground(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); break; } default: {} } return TRUE; }
FX_BOOL CFWL_CheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { if (!pParams) return FALSE; switch (pParams->m_iPart) { case CFWL_Part::Border: { DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); break; } case CFWL_Part::Edge: { DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix); break; } case CFWL_Part::Background: { FillBackground(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); if (pParams->m_dwStates & CFWL_PartState_Focused) { pParams->m_rtPart = *(CFX_RectF*)pParams->m_pData; DrawFocus(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); } break; } case CFWL_Part::CheckBox: { DrawBoxBk(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart, pParams->m_dwStates, &pParams->m_matrix); if ((pParams->m_dwStates & CFWL_PartState_Checked) | (pParams->m_dwStates & CFWL_PartState_Neutral)) { DrawSign(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart, pParams->m_dwStates, &pParams->m_matrix); } DrawSignBorder( pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart, pParams->m_dwStates & CFWL_PartState_Disabled, &pParams->m_matrix); break; } default: { return FALSE; } } return TRUE; }
bool Format7DrawingArea::on_expose_event( GdkEventExpose* event ) { Glib::RefPtr<Gdk::Window> window = get_window(); if( window == NULL) { return true; } Cairo::RefPtr<Cairo::Context> refCairo = window->create_cairo_context(); // clip to the area indicated by the expose event so that we only redraw // the portion of the window that needs to be redrawn refCairo->rectangle( event->area.x, event->area.y, event->area.width, event->area.height); refCairo->clip(); // Get width / height of widget int width; int height; window->get_size( width, height ); // Figure out which scale to use (horizontal or vertical) const float horzScale = m_maxWidth / (float)width; const float vertScale = m_maxHeight / (float)height; m_previewScale = (horzScale < vertScale) ? vertScale : horzScale; Gtk::AspectFrame* pFrame = (Gtk::AspectFrame*)get_parent(); float fRatio = m_maxWidth / (float)m_maxHeight; if ( fRatio != pFrame->property_ratio()) { pFrame->set( 0.0, 0.0, fRatio, false ); } unsigned int scaledLeft = static_cast<unsigned int>(ToScaled( m_left )); unsigned int scaledTop = static_cast<unsigned int>(ToScaled( m_top )); unsigned int scaledWidth = static_cast<unsigned int>(ToScaled( m_width )); unsigned int scaledHeight = static_cast<unsigned int>(ToScaled( m_height )); // Fill the background with the PGR color FillBackground( refCairo, event->area.x, event->area.y, event->area.width, event->area.height); // Draw the data on top of the filled background DrawRectangle( refCairo, scaledLeft, scaledTop, scaledWidth, scaledHeight ); DrawDashedLines( refCairo, scaledLeft, scaledTop, scaledWidth, scaledHeight ); DrawImageDimensionsText( refCairo, m_left, m_top, m_width, m_height ); DrawCurrentCursorPositionText( refCairo, m_currX, m_currY ); if ( m_imageSizeChanged == true ) { if ( m_left != m_lastFiredLeft || m_top != m_lastFiredTop || m_width != m_lastFiredWidth || m_height != m_lastFiredHeight ) { m_signal_image_size_changed( m_left, m_top, m_width, m_height ); m_lastFiredLeft = m_left; m_lastFiredTop = m_top; m_lastFiredWidth = m_width; m_lastFiredHeight = m_height; } m_imageSizeChanged = false; } return true; }
// Должна вернуть true, если данные изменились (то есть будет isForce при полной перерисовке) bool CBackground::PrepareBackground(CVirtualConsole* pVCon, HDC&/*OUT*/ phBgDc, COORD&/*OUT*/ pbgBmpSize) { if (!this) { _ASSERTE(this!=NULL); return false; } _ASSERTE(isMainThread() && "Must be executed in main thread"); bool bSucceeded = true; bool lbForceUpdate = false; LONG lBgWidth = 0, lBgHeight = 0; BOOL lbVConImage = FALSE; if (gpSet->isBgPluginAllowed) { if (HasPluginBackgroundImage(&lBgWidth, &lBgHeight) && lBgWidth && lBgHeight) { lbVConImage = TRUE; } } LONG lMaxBgWidth = 0, lMaxBgHeight = 0; bool bIsForeground = gpConEmu->isMeForeground(true); // Если плагин свой фон не подсунул if (!lbVConImage) { //if (mp_PluginBg) //{ // delete mp_PluginBg; // mp_PluginBg = NULL; //} #ifndef APPDISTINCTBACKGROUND // То работаем на общих основаниях, через настройки (или AppDistinct) return gpSetCls->PrepareBackground(pVCon, &phBgDc, &pbgBmpSize); #else CBackgroundInfo* pBgFile = pVCon->GetBackgroundObject(); if (!pBgFile) { _ASSERTE(FALSE && "Background object must be created in VCon"); return false; } if (!mb_NeedBgUpdate) { if ((hBgDc == NULL) || (mb_BgLastFade == bIsForeground && gpSet->isFadeInactive) || (!gpSet->isFadeInactive && mb_BgLastFade)) { NeedBackgroundUpdate(); } } pBgFile->PollBackgroundFile(); RECT rcWork = {0, 0, pVCon->GetVConWidth(), pVCon->GetVConHeight()}; // необходимо проверить размер требуемой картинки // -- здесь - всегда только файловая подложка if ((gpSet->bgOperation == eUpLeft) || (gpSet->bgOperation == eUpRight) || (gpSet->bgOperation == eDownLeft) || (gpSet->bgOperation == eDownRight) || (gpSet->bgOperation == eCenter)) { // MemoryDC создается всегда по размеру картинки, т.е. изменение размера окна - игнорируется } else { // Смотрим дальше if (gpSet->bgOperation == eStretch) { // Строго по размеру клиентской (точнее Workspace) области окна lMaxBgWidth = rcWork.right - rcWork.left; lMaxBgHeight = rcWork.bottom - rcWork.top; } else if (gpSet->bgOperation == eFit || gpSet->bgOperation == eFill) { lMaxBgWidth = rcWork.right - rcWork.left; lMaxBgHeight = rcWork.bottom - rcWork.top; // Correct aspect ratio const BITMAPFILEHEADER* pBgImgData = pBgFile->GetBgImgData(); const BITMAPINFOHEADER* pBmp = pBgImgData ? (const BITMAPINFOHEADER*)(pBgImgData+1) : NULL; if (pBmp && (rcWork.bottom - rcWork.top) > 0 && (rcWork.right - rcWork.left) > 0) { double ldVCon = (rcWork.right - rcWork.left) / (double)(rcWork.bottom - rcWork.top); double ldImg = pBmp->biWidth / (double)pBmp->biHeight; if (ldVCon > ldImg) { if (gpSet->bgOperation == eFit) lMaxBgWidth = (LONG)(lMaxBgHeight * ldImg); else lMaxBgHeight = (LONG)(lMaxBgWidth / ldImg); } else { if (gpSet->bgOperation == eFill) lMaxBgWidth = (LONG)(lMaxBgHeight * ldImg); else lMaxBgHeight = (LONG)(lMaxBgWidth / ldImg); } } } else if (gpSet->bgOperation == eTile) { // Max между клиентской (точнее Workspace) областью окна и размером текущего монитора // Окно может быть растянуто на несколько мониторов, т.е. размер клиентской области может быть больше HMONITOR hMon = MonitorFromWindow(ghWnd, MONITOR_DEFAULTTONEAREST); MONITORINFO mon = {sizeof(MONITORINFO)}; GetMonitorInfo(hMon, &mon); // lMaxBgWidth = klMax(rcWork.right - rcWork.left,mon.rcMonitor.right - mon.rcMonitor.left); lMaxBgHeight = klMax(rcWork.bottom - rcWork.top,mon.rcMonitor.bottom - mon.rcMonitor.top); } if (bgSize.X != lMaxBgWidth || bgSize.Y != lMaxBgHeight) NeedBackgroundUpdate(); } if (mb_NeedBgUpdate) { mb_NeedBgUpdate = false; lbForceUpdate = true; _ASSERTE(isMainThread()); //MSectionLock SBG; SBG.Lock(&mcs_BgImgData); //BITMAPFILEHEADER* pImgData = mp_BgImgData; BackgroundOp op = (BackgroundOp)gpSet->bgOperation; const BITMAPFILEHEADER* pBgImgData = pBgFile->GetBgImgData(); BOOL lbImageExist = (pBgImgData != NULL); //BOOL lbVConImage = FALSE; //LONG lBgWidth = 0, lBgHeight = 0; //CVirtualConsole* pVCon = gpConEmu->ActiveCon(); ////MSectionLock SBK; //if (apVCon && gpSet->isBgPluginAllowed) //{ // //SBK.Lock(&apVCon->csBkImgData); // if (apVCon->HasBackgroundImage(&lBgWidth, &lBgHeight) // && lBgWidth && lBgHeight) // { // lbVConImage = lbImageExist = TRUE; // } //} //mb_WasVConBgImage = lbVConImage; if (lbImageExist) { mb_BgLastFade = (!bIsForeground && gpSet->isFadeInactive); TODO("Переделать, ориентироваться только на размер картинки - неправильно"); TODO("DoubleView - скорректировать X,Y"); //if (lbVConImage) //{ // if (lMaxBgWidth && lMaxBgHeight) // { // lBgWidth = lMaxBgWidth; // lBgHeight = lMaxBgHeight; // } // if (!mp_Bg->CreateField(lBgWidth, lBgHeight) || // !apVCon->PutBackgroundImage(mp_Bg, 0,0, lBgWidth, lBgHeight)) // { // delete mp_Bg; // mp_Bg = NULL; // } //} //else { const BITMAPINFOHEADER* pBmp = (const BITMAPINFOHEADER*)(pBgImgData+1); if (!lMaxBgWidth || !lMaxBgHeight) { // Сюда мы можем попасть только в случае eUpLeft/eUpRight/eDownLeft/eDownRight lMaxBgWidth = pBmp->biWidth; lMaxBgHeight = pBmp->biHeight; } //LONG lImgX = 0, lImgY = 0, lImgW = lMaxBgWidth, lImgH = lMaxBgHeight; //if ((gpSet->bgOperation == eFit || gpSet->bgOperation == eFill) // && (rcWork.bottom - rcWork.top) > 0 && (rcWork.right - rcWork.left) > 0) //{ // double ldVCon = (rcWork.right - rcWork.left) / (double)(rcWork.bottom - rcWork.top); // double ldImg = pBmp->biWidth / (double)pBmp->biHeight; // if (ldVCon > ldImg) // { // if (gpSet->bgOperation == eFit) // lMaxBgWidth = lMaxBgHeight * ldImg; // else // lMaxBgHeight = lMaxBgWidth / ldImg; // } // else // { // if (gpSet->bgOperation == eFill) // lMaxBgWidth = lMaxBgHeight * ldImg; // else // lMaxBgHeight = lMaxBgWidth / ldImg; // } //} if (!CreateField(lMaxBgWidth, lMaxBgHeight) || !FillBackground(pBgImgData, 0,0,lMaxBgWidth,lMaxBgHeight, op, mb_BgLastFade)) { bSucceeded = false; } } } else { bSucceeded = false; } } pBgFile->Release(); #endif } else { if (!mb_NeedBgUpdate) { if ((mb_BgLastFade == bIsForeground && gpSet->isFadeInactive) || (!gpSet->isFadeInactive && mb_BgLastFade)) { NeedBackgroundUpdate(); } } //if (mp_PluginBg == NULL) //{ // NeedBackgroundUpdate(); //} if (mb_NeedBgUpdate) { mb_NeedBgUpdate = false; lbForceUpdate = true; //if (!mp_PluginBg) // mp_PluginBg = new CBackground; mb_BgLastFade = (!bIsForeground && gpSet->isFadeInactive); TODO("Переделать, ориентироваться только на размер картинки - неправильно"); TODO("DoubleView - скорректировать X,Y"); if (lMaxBgWidth && lMaxBgHeight) { lBgWidth = lMaxBgWidth; lBgHeight = lMaxBgHeight; } if (!CreateField(lBgWidth, lBgHeight) || !PutPluginBackgroundImage(0,0, lBgWidth, lBgHeight)) { //delete mp_PluginBg; //mp_PluginBg = NULL; bSucceeded = false; } } // Check if the bitmap was prepared for the current Far state if ((mp_BkImgData && pVCon) // Don't use isFilePanel here because it is `false` when any dialog is active in Panels && ((!(pVCon->isEditor || pVCon->isViewer) && !(mp_BkImgData->dwDrawnPlaces & pbp_Panels)) || (pVCon->isEditor && !(mp_BkImgData->dwDrawnPlaces & pbp_Editor)) || (pVCon->isViewer && !(mp_BkImgData->dwDrawnPlaces & pbp_Viewer)) )) { lbForceUpdate = false; phBgDc = NULL; pbgBmpSize = MakeCoord(0, 0); goto wrap; } } if (bSucceeded) { phBgDc = hBgDc; pbgBmpSize = bgSize; } else { phBgDc = NULL; pbgBmpSize = MakeCoord(0,0); } wrap: return lbForceUpdate; }
// Создает (или возвращает уже созданный) HDC (CompatibleDC) для mp_BkImgData bool CBackground::PutPluginBackgroundImage(/*CBackground* pBack,*/ LONG X, LONG Y, LONG Width, LONG Height) { if (!this) return NULL; _ASSERTE(isMainThread()); // Сразу mb_BkImgChanged = FALSE; /*if (mb_BkImgDelete && mp_BkImgData) { free(mp_BkImgData); mp_BkImgData = NULL; mb_BkImgExist = FALSE; return false; }*/ if (!mb_BkImgExist) return false; MSectionLock SC; SC.Lock(mcs_BkImgData, FALSE); if (mb_BkEmfChanged) { // Сразу сброс mb_BkEmfChanged = FALSE; if (!mp_BkEmfData) { _ASSERTE(mp_BkEmfData!=NULL); return false; } // Нужно перекинуть EMF в mp_BkImgData BITMAPINFOHEADER bi = mp_BkEmfData->bi; size_t nBitSize = bi.biWidth*bi.biHeight*sizeof(COLORREF); size_t nWholeSize = sizeof(CESERVER_REQ_SETBACKGROUND)+nBitSize; //-V103 //-V119 if (!mp_BkImgData || (mn_BkImgDataMax < nWholeSize)) { if (mp_BkImgData) free(mp_BkImgData); mp_BkImgData = (CESERVER_REQ_SETBACKGROUND*)malloc(nWholeSize); if (!mp_BkImgData) { _ASSERTE(mp_BkImgData!=NULL); return false; } } *mp_BkImgData = *mp_BkEmfData; mp_BkImgData->bmp.bfType = 0x4D42/*BM*/; mp_BkImgData->bmp.bfSize = nBitSize+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); //-V119 // Теперь нужно сформировать DIB и нарисовать в нем EMF HDC hScreen = GetDC(NULL); //RECT rcMeta = {0,0, mn_BkImgWidth, mn_BkImgHeight}; // (in pixels) //RECT rcMetaMM = {0,0, mn_BkImgWidth*10, mn_BkImgHeight*10}; // (in .01-millimeter units) //HDC hdcEmf = CreateEnhMetaFile(NULL, NULL, &rcMetaMM, L"ConEmu\0Far Background\0\0"); //if (!hdcEmf) //{ // _ASSERTE(hdcEmf!=NULL); // return; //} HDC hdcDib = CreateCompatibleDC(hScreen); if (!hdcDib) { _ASSERTE(hdcDib!=NULL); //DeleteEnhMetaFile(hdcEmf); return false; } COLORREF* pBits = NULL; HBITMAP hDib = CreateDIBSection(hScreen, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0); ReleaseDC(NULL, hScreen); hScreen = NULL; if (!hDib || !pBits) { _ASSERTE(hDib && pBits); return false; } HBITMAP hOld = (HBITMAP)SelectObject(hdcDib, hDib); size_t nBitsSize = bi.biWidth*bi.biHeight*sizeof(COLORREF); // Залить черным - по умолчанию #ifdef _DEBUG memset(pBits, 128, nBitSize); #else memset(pBits, 0, nBitsSize); #endif DWORD nEmfBits = mp_BkEmfData->bmp.bfSize - sizeof(BITMAPFILEHEADER) - sizeof(BITMAPINFOHEADER); LPBYTE pEmfBits = (LPBYTE)(mp_BkEmfData+1); HENHMETAFILE hdcEmf = SetEnhMetaFileBits(nEmfBits, pEmfBits); RECT rcPlay = {0,0, bi.biWidth, bi.biHeight}; DWORD nPlayErr = 0; if (hdcEmf) { #ifdef _DEBUG ENHMETAHEADER emh = {0}; DWORD PixelsX, PixelsY, MMX, MMY, cx, cy; emh.nSize = sizeof(ENHMETAHEADER); if( GetEnhMetaFileHeader( hdcEmf, sizeof( ENHMETAHEADER ), &emh ) ) { // Get the characteristics of the output device HDC hDC = GetDC(NULL); PixelsX = GetDeviceCaps( hDC, HORZRES ); PixelsY = GetDeviceCaps( hDC, VERTRES ); MMX = GetDeviceCaps( hDC, HORZSIZE ) * 100; MMY = GetDeviceCaps( hDC, VERTSIZE ) * 100; ReleaseDC(NULL, hDC); // Calculate the rect in which to draw the metafile based on the // intended size and the current output device resolution // Remember that the intended size is given in 0.01mm units, so // convert those to device units on the target device cx = (int)((float)(emh.rclFrame.right - emh.rclFrame.left) * PixelsX / (MMX)); cy = (int)((float)(emh.rclFrame.bottom - emh.rclFrame.top) * PixelsY / (MMY)); //pw->PreferredSize.cx = ip.MulDivI32((emh.rclFrame.right - emh.rclFrame.left), PixelsX, MMX); //pw->PreferredSize.cy = ip.MulDivI32((emh.rclFrame.bottom - emh.rclFrame.top), PixelsY, MMY); _ASSERTE(cx>0 && cy>0); //if (pw->PreferredSize.cx < 0) pw->PreferredSize.cx = -pw->PreferredSize.cx; //if (pw->PreferredSize.cy < 0) pw->PreferredSize.cy = -pw->PreferredSize.cy; //rcPlay = MakeRect(emh.rclBounds.left,emh.rclBounds.top,emh.rclBounds.right,emh.rclBounds.bottom); } #endif if (!PlayEnhMetaFile(hdcDib, hdcEmf, &rcPlay)) { nPlayErr = GetLastError(); _ASSERTE(FALSE && (nPlayErr == 0)); } GdiFlush(); memmove(mp_BkImgData+1, pBits, nBitSize); } UNREFERENCED_PARAMETER(nPlayErr); SelectObject(hdcDib, hOld); DeleteObject(hDib); DeleteDC(hdcDib); if (hdcEmf) { DeleteEnhMetaFile(hdcEmf); } else { return false; } } if (!mp_BkImgData) { // Нужен ли тут? Или допустимая ситуация? _ASSERTE(mp_BkImgData!=NULL); return false; } bool lbFade = false; if (gpSet->isFadeInactive && !gpConEmu->isMeForeground(false)) lbFade = true; bool lbRc = FillBackground(&mp_BkImgData->bmp, X, Y, Width, Height, eUpLeft, lbFade); //mb_BkImgChanged = FALSE; return lbRc; }
/* Fill the background - should be overridden to actually draw the correct thing. */ void Demo1Main::SetupBackgroundBuffer() { // Put any special code to call different render functions for different states here FillBackground( 0xff00ff ); }
/* Draw the background of the screen. This fills the background with black Then puts some random colour on it Then demos various ways of drawing shapes, images, etc */ void BouncingBallMain::SetupBackgroundBuffer() { FillBackground( 0 ); for ( int iX = 0 ; iX < GetScreenWidth() ; iX++ ) for ( int iY = 0 ; iY < this->GetScreenHeight() ; iY++ ) switch( rand()%100 ) { case 0: SetBackgroundPixel( iX, iY, 0xFF0000 ); break; case 1: SetBackgroundPixel( iX, iY, 0x00FF00 ); break; case 2: SetBackgroundPixel( iX, iY, 0x0000FF ); break; case 3: SetBackgroundPixel( iX, iY, 0xFFFF00 ); break; case 4: SetBackgroundPixel( iX, iY, 0x00FFFF ); break; case 5: SetBackgroundPixel( iX, iY, 0xFF00FF ); break; } DrawBackgroundVerticalSidedRegion( 650, 750, // X 100, 50, // Top line 150, 180, // Bottom line 0xff0000 ); int iLineThickness = 2; // Draw a triangle where all three points are specified. DrawBackgroundTriangle( 300,300, 325,275, 350,350, 0x00ffff ); DrawBackgroundTriangle( 425,375, 450,450, 400,375, 0x00ffff ); DrawBackgroundTriangle( 550,550, 525,475, 450,500, 0x00ffff ); // Draw various polygons // DrawBackgroundPolygon( 100, 100, 150, 100, 250, 200, 150, 200, 0xff0000 ); // DrawBackgroundPolygon( 100, 300, 200, 275, 300, 325, 250, 400, 150, 375, 0x00ff00 ); // DrawBackgroundPolygon( 400, 100, 500, 150, 600, 100, 550, 200, 450, 200, 400, 250, 0x0000ff ); // Draw a polygon and some lines joining the points. DrawBackgroundPolygon( 100, 100, 150, 100, 250, 200, 150, 200, 100, 300, 200, 275, 300, 325, 50, 400, 0xff00ff ); DrawBackgroundLine( 100, 100, 150, 100, 0xffffff ); DrawBackgroundLine( 150, 100, 250, 200, 0xffffff ); DrawBackgroundLine( 250, 200, 150, 200, 0xffffff ); DrawBackgroundLine( 150, 200, 100, 300, 0xffffff ); DrawBackgroundLine( 100, 300, 200, 275, 0xffffff ); DrawBackgroundLine( 200, 275, 300, 325, 0xffffff ); DrawBackgroundLine( 300, 325, 50, 400, 0xffffff ); DrawBackgroundLine( 50, 400, 100, 100, 0xffffff ); DrawBackgroundPolygon( 350, 100, 500, 150, 600, 100, 550, 200, 450, 200, 400, 250, 410, 180, 0x00ff00 ); DrawBackgroundLine( 350, 100, 500, 150, 0xffffff ); DrawBackgroundLine( 500, 150, 600, 100, 0xffffff ); DrawBackgroundLine( 600, 100, 550, 200, 0xffffff ); DrawBackgroundLine( 550, 200, 450, 200, 0xffffff ); DrawBackgroundLine( 450, 200, 400, 250, 0xffffff ); DrawBackgroundLine( 400, 250, 410, 180, 0xffffff ); DrawBackgroundLine( 410, 180, 350, 100, 0xffffff ); // Draw an image loaded from a file. ImageData im, im2; im2.LoadImage( "demo.png" ); im.ShrinkFrom( &im2, 2 ); // Note: image loaded only once, above, and now we will draw it nine times for ( int i = 0 ; i < 3 ; i++ ) for ( int j = 0 ; j < 3 ; j++ ) im.RenderImageWithMask( this->GetBackground(), 0, 0, i*100, j*100 + 300, im.GetWidth(), im.GetHeight() ); // Draw some tiles using the tile manager // Specify how many tiles wide and high m.SetSize( 10, 10 ); // Specify the screen x,y of top left corner m.SetBaseTilesPositionOnScreen( 450, 300 ); // Tell it to draw tiles from x1,y1 to x2,y2 in tile array, // to the background of this screen m.DrawAllTiles( this, this->GetBackground(), 0, 0, 9, 9 ); }
// Pixmap caching utility void MotifUI::GetPixmaps(Widget w, char *name, Pixmap *pixmap, Pixmap *mask) { // Try to find pixmap in cache PixmapLookupList pixmaps = pixmap_table; int i; for (i = 0; i < n_pixmaps; i++, pixmaps++) if (!strcmp((**pixmaps).name, name)) { *pixmap = (**pixmaps).pixmap; if (mask) *mask = (**pixmaps).mask; return; } Pixmap _mask; char *s; SubstitutionRec subs[1]; char *bmPath; char *PIXMAP_DIR = "/usr/dt/appconfig/icons/%L/%B:" "/usr/dt/appconfig/icons/C/%B:" "/usr/include/X11/bitmaps/%B"; if (*name == '/') s = name; else { #ifdef NO_CDE if ((s = getenv("XBMLANGPATH")) && *s) #else if ((s = getenv("XMICONSEARCHPATH")) && *s) #endif { bmPath = new char [strlen(s) + strlen(PIXMAP_DIR) + 2]; sprintf(bmPath, "%s:%s", PIXMAP_DIR, s); } else bmPath = PIXMAP_DIR; subs[0].match = 'B'; subs[0].substitution = name; s = XtFindFile(bmPath, subs, XtNumber(subs), NULL); if (bmPath != PIXMAP_DIR) delete [] bmPath; } struct stat statbuf; if (!s || stat(s, &statbuf) < 0) { *pixmap = XmUNSPECIFIED_PIXMAP; if (mask) *mask = XmUNSPECIFIED_PIXMAP; return; } int len = strlen(s); if (!strcmp(s + len - 3, ".pm")) { XpmAttributes attributes; memset((char *)&attributes, 0, sizeof(XpmAttributes)); #ifdef NO_CDE XpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes); #else _DtXpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes); #endif if (_mask) FillBackground(w, *pixmap, _mask); #ifdef NO_CDE XpmFreeAttributes(&attributes); #else _DtXpmFreeAttributes(&attributes); #endif } else { if (UIClass() == MAIN_WINDOW) *pixmap = XmGetPixmapByDepth(XtScreen(w), s, white, black, depth); else *pixmap = XmGetPixmapByDepth(XtScreen(w), s, black, white, depth); char *s1 = new char [len + 3]; strcpy(s1, s); strcpy(s1 + len - 3, "_m.bm"); if (stat(s1, &statbuf) < 0) _mask = XmUNSPECIFIED_PIXMAP; else { _mask = XmGetPixmapByDepth(XtScreen(w), s1, white, black, 1); FillBackground(w, *pixmap, _mask); } delete [] s1; } if (mask) *mask = _mask; if (s != name) XtFree(s); // Add pixmap to table if (!(n_pixmaps % 8)) { pixmaps = new PixmapLookup [n_pixmaps + 8]; for (i = 0; i < n_pixmaps; i++) pixmaps[i] = pixmap_table[i]; for (i = n_pixmaps; i < n_pixmaps + 8; i++) pixmaps[i] = new PixmapLookupStruct; delete []pixmap_table; pixmap_table = pixmaps; } pixmap_table[n_pixmaps]->name = strdup(name); pixmap_table[n_pixmaps]->pixmap = *pixmap; pixmap_table[n_pixmaps]->mask = _mask; n_pixmaps++; }
void avtRayCompositer::Execute(void) { int i, j; avtVolume *volume = GetTypedInput()->GetVolume(); if (volume == NULL) { // This comes up in the following scenario: // An internal error occurs in the sampling phase. An exception is // thrown. That exception causes avtSamplePoints::SetVolume to be // not called. When its not called, its data member "volume" is // not initialized. So we get a NULL here. // // So: in summary, we only get into this situation if there was an // error before this module was called. EXCEPTION0(ImproperUseException); } // // Determine the size of the screen. // int height = volume->GetRestrictedVolumeHeight(); int width = volume->GetRestrictedVolumeWidth(); // // This is a test to determine if there is nothing in the partition we // are supposed to composite -- since we don't have access to the // partition, this is a bit of a hack and assumes how the partitioning // is done. // if (volume->GetRestrictedMinHeight() >= volume->GetVolumeHeight() || height <= 0 || width <= 0) { SetOutputImage(NULL); return; } volume->SetProgressCallback(RCPixelProgressCallback, this); // // Create an image that we can place each pixel into. // vtkImageData *image = avtImageRepresentation::NewImage(width, height); // // Populate an initial image, either with the background or with an // opaque image that is to be inserted into the middle of the rendering. // unsigned char *data = (unsigned char *)image->GetScalarPointer(0, 0, 0); int nPixels = width*height; double *zbuffer = new double[nPixels]; for (i = 0 ; i < nPixels ; i++) { zbuffer[i] = 1.; } // // Draw the initial background into the image. // int fullHeight = volume->GetVolumeHeight(); int fullWidth = volume->GetVolumeWidth(); vtkImageData *fullImage = avtImageRepresentation::NewImage(fullWidth, fullHeight); unsigned char *fulldata = (unsigned char *) fullImage->GetScalarPointer(0, 0, 0); FillBackground(fulldata, fullWidth, fullHeight); // // Now that we have the background in the full image, copy it into what // we need for this image. // int minWidth = volume->GetRestrictedMinWidth(); int minHeight = volume->GetRestrictedMinHeight(); for (i = 0 ; i < nPixels ; i++) { int restrictedWidth = i % width; int restrictedHeight = i / width; int realWidth = restrictedWidth + minWidth; int realHeight = restrictedHeight + minHeight; int indexIntoFullData = realHeight*fullWidth + realWidth; for (j = 0 ; j < 3 ; j++) { data[3*i+j] = fulldata[3*indexIntoFullData+j]; } } // // We were given an opaque image to insert into the picture. Worse, // the image probably has different dimensions if we are running in // parallel. This is captured by the notion of a restricted volume. // if (*opaqueImage != NULL) { int minW = volume->GetRestrictedMinWidth(); int minH = volume->GetRestrictedMinHeight(); vtkImageData *opaqueImageVTK = opaqueImage->GetImage().GetImageVTK(); float *opaqueImageZB = opaqueImage->GetImage().GetZBuffer(); unsigned char *opaqueImageData = (unsigned char *)opaqueImageVTK->GetScalarPointer(0, 0, 0); int n_comp = opaqueImageVTK->GetNumberOfScalarComponents(); for (int i = 0 ; i < width ; i++) { for (int j = 0 ; j < height ; j++) { int index = j*width + i; int opaqueImageIndex = (j+minH)*fullWidth + (i+minW); zbuffer[index] = opaqueImageZB[opaqueImageIndex]; if (zbuffer[index] != 1.) { data[3*index ] = opaqueImageData[n_comp*opaqueImageIndex]; data[3*index + 1] = opaqueImageData[n_comp*opaqueImageIndex+1]; data[3*index + 2] = opaqueImageData[n_comp*opaqueImageIndex+2]; } } } } // // Have the volume cast our ray function on all of its valid rays and put // the output in this screen. There is a lot of work here. // volume->GetPixels(rayfoo, data, zbuffer); // // Tell our output what its new image is. // SetOutputImage(image); // // Clean up memory. // image->Delete(); fullImage->Delete(); delete [] zbuffer; }
void CXTPSkinObjectTrackBar::OnDraw(CDC* pDC) { CXTPClientRect rc(this); CXTPBufferDC dcMem(*pDC, rc); NMCUSTOMDRAW nm; ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_PREPAINT; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); LRESULT lrCdrf = GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); FillBackground(&dcMem, rc); if (::GetFocus() == m_hWnd && ((SendMessage(WM_QUERYUISTATE) & UISF_HIDEFOCUS) == 0)) { dcMem.SetBkColor(GetColor(COLOR_BTNHIGHLIGHT)); DrawFocusRect(dcMem, &rc); } FillDrawRect(); if (lrCdrf & CDRF_NOTIFYITEMDRAW) { ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_ITEMPREPAINT; nm.dwItemSpec = TBCD_TICS; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); } DrawTics(&dcMem); if (lrCdrf & CDRF_NOTIFYITEMDRAW) { ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_ITEMPOSTPAINT; nm.dwItemSpec = TBCD_TICS; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_ITEMPREPAINT; nm.dwItemSpec = TBCD_CHANNEL; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); } DrawChannel(&dcMem); if (lrCdrf & CDRF_NOTIFYITEMDRAW) { ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_ITEMPOSTPAINT; nm.dwItemSpec = TBCD_CHANNEL; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_ITEMPREPAINT; nm.dwItemSpec = TBCD_THUMB; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); } DrawThumb(&dcMem); if (lrCdrf & CDRF_NOTIFYITEMDRAW) { ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_ITEMPOSTPAINT; nm.dwItemSpec = TBCD_THUMB; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); } if (lrCdrf & CDRF_NOTIFYPOSTPAINT) { ZeroMemory(&nm, sizeof(NMCUSTOMDRAW)); nm.hdc = dcMem.GetSafeHdc(); nm.dwDrawStage = CDDS_POSTPAINT; nm.hdr.code = NM_CUSTOMDRAW; nm.hdr.hwndFrom = GetSafeHwnd(); nm.hdr.idFrom = GetDlgCtrlID(); GetParent()->SendMessage(WM_NOTIFY, (WPARAM)GetDlgCtrlID(), (LPARAM)&nm); } }
void MyWindow :: Draw() { //just fill the background FillBackground(); }
/* Fill the background - should be overridden to actually draw the correct thing. */ void BaseEngine::SetupBackgroundBuffer() { // Put any special code to call different render functions for different states here FillBackground( 0xffff00 ); }
int main(int argc, char *argv[]) { const SDL_VideoInfo *info; SDL_Surface *screen; int w, h; Uint8 video_bpp; Uint32 videoflags; int i, done; SDL_Event event; SDL_Surface *light; int mouse_pressed; Uint32 ticks, lastticks; /* Initialize SDL */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } /* Alpha blending doesn't work well at 8-bit color */ #ifdef _WIN32_WCE /* Pocket PC */ w = 240; h = 320; #else w = 640; h = 480; #endif info = SDL_GetVideoInfo(); if (info->vfmt->BitsPerPixel > 8) { video_bpp = info->vfmt->BitsPerPixel; } else { video_bpp = 16; fprintf(stderr, "forced 16 bpp mode\n"); } videoflags = SDL_SWSURFACE; for (i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-bpp") == 0) { video_bpp = atoi(argv[++i]); if (video_bpp <= 8) { video_bpp = 16; fprintf(stderr, "forced 16 bpp mode\n"); } } else if (strcmp(argv[i], "-hw") == 0) { videoflags |= SDL_HWSURFACE; } else if (strcmp(argv[i], "-warp") == 0) { videoflags |= SDL_HWPALETTE; } else if (strcmp(argv[i], "-width") == 0 && argv[i + 1]) { w = atoi(argv[++i]); } else if (strcmp(argv[i], "-height") == 0 && argv[i + 1]) { h = atoi(argv[++i]); } else if (strcmp(argv[i], "-resize") == 0) { videoflags |= SDL_RESIZABLE; } else if (strcmp(argv[i], "-noframe") == 0) { videoflags |= SDL_NOFRAME; } else if (strcmp(argv[i], "-fullscreen") == 0) { videoflags |= SDL_FULLSCREEN; } else { fprintf(stderr, "Usage: %s [-width N] [-height N] [-bpp N] [-warp] [-hw] [-fullscreen]\n", argv[0]); quit(1); } } /* Set video mode */ if ((screen = SDL_SetVideoMode(w, h, video_bpp, videoflags)) == NULL) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", w, h, video_bpp, SDL_GetError()); quit(2); } FillBackground(screen); /* Create the light */ light = CreateLight(82); if (light == NULL) { quit(1); } /* Load the sprite */ if (LoadSprite(screen, "icon.bmp") < 0) { SDL_FreeSurface(light); quit(1); } /* Print out information about our surfaces */ printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel); if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { printf("Screen is in video memory\n"); } else { printf("Screen is in system memory\n"); } if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { printf("Screen has double-buffering enabled\n"); } if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { printf("Sprite is in video memory\n"); } else { printf("Sprite is in system memory\n"); } /* Run a sample blit to trigger blit acceleration */ MoveSprite(screen, NULL); if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) { printf("Sprite blit uses hardware alpha acceleration\n"); } else { printf("Sprite blit dosn't uses hardware alpha acceleration\n"); } /* Set a clipping rectangle to clip the outside edge of the screen */ { SDL_Rect clip; clip.x = 32; clip.y = 32; clip.w = screen->w - (2 * 32); clip.h = screen->h - (2 * 32); SDL_SetClipRect(screen, &clip); } /* Wait for a keystroke */ lastticks = SDL_GetTicks(); done = 0; mouse_pressed = 0; while (!done) { /* Update the frame -- move the sprite */ if (mouse_pressed) { MoveSprite(screen, light); mouse_pressed = 0; } else { MoveSprite(screen, NULL); } /* Slow down the loop to 30 frames/second */ ticks = SDL_GetTicks(); if ((ticks - lastticks) < FRAME_TICKS) { #ifdef CHECK_SLEEP_GRANULARITY fprintf(stderr, "Sleeping %d ticks\n", FRAME_TICKS - (ticks - lastticks)); #endif SDL_Delay(FRAME_TICKS - (ticks - lastticks)); #ifdef CHECK_SLEEP_GRANULARITY fprintf(stderr, "Slept %d ticks\n", (SDL_GetTicks() - ticks)); #endif } lastticks = ticks; /* Check for events */ while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_VIDEORESIZE: screen = SDL_SetVideoMode(event.resize.w, event.resize.h, video_bpp, videoflags); if (screen) { FillBackground(screen); } break; /* Attract sprite while mouse is held down */ case SDL_MOUSEMOTION: if (event.motion.state != 0) { AttractSprite(event.motion.x, event.motion.y); mouse_pressed = 1; } break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == 1) { AttractSprite(event.button.x, event.button.y); mouse_pressed = 1; } else { SDL_Rect area; area.x = event.button.x - 16; area.y = event.button.y - 16; area.w = 32; area.h = 32; SDL_FillRect(screen, &area, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_UpdateRects(screen, 1, &area); } break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { done = 1; } if (event.key.keysym.sym == SDLK_RETURN) { SDL_WM_ToggleFullScreen(screen); } break; case SDL_QUIT: done = 1; break; default: break; } } } SDL_FreeSurface(light); SDL_FreeSurface(sprite); SDL_FreeSurface(backing); /* Print out some timing information */ if (flashes > 0) { printf("%d alpha blits, ~%4.4f ms per blit\n", flashes, (float) flashtime / flashes); } SDL_Quit(); return (0); }
FX_BOOL CFWL_FormTP::DrawBackground(CFWL_ThemeBackground* pParams) { if (!pParams) return FALSE; int32_t iActive = 0; if (pParams->m_dwStates & FWL_PARTSTATE_FRM_Inactive) { iActive = 1; } FWLTHEME_STATE eState = FWLTHEME_STATE_Normal; switch (pParams->m_dwStates & 0x03) { case FWL_PARTSTATE_FRM_Hover: { eState = FWLTHEME_STATE_Hover; break; } case FWL_PARTSTATE_FRM_Pressed: { eState = FWLTHEME_STATE_Pressed; break; } case FWL_PARTSTATE_FRM_Disabled: { eState = FWLTHEME_STATE_Disabale; break; } default: {} } switch (pParams->m_iPart) { case FWL_PART_FRM_Border: { DrawFormBorder(pParams->m_pGraphics, &pParams->m_rtPart, eState, &pParams->m_matrix, iActive); break; } case FWL_PART_FRM_Edge: { DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix); break; } case FWL_PART_FRM_Background: { FillBackground(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); break; } case FWL_PART_FRM_Caption: { DrawCaption(pParams->m_pGraphics, &pParams->m_rtPart, eState, &pParams->m_matrix, iActive); break; } case FWL_PART_FRM_NarrowCaption: { DrawNarrowCaption(pParams->m_pGraphics, &pParams->m_rtPart, eState, &pParams->m_matrix, iActive); break; } case FWL_PART_FRM_CloseBox: { DrawCloseBox(pParams->m_pGraphics, &pParams->m_rtPart, eState, &pParams->m_matrix, iActive); break; } case FWL_PART_FRM_MinimizeBox: { DrawMinimizeBox(pParams->m_pGraphics, &pParams->m_rtPart, eState, &pParams->m_matrix, iActive); break; } case FWL_PART_FRM_MaximizeBox: { DrawMaximizeBox(pParams->m_pGraphics, &pParams->m_rtPart, eState, pParams->m_dwData, &pParams->m_matrix, iActive); break; } case FWL_PART_FRM_Icon: { DrawIconImage(pParams->m_pGraphics, pParams->m_pImage, &pParams->m_rtPart, eState, &pParams->m_matrix, iActive); break; } default: {} } return TRUE; }
/* Draw the background of the screen. This fills the background with black Then puts some random colour on it Then demos various ways of drawing shapes, images, etc */ void BouncingBallMain::SetupBackgroundBuffer() { FillBackground( 0 ); for ( int iX = 0 ; iX < GetScreenWidth() ; iX++ ) for ( int iY = 0 ; iY < this->GetScreenHeight() ; iY++ ) switch( rand()%100 ) { case 0: SetBackgroundPixel( iX, iY, 0xFF0000 ); break; case 1: SetBackgroundPixel( iX, iY, 0x00FF00 ); break; case 2: SetBackgroundPixel( iX, iY, 0x0000FF ); break; case 3: SetBackgroundPixel( iX, iY, 0xFFFF00 ); break; case 4: SetBackgroundPixel( iX, iY, 0x00FFFF ); break; case 5: SetBackgroundPixel( iX, iY, 0xFF00FF ); break; } DrawBackgroundVerticalSidedRegion( 650, 750, // X 100, 50, // Top line 150, 180, // Bottom line 0xff0000 ); int iLineThickness = 2; // Draw a triangle where all three points are specified. DrawBackgroundTriangle( 300,300, 325,275, 350,350, 0x00ffff ); DrawBackgroundTriangle( 425,375, 450,450, 400,375, 0x00ffff ); DrawBackgroundTriangle( 550,550, 525,475, 450,500, 0x00ffff ); // Draw various polygons // DrawBackgroundPolygon( 100, 100, 150, 100, 250, 200, 150, 200, 0xff0000 ); // DrawBackgroundPolygon( 100, 300, 200, 275, 300, 325, 250, 400, 150, 375, 0x00ff00 ); // DrawBackgroundPolygon( 400, 100, 500, 150, 600, 100, 550, 200, 450, 200, 400, 250, 0x0000ff ); // Draw a polygon and some lines joining the points. DrawBackgroundPolygon( 100, 100, 150, 100, 250, 200, 150, 200, 100, 300, 200, 275, 300, 325, 50, 400, 0xff00ff ); DrawBackgroundLine( 100, 100, 150, 100, 0xffffff ); DrawBackgroundLine( 150, 100, 250, 200, 0xffffff ); DrawBackgroundLine( 250, 200, 150, 200, 0xffffff ); DrawBackgroundLine( 150, 200, 100, 300, 0xffffff ); DrawBackgroundLine( 100, 300, 200, 275, 0xffffff ); DrawBackgroundLine( 200, 275, 300, 325, 0xffffff ); DrawBackgroundLine( 300, 325, 50, 400, 0xffffff ); DrawBackgroundLine( 50, 400, 100, 100, 0xffffff ); DrawBackgroundPolygon( 350, 100, 500, 150, 600, 100, 550, 200, 450, 200, 400, 250, 410, 180, 0x00ff00 ); DrawBackgroundLine( 350, 100, 500, 150, 0xffffff ); DrawBackgroundLine( 500, 150, 600, 100, 0xffffff ); DrawBackgroundLine( 600, 100, 550, 200, 0xffffff ); DrawBackgroundLine( 550, 200, 450, 200, 0xffffff ); DrawBackgroundLine( 450, 200, 400, 250, 0xffffff ); DrawBackgroundLine( 400, 250, 410, 180, 0xffffff ); DrawBackgroundLine( 410, 180, 350, 100, 0xffffff ); // Draw an image loaded from a file. ImageData im, im2; // Load the image file into an image object - at the normal size im2.LoadImage( "demo.png" ); // Create a second image from the first, by halving the size im.ShrinkFrom( &im2, 2 ); // Note: image loaded only once, above, and now we will draw it nine times #if 0 for ( int i = 0 ; i < 3 ; i++ ) for ( int j = 0 ; j < 3 ; j++ ) im.RenderImageWithMask( this->GetBackground(), 0, 0, i*100, j*100 + 300, im.GetWidth(), im.GetHeight() ); #endif // Well done if you are reading this since it means that you bothered to go through the source code. // Here is an example of drawing an image rotated, or with changed brightness, different transparency position, etc. // Change the #if 0 to #if 1, and possibly comment out the code above: #if 1 for ( int i = 0; i < 3; i++ ) for ( int j = 0; j < 3; j++ ) im.FlexibleRenderImageWithMask( this->GetBackground(), 0,0, // x and y source i * 100,j * 100 + 300, // x and y dest im.GetWidth(),im.GetHeight(), // Height and width to copy i + j, // Rotation value 0, 0, // Transparency pixel - which pixel gives transparency colour, or use -1,-1 for no transparency 100+(i-j)*20, // Brightness percentage -1, // 0x00ff00, // Alternate pixels -1, // 0x0000ff, // Every third pixel -1, // 0xffffff, // Every fourth pixel i == 0 ? -1 : 0x404040 * i // Average with this colour ); #endif // Draw some tiles using the tile manager // Specify how many tiles wide and high obTileManager.SetSize( 10, 10 ); // Specify the screen x,y of top left corner obTileManager.SetBaseTilesPositionOnScreen( 450,300 ); // Tell it to draw tiles from x1,y1 to x2,y2 in tile array, // to the background of this screen obTileManager.DrawAllTiles( this,this->GetBackground(),0,0,9,9 ); }