void GBDebuggerView::AcceptClick(short x, short y, int /*clicks*/) { UpdateTarget(); if ( target && x > Width() / 2 && x < Width() - kEdgeSpace && y > kEdgeSpace + kStatusBoxHeight - 10 && y < kEdgeSpace + kStatusBoxHeight ) StartStopBrain(); }
Geom::PointInt Viewer::CenterPositionScreen() { auto rect = wxToRect(GetScreenRect()); return { rect.Left() + rect.Width() / 2, rect.Top() + rect.Height() / 2 }; }
// MessageReceiced void DimensionsControl::MessageReceived(BMessage *message) { switch (message->what) { case MSG_WIDTH_CHANGED: SetWidth(Width()); break; case MSG_HEIGHT_CHANGED: SetHeight(Height()); break; case MSG_COMMON_FORMAT: { int32 format; if (message->FindInt32("format", &format) == B_OK) { uint32 width; uint32 height; switch (format) { case FORMAT_160_120: width = 160; height = 120; break; case FORMAT_320_240: width = 320; height = 240; break; case FORMAT_400_300: width = 400; height = 300; break; case FORMAT_640_480: width = 640; height = 480; break; case FORMAT_800_600: width = 800; height = 600; break; case FORMAT_1024_768: width = 1024; height = 768; break; case FORMAT_1152_864: width = 1152; height = 864; break; case FORMAT_1280_800: width = 1280; height = 800; break; case FORMAT_1280_960: width = 1280; height = 960; break; case FORMAT_1280_1024: width = 1280; height = 1024; break; case FORMAT_1400_1050: width = 1400; height = 1050; break; case FORMAT_1600_1200: width = 1600; height = 1200; break; case FORMAT_1920_1200: width = 1920; height = 1200; break; case FORMAT_2048_1536: width = 2048; height = 1536; break; case FORMAT_384_288: width = 384; height = 288; break; case FORMAT_768_576: width = 768; height = 576; break; case FORMAT_720_540: width = 720; height = 540; break; case FORMAT_1280_720: width = 1280; height = 720; break; case FORMAT_1920_1080: width = 1920; height = 1080; break; case FORMAT_352_240: width = 352; height = 240; break; case FORMAT_768_524: width = 768; height = 524; break; case FORMAT_720_492: width = 720; height = 492; break; case FORMAT_720_480: width = 720; height = 480; break; case FORMAT_720_576: width = 720; height = 576; break; case FORMAT_384_216: width = 384; height = 216; break; case FORMAT_768_432: width = 768; height = 432; break; case FORMAT_720_405: width = 720; height = 405; break; case FORMAT_384_164: width = 384; height = 164; break; case FORMAT_768_327: width = 768; height = 327; break; case FORMAT_720_306: width = 720; height = 306; break; default: width = 384; height = 288; break; } _SetDimensions(width, height); } break; } default: BGridView::MessageReceived(message); break; } }
int ColorSample::Right() { return getImage()->X() + Width(); }
QRectF QAttribute::boundingRect() const { return QRectF(ref->x()+AvX(),ref->Ay(),Width(),Height()); }
void cPlayer::Render() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, playerSheet->at(animControl->Index())->Texture()); glBegin(GL_QUADS); glTexCoord2f(playerSheet->at(animControl->Index())->X0(), playerSheet->at(animControl->Index())->Y1()); glVertex3i(x, y, 49); glTexCoord2f(playerSheet->at(animControl->Index())->X1(), playerSheet->at(animControl->Index())->Y1()); glVertex3i(x + Width(), y, 49); glTexCoord2f(playerSheet->at(animControl->Index())->X1(), playerSheet->at(animControl->Index())->Y0()); glVertex3i(x + Width(), y + Height(), 49); glTexCoord2f(playerSheet->at(animControl->Index())->X0(), playerSheet->at(animControl->Index())->Y0()); glVertex3i(x, y + Height(), 49); glEnd(); glDisable(GL_TEXTURE_2D); }
inline AIReal IASRealRectCartesian::Area() const { return Width() * Height(); }
// Column major grid dissection order for the sparse // QR decomposition algorithm. void grid_dissection_order( const grid2 *g0, int *perm ) { int width = Width(*g0); int height = Height(*g0); int size = width*height; int mid, x, y, i, *p; grid2 g1, g2, gs; g1 = g2 = gs = *g0; if( width >= 4 || height >= 4 ) { #ifdef DEBUG_DISSECTION_ORDER printf( "dissecting %dx%d grid based at %d:\n", width, height, g0->base ); #endif if( width < height ) { mid = height / 2; // 1st grid g1.ran[1][1] = g0->ran[1][0] + mid-1; // 2nd grid g2.base = g0->base + Size(g1); g2.ran[1][0] = g0->ran[1][0] + mid+1; // Separating grid gs.base = g2.base + Size(g2); gs.ran[1][0] = g0->ran[1][0] + mid-1; gs.ran[1][1] = g0->ran[1][0] + mid+1; #ifdef DEBUG_DISSECTION_ORDER printf( "\tg1: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g1.base, g1.ran[0][0], g1.ran[0][1], g1.ran[1][0], g1.ran[1][1] ); printf( "\tgs: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", gs.base, gs.ran[0][0], gs.ran[0][1], gs.ran[1][0], gs.ran[1][1] ); printf( "\tg2: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g2.base, g2.ran[0][0], g2.ran[0][1], g2.ran[1][0], g2.ran[1][1] ); printf( "\n" ); printf( "Mapping Nodes:\n" ); #endif for( i=g0->base, p=perm+i; i < size; ++i, ++p ) { Node(*g0,i,x,y); #ifdef DEBUG_DISSECTION_ORDER printf( "\tNode %d @ (%d,%d) -> ", i, x, y ); if( y >= g2.ran[1][0] ) printf("%d (g2)\n", Index(g2,x,y)); else if( y >= gs.ran[1][0] ) printf("%d (gs)\n", Index(gs,x,y)); else printf("%d (g1)\n", Index(g1,x,y)); #endif if( y >= g2.ran[1][0] ) {*p = Index(g2,x,y); continue;} if( y >= gs.ran[1][0] ) {*p = Index(gs,x,y); continue;} *p = Index(g1,x,y); } // for( i, p ) grid_dissection_order( &g1, perm ); grid_dissection_order( &g2, perm ); } else { // width >= height mid = width / 2; // 1st grid g1.ran[0][1] = g0->ran[0][0] + mid-1; // 2nd grid g2.base = g0->base + Size(g1); g2.ran[0][0] = g0->ran[0][0] + mid+1; // Separating grid gs.base = g2.base + Size(g2); gs.ran[0][0] = g0->ran[0][0] + mid-1; gs.ran[0][1] = g0->ran[0][0] + mid+1; #ifdef DEBUG_DISSECTION_ORDER printf( "\tg1: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g1.base, g1.ran[0][0], g1.ran[0][1], g1.ran[1][0], g1.ran[1][1] ); printf( "\tgs: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", gs.base, gs.ran[0][0], gs.ran[0][1], gs.ran[1][0], gs.ran[1][1] ); printf( "\tg2: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g2.base, g2.ran[0][0], g2.ran[0][1], g2.ran[1][0], g2.ran[1][1] ); printf( "\n" ); printf( "Mapping Nodes:\n" ); #endif i = Index(*g0,gs.ran[0][0],gs.ran[1][0]); for( p=perm+i; i < size; ++i, ++p ) { Node(*g0,i,x,y); #ifdef DEBUG_DISSECTION_ORDER printf( "\tNode %d @ (%d,%d) -> ", i, x, y ); if( x >= g2.ran[0][0] ) printf("%d (g2)\n", Index(g2,x,y)); else if( x >= gs.ran[0][0] ) printf("%d (gs)\n", Index(gs,x,y)); else printf("%d (g1)\n", *p); #endif if( x >= g2.ran[0][0] ) {*p = Index(g2,x,y); continue;} if( x >= gs.ran[0][0] ) {*p = Index(gs,x,y); continue;} } // for( i, p ) grid_dissection_order( &g1, perm ); grid_dissection_order( &g2, perm ); } // if( width < height ) } }
//----------------------------------------------------------------------- void TextBlock::OnRenderSizeChanged(std::uint32_t widthIn, std::uint32_t heightIn) { Width(widthIn); Height(heightIn); }
void MyWindow::OnCreate() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); // clear window first: it might take a moment before image loads glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(); // load image _images[0].Load("left.bmp"); _images[1].Load("right.bmp"); _images[2].Load("top.bmp"); _images[3].Load("bottom.bmp"); _images[4].Load("front.bmp"); _images[5].Load("back.bmp"); _images[6].Load("map.bmp"); glGenTextures(7, &_textures[0]); // build 2D mip-maps from image for (int i = 0; i<7;i++) { glBindTexture(GL_TEXTURE_2D, _textures[i]); _images[i].gluBuild2DMipmaps(); _images[i].Free(); }; // set the projection required glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0f, +1.0f, -1.0f, +1.0f, 1.0f, +10.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0,0, Width(), Height()); glEnable(GL_DEPTH_TEST); // set the background clear colour to black glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set the shade model to smooth (Gouraud shading) glShadeModel(GL_SMOOTH); // remove back faces glEnable(GL_CULL_FACE); _material1.create(Color::black(), Color(0.8f,0.8f,0.8f,1.0f)); _material2.create(Color::black(), Color(0.7f,0.7f,0.7f,1.0f)); _material3.create(Color::black(), Color::black(), Color::yellow()); // setup some lights (ambient is turned off on all lights) _light1.create(0, Color::black(), Color(0.5f,0.5f,0.5f,1.0f)); _light2.create(1, Color::black(), Color(0.5f,0.5f,0.5f,1.0f)); _light3.create(2, Color::black(), Color(0.5f,0.5f,0.0f,1.0f)); // turn the global ambient off by setting it to zero glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Color::black().rgba()); // Turn on the lights _light1.apply(); _light2.apply(); _light3.apply(); _cylinder.create(0.5f, 1.0f, 10, 5, true); // setup the two spheres _sphere1.create(0.1f, 10, 10, false); _sphere.create(1.0f, 40, 40, true); _cameraAngle = 30.0; _cameraPosition = -5.0; _cameraRotation = 0.0; _fullscreen = false; }
void CHudTexture::DrawSelf( int x, int y, const Color& clr ) const { DrawSelf( x, y, Width(), Height(), clr ); }
LONG BitmapButton::ProcessMessage(HWND hWnd, size_t msg, size_t wParam, LONG lParam) { if (msg == WM_LBUTTONDOWN) { long res = CallWindowProc(DefaultHandler, hWnd, msg, wParam, lParam); SendMessage(hWnd, BM_SETSTATE, (WPARAM)BST_PUSHED, 0); InvalidateRect(hWnd, NULL, false); return res; } else if (msg == WM_LBUTTONUP) { long res = CallWindowProc(DefaultHandler, hWnd, msg, wParam, lParam); SendMessage(hWnd, BM_SETSTATE, (WPARAM)0, 0); InvalidateRect(hWnd, NULL, false); return res; } else if ((msg == WM_COMMAND) || (msg == BN_CLICKED)) { if (clickHandler) { clickHandler(); return true; } else if (dClickHandler) { (clickListener->*dClickHandler)(); return true; } else return false; } else if (msg == WM_ERASEBKGND) { /* HBRUSH hOldBrush; HPEN hOldPen; RECT rect; HDC hDC; hDC = GetDC(hWnd); hOldBrush = (HBRUSH)SelectObject(hDC, erasePen); hOldPen = (HPEN)SelectObject(hDC, eraseBrush); GetUpdateRect(hWnd, &rect, FALSE); ::Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom); SelectObject(hDC, hOldPen); SelectObject(hDC, hOldBrush); InvalidateRect(hWnd, NULL, FALSE); */ return true; } else if (msg == WM_PAINT) { HDC tmp = dc; PAINTSTRUCT ps; RECT rect; BeginPaint(hWnd, &ps); rect.left = 0; rect.right = Width(); rect.top = 0; rect.bottom = Height(); HBRUSH hOldBrush = (HBRUSH)SelectObject(dc, erasePen); HPEN hOldPen = (HPEN)SelectObject(dc, eraseBrush); ::Rectangle(dc, rect.left, rect.top, rect.right, rect.bottom); SelectObject(dc, hOldPen); SelectObject(dc, hOldBrush); int state = SendMessage(hWnd, BM_GETSTATE, 0, 0); Bitmap *bit; int offset; if ((state & BST_PUSHED) == 0) { DrawEdge(dc, &rect, EDGE_RAISED, BF_ADJUST | BF_RECT); if (IsEnabled()) bit = upBitmap; else bit = disabledBitmap; offset = 0; } else { DrawEdge(dc, &rect, EDGE_SUNKEN, BF_ADJUST | BF_RECT); bit = downBitmap; offset = 1; } bit->Copy(*this, (Width() - bit->Width()) / 2 + offset, (Height() - bit->Height()) / 2 + offset, bit->Width(), bit->Height(), 0, 0); dc = tmp; return false; } return false; }
//----------------------------------------------------------------------------- // Computes a single point //----------------------------------------------------------------------------- void C_Shield::ComputePoint( float s, float t, Vector& pt, Vector& normal, float& opacity ) { // Precache some computations for the point on the spline at (s, t). m_SplinePatch.SetupPatchQuery( s, t ); // Get the position + normal m_SplinePatch.GetPointAndNormal( pt, normal ); // From here on down is all futzing with opacity // Check neighbors for activity... bool active = IsPanelActive(m_SplinePatch.m_is, m_SplinePatch.m_it); if (m_SplinePatch.m_fs == 0.0f) active = active || IsPanelActive(m_SplinePatch.m_is - 1, m_SplinePatch.m_it); if (m_SplinePatch.m_ft == 0.0f) active = active || IsPanelActive(m_SplinePatch.m_is, m_SplinePatch.m_it - 1); if (!active) { // If the panel's not active, it's transparent. opacity = 0.0f; } else { if ((s == 0.0f) || (t == 0.0f) || (s == (Width() - 1.0f)) || (t == (Height() - 1.0f)) ) { // If it's on the edge, it's max opacity opacity = 192.0f; } else { // Channel zero is the opacity data opacity = m_SplinePatch.GetChannel( 0 ); // Make the shield translucent if the owner is the local player... // Also don't mess with the edges.. if (m_ShieldOwnedByLocalPlayer) { // Channel 1 is the opacity blend float blendFactor = m_SplinePatch.GetChannel( 1 ); blendFactor = clamp( blendFactor, 0.0f, 1.0f ); float blendValue = 1.0f; Vector delta; VectorSubtract( pt, GetAbsOrigin(), delta ); float dist = VectorLength( delta ); if (dist != 0.0f) { delta *= 1.0f / dist; float dot = DotProduct( m_ViewDir, delta ); float angle = acos( dot ); float fov = M_PI * render->GetFieldOfView() / 180.0f; if (angle < fov * .2f) blendValue = 0.1f; else if (angle < fov * 0.4f) { // Want a cos falloff between .2 and .4 // 0.1 at .2 and 1.0 at .4 angle -= fov * 0.2f; blendValue = 1.0f - 0.9f * 0.5f * (cos ( M_PI * angle / (fov * 0.2f) ) + 1.0f); } } // Interpolate between 1 and the blend value based on the blend factor... opacity *= (1.0f - blendFactor) + blendFactor * blendValue; } opacity = clamp( opacity, 0.0f, 192.0f ); } } opacity *= m_FadeValue; }
bool C_Shield::TestCollision( const Ray_t& ray, unsigned int mask, trace_t& trace ) { // Can't block anything if we're EMPed, or we've got no power left to block if ( m_bIsEMPed ) return false; if ( m_flPowerLevel <= 0 ) return false; // Here, we're gonna test for collision. // If we don't stop this kind of bullet, we'll generate an effect here // but we won't change the trace to indicate a collision. // It's just polygon soup... int hitgroup; bool firstTri; int v1[2], v2[2], v3[2]; float ihit, jhit; float mint = FLT_MAX; float t; int h = Height(); int w = Width(); for (int i = 0; i < h - 1; ++i) { for (int j = 0; j < w - 1; ++j) { // Don't test if this panel ain't active... if (!IsPanelActive( j, i )) continue; // NOTE: Structure order of points so that our barycentric // axes for each triangle are along the (u,v) directions of the mesh // The barycentric coords we'll need below // Two triangles per quad... t = IntersectRayWithTriangle( ray, GetPoint( j, i + 1 ), GetPoint( j + 1, i + 1 ), GetPoint( j, i ), true ); if ((t >= 0.0f) && (t < mint)) { mint = t; v1[0] = j; v1[1] = i + 1; v2[0] = j + 1; v2[1] = i + 1; v3[0] = j; v3[1] = i; ihit = i; jhit = j; firstTri = true; } t = IntersectRayWithTriangle( ray, GetPoint( j + 1, i ), GetPoint( j, i ), GetPoint( j + 1, i + 1 ), true ); if ((t >= 0.0f) && (t < mint)) { mint = t; v1[0] = j + 1; v1[1] = i; v2[0] = j; v2[1] = i; v3[0] = j + 1; v3[1] = i + 1; ihit = i; jhit = j; firstTri = false; } } } if (mint == FLT_MAX) return false; // Stuff the barycentric coordinates of the triangle hit into the hit group // For the first triangle, the first edge goes along u, the second edge goes // along -v. For the second triangle, the first edge goes along -u, // the second edge goes along v. const Vector& v1vec = GetPoint(v1[0], v1[1]); const Vector& v2vec = GetPoint(v2[0], v2[1]); const Vector& v3vec = GetPoint(v3[0], v3[1]); float u, v; bool ok = ComputeIntersectionBarycentricCoordinates( ray, v1vec, v2vec, v3vec, u, v ); Assert( ok ); if ( !ok ) { return false; } if (firstTri) v = 1.0 - v; else u = 1.0 - u; v += ihit; u += jhit; v /= (h - 1); u /= (w - 1); // Compress (u,v) into 1 dot 15, v in top bits hitgroup = (((int)(v * (1 << 15))) << 16) + (int)(u * (1 << 15)); Vector normal; float intercept; ComputeTrianglePlane( v1vec, v2vec, v3vec, normal, intercept ); UTIL_SetTrace( trace, ray, this, mint, hitgroup, CONTENTS_SOLID, normal, intercept ); return true; }
void MpScrollWindow::SetFrameStyle (int style) { FrameStyle = style; Resize(Width(),Height()); }
void CPopupMenu::Draw (HSURFACE hScreen) { // would a flashing cursor be visible? LTBOOL bFlashingVisible = fmod (m_pClientDE->GetTime(), CURSORBLINKTIME) < (CURSORBLINKTIME / 2.0f); // draw the background to the screen m_pClientDE->DrawSurfaceToSurface (hScreen, m_hBackground, NULL, m_nLeft, m_nTop); // create the font and color we may need for any edit controls... HSTRING hstrFont = m_pClientDE->FormatString (IDS_INGAMEFONT); HLTFONT hFont = m_pClientDE->CreateFont (m_pClientDE->GetStringData(hstrFont), 8, 16, LTFALSE, LTFALSE, LTFALSE); m_pClientDE->FreeString (hstrFont); HLTCOLOR hForeText = m_pClientDE->SetupColor1 (1.0f, 1.0f, 1.0f, LTFALSE); // if a title exists, draw it int nCurrentY = BORDERSIZE + m_nTopMargin; if (m_hTitle) { uint32 nWidth, nHeight; m_pClientDE->GetSurfaceDims (m_hTitle, &nWidth, &nHeight); LTRect rcSrc; rcSrc.left = 0; rcSrc.top = 0; rcSrc.right = nWidth; rcSrc.bottom = nHeight; if ((int)nWidth > Width() - (BORDERSIZE << 1) - m_nLeftMargin) { rcSrc.right -= nWidth - (Width() - (BORDERSIZE << 1) - m_nLeftMargin); } if (nCurrentY + (int)nHeight > Height() - BORDERSIZE) { rcSrc.bottom -= (nCurrentY + nHeight) - (Height() - BORDERSIZE); } m_pClientDE->DrawSurfaceToSurface (hScreen, m_hTitle, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft, BORDERSIZE + m_nTopMargin + m_nTop); nCurrentY += (int) nHeight + m_nTopMargin; } // draw each item uint32 nCurrentItem = m_nFirstItem; while (nCurrentItem < m_nItems && nCurrentY < m_nBottom) { // get this item's width and clamp it if necessary uint32 nWidth, nHeight; m_pClientDE->GetSurfaceDims (m_itemArray[nCurrentItem].hSurface, &nWidth, &nHeight); LTRect rcSrc; rcSrc.left = 0; rcSrc.top = 0; rcSrc.right = nWidth; rcSrc.bottom = nHeight; if ((int)nWidth > Width() - (BORDERSIZE << 1) - m_nLeftMargin) { rcSrc.right -= nWidth - (Width() - (BORDERSIZE << 1) - m_nLeftMargin); } if (nCurrentY + m_itemArray[nCurrentItem].nHeight > Height() - BORDERSIZE) { rcSrc.bottom -= (nCurrentY + m_itemArray[nCurrentItem].nHeight) - (Height() - BORDERSIZE); } if (nCurrentItem == m_nSelection) { //HLTCOLOR hRed = m_pClientDE->SetupColor2 (1.0f, 0.0f, 0.0f, LTFALSE); //m_pClientDE->DrawSurfaceSolidColor (hScreen, m_itemArray[nCurrentItem].hSurface, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft, nCurrentY + m_nTop, NULL, hRed); m_pClientDE->DrawSurfaceToSurface (hScreen, m_itemArray[nCurrentItem].hSelected, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft, nCurrentY + m_nTop); } else { if (!m_itemArray[nCurrentItem].bEnabled) { //HLTCOLOR hDisabledColor = m_pClientDE->SetupColor2 (0.3f, 0.3f, 0.3f, LTFALSE); //m_pClientDE->DrawSurfaceSolidColor (hScreen, m_itemArray[nCurrentItem].hSurface, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft, nCurrentY + m_nTop, NULL, hDisabledColor); m_pClientDE->DrawSurfaceToSurface (hScreen, m_itemArray[nCurrentItem].hSurface, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft, nCurrentY + m_nTop); } else { m_pClientDE->DrawSurfaceToSurface (hScreen, m_itemArray[nCurrentItem].hSurface, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft, nCurrentY + m_nTop); } } // if this item is an edit control, draw the editable string... if (m_itemArray[nCurrentItem].nType == Edit && m_itemArray[nCurrentItem].pData) { char* pString = ((nCurrentItem == m_nSelection) && m_bEditing) ? m_strEdit : (char*)m_itemArray[nCurrentItem].pData; if (strlen (pString) == 0) { nWidth = 0; } else { HSURFACE hSurface = LTNULL; if (m_bEditing && nCurrentItem == m_nSelection) { hSurface = CTextHelper::CreateSurfaceFromString (m_pClientDE, hFont, m_strEdit, hForeText); } else { hSurface = CTextHelper::CreateSurfaceFromString (m_pClientDE, hFont, (char*)m_itemArray[nCurrentItem].pData, hForeText); } // get the source rect and clip it if necessary m_pClientDE->GetSurfaceDims (hSurface, &nWidth, &nHeight); rcSrc.right = nWidth; rcSrc.bottom = nHeight; if (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth > (Width() - (BORDERSIZE << 1) - m_nLeftMargin)) { rcSrc.right -= (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth) - (Width() - (BORDERSIZE << 1) - m_nLeftMargin); } if (nCurrentY + (int)nHeight > Height() - BORDERSIZE) { rcSrc.bottom -= (nCurrentY + (int)nHeight) - (Height() - BORDERSIZE); } m_pClientDE->DrawSurfaceToSurface (hScreen, hSurface, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft + m_itemArray[nCurrentItem].nSecondColumn, nCurrentY + m_nTop); m_pClientDE->DeleteSurface (hSurface); } // if we're editing, draw a flashing cursor if (m_bEditing && bFlashingVisible && nCurrentItem == m_nSelection) { rcSrc.right = m_cxCursor; // if we're editing, we should be able to assume that we don't need to clip vertically if (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth + (int)m_cxCursor > (Width() - (BORDERSIZE << 1) - m_nLeftMargin)) { rcSrc.right -= (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth + (int)m_cxCursor) - (Width() - (BORDERSIZE << 1) - m_nLeftMargin); } m_pClientDE->DrawSurfaceToSurface (hScreen, m_hCursor, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft + m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth, nCurrentY + m_nTop); } } // if this item is a multiple-choice control, draw the selected string... if (m_itemArray[nCurrentItem].nType == Multiple && m_itemArray[nCurrentItem].pData) { // find the current string char* pList = new char [strlen ((char*)m_itemArray[nCurrentItem].pData) + 1]; strcpy (pList, (char*)m_itemArray[nCurrentItem].pData); char* ptr = strtok (pList, "|");// put the delimeter in the string resources!!!! for (uint32 i = 0; i < m_itemArray[nCurrentItem].nData; i++) { ptr = strtok (NULL, "|"); assert (ptr); } HSURFACE hSurface = CTextHelper::CreateSurfaceFromString (m_pClientDE, hFont, ptr, hForeText); delete [] pList; // get the source rect and clip it if necessary m_pClientDE->GetSurfaceDims (hSurface, &nWidth, &nHeight); rcSrc.right = nWidth; rcSrc.bottom = nHeight; if (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth > (Width() - (BORDERSIZE << 1) - m_nLeftMargin)) { rcSrc.right -= (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth) - (Width() - (BORDERSIZE << 1) - m_nLeftMargin); } if (nCurrentY + (int)nHeight > Height() - BORDERSIZE) { rcSrc.bottom -= (nCurrentY + (int)nHeight) - (Height() - BORDERSIZE); } m_pClientDE->DrawSurfaceToSurface (hScreen, hSurface, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft + m_itemArray[nCurrentItem].nSecondColumn, nCurrentY + m_nTop); m_pClientDE->DeleteSurface (hSurface); } // if this item is a KeyConfig control, draw the associated key... if (m_itemArray[nCurrentItem].nType == KeyConfig && m_itemArray[nCurrentItem].pData) { HSURFACE hSurface = LTNULL; if (nCurrentItem == m_nSelection && m_bConfiguring) { hSurface = CTextHelper::CreateSurfaceFromString (m_pClientDE, hFont, "Press a key...", hForeText); } else { hSurface = CTextHelper::CreateSurfaceFromString (m_pClientDE, hFont, (char*)m_itemArray[nCurrentItem].pData, hForeText); } // get the source rect and clip it if necessary m_pClientDE->GetSurfaceDims (hSurface, &nWidth, &nHeight); rcSrc.right = nWidth; rcSrc.bottom = nHeight; if (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth > (Width() - (BORDERSIZE << 1) - m_nLeftMargin)) { rcSrc.right -= (m_itemArray[nCurrentItem].nSecondColumn + (int)nWidth) - (Width() - (BORDERSIZE << 1) - m_nLeftMargin); } if (nCurrentY + (int)nHeight > Height() - BORDERSIZE) { rcSrc.bottom -= (nCurrentY + (int)nHeight) - (Height() - BORDERSIZE); } m_pClientDE->DrawSurfaceToSurface (hScreen, hSurface, &rcSrc, BORDERSIZE + m_nLeftMargin + m_nLeft + m_itemArray[nCurrentItem].nSecondColumn, nCurrentY + m_nTop); m_pClientDE->DeleteSurface (hSurface); } // if this item is a Slider, draw the slider... if (m_itemArray[nCurrentItem].nType == Slider && m_itemArray[nCurrentItem].pData) { CSlider* pSlider = (CSlider*) m_itemArray[nCurrentItem].pData; int nHeight = pSlider->GetHeight(); int y = (m_itemArray[nCurrentItem].nHeight - nHeight) / 2; if (y + nCurrentY + nHeight <= Height() - BORDERSIZE) { pSlider->Draw (hScreen, BORDERSIZE + m_nLeftMargin + m_nLeft + m_itemArray[nCurrentItem].nSecondColumn, m_nTop + nCurrentY + y); } } // increment the current y value and go on to the next item... nCurrentY += m_itemArray[nCurrentItem].nHeight; if (nCurrentY < Height() - BORDERSIZE) m_nLastItem = nCurrentItem; nCurrentItem++; } // clean up m_pClientDE->DeleteFont (hFont); }
void MpScrollWindow::SetFrameMidWidth (int width) { FrameMidWidth = width; Resize(Width(),Height()); }
LTBOOL CPopupMenu::Init (ILTClient* pClientDE, CRiotMenu* pRiotMenu) { if (!pClientDE) return LTFALSE; m_pClientDE = pClientDE; m_pRiotMenu = pRiotMenu; // load the menu border pieces HSURFACE hBorderTL = LTNULL; HSURFACE hBorderTR = LTNULL; HSURFACE hBorderBR = LTNULL; HSURFACE hBorderBL = LTNULL; HSURFACE hBorderL = LTNULL; HSURFACE hBorderT = LTNULL; HSURFACE hBorderR = LTNULL; HSURFACE hBorderB = LTNULL; HLTFONT hFont = LTNULL; HSTRING hString = LTNULL; if (LTFALSE) { fail: if (hBorderTL) m_pClientDE->DeleteSurface (hBorderTL); if (hBorderTR) m_pClientDE->DeleteSurface (hBorderTR); if (hBorderBR) m_pClientDE->DeleteSurface (hBorderBR); if (hBorderBL) m_pClientDE->DeleteSurface (hBorderBL); if (hBorderL) m_pClientDE->DeleteSurface (hBorderL); if (hBorderR) m_pClientDE->DeleteSurface (hBorderR); if (hBorderT) m_pClientDE->DeleteSurface (hBorderT); if (hBorderB) m_pClientDE->DeleteSurface (hBorderB); if (hFont) m_pClientDE->DeleteFont (hFont); if (hString) m_pClientDE->FreeString (hString); return LTFALSE; } if (!(hBorderTL = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuTL.pcx"))) goto fail; if (!(hBorderTR = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuTR.pcx"))) goto fail; if (!(hBorderBR = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuBR.pcx"))) goto fail; if (!(hBorderBL = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuBL.pcx"))) goto fail; if (!(hBorderL = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuL.pcx"))) goto fail; if (!(hBorderT = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuT.pcx"))) goto fail; if (!(hBorderR = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuR.pcx"))) goto fail; if (!(hBorderB = m_pClientDE->CreateSurfaceFromBitmap ("interface/PopupMenuB.pcx"))) goto fail; // create the cursor HSTRING hstrFont = m_pClientDE->FormatString (IDS_INGAMEFONT); hFont = m_pClientDE->CreateFont (m_pClientDE->GetStringData(hstrFont), 8, 16, LTFALSE, LTFALSE, LTFALSE); m_pClientDE->FreeString (hstrFont); if (!hFont) goto fail; HLTCOLOR hForeText = m_pClientDE->SetupColor1 (1.0f, 1.0f, 1.0f, LTFALSE); m_hCursor = CTextHelper::CreateSurfaceFromString (m_pClientDE, hFont, "_", hForeText); if (!m_hCursor) goto fail; uint32 nDummy; m_pClientDE->GetSurfaceDims (m_hCursor, &m_cxCursor, &nDummy); m_pClientDE->DeleteFont (hFont); hFont = LTNULL; // create the menu background m_hBackground = m_pClientDE->CreateSurface (Width(), Height()); if (!m_hBackground) goto fail; m_pClientDE->FillRect (m_hBackground, NULL, NULL); m_pClientDE->DrawSurfaceToSurface (m_hBackground, hBorderTL, NULL, 0, 0); m_pClientDE->DrawSurfaceToSurface (m_hBackground, hBorderTR, NULL, Width() - BORDERSIZE, 0); m_pClientDE->DrawSurfaceToSurface (m_hBackground, hBorderBR, NULL, Width() - BORDERSIZE, Height() - BORDERSIZE); m_pClientDE->DrawSurfaceToSurface (m_hBackground, hBorderBL, NULL, 0, Height() - BORDERSIZE); LTRect rcDst; rcDst.left = 0; rcDst.top = BORDERSIZE; rcDst.right = BORDERSIZE; rcDst.bottom = Height() - BORDERSIZE; LTRect rcSrc; rcSrc.left = 0; rcSrc.top = 0; rcSrc.right = BORDERSIZE; rcSrc.bottom = 1; m_pClientDE->ScaleSurfaceToSurface (m_hBackground, hBorderL, &rcDst, &rcSrc); /* LTRect rcD, rcS; rcD.left = 10; rcD.top = 10; rcD.right = 16; rcD.bottom = 11; rcS.left = 0; rcS.top = 0; rcS.right = 5; rcS.bottom = 0; m_pClientDE->ScaleSurfaceToSurface (m_hBackground, hBorderL, &rcD, &rcS); rcD.left = 20; rcD.top = 20; rcD.right = 26; rcD.bottom = 26; m_pClientDE->DrawSurfaceToSurface (m_hBackground, hBorderL, NULL, rcD.left, rcD.top); */ rcDst.right = Width(); rcDst.left = Width() - BORDERSIZE; m_pClientDE->ScaleSurfaceToSurface (m_hBackground, hBorderR, &rcDst, &rcSrc); rcDst.left = BORDERSIZE; rcDst.top = 0; rcDst.right = Width() - BORDERSIZE; rcDst.bottom = BORDERSIZE; rcSrc.right = 1; rcSrc.bottom = BORDERSIZE; m_pClientDE->ScaleSurfaceToSurface (m_hBackground, hBorderT, &rcDst, &rcSrc); rcDst.top = Height() - BORDERSIZE; rcDst.bottom = Height(); m_pClientDE->ScaleSurfaceToSurface (m_hBackground, hBorderB, &rcDst, &rcSrc); // clean up m_pClientDE->DeleteSurface (hBorderTL); m_pClientDE->DeleteSurface (hBorderTR); m_pClientDE->DeleteSurface (hBorderBR); m_pClientDE->DeleteSurface (hBorderBL); m_pClientDE->DeleteSurface (hBorderL); m_pClientDE->DeleteSurface (hBorderT); m_pClientDE->DeleteSurface (hBorderR); m_pClientDE->DeleteSurface (hBorderB); return LTTRUE; }
inline void IASRealRect::Center(const AIRealRect ¢erRect) { Offset(centerRect.left + ((centerRect.right - centerRect.left) - Width()) / 2, centerRect.top + ((centerRect.bottom - centerRect.top) - Height()) / 2); }
void IGraphicsLice::PrepDraw() { mDrawBitmap = new LICE_SysBitmap(Width(), Height()); mTmpBitmap = new LICE_MemBitmap(); }
inline void IASRealRectCartesian::Center(const AIRealRect ¢erRect) { Offset(centerRect.left + ((centerRect.right - centerRect.left) - Width()) / 2.0f, centerRect.bottom + ((centerRect.top - centerRect.bottom) - Height()) / 2.0f); }
void FleetButton::Init(const std::vector<int>& fleet_IDs, SizeType size_type) { //std::cout << "FleetButton::Init" << std::endl; // get fleets std::vector<TemporaryPtr<const Fleet> > fleets; for (std::vector<int>::const_iterator it = fleet_IDs.begin(); it != fleet_IDs.end(); ++it) { TemporaryPtr<const Fleet> fleet = GetFleet(*it); if (!fleet) { ErrorLogger() << "FleetButton::FleetButton couldn't get fleet with id " << *it; continue; } m_fleets.push_back(*it); fleets.push_back(fleet); } // determine owner(s) of fleet(s). Only care whether or not there is more than one owner, as owner // is used to determine colouration int owner_id = ALL_EMPIRES; int multiple_owners = false; if (fleets.empty()) { // leave as ALL_EMPIRES } else if (fleets.size() == 1) { owner_id = (*fleets.begin())->Owner(); } else { owner_id = (*fleets.begin())->Owner(); // use ALL_EMPIRES if there are multiple owners (including no owner and an owner) for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) { TemporaryPtr<const Fleet> fleet = *it; if (fleet->Owner() != owner_id) { owner_id = ALL_EMPIRES; multiple_owners = true; break; } } } // get fleet colour if (multiple_owners) { SetColor(GG::CLR_WHITE); } else if (owner_id == ALL_EMPIRES) { // all ships owned by now empire bool monsters = true; // find if any ship in fleets in button is not a monster for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) { TemporaryPtr<const Fleet> fleet = *it; for (std::set<int>::const_iterator ship_it = fleet->ShipIDs().begin(); ship_it != fleet->ShipIDs().end(); ++ship_it) { if (TemporaryPtr<const Ship> ship = GetShip(*ship_it)) { if (!ship->IsMonster()) { monsters = false; break; } } } } if (monsters) SetColor(GG::CLR_RED); else SetColor(GG::CLR_WHITE); } else { // single empire owner if (const Empire* empire = GetEmpire(owner_id)) SetColor(empire->Color()); else SetColor(GG::CLR_GRAY); // should never be necessary... but just in case } // determine direction button should be rotated to orient along a starlane GLfloat pointing_angle = 0.0f; TemporaryPtr<const Fleet> first_fleet; if (!m_fleets.empty()) first_fleet = *fleets.begin(); if (first_fleet && first_fleet->SystemID() == INVALID_OBJECT_ID && first_fleet->NextSystemID() != INVALID_OBJECT_ID) { int next_sys_id = first_fleet->NextSystemID(); if (TemporaryPtr<const UniverseObject> obj = GetUniverseObject(next_sys_id)) { // fleet is not in a system and has a valid next destination, so can orient it in that direction // fleet icons might not appear on the screen in the exact place corresponding to their // actual universe position, but if they're moving along a starlane, this code will assume // their apparent position will only be different from their true position in a direction // parallel with the starlane, so the direction from their true position to their destination // position can be used to get a direction vector to orient the icon float dest_x = obj->X(), dest_y = obj->Y(); float cur_x = first_fleet->X(), cur_y = first_fleet->Y(); const MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd(); GG::Pt dest = map_wnd->ScreenCoordsFromUniversePosition(dest_x, dest_y); GG::Pt cur = map_wnd->ScreenCoordsFromUniversePosition(cur_x, cur_y); GG::Pt direction_vector = dest - cur; if (direction_vector.x != GG::X0 || direction_vector.y != GG::Y0) pointing_angle = 360.0f / TWO_PI * std::atan2(static_cast<float>(Value(direction_vector.y)), static_cast<float>(Value(direction_vector.x))) + 90; } } // select icon(s) for fleet(s) int num_ships = 0; for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) { TemporaryPtr<const Fleet> fleet = *it; if (fleet) num_ships += fleet->NumShips(); } boost::shared_ptr<GG::Texture> size_texture = FleetSizeIcon(num_ships, size_type); std::vector<boost::shared_ptr<GG::Texture> > head_textures = FleetHeadIcons(fleets, size_type); // add RotatingGraphics for all icons needed if (size_texture) { RotatingGraphic* icon = new RotatingGraphic(size_texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); icon->SetPhaseOffset(pointing_angle); icon->SetRPM(0.0f); icon->SetColor(this->Color()); m_icons.push_back(icon); Resize(GG::Pt(size_texture->DefaultWidth(), size_texture->DefaultHeight())); AttachChild(icon); } for (std::vector<boost::shared_ptr<GG::Texture> >::const_iterator it = head_textures.begin(); it != head_textures.end(); ++it) { RotatingGraphic* icon = new RotatingGraphic(*it, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); icon->SetPhaseOffset(pointing_angle); icon->SetRPM(0.0f); icon->SetColor(this->Color()); m_icons.push_back(icon); if (Width() < (*it)->DefaultWidth()) Resize(GG::Pt((*it)->DefaultWidth(), (*it)->DefaultHeight())); AttachChild(icon); } // set up selection indicator m_selection_indicator = new RotatingGraphic(FleetSelectionIndicatorIcon(), GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); m_selection_indicator->SetRPM(ClientUI::SystemSelectionIndicatorRPM()); LayoutIcons(); // Scanlines for not currently-visible objects? int empire_id = HumanClientApp::GetApp()->EmpireID(); if (empire_id == ALL_EMPIRES || !GetOptionsDB().Get<bool>("UI.system-fog-of-war")) return; bool at_least_one_fleet_visible = false; for (std::vector<int>::const_iterator it = m_fleets.begin(); it != m_fleets.end(); ++it) { if (GetUniverse().GetObjectVisibilityByEmpire(*it, empire_id) >= VIS_BASIC_VISIBILITY) { at_least_one_fleet_visible = true; break; } } // Create scanline renderer control m_scanline_control = new ScanlineControl(GG::X0, GG::Y0, Width(), Height()); if (!at_least_one_fleet_visible) AttachChild(m_scanline_control); }
const Matrix<Real>& bPre, const Matrix<Real>& cPre, Matrix<Real>& x, Matrix<Real>& y, Matrix<Real>& z, const IPFCtrl<Real>& ctrl ) { DEBUG_ONLY(CSE cse("qp::direct::IPF")) // Equilibrate the QP by diagonally scaling A auto Q = QPre; auto A = APre; auto b = bPre; auto c = cPre; const Int m = A.Height(); const Int n = A.Width(); Matrix<Real> dRow, dCol; if( ctrl.equilibrate ) { GeomEquil( A, dRow, dCol, ctrl.print ); DiagonalSolve( LEFT, NORMAL, dRow, b ); DiagonalSolve( LEFT, NORMAL, dCol, c ); // TODO: Replace with SymmetricDiagonalSolve { DiagonalSolve( LEFT, NORMAL, dCol, Q ); DiagonalSolve( RIGHT, NORMAL, dCol, Q ); } if( ctrl.primalInit ) DiagonalScale( LEFT, NORMAL, dCol, x ); if( ctrl.dualInit )
StyleParam::Value StyleParam::parseString(StyleParamKey key, const std::string& _value) { switch (key) { case StyleParamKey::extrude: { return parseExtrudeString(_value); } case StyleParamKey::text_wrap: { int textWrap; if (_value == "false") { return std::numeric_limits<uint32_t>::max(); } if (_value == "true") { return uint32_t(15); // DEFAULT } if (parseInt(_value, textWrap) > 0 && textWrap > 0) { return static_cast<uint32_t>(textWrap); } return std::numeric_limits<uint32_t>::max(); } case StyleParamKey::text_offset: case StyleParamKey::offset: { UnitVec<glm::vec2> vec; if (!parseVec2(_value, { Unit::pixel }, vec) || std::isnan(vec.value.y)) { LOGW("Invalid offset parameter '%s'.", _value.c_str()); } return vec.value; } case StyleParamKey::size: { UnitVec<glm::vec2> vec; if (!parseVec2(_value, { Unit::pixel }, vec)) { LOGW("Invalid size parameter '%s'.", _value.c_str()); } return vec.value; } case StyleParamKey::transition_hide_time: case StyleParamKey::transition_show_time: case StyleParamKey::transition_selected_time: case StyleParamKey::text_transition_hide_time: case StyleParamKey::text_transition_show_time: case StyleParamKey::text_transition_selected_time: { float time = 0.0f; if (!parseTime(_value, time)) { LOGW("Invalid time param '%s'", _value.c_str()); } return time; } case StyleParamKey::text_font_family: case StyleParamKey::text_font_weight: case StyleParamKey::text_font_style: { std::string normalized = _value; std::transform(normalized.begin(), normalized.end(), normalized.begin(), ::tolower); return normalized; } case StyleParamKey::anchor: case StyleParamKey::text_anchor: { LabelProperty::Anchors anchors; for (auto& anchor : splitString(_value, ',')) { if (anchors.count == LabelProperty::max_anchors) { break; } LabelProperty::Anchor labelAnchor; if (LabelProperty::anchor(anchor, labelAnchor)) { anchors.anchor[anchors.count++] = labelAnchor; } else { LOG("Invalid anchor %s", anchor.c_str()); } } return anchors; } case StyleParamKey::placement: { LabelProperty::Placement placement = LabelProperty::Placement::vertex; if (!LabelProperty::placement(_value, placement)) { LOG("Invalid placement parameter, Setting vertex as default."); } return placement; } case StyleParamKey::text_align: case StyleParamKey::text_source: case StyleParamKey::text_transform: case StyleParamKey::sprite: case StyleParamKey::sprite_default: case StyleParamKey::style: case StyleParamKey::outline_style: case StyleParamKey::repeat_group: case StyleParamKey::text_repeat_group: return _value; case StyleParamKey::text_font_size: { float fontSize = 0.f; if (!parseFontSize(_value, fontSize)) { LOGW("Invalid font-size '%s'.", _value.c_str()); } return fontSize; } case StyleParamKey::flat: case StyleParamKey::interactive: case StyleParamKey::text_interactive: case StyleParamKey::tile_edges: case StyleParamKey::visible: case StyleParamKey::text_visible: case StyleParamKey::outline_visible: case StyleParamKey::collide: case StyleParamKey::text_optional: case StyleParamKey::text_collide: if (_value == "true") { return true; } if (_value == "false") { return false; } LOGW("Invalid boolean value %s for key %s", _value.c_str(), StyleParam::keyName(key).c_str()); break; case StyleParamKey::text_order: LOGW("text:order parameter is ignored."); break; case StyleParamKey::order: case StyleParamKey::outline_order: case StyleParamKey::priority: case StyleParamKey::text_priority: { int num; if (parseInt(_value, num) > 0) { if (num >= 0) { return static_cast<uint32_t>(num); } } LOGW("Invalid '%s' value '%s'", keyName(key).c_str(), _value.c_str()); break; } case StyleParamKey::placement_spacing: { ValueUnitPair placementSpacing; placementSpacing.unit = Unit::pixel; int pos = parseValueUnitPair(_value, 0, placementSpacing); if (pos < 0) { LOGW("Invalid placement spacing value '%s'", _value.c_str()); placementSpacing.value = 80.0f; placementSpacing.unit = Unit::pixel; } else { if (placementSpacing.unit != Unit::pixel) { LOGW("Invalid unit provided for placement spacing"); } } return Width(placementSpacing); } case StyleParamKey::repeat_distance: case StyleParamKey::text_repeat_distance: { ValueUnitPair repeatDistance; repeatDistance.unit = Unit::pixel; int pos = parseValueUnitPair(_value, 0, repeatDistance); if (pos < 0) { LOGW("Invalid repeat distance value '%s'", _value.c_str()); repeatDistance.value = 256.0f; repeatDistance.unit = Unit::pixel; } else { if (repeatDistance.unit != Unit::pixel) { LOGW("Invalid unit provided for repeat distance"); } } return Width(repeatDistance); } case StyleParamKey::width: case StyleParamKey::outline_width: { ValueUnitPair width; width.unit = Unit::meter; int pos = parseValueUnitPair(_value, 0, width); if (pos < 0) { LOGW("Invalid width value '%s'", _value.c_str()); width.value = 2.0f; width.unit = Unit::pixel; } return Width(width); } case StyleParamKey::angle: { double num; if (_value == "auto") { return std::nanf("1"); } else if (parseFloat(_value, num) > 0) { return static_cast<float>(num); } break; } case StyleParamKey::miter_limit: case StyleParamKey::outline_miter_limit: case StyleParamKey::placement_min_length_ratio: case StyleParamKey::text_font_stroke_width: { double num; if (parseFloat(_value, num) > 0) { return static_cast<float>(num); } break; } case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: return parseColor(_value); case StyleParamKey::cap: case StyleParamKey::outline_cap: return static_cast<uint32_t>(CapTypeFromString(_value)); case StyleParamKey::join: case StyleParamKey::outline_join: return static_cast<uint32_t>(JoinTypeFromString(_value)); default: break; } return none_type{}; }
int RowWidth() const { return Width() - Padding() * 2; }
inline CPoint CRect::Centre() const { return CPoint(left + (Width() / 2), top + (Height() / 2)); }
reg_t GfxText32::createTextBitmap(reg_t textObject, uint16 maxWidth, uint16 maxHeight, reg_t prevHunk) { reg_t stringObject = readSelector(_segMan, textObject, SELECTOR(text)); // The object in the text selector of the item can be either a raw string // or a Str object. In the latter case, we need to access the object's data // selector to get the raw string. if (_segMan->isHeapObject(stringObject)) stringObject = readSelector(_segMan, stringObject, SELECTOR(data)); Common::String text = _segMan->getString(stringObject); // HACK: The character offsets of the up and down arrow buttons are off by one // in GK1, for some unknown reason. Fix them here. if (text.size() == 1 && (text[0] == 29 || text[0] == 30)) { text.setChar(text[0] + 1, 0); } GuiResourceId fontId = readSelectorValue(_segMan, textObject, SELECTOR(font)); GfxFont *font = _cache->getFont(fontId); bool dimmed = readSelectorValue(_segMan, textObject, SELECTOR(dimmed)); int16 alignment = readSelectorValue(_segMan, textObject, SELECTOR(mode)); uint16 foreColor = readSelectorValue(_segMan, textObject, SELECTOR(fore)); uint16 backColor = readSelectorValue(_segMan, textObject, SELECTOR(back)); Common::Rect nsRect = g_sci->_gfxCompare->getNSRect(textObject); uint16 width = nsRect.width() + 1; uint16 height = nsRect.height() + 1; // Limit rectangle dimensions, if requested if (maxWidth > 0) width = maxWidth; if (maxHeight > 0) height = maxHeight; // Upscale the coordinates/width if the fonts are already upscaled if (_screen->fontIsUpscaled()) { width = width * _screen->getDisplayWidth() / _screen->getWidth(); height = height * _screen->getDisplayHeight() / _screen->getHeight(); } int entrySize = width * height + BITMAP_HEADER_SIZE; reg_t memoryId = NULL_REG; if (prevHunk.isNull()) { memoryId = _segMan->allocateHunkEntry("TextBitmap()", entrySize); writeSelector(_segMan, textObject, SELECTOR(bitmap), memoryId); } else { memoryId = prevHunk; } byte *memoryPtr = _segMan->getHunkPointer(memoryId); if (prevHunk.isNull()) memset(memoryPtr, 0, BITMAP_HEADER_SIZE); byte *bitmap = memoryPtr + BITMAP_HEADER_SIZE; memset(bitmap, backColor, width * height); // Save totalWidth, totalHeight WRITE_LE_UINT16(memoryPtr, width); WRITE_LE_UINT16(memoryPtr + 2, height); int16 charCount = 0; uint16 curX = 0, curY = 0; const char *txt = text.c_str(); int16 textWidth, textHeight, totalHeight = 0, offsetX = 0, offsetY = 0; uint16 start = 0; // Calculate total text height while (*txt) { charCount = GetLongest(txt, width, font); if (charCount == 0) break; Width(txt, 0, (int16)strlen(txt), fontId, textWidth, textHeight, true); totalHeight += textHeight; txt += charCount; while (*txt == ' ') txt++; // skip over breaking spaces } txt = text.c_str(); // Draw text in buffer while (*txt) { charCount = GetLongest(txt, width, font); if (charCount == 0) break; Width(txt, start, charCount, fontId, textWidth, textHeight, true); switch (alignment) { case SCI_TEXT32_ALIGNMENT_RIGHT: offsetX = width - textWidth; break; case SCI_TEXT32_ALIGNMENT_CENTER: // Center text both horizontally and vertically offsetX = (width - textWidth) / 2; offsetY = (height - totalHeight) / 2; break; case SCI_TEXT32_ALIGNMENT_LEFT: offsetX = 0; break; default: warning("Invalid alignment %d used in TextBox()", alignment); } for (int i = 0; i < charCount; i++) { unsigned char curChar = txt[i]; font->drawToBuffer(curChar, curY + offsetY, curX + offsetX, foreColor, dimmed, bitmap, width, height); curX += font->getCharWidth(curChar); } curX = 0; curY += font->getHeight(); txt += charCount; while (*txt == ' ') txt++; // skip over breaking spaces } return memoryId; }
inline CSize CRect::Size() const { return CSize(Width(), Height()); }
void GfxText16::StringWidth(const char *str, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight) { Width(str, 0, (int16)strlen(str), orgFontId, textWidth, textHeight, true); }
bool AABoundingBox::IntersectsWith(const AABoundingBox &otherBox) const { Vector3 diff = Center - otherBox.Center; return abs(diff.x) < 0.5 * (Width() + otherBox.Width()) && abs(diff.y) < 0.5 * (Height() + otherBox.Height()) && abs(diff.z) < 0.5 * (Depth() + otherBox.Depth()); }