inline void IASRect::Center(const ADMRect& centerRect) { Offset(centerRect.left + ((centerRect.right - centerRect.left) - Width()) / 2, centerRect.top + ((centerRect.bottom - centerRect.top) - Height()) / 2); }
BOOL CClientCapture::Paint(HDC hDC, CPalette * m_pPalette, LPRECT lpDCRect, LPRECT lpDIBRect) const { if (!m_pBMI) return FALSE; HPALETTE hPal = NULL; // Our DIB's palette HPALETTE hOldPal = NULL; // Previous palette // Get the DIB's palette, then select it into DC if (m_pPalette != NULL) { hPal = (HPALETTE) m_pPalette->m_hObject; // Select as background since we have // already realized in forground if needed hOldPal = ::SelectPalette(hDC, hPal, TRUE); } /* Make sure to use the stretching mode best for color pictures */ ::SetStretchBltMode(hDC, COLORONCOLOR); /* Determine whether to call StretchDIBits() or SetDIBitsToDevice() */ BOOL bSuccess = FALSE; if ((RECTWIDTH(lpDCRect) == RECTWIDTH(lpDIBRect)) && (RECTHEIGHT(lpDCRect) == RECTHEIGHT(lpDIBRect))){ bSuccess = ::SetDIBitsToDevice(hDC, // hDC lpDCRect->left, // DestX lpDCRect->top, // DestY RECTWIDTH(lpDCRect), // nDestWidth RECTHEIGHT(lpDCRect), // nDestHeight lpDIBRect->left, // SrcX (int)Height() - lpDIBRect->top - RECTHEIGHT(lpDIBRect), // SrcY 0, // nStartScan (WORD)Height(), // nNumScans m_pBits, // lpBits m_pBMI, // lpBitsInfo DIB_RGB_COLORS); // wUsage } else bSuccess = ::StretchDIBits(hDC, // hDC lpDCRect->left, // DestX lpDCRect->top, // DestY RECTWIDTH(lpDCRect), // nDestWidth RECTHEIGHT(lpDCRect), // nDestHeight lpDIBRect->left, // SrcX lpDIBRect->top, // SrcY RECTWIDTH(lpDIBRect), // wSrcWidth RECTHEIGHT(lpDIBRect), // wSrcHeight m_pBits, // lpBits m_pBMI, // lpBitsInfo DIB_RGB_COLORS, // wUsage SRCCOPY); // dwROP /* Reselect old palette */ if (hOldPal != NULL) { ::SelectPalette(hDC, hOldPal, TRUE); } return bSuccess; }
void RenderHeightMap(BYTE pHeightMap[]) { int X = 0, Y = 0; // Create some variables to walk the array with. int x, y, z; // Create some variables for readability bool bSwitchSides = false; // Make sure our height data is valid if(!pHeightMap) return; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Now comes the juice of our detail texture. We want to combine the // terrain texture and the detail texture together. To blend the two // textures nicely, we will want to use some ARB extension defines // for our texture properties. The first one, GL_COMBINE_ARB, allows // us to use combine texture properties, which brings us to our second // one: GL_RGB_SCALE_ARB. With this texture property, we can now // increase the gamma of our second texture so that it does not darken // the texture beneath it. This works great for lightmaps and detail // textures. I believe that the GL_RGB_SCALE_ARB property only accepts // 1, 2 or 4 as a valid scale value. 2 works just fine, where 4 is // too bright. // // To tile the detail texture appropriately, the texture matrix is // effected. When we enter into the texture matrix mode, it allows us // to effect the current position of the selected texture. This isn't // necessary to use, since we could just calculate the detail texture // coordinates on our own, but I thought it would be nice to introduce // this functionality. All we do is just scale the texture by a certain // amount, which can provide different levels of detail. By hitting the // SPACE bar on the keyboard, you are able to cycle through different // scale values to see the one that works best for you. It is good to // add a third texture on top that is the same detail texture, but with // a different scale value. // Activate the first texture ID and bind the tree background to it glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, g_Texture[0]); // If we want detail texturing on, let's render the second texture if(g_bDetail) { // Activate the second texture ID and bind the fog texture to it glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); // Here we turn on the COMBINE properties and increase our RGB // gamma for the detail texture. 2 seems to work just right. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2); // Bind the detail texture glBindTexture(GL_TEXTURE_2D, g_Texture[1]); // Now we want to enter the texture matrix. This will allow us // to change the tiling of the detail texture. glMatrixMode(GL_TEXTURE); // Reset the current matrix and apply our chosen scale value glLoadIdentity(); glScalef((float)g_DetailScale, (float)g_DetailScale, 1); // Leave the texture matrix and set us back in the model view matrix glMatrixMode(GL_MODELVIEW); } /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // We want to render triangle strips glBegin( GL_TRIANGLE_STRIP ); // Go through all of the rows of the height map for ( X = 0; X <= MAP_SIZE; X += STEP_SIZE ) { // Check if we need to render the opposite way for this column if(bSwitchSides) { // Render a column of the terrain, for this current X. // We start at MAP_SIZE and render down to 0. for ( Y = MAP_SIZE; Y >= 0; Y -= STEP_SIZE ) { // Get the (X, Y, Z) value for the bottom left vertex x = X; y = Height(pHeightMap, X, Y ); z = Y; // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); // Get the (X, Y, Z) value for the bottom right vertex x = X + STEP_SIZE; y = Height(pHeightMap, X + STEP_SIZE, Y ); z = Y; // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); } } else { // Render a column of the terrain, for this current X. // We start at 0 and render down up to MAP_SIZE. for ( Y = 0; Y <= MAP_SIZE; Y += STEP_SIZE ) { // Get the (X, Y, Z) value for the bottom right vertex x = X + STEP_SIZE; y = Height(pHeightMap, X + STEP_SIZE, Y ); z = Y; // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); // Get the (X, Y, Z) value for the bottom left vertex x = X; y = Height(pHeightMap, X, Y ); z = Y; // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); } } // Switch the direction the column renders to allow the fluid tri strips bSwitchSides = !bSwitchSides; } // Stop rendering triangle strips glEnd(); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Now let's clean up our multitexturing so it doesn't effect anything else // Turn the second multitexture pass off glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); // Turn the first multitexture pass off glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * }
void Graphics_::Clear(int color) { Rectangle(0,0,Width(),Height(),color); Scroll(0); }
static void raw_Remove(pNode& t, pNode p, pNode del_parent) { if (p->Key < t->Key) { raw_Remove(t->Left, p, t); Balance(t); } else if (p->Key > t->Key) { raw_Remove(t->Right, p, t); Balance(t); } if (p->Key == t->Key) { if (!del_parent && !t->Left && !t->Right) // Если удаляем корень { delete t; t = NULL; return; } // Если левое поддерево длиннее, то берем из него элемент на замену if (Height(p->Left) > Height(p->Right)) { pNode rem = p->Left, // Элемент на замену rem_parent; // Родитель элемента на замену FindMax(rem, rem_parent); // Если у удаляемого элемента всего один сын - левый if (!rem_parent) { t = rem; } else { rem_parent->Right = NULL; rem->Right = p->Right; rem->Left = p->Left; t = rem; } } else { // Если удаляемый узел - лист if (p->Left == p->Right && !p->Left) { t = NULL; return; } pNode rem = p->Right, // Элемент на замену rem_parent; // Родитель элемента на замену FindMin(rem, rem_parent); // Если у удаляемого узла один сын - правый if (!rem_parent) { t = rem; } else { t = rem; rem->Left = p->Left; rem->Right = p->Right; rem_parent->Left = NULL; } } } }
//---------------------------------------------------------------------------// // OnMouseDown // //---------------------------------------------------------------------------// void CMGTreeView::OnMouseDown(int iX, int iY, int iButton) { CMGControl::OnMouseDown(iX,iY,iButton); if (iButton == 1) { int Offset = m_ScrollBar->IsVisible() ? (int)(m_ScrollBar->GetPos() * (m_Root->GetTotalHeight() - Height())) : 0; CMGTreeItem *pItemAt = GetItemAt(iX, iY+Offset); if (pItemAt) { if (pItemAt->IsFolder()) { if (iX < (pItemAt->Left()+12)) { if (pItemAt->IsExpanded()) pItemAt->Collapse(); else pItemAt->Expand(); } else { SelectItem(pItemAt); } } else { if (iX >= (pItemAt->Left()+12)) { SelectItem(pItemAt); BeginDrag (); } } } } else if (m_ScrollBar->IsVisible()) { if (iButton == 4) m_ScrollBar->SetPos(m_ScrollBar->GetPos()-0.1f); else if (iButton == 5) m_ScrollBar->SetPos(m_ScrollBar->GetPos()+0.1f); } Update(); }
///////////////////////////////// // IntroScreen ///////////////////////////////// IntroScreen::IntroScreen() : GG::Wnd(GG::X0, GG::Y0, GG::GUI::GetGUI()->AppWidth(), GG::GUI::GetGUI()->AppHeight(), GG::NO_WND_FLAGS), m_single_player(nullptr), m_quick_start(nullptr), m_multi_player(nullptr), m_load_game(nullptr), m_options(nullptr), m_pedia(nullptr), m_about(nullptr), m_website(nullptr), m_credits(nullptr), m_exit_game(nullptr), m_menu(nullptr), m_splash(nullptr), m_logo(nullptr), m_version(nullptr) { m_menu = new CUIWnd(UserString("INTRO_WINDOW_TITLE"), GG::X1, GG::Y1, MAIN_MENU_WIDTH, MAIN_MENU_HEIGHT, GG::ONTOP | GG::INTERACTIVE); m_splash = new GG::StaticGraphic(ClientUI::GetTexture(ClientUI::ArtDir() / "splash.png"), GG::GRAPHIC_FITGRAPHIC, GG::INTERACTIVE); m_logo = new GG::StaticGraphic(ClientUI::GetTexture(ClientUI::ArtDir() / "logo.png"), GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); m_version = new CUILabel(FreeOrionVersionString(), GG::FORMAT_NOWRAP, GG::INTERACTIVE); m_version->MoveTo(GG::Pt(Width() - m_version->Width(), Height() - m_version->Height())); AttachChild(m_splash); m_splash->AttachChild(m_logo); m_splash->AttachChild(m_menu); m_splash->AttachChild(m_version); //create buttons m_single_player = new CUIButton(UserString("INTRO_BTN_SINGLE_PLAYER")); m_quick_start = new CUIButton(UserString("INTRO_BTN_QUICK_START")); m_multi_player = new CUIButton(UserString("INTRO_BTN_MULTI_PLAYER")); m_load_game = new CUIButton(UserString("INTRO_BTN_LOAD_GAME")); m_options = new CUIButton(UserString("INTRO_BTN_OPTIONS")); m_pedia = new CUIButton(UserString("INTRO_BTN_PEDIA")); m_about = new CUIButton(UserString("INTRO_BTN_ABOUT")); m_website = new CUIButton(UserString("INTRO_BTN_WEBSITE")); m_credits = new CUIButton(UserString("INTRO_BTN_CREDITS")); m_exit_game = new CUIButton(UserString("INTRO_BTN_EXIT")); //attach buttons m_menu->AttachChild(m_single_player); m_menu->AttachChild(m_quick_start); m_menu->AttachChild(m_multi_player); m_menu->AttachChild(m_load_game); m_menu->AttachChild(m_options); m_menu->AttachChild(m_pedia); m_menu->AttachChild(m_about); m_menu->AttachChild(m_website); m_menu->AttachChild(m_credits); m_menu->AttachChild(m_exit_game); //connect signals and slots GG::Connect(m_single_player->LeftClickedSignal, &IntroScreen::OnSinglePlayer, this); GG::Connect(m_quick_start->LeftClickedSignal, &IntroScreen::OnQuickStart, this); GG::Connect(m_multi_player->LeftClickedSignal, &IntroScreen::OnMultiPlayer, this); GG::Connect(m_load_game->LeftClickedSignal, &IntroScreen::OnLoadGame, this); GG::Connect(m_options->LeftClickedSignal, &IntroScreen::OnOptions, this); GG::Connect(m_pedia->LeftClickedSignal, &IntroScreen::OnPedia, this); GG::Connect(m_about->LeftClickedSignal, &IntroScreen::OnAbout, this); GG::Connect(m_website->LeftClickedSignal, &IntroScreen::OnWebsite, this); GG::Connect(m_credits->LeftClickedSignal, &IntroScreen::OnCredits, this); GG::Connect(m_exit_game->LeftClickedSignal, &IntroScreen::OnExitGame, this); DoLayout(); }
int swDesktop::Init() { swMain* Main = swMain::Instance(); if(!Main){ Debug << " No main instance ??";DEND; return -1; } // Just a test!! (*Main) += sigc::mem_fun(this, &swDesktop::_CanExit); // ---------------------------------------------------- swNCurses* _n = Main->CursesInstance(); if(! _n ) { Debug << " No Curses instance ??";DEND; return -1; } SetGeometry( Rect(0,0, _n->Width(), _n->Height()) ); _wr->Clear(); _wr->Fill( Rect(0,0, _n->Width(), _n->Height()), swTAttr(7, 0, A_BOLD), ACS_CKBOARD); // ------------------------------------------------- TESTS swLabel* label = new swLabel(this,0,"desk label test"); label->SetGeometry( Rect( 0,0, Width(), 1)); String S; S << "<fgcolor yellow; strong;>Label</strong; fgcolor white;> test in desktop: my W=" << Width() << ": my H=" << Height(); (*label)<< S; Update(); return 0; }
int Height(struct TNode* root){ if(!root){ return 0; } return max(Height(root->left),Height(root->right))+1; }
void RenderHeightMap(BYTE pHeightMap[]) { int X = 0, Y = 0; // Create some variables to walk the array with. int x, y, z; // Create some variables for readability bool bSwitchSides = false; // Make sure our height data is valid if(!pHeightMap) return; // Activate the first texture ID and bind the tree background to it glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, g_Texture[0]); // If we want detail texturing on, let's render the second texture if(g_bDetail) { // Activate the second texture ID and bind the fog texture to it glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); // Here we turn on the COMBINE properties and increase our RGB // gamma for the detail texture. 2 seems to work just right. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2); // Bind the detail texture glBindTexture(GL_TEXTURE_2D, g_Texture[1]); // Now we want to enter the texture matrix. This will allow us // to change the tiling of the detail texture. glMatrixMode(GL_TEXTURE); // Reset the current matrix and apply our chosen scale value glLoadIdentity(); glScalef((float)g_DetailScale, (float)g_DetailScale, 1); // Leave the texture matrix and set us back in the model view matrix glMatrixMode(GL_MODELVIEW); } // We want to render triangle strips glBegin( GL_TRIANGLE_STRIP ); // Go through all of the rows of the height map for ( X = 0; X <= MAP_SIZE; X += STEP_SIZE ) { // Check if we need to render the opposite way for this column if(bSwitchSides) { // Render a column of the terrain, for this current X. // We start at MAP_SIZE and render down to 0. for ( Y = MAP_SIZE; Y >= 0; Y -= STEP_SIZE ) { // Get the (X, Y, Z) value for the bottom left vertex x = X; y = Height(pHeightMap, X, Y ); z = Y; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the fog coordinate for this vertex, depending on it's height // and the current depth of the fog. SetFogCoord(g_FogDepth, (float)y); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); // Get the (X, Y, Z) value for the bottom right vertex x = X + STEP_SIZE; y = Height(pHeightMap, X + STEP_SIZE, Y ); z = Y; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the fog coordinate for this vertex SetFogCoord(g_FogDepth, (float)y); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); } } else { // Render a column of the terrain, for this current X. // We start at 0 and render down up to MAP_SIZE. for ( Y = 0; Y <= MAP_SIZE; Y += STEP_SIZE ) { // Get the (X, Y, Z) value for the bottom right vertex x = X + STEP_SIZE; y = Height(pHeightMap, X + STEP_SIZE, Y ); z = Y; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the fog coordinate for this vertex SetFogCoord(g_FogDepth, (float)y); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); // Get the (X, Y, Z) value for the bottom left vertex x = X; y = Height(pHeightMap, X, Y ); z = Y; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the fog coordinate for this vertex SetFogCoord(g_FogDepth, (float)y); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set the current texture coordinate and render the vertex SetTextureCoord( (float)x, (float)z ); glVertex3i(x, y, z); } } // Switch the direction the column renders to allow the fluid tri strips bSwitchSides = !bSwitchSides; } // Stop rendering triangle strips glEnd(); // Turn the second multitexture pass off glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); // Turn the first multitexture pass off glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); }
// SetModeAndValue void ColorField::SetModeAndValue(SelectedColorMode mode, float fixedValue) { float R(0), G(0), B(0); float H(0), S(0), V(0); float width = Width(); float height = Height(); switch (fMode) { case R_SELECTED: { R = fFixedValue * 255; G = round(fMarkerPosition.x / width * 255.0); B = round(255.0 - fMarkerPosition.y / height * 255.0); }; break; case G_SELECTED: { R = round(fMarkerPosition.x / width * 255.0); G = fFixedValue * 255; B = round(255.0 - fMarkerPosition.y / height * 255.0); }; break; case B_SELECTED: { R = round(fMarkerPosition.x / width * 255.0); G = round(255.0 - fMarkerPosition.y / height * 255.0); B = fFixedValue * 255; }; break; case H_SELECTED: { H = fFixedValue; S = fMarkerPosition.x / width; V = 1.0 - fMarkerPosition.y / height; }; break; case S_SELECTED: { H = fMarkerPosition.x / width * 6.0; S = fFixedValue; V = 1.0 - fMarkerPosition.y / height; }; break; case V_SELECTED: { H = fMarkerPosition.x / width * 6.0; S = 1.0 - fMarkerPosition.y / height; V = fFixedValue; }; break; } if (fMode & (H_SELECTED | S_SELECTED | V_SELECTED)) { HSV_to_RGB(H, S, V, R, G, B); R *= 255.0; G *= 255.0; B *= 255.0; } rgb_color color = { (uint8)round(R), (uint8)round(G), (uint8)round(B), 255 }; if (fFixedValue != fixedValue || fMode != mode) { fFixedValue = fixedValue; fMode = mode; _Update(); } SetMarkerToColor(color); }
void CBadTrustDialog::OnInitDialog() { // // Get the background brush for our edit controls // m_hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); // Load the icon LPSTR idi; switch (m_rrn.hrValid) { case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): case TRUST_E_NOSIGNATURE: idi = IDI_EXCLAMATION; break; default: idi = IDI_HAND; break; } HICON hicon = LoadIcon(NULL, idi); ::SendDlgItemMessage(m_hWnd, IDC_BADTRUSTICON, STM_SETICON, (WPARAM)hicon, (LPARAM)0); // Set the window title { TCHAR sz[128]; WideCharToMultiByte(CP_ACP, 0, m_rrn.wszDialogTitle, -1, (LPSTR)sz, 128, NULL, NULL); ::SetWindowText(GetWindow(), sz); } // Set the banter text int cchBanter2; { const int cchMax = INTERNET_MAX_URL_LENGTH+64; TCHAR sz[cchMax]; // Set the top level banter ::LoadString(hinst, IDS_BADTRUSTBANTER1, &sz[0], cchMax); ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER1), &sz[0]); // Set the program name { // // The 'program' name we see can in fact often be a full URL. URLs // can be very long, up to 1024 or so. // if (m_rrn.wszProgramName) { WideCharToMultiByte(CP_ACP, 0, m_rrn.wszProgramName, -1, &sz[0], cchMax, NULL, NULL); } else ::LoadString(hinst, IDS_UNKNOWNPROGRAM, &sz[0], cchMax); TCHAR szF[cchMax]; ::FormatMessage(hinst, &szF[0], cchMax, IDS_BADTRUSTBANTER2, &sz[0]); ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER2), &szF[0]); cchBanter2 = lstrlen(&szF[0]); // // This control is read-only. Note that the text on the control // can be copied using the context menu in the control. // SendMessage(WindowOf(IDC_BADTRUSTBANTER2), EM_SETREADONLY, (WPARAM)TRUE, 0); } // Set the trailing banter UINT ids; switch (m_rrn.hrValid) { case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): case TRUST_E_NOSIGNATURE: ids = IDS_BADTRUSTBANTER31; break; case CERT_E_EXPIRED: case CERT_E_VALIDIYPERIODNESTING: ids = IDS_BADTRUSTBANTER32; break; case NTE_BAD_SIGNATURE: ids = IDS_BADTRUSTBANTER33; break; default: ids = IDS_BADTRUSTBANTER34; break; } ::LoadString(hinst, ids, &sz[0], cchMax); ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER3), &sz[0]); } // Position the controls so that all are visible { UINT spacing = GetSystemMetrics(SM_CYFIXEDFRAME) * 2; RECT rc1, rc2, rc3; int h; POINT pt; // // Where on the screen is the client area of the dialog? // pt.x = 0; pt.y = 0; ClientToScreen(GetWindow(), &pt); // // Find first text box location // GetWindowRect(WindowOf(IDC_BADTRUSTBANTER1), &rc1); // // Adjust second text box size // SizeControlToFitText(WindowOf(IDC_BADTRUSTBANTER2)); // // Adjust second text box location // GetWindowRect(WindowOf(IDC_BADTRUSTBANTER2), &rc2); rc2.top = rc1.bottom + spacing; ::SetWindowPos(WindowOf(IDC_BADTRUSTBANTER2), NULL, rc2.left - pt.x, rc2.top - pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); GetWindowRect(WindowOf(IDC_BADTRUSTBANTER2), &rc2); // // Adjust third text box location // GetWindowRect(WindowOf(IDC_BADTRUSTBANTER3), &rc3); h = Height(rc3); rc3.top = rc2.bottom + spacing; rc3.bottom = rc3.top + h; ::SetWindowPos(WindowOf(IDC_BADTRUSTBANTER3), NULL, rc3.left - pt.x, rc3.top - pt.y, Width(rc3), Height(rc3), SWP_NOZORDER); // // Adjust the button locations // RECT rcOk, rcCancel, rcDetails; GetWindowRect(WindowOf(IDOK), &rcOk); GetWindowRect(WindowOf(IDCANCEL), &rcCancel); GetWindowRect(WindowOf(IDC_DETAILS), &rcDetails); rcOk.top = rc3.bottom + spacing; rcCancel.top = rcOk.top; rcDetails.top = rcOk.top; ::SetWindowPos(WindowOf(IDOK), NULL, rcOk.left-pt.x, rcOk.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE); ::SetWindowPos(WindowOf(IDCANCEL), NULL, rcCancel.left-pt.x, rcCancel.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE); ::SetWindowPos(WindowOf(IDC_DETAILS), NULL, rcDetails.left-pt.x, rcDetails.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE); GetWindowRect(WindowOf(IDOK), &rcOk); GetWindowRect(WindowOf(IDCANCEL), &rcCancel); GetWindowRect(WindowOf(IDC_DETAILS), &rcDetails); // // Adjust the overall dialog box size // RECT rcMe; ::GetWindowRect(GetWindow(), &rcMe); // screen coords rcMe.bottom = rcOk.bottom + spacing + GetSystemMetrics(SM_CYFIXEDFRAME); ::SetWindowPos(GetWindow(), NULL, 0,0,Width(rcMe),Height(rcMe), SWP_NOZORDER | SWP_NOMOVE); // // Center ourselves in the parent window // HWND hwndParent = ::GetParent(GetWindow()); if (hwndParent == NULL) hwndParent = ::GetDesktopWindow(); RECT rcParent; ::GetWindowRect(GetWindow(), &rcMe); // screen coords ::GetWindowRect(hwndParent, &rcParent); // screen coords POINT ptParent = Center(rcParent); POINT ptMe = Center(rcMe); pt.x = ptParent.x - ptMe.x; pt.y = ptParent.y - ptMe.y; ::SetWindowPos ( GetWindow(), NULL, pt.x, pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE ); } // // Make sure we're on the screen // EnsureOnScreen(GetWindow()); // // Bring ourselves to the attention of the user // SetForegroundWindow(GetWindow()); }
void MpButton::Draw (void) { // draw pixmap icon if (pixmap) { int // clip boundaries copy_w = MpMin((int)icon_width,Width()-2*GetFrameTotalWidth()), copy_h = MpMin((int)icon_height,Height()-2*GetFrameTotalWidth()), src_x = MpMin(0,icon_width-copy_w), src_y = MpMin(0,icon_height-copy_h), // copy destination dest_x = (state & icon_align_left) // left aligned icon ? GetFrameTotalWidth()+GetXPadding() : (state & icon_align_right) // right aligned icon ? Width()-GetFrameTotalWidth()-copy_w-GetXPadding() : (Width()-copy_w)/2, // centered icon dest_y = (Height()-copy_h)/2; // set clip mask if (mask) { XSetClipOrigin(Mp.theDisplay,Mp.theTextGC,dest_x,dest_y); XSetClipMask(Mp.theDisplay,Mp.theTextGC,mask); } // draw icon XCopyArea(Mp.theDisplay,pixmap,Win(),Mp.theTextGC, src_x,src_y, copy_w,copy_h, dest_x,dest_y); // reset clip mask if (mask) XSetClipMask(Mp.theDisplay,Mp.theTextGC,None); // draw label together with left or right aligned icon if (state & icon_align_left) { PlaceText(Get().c_str(), MpRectangle<short>(GetFrameTotalWidth()+copy_w+GetXPadding(), GetFrameTotalWidth()+GetYPadding(), Width()-2*GetFrameTotalWidth()-copy_w-GetXPadding(), Height()-2*GetFrameTotalWidth()-GetYPadding()), GetFont(), (state & in_pulldown) ? ((GetMode() & ~AlignMask) | AlignLeft | AlignVCenter) : GetMode()); } else if (state & icon_align_right) { PlaceText(Get().c_str(), MpRectangle<short>(GetFrameTotalWidth()+GetXPadding(), GetFrameTotalWidth()+GetYPadding(), Width()-2*GetFrameTotalWidth()-copy_w-GetXPadding(), Height()-2*GetFrameTotalWidth()-GetYPadding()), GetFont(), (state & in_pulldown) ? ((GetMode() & ~AlignMask) | AlignLeft | AlignVCenter) : GetMode()); } // else text string is not drawn // no icon } else { // In a pulldown menu the labels are always aligned left, otherwise // the aligment is not overwritten. PlaceText(Get().c_str(), GetXPadding() + GetFrameTotalWidth(), GetYPadding() + GetFrameTotalWidth(), GetFont(), (state & in_pulldown) ? ((GetMode() & ~AlignMask) | AlignLeft | AlignVCenter) : GetMode()); } }
void RenderHeightMap(BYTE *pHeightMap, GLuint terrainTex) { int X = 0, Y = 0; // 点在高度图上的坐标 int x, y, z; // 点的三维坐标 BOOL bSwitchSides = FALSE; if (!pHeightMap) // 保证高度有效 { return; } glBindTexture(GL_TEXTURE_2D, terrainTex); // 绑定纹理 glBegin(GL_TRIANGLE_STRIP); // 开始绘制地形 for (X = 0; X <= MAP_SIZE; X += STEP_SIZE) // 遍历高度图 { if (bSwitchSides) // 是否从反方向读取高度图 { // 在当前X坐标上渲染地形 for (Y = MAP_SIZE; Y >= 0; Y -= STEP_SIZE) // 从MAP_SIZE到0 { // 取得底部左顶点的 (X, Y, Z)值 x = X; y = Height(pHeightMap, X, Y); z = Y; // 提交点并设置当前纹理坐标 SetTextureCoord((float)x, (float)z); glVertex3i(x, y, z); // 取得底部右顶点的 (X, Y, Z)值 x = X + STEP_SIZE; y = Height(pHeightMap, X + STEP_SIZE, Y); z = Y; // 提交点并设置当前纹理坐标 SetTextureCoord((float)x, (float)z); glVertex3i(x, y, z); } } else { // 在当前X坐标上渲染地形 for (Y = 0; Y <= MAP_SIZE; Y += STEP_SIZE) // 从0到MAP_SIZE { // 取得底部右顶点的(x, y, z)值 x = X + STEP_SIZE; y = Height(pHeightMap, X + STEP_SIZE, Y); z = Y; // 提交点并设置当前纹理坐标 SetTextureCoord((float)x, (float)z); glVertex3i(x, y, z); // 取得底部左顶点的(x, y, z)值 x = X; y = Height(pHeightMap, X, Y); z = Y; // 提交点并设置当前纹理坐标 SetTextureCoord((float)x, (float)z); glVertex3i(x, y, z); } } bSwitchSides = !bSwitchSides; // 改变绘制方向 } glEnd(); // 结束绘制地形 }
} // We must use a lazy algorithm so that the symmetric pivoting does not move // data from a fully-updated to partially-updated region (and vice-versa) template<typename F> inline void Panel ( Matrix<F>& AFull, Matrix<F>& dSub, Matrix<Int>& p, Matrix<F>& X, Matrix<F>& Y, Int bsize, Int off=0, bool conjugate=false, LDLPivotType pivotType=BUNCH_KAUFMAN_A, Base<F> gamma=0 ) { DEBUG_ONLY(CSE cse("ldl::pivot::Panel")) const Int nFull = AFull.Height(); auto A = AFull( IR(off,nFull), IR(off,nFull) ); const Int n = A.Height(); Zeros( X, n, bsize ); Zeros( Y, n, bsize ); if( n == 0 ) return; DEBUG_ONLY( if( A.Width() != n ) LogicError("A must be square"); if( dSub.Height() != n-1 || dSub.Width() != 1 ) LogicError("dSub is the wrong size" ); if( p.Height() != n || p.Width() != 1 ) LogicError("permutation vector is the wrong size"); ) Int k=0; while( k < bsize )
//============================================================================= void ZernikeMom::FindSegmentNormalisations(){ // first find the middle points of segments map<int,int> counts; int frame=SegmentData()->getCurrentFrame(); x_avg.clear(); y_avg.clear(); scaling.clear(); int width = Width(true), height = Height(true); for (int y=0; y<height; y++) for (int x=0; x<width; x++){ vector<int> svec = SegmentVector(frame, x, y); for (size_t j=0; j<svec.size(); j++) { const int label=svec[j]; if(counts.count(label)) counts[label]++; else counts[label]=1; if(x_avg.count(label)){ x_avg[label] += x; y_avg[label] += y; } else{ x_avg[label] = x; y_avg[label] = y; } } } map<int,double>::iterator it; for(it=x_avg.begin();it != x_avg.end();it++){ const int l=it->first; it->second /= counts[l]; y_avg[l] /= counts[l]; } // now the segment middle points are calculated // then find the sizes of the segments, i.e. their largest // (x-x_avg)^2 + (y-y_avg)^2 for (int y=0; y<height; y++) for (int x=0; x<width; x++){ vector<int> svec = SegmentVector(frame, x, y); for (size_t j=0; j<svec.size(); j++) { const int label=svec[j]; double dx=x-x_avg[label]; double dy=y-y_avg[label]; double r2=dx*dx+dy*dy; if(scaling.count(label)){ if(r2>scaling[label]) scaling[label]=r2; } else scaling[label]=r2; } } // invert the scaling and take square root for(it=scaling.begin();it != scaling.end();it++) if(it->second) it->second=1/sqrt(it->second); }
GlowWidget::AutoPackError GlowWidgetLabelWidget::OnAutoPack( int hSize, int vSize, AutoPackOptions hOption, AutoPackOptions vOption, int& leftMargin, int& rightMargin, int& topMargin, int& bottomMargin) { GLOW_DEBUGSCOPE("GlowWidgetLabelWidget::OnAutoPack"); int hnew = Width(); int pwidth = 0, pheight = 0; FindPreferredSize(pwidth, pheight); if (hSize != unspecifiedSize) { if (hSize < 2) { return hAutoPackError; } if (hSize < pwidth) { pwidth = hSize; } } if (hOption == forcedSize || hOption == expandPreferredSize) { hnew = hSize; } else if (hOption == preferredSize) { hnew = pwidth; } int vnew = Height(); if (vSize != unspecifiedSize) { if (vSize < 2) { return vAutoPackError; } if (vSize < pheight) { pheight = vSize; } } if (vOption == forcedSize || vOption == expandPreferredSize) { vnew = vSize; } else if (vOption == preferredSize) { vnew = pheight; } Reshape(hnew, vnew); return noAutoPackError; }
void IGraphics::PrepDraw() { mDrawBitmap = new LICE_SysBitmap(Width(), Height()); mTmpBitmap = new LICE_MemBitmap(); }
void LowerBlocked ( AbstractDistMatrix<F>& APre, AbstractDistMatrix<F>& householderScalarsPre ) { DEBUG_CSE DEBUG_ONLY(AssertSameGrids( APre, householderScalarsPre )) DistMatrixReadWriteProxy<F,F,MC,MR> AProx( APre ); DistMatrixWriteProxy<F,F,STAR,STAR> householderScalarsProx( householderScalarsPre ); auto& A = AProx.Get(); auto& householderScalars = householderScalarsProx.Get(); const Grid& g = A.Grid(); const Int n = A.Height(); householderScalars.Resize( Max(n-1,0), 1 ); DistMatrix<F,MC,STAR> UB1_MC_STAR(g), V21_MC_STAR(g); DistMatrix<F,MR,STAR> V01_MR_STAR(g), VB1_MR_STAR(g), UB1_MR_STAR(g); DistMatrix<F,STAR,STAR> G11_STAR_STAR(g); const Int bsize = Blocksize(); for( Int k=0; k<n-1; k+=bsize ) { const Int nb = Min(bsize,n-1-k); const Range<Int> ind0( 0, k ), ind1( k, k+nb ), indB( k, n ), indR( k, n ), ind2( k+nb, n ); auto ABR = A( indB, indR ); auto A22 = A( ind2, ind2 ); auto householderScalars1 = householderScalars( ind1, ALL ); UB1_MC_STAR.AlignWith( ABR ); UB1_MR_STAR.AlignWith( ABR ); VB1_MR_STAR.AlignWith( ABR ); UB1_MC_STAR.Resize( n-k, nb ); UB1_MR_STAR.Resize( n-k, nb ); VB1_MR_STAR.Resize( n-k, nb ); G11_STAR_STAR.Resize( nb, nb ); hessenberg::LowerPanel ( ABR, householderScalars1, UB1_MC_STAR, UB1_MR_STAR, VB1_MR_STAR, G11_STAR_STAR ); auto AB0 = A( indB, ind0 ); auto A2R = A( ind2, indR ); auto U21_MC_STAR = UB1_MC_STAR( IR(nb,END), ALL ); // AB0 := AB0 - (UB1 inv(G11)^H UB1^H AB0) // = AB0 - (UB1 ((AB0^H UB1) inv(G11))^H) // ------------------------------------------- V01_MR_STAR.AlignWith( AB0 ); Zeros( V01_MR_STAR, k, nb ); LocalGemm( ADJOINT, NORMAL, F(1), AB0, UB1_MC_STAR, F(0), V01_MR_STAR ); El::AllReduce( V01_MR_STAR, AB0.ColComm() ); LocalTrsm ( RIGHT, UPPER, NORMAL, NON_UNIT, F(1), G11_STAR_STAR, V01_MR_STAR ); LocalGemm ( NORMAL, ADJOINT, F(-1), UB1_MC_STAR, V01_MR_STAR, F(1), AB0 ); // A2R := (A2R - U21 inv(G11)^H VB1^H)(I - UB1 inv(G11) UB1^H) // ----------------------------------------------------------- // A2R := A2R - U21 inv(G11)^H VB1^H // (note: VB1 is overwritten) LocalTrsm ( RIGHT, UPPER, NORMAL, NON_UNIT, F(1), G11_STAR_STAR, VB1_MR_STAR ); LocalGemm ( NORMAL, ADJOINT, F(-1), U21_MC_STAR, VB1_MR_STAR, F(1), A2R ); // A2R := A2R - ((A2R UB1) inv(G11)) UB1^H V21_MC_STAR.AlignWith( A2R ); Zeros( V21_MC_STAR, A2R.Height(), nb ); LocalGemm( NORMAL, NORMAL, F(1), A2R, UB1_MR_STAR, F(0), V21_MC_STAR ); El::AllReduce( V21_MC_STAR, A2R.RowComm() ); LocalTrsm ( RIGHT, UPPER, NORMAL, NON_UNIT, F(1), G11_STAR_STAR, V21_MC_STAR ); LocalGemm ( NORMAL, ADJOINT, F(-1), V21_MC_STAR, UB1_MR_STAR, F(1), A2R ); } }
// The OS is announcing what needs to be redrawn, // which may be a larger area than what is strictly dirty. bool IGraphics::Draw(IRECT* pR) { // #pragma REMINDER("Mutex set while drawing") // WDL_MutexLock lock(&mMutex); int i, j, n = mControls.GetSize(); if (!n) { return true; } if (mStrict) { mDrawRECT = *pR; int n = mControls.GetSize(); IControl** ppControl = mControls.GetList(); for (int i = 0; i < n; ++i, ++ppControl) { IControl* pControl = *ppControl; if (!(pControl->IsHidden()) && pR->Intersects(pControl->GetRECT())) { pControl->Draw(this); } pControl->SetClean(); } } else { IControl* pBG = mControls.Get(0); if (pBG->IsDirty()) // Special case when everything needs to be drawn. { mDrawRECT = *(pBG->GetRECT()); for (int j = 0; j < n; ++j) { IControl* pControl2 = mControls.Get(j); if (!j || !(pControl2->IsHidden())) { pControl2->Draw(this); pControl2->SetClean(); } } } else { for (i = 1; i < n; ++i) // loop through all controls starting from one (not bg) { IControl* pControl = mControls.Get(i); // assign control i to pControl if (pControl->IsDirty()) // if pControl is dirty { // printf("control %i is Dirty\n", i); mDrawRECT = *(pControl->GetRECT()); // put the rect in the mDrawRect member variable for (j = 0; j < n; ++j) // loop through all controls { IControl* pControl2 = mControls.Get(j); // assign control j to pControl2 // if control1 == control2 OR control2 is not hidden AND control2's rect intersects mDrawRect if (!pControl2->IsHidden() && (i == j || pControl2->GetRECT()->Intersects(&mDrawRECT))) { //if ((i == j) && (!pControl2->IsHidden())|| (!(pControl2->IsHidden()) && pControl2->GetRECT()->Intersects(&mDrawRECT))) { //printf("control %i and %i \n", i, j); pControl2->Draw(this); } } pControl->SetClean(); } } } } #ifndef NDEBUG if (mShowControlBounds) { for (int j = 1; j < mControls.GetSize(); j++) { IControl* pControl = mControls.Get(j); DrawRect(&CONTROL_BOUNDS_COLOR, pControl->GetRECT()); } WDL_String str; str.SetFormatted(32, "x: %i, y: %i", mMouseX, mMouseY); IText txt(20, &CONTROL_BOUNDS_COLOR); IRECT rect(Width() - 150, Height() - 20, Width(), Height()); DrawIText(&txt, str.Get(), &rect); } #endif return DrawScreen(pR); }
void IntroScreen::DoLayout() { m_splash->Resize(this->Size()); m_logo->Resize(GG::Pt(this->Width(), this->Height() / 10)); m_version->MoveTo(GG::Pt(this->Width() - m_version->Width(), this->Height() - m_version->Height())); //size calculation consts and variables const GG::X MIN_BUTTON_WIDTH(160); const GG::Y MIN_BUTTON_HEIGHT(40); GG::X button_width(0); //width of the buttons GG::Y button_cell_height(0); //height of the buttons const GG::X H_MAINMENU_MARGIN(40); //horizontal empty space const GG::Y V_MAINMENU_MARGIN(40); //vertical empty space GG::X mainmenu_width(0); //width of the mainmenu GG::Y mainmenu_height(0); //height of the mainmenu //calculate necessary button width button_width = std::max(button_width, m_single_player->MinUsableSize().x); button_width = std::max(button_width, m_quick_start->MinUsableSize().x); button_width = std::max(button_width, m_multi_player->MinUsableSize().x); button_width = std::max(button_width, m_load_game->MinUsableSize().x); button_width = std::max(button_width, m_options->MinUsableSize().x); button_width = std::max(button_width, m_pedia->MinUsableSize().x); button_width = std::max(button_width, m_about->MinUsableSize().x); button_width = std::max(button_width, m_website->MinUsableSize().x); button_width = std::max(button_width, m_credits->MinUsableSize().x); button_width = std::max(button_width, m_exit_game->MinUsableSize().x); button_width = std::max(MIN_BUTTON_WIDTH, button_width); //calculate necessary button height button_cell_height = std::max(MIN_BUTTON_HEIGHT, m_exit_game->MinUsableSize().y); //culate window width and height mainmenu_width = button_width + H_MAINMENU_MARGIN; mainmenu_height = 10.75 * button_cell_height + V_MAINMENU_MARGIN; // 10 rows + 0.75 before exit button // place buttons GG::Pt button_ul(GG::X(15), GG::Y(12)); GG::Pt button_lr(button_width, m_exit_game->MinUsableSize().y); button_lr += button_ul; m_single_player->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_quick_start->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_multi_player->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_load_game->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_options->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_pedia->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_about->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_website->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height); button_lr.y += GG::Y(button_cell_height); m_credits->SizeMove(button_ul, button_lr); button_ul.y += GG::Y(button_cell_height) * 1.75; button_lr.y += GG::Y(button_cell_height) * 1.75; m_exit_game->SizeMove(button_ul, button_lr); // position menu window GG::Pt ul(Width() * GetOptionsDB().Get<double>("UI.main-menu.x") - mainmenu_width/2, Height() * GetOptionsDB().Get<double>("UI.main-menu.y") - mainmenu_height/2); GG::Pt lr(Width() * GetOptionsDB().Get<double>("UI.main-menu.x") + mainmenu_width/2, Height() * GetOptionsDB().Get<double>("UI.main-menu.y") + mainmenu_height/2); m_menu->SizeMove(ul, lr); }
void WebListBox::GetFrameRect(WebRect *rect) { rect->Set(0,0,Width()-1,Height()-1); }
float Slope(float x) const { return ((Height(x + dx) - Height(x)) / dx); }
void WebListBox::GetContentRect(WebRect *rect) { DISPLAY_INT pad = GetMargin() + GetPadding() + GetBorder(); rect->Set(pad, pad, Width() - pad - 1, Height() - pad - 1); }
static size_t BalanceFactor(pNode p) { if (!p) return 0; return Height(p->Right) - Height(p->Left); }
bool Cone::InitAverage(const MiscLib::Vector< Vec3f > &samples) { // setup all the planes size_t c = samples.size() / 2; MiscLib::Vector< GfxTL::Vector4Df > planes(c); #pragma omp parallel for schedule(static) for (int i = 0; i < static_cast<int>(c); ++i) { for(unsigned int j = 0; j < 3; ++j) planes[i][j] = samples[i][j]; planes[i][3] = samples[i].dot(samples[i + c]); } // compute center by intersecting the three planes given by (p1, n1) // (p2, n2) and (p3, n3) // set up linear system double a[4 * 3]; double d1 = samples[0].dot(samples[c + 0]); double d2 = samples[1].dot(samples[c + 1]); double d3 = samples[2].dot(samples[c + 2]); // column major a[0 + 0 * 3] = samples[c + 0][0]; a[1 + 0 * 3] = samples[c + 1][0]; a[2 + 0 * 3] = samples[c + 2][0]; a[0 + 1 * 3] = samples[c + 0][1]; a[1 + 1 * 3] = samples[c + 1][1]; a[2 + 1 * 3] = samples[c + 2][1]; a[0 + 2 * 3] = samples[c + 0][2]; a[1 + 2 * 3] = samples[c + 1][2]; a[2 + 2 * 3] = samples[c + 2][2]; a[0 + 3 * 3] = d1; a[1 + 3 * 3] = d2; a[2 + 3 * 3] = d3; if(dmat_solve(3, 1, a)) return false; m_center[0] = a[0 + 3 * 3]; m_center[1] = a[1 + 3 * 3]; m_center[2] = a[2 + 3 * 3]; LevMarPlaneDistance planeDistance; LevMar(planes.begin(), planes.end(), planeDistance, (float *)m_center); MiscLib::Vector< GfxTL::Vector3Df > spoints(c); #pragma omp parallel for schedule(static) for (int i = 0; i < static_cast<int>(c); ++i) { spoints[i] = GfxTL::Vector3Df(samples[i] - m_center); spoints[i].Normalize(); } GfxTL::Vector3Df axisDir; GfxTL::MeanOfNormals(spoints.begin(), spoints.end(), &axisDir); m_axisDir = GfxTL::Vector3Df(axisDir); // make sure axis points in good direction // the axis is defined to point into the interior of the cone float heightSum = 0; #pragma omp parallel for schedule(static) reduction(+:heightSum) for(int i = 0; i < static_cast<int>(c); ++i) heightSum += Height(samples[i]); if(heightSum < 0) m_axisDir *= -1; float angleReduction = 0; #pragma omp parallel for schedule(static) reduction(+:angleReduction) for(int i = 0; i < static_cast<int>(c); ++i) { float angle = m_axisDir.dot(samples[i + c]); if(angle < -1) // clamp angle to [-1, 1] angle = -1; else if(angle > 1) angle = 1; if(angle < 0) // m_angle = omega + 90 angle = std::acos(angle) - float(M_PI) / 2; else // m_angle = 90 - omega angle = float(M_PI) / 2 - std::acos(angle); angleReduction += angle; } angleReduction /= c; m_angle = angleReduction; if(m_angle < 1.0e-6 || m_angle > float(M_PI) / 2 - 1.0e-6) return false; //if(m_angle > 1.3962634015954636615389526147909) // 80 degrees if(m_angle > 1.4835298641951801403851371532153f) // 85 degrees return false; m_normal = Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0); m_normalY = m_normal[1] * m_axisDir; m_n2d[0] = std::cos(m_angle); m_n2d[1] = -std::sin(m_angle); m_hcs.FromNormal(m_axisDir); m_angularRotatedRadians = 0; return true; }
BOOL CClientCapture::DrawBitmap(CDC *dc, HDC hDC, CRect *rect, CRect *dest, CBitmap &bitmap){ ////////////////////////////////////////////////////// // Create logical palette if device support a palette if( dc->GetDeviceCaps(RASTERCAPS) & RC_PALETTE ) { UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256); LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize]; pLP->palVersion = 0x300; pLP->palNumEntries = GetSystemPaletteEntries( *dc, 0, 255, pLP->palPalEntry ); // Create the palette pal.CreatePalette( pLP ); delete[] pLP; } // END CREATE PALETTE ////////////////////////////////////////////////////// ///////////////////////////// ///////////////////////////// BITMAP bm; BITMAPINFOHEADER bi; DWORD dwLen; HANDLE handle; HDC hPDC; HPALETTE hPal; ASSERT( bitmap.GetSafeHandle() ); // If a palette has not been supplied use defaul palette hPal = (HPALETTE) pal.GetSafeHandle(); if (hPal==NULL) hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE); // Get bitmap information bitmap.GetObject(sizeof(bm),(LPSTR)&bm); // Initialize the bitmapinfoheader bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bm.bmWidth; bi.biHeight = bm.bmHeight; bi.biPlanes = 1; bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; // Compute the size of the infoheader and the color table int nColors = (1 << bi.biBitCount); if( nColors > 256 ) nColors = 0; dwLen = bi.biSize + nColors * sizeof(RGBQUAD); // We need a device context to get the DIB from hPDC = dc->GetSafeHdc(); //hDC = GetDC(NULL); hPal = SelectPalette(hPDC,hPal,FALSE); RealizePalette(hPDC); // Allocate enough memory to hold bitmapinfoheader and color table if(hDIB) GlobalFree( hDIB ); hDIB = GlobalAlloc(GMEM_FIXED,dwLen); if (!hDIB){ SelectPalette(hPDC,hPal,FALSE); return NULL; } lpbi = (LPBITMAPINFOHEADER)hDIB; *lpbi = bi; // Call GetDIBits with a NULL lpBits param, so the device driver // will calculate the biSizeImage field GetDIBits(hPDC, (HBITMAP)bitmap.GetSafeHandle(), 0L, (DWORD)bi.biHeight, (LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS); bi = *lpbi; // If the driver did not fill in the biSizeImage field, then compute it // Each scan line of the image is aligned on a DWORD (32bit) boundary if (bi.biSizeImage == 0){ bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8) * bi.biHeight; } // Realloc the buffer so that it can hold all the bits dwLen += bi.biSizeImage; if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE)) hDIB = handle; else{ GlobalFree(hDIB); hDIB = 0; // Reselect the original palette SelectPalette(hDC,hPal,FALSE); return NULL; } // Get the bitmap bits lpbi = (LPBITMAPINFOHEADER)hDIB; m_pBMI = (LPBITMAPINFO)hDIB; m_pBits = (LPBYTE)hDIB + (bi.biSize + nColors * sizeof(RGBQUAD)); /////////////////////////////////////////////// /////////////////////////////////////////////// HPALETTE hOldPal = NULL; // Previous palette // Get the DIB's palette, then select it into DC if (&pal != NULL) { hPal = (HPALETTE) pal.m_hObject; // Select as background since we have // already realized in forground if needed hOldPal = ::SelectPalette(hDC, hPal, TRUE); } /* Make sure to use the stretching mode best for color pictures */ ::SetStretchBltMode(hDC, COLORONCOLOR); BOOL bSuccess = FALSE; UINT start(0), end, step_size(1);//, offset_y(0); end = step_size; if((UINT)bm.bmHeight < step_size) end = (int)bm.bmHeight; while(start < (UINT)bm.bmHeight){ GetDIBits( hPDC, (HBITMAP)bitmap.GetSafeHandle(), start, // Start scan line end - start, // # of scan lines (LPBYTE) m_pBits, //lpbi // address for bitmap bits (LPBITMAPINFO)lpbi, // address of bitmapinfo (DWORD)DIB_RGB_COLORS); // Use RGB for color table bSuccess = ::SetDIBitsToDevice(hDC, // hDC rect->left, // DestX rect->top, // DestY RECTWIDTH(rect), // nDestWidth RECTHEIGHT(rect), // nDestHeight rect->left, // SrcX (int)Height() - rect->top - RECTHEIGHT(rect), // SrcY start, // nStartScan end - start, // nNumScans m_pBits, // lpBits m_pBMI, // lpBitsInfo DIB_RGB_COLORS); // wUsage start = end; end = start + step_size; if((UINT)bm.bmHeight < end) end = (UINT)bm.bmHeight; } /* Reselect old palette */ if (hOldPal != NULL) { ::SelectPalette(hDC, hOldPal, TRUE); } return bSuccess; }
size_t FirewireVideo::SizeBytes() const { return (Width() * Height() * VideoFormatFromString(PixFormat()).bpp) / 8; }
void Panel::Draw() { //Draw panel KrRGBA *pixels = getCanvasResource()->Pixels(); ColorScheme* cs = get_color_scheme(); int width = Width(), height = Height(); if(flags.IsSet(FLAG_HASSHADOWS)) { width -= SHADOW_THICKNESS; height -= SHADOW_THICKNESS; } if(bInvertBevel) { KrRGBA aux; aux = colorUp; colorUp = colorDown; colorDown = aux; } //Fill background int i, j; for(j = 0; j < height; j++) { KrRGBA color(SlowCanvas::MixColors(Panel::getColorUp(), Panel::getColorDown(), j/(double)height)); for(i = 0; i < width; i++) { pixels[ j*Width() + i ] = color; } } //Glass effect if(height < 55) { KrRGBA glass(cs->editor_glass_r, cs->editor_glass_g, cs->editor_glass_b); int hm = height/2; for(j = 0; j < hm; j++) { for(i = 0; i < width; i++) { pixels[ j*Width() + i ] = SlowCanvas::MixColors(pixels[ j*Width() + i ], glass, .8*j/(double)hm); } } } KrRGBA colorBorder(cs->editor_border_r, cs->editor_border_g, cs->editor_border_b); //Horizontal lines for(i = 0; i < width; i++) { pixels[ i ] = colorBorder; pixels[ (height-1)*Width() + i ] = colorBorder; } //Vertical lines for(j = 0; j < height; j++) { pixels[ j*Width() ] = colorBorder; pixels[ j*Width() + (width-1) ] = colorBorder; } //Corner pixels pixels[ 1 + 1*Width() ] = colorBorder; pixels[ (width - 2) + 1*Width() ] = colorBorder; pixels[ (width - 2) + (height - 2)*Width() ] = colorBorder; pixels[ 1 + (height - 2)*Width() ] = colorBorder; //Restore colors if(bInvertBevel) { KrRGBA aux; aux = colorUp; colorUp = colorDown; colorDown = aux; } //Make trasparent corners KrRGBA transp(0, 0, 0, 0); pixels[ 0 + 0*Width() ] = transp; pixels[ 1 + 0*Width() ] = transp; pixels[ 0 + 1*Width() ] = transp; pixels[ (width - 1) + 0*Width() ] = transp; pixels[ (width - 2) + 0*Width() ] = transp; pixels[ (width - 1) + 1*Width() ] = transp; if(!flags.IsSet(FLAG_HASSHADOWS)) { pixels[ (width - 1) + (height - 1)*Width() ] = transp; pixels[ (width - 2) + (height - 1)*Width() ] = transp; pixels[ (width - 1) + (height - 2)*Width() ] = transp; } pixels[ 0 + (height - 1)*Width() ] = transp; pixels[ 1 + (height - 1)*Width() ] = transp; pixels[ 0 + (height - 2)*Width() ] = transp; if(flags.IsSet(FLAG_HASSHADOWS)) { KrRGBA colorShadow; double shadowFactor; colorShadow.c.red = cs->editor_shadow_r; colorShadow.c.green = cs->editor_shadow_g; colorShadow.c.blue = cs->editor_shadow_b; colorShadow.c.alpha = SHADOW_MAX; //Corner pixels[ (width - 1) + (height - 1)*Width() ] = colorShadow; pixels[ (width - 2) + (height - 1)*Width() ] = colorShadow; pixels[ (width - 1) + (height - 2)*Width() ] = colorShadow; //Vertical shadow for(i = width; i < Width(); i++) { for(int j = SHADOW_THICKNESS; j < Height(); j++) { shadowFactor = 1.0 - (i - width)/(double)SHADOW_THICKNESS; shadowFactor *= (j >= height)?(1.0 - (j - height)/(double)SHADOW_THICKNESS):1.0; shadowFactor *= (j - SHADOW_THICKNESS < SHADOW_FADE)?(j - SHADOW_THICKNESS)/(double)SHADOW_FADE:1.0; colorShadow.c.alpha = SHADOW_MAX*shadowFactor; pixels[ j*Width() + i ] = colorShadow; } } //Horizontal shadow for(i = SHADOW_THICKNESS; i < Width() - SHADOW_THICKNESS; i++) { for(int j = height; j < Height(); j++) { shadowFactor = 1.0 - (j - height)/(double)SHADOW_THICKNESS; shadowFactor *= (i - SHADOW_THICKNESS < SHADOW_FADE)?(i - SHADOW_THICKNESS)/(double)SHADOW_FADE:1.0; colorShadow.c.alpha = SHADOW_MAX*shadowFactor; pixels[ j*Width() + i ] = colorShadow; } } } getCanvasResource()->Refresh(); }
inline int IASRect::Area() const { return Width() * Height(); }