DemoContext::DemoContext() { ColorView* background = new ColorView(this, Color(63, 63, 63)); background->SetExpand(View::EXPAND_BOTH); m_contextView.AddChild(background); LinearSizerView* sizer = new LinearSizerView(this, LinearSizerView::ORIENTATION_HORIZONTAL); sizer->SetExpand(View::EXPAND_HORIZONTAL); m_contextView.AddChild(sizer); View* child; child = new ColorView(this, Color(255, 0, 0)); child->SetMinSize(SizeI(50, 50)); sizer->AddChild(child); child = new ColorView(this, Color(0, 255, 0)); child->SetName("child"); child->SetMinSize(SizeI(50, 50)); child->SetExpand(View::EXPAND_HORIZONTAL); sizer->AddChild(child); child = new ColorView(this, Color(0, 0, 255)); child->SetMinSize(SizeI(50, 50)); sizer->AddChild(child); }
void UpdateWindowSize(DialogData* pdd, const int cx, const int cy, HWND hwnd) { const int nDeltaX = cx - pdd->sizeClient.dx; const int nDeltaY = cy - pdd->sizeClient.dy; HDWP hdwp = BeginDeferWindowPos(pdd->nItemCount); for (int i = 0; i < pdd->nItemCount; i++) { const DialogSizerSizingItem* psd = pdd->psd + i; HWND hwndChild = GetDlgItem(hwnd, psd->uControlID); RectI rect = MapRectToWindow(WindowRect(hwndChild), HWND_DESKTOP, hwnd); // Adjust the window horizontally if (psd->uSizeInfo & DS_MoveX) rect.x += nDeltaX; // Adjust the window vertically if (psd->uSizeInfo & DS_MoveY) rect.y += nDeltaY; // Size the window horizontally if (psd->uSizeInfo & DS_SizeX) rect.dx += nDeltaX; // Size the window vertically if (psd->uSizeInfo & DS_SizeY) rect.dy += nDeltaY; DeferWindowPos(hdwp, hwndChild, nullptr, rect.x, rect.y, rect.dx, rect.dy, SWP_NOACTIVATE | SWP_NOZORDER); } EndDeferWindowPos(hdwp); pdd->sizeClient = SizeI(cx, cy); // If we have a sizing grip enabled then adjust it's position pdd->UpdateGripper(); }
bool FontGlyphTextureCache::init(FontCore* font) { if (LN_REQUIRE(font)) return false; m_font = font; m_maxCacheGlyphs = 1024;// TODO 定数なのはなんとかしたい // TODO: 最大に達するとなんか落ちる // すべてのグリフが収まるビットマップサイズ FontGlobalMetrics metrix; m_font->getGlobalMetrics(&metrix); int mw = std::ceil(metrix.boundingMaxX - metrix.boundingMinX); int mh = std::ceil(metrix.boundingMaxY - metrix.boundingMinY); // 横方向に並べる数 // +1.0 は切り捨て対策。テクスチャサイズはmaxCharactersが収まる大きさであれば良い。(小さくなければOK) m_glyphWidthCount = (int)(sqrt((double)m_maxCacheGlyphs) + 1.0); // キャッシュ用テクスチャ作成 int w = std::max(mw, mh); m_glyphMaxBitmapSize = SizeI(w, w); SizeI textureSize(m_glyphWidthCount * w, m_glyphWidthCount * w); m_fillGlyphsTexture = newObject<Texture2D>(textureSize.width, textureSize.height, TextureFormat::RGBA8); m_fillGlyphsTexture->setResourceUsage(GraphicsResourceUsage::Dynamic); // TODO: 最大 DeviceSize チェック // 検索に使う情報をリセット m_curPrimUsedFlags.resize(m_maxCacheGlyphs); for (int i = 0; i < m_maxCacheGlyphs; i++) { m_indexStack.push(i); } resetUsedFlags(); return true; }
static RenderedBitmap *ThumbFromCoverPage(Doc doc, SizeI size) { ImageData *coverImage = doc.GetCoverImage(); if (!coverImage) return nullptr; Bitmap *coverBmp = BitmapFromData(coverImage->data, coverImage->len); if (!coverBmp) return nullptr; Bitmap res(size.dx, size.dy, PixelFormat24bppRGB); float scale = (float)size.dx / (float)coverBmp->GetWidth(); int fromDy = size.dy; if (scale < 1.f) fromDy = (int)((float)coverBmp->GetHeight() * scale); Graphics g(&res); g.SetInterpolationMode(InterpolationModeHighQualityBicubic); Status ok = g.DrawImage(coverBmp, Rect(0, 0, size.dx, size.dy), 0, 0, coverBmp->GetWidth(), fromDy, UnitPixel); if (ok != Ok) { delete coverBmp; return nullptr; } HBITMAP hbmp; ok = res.GetHBITMAP((ARGB)Color::White, &hbmp); delete coverBmp; if (ok == Ok) return new RenderedBitmap(hbmp, SizeI(size.dx, size.dy)); return nullptr; }
void EbookController::CloseCurrentDocument() { ctrls->pagesLayout->GetPage1()->SetPage(nullptr); ctrls->pagesLayout->GetPage2()->SetPage(nullptr); StopFormattingThread(); DeletePages(&pages); doc.Delete(); pageSize = SizeI(0, 0); }
void EbookController::CloseCurrentDocument() { ctrls->page->SetPage(NULL); StopFormattingThread(); DeletePageShown(); DeletePages(&pagesFromBeginning); DeletePages(&pagesFromPage); doc.Delete(); formattingTemp.reparseIdx = 0; // mark as being laid out from the beginning pageSize = SizeI(0, 0); }
bool PdfCreator::AddImagePage(Bitmap *bmp, float imgDpi) { HBITMAP hbmp; if (bmp->GetHBITMAP((ARGB)Color::White, &hbmp) != Ok) return false; if (!imgDpi) imgDpi = bmp->GetHorizontalResolution(); bool ok = AddImagePage(hbmp, SizeI(bmp->GetWidth(), bmp->GetHeight()), imgDpi); DeleteObject(hbmp); return ok; }
/* Return size of a text <txt> in a given <hwnd>, taking into account its font */ SizeI TextSizeInHwnd(HWND hwnd, const WCHAR *txt) { SIZE sz; size_t txtLen = str::Len(txt); HDC dc = GetWindowDC(hwnd); /* GetWindowDC() returns dc with default state, so we have to first set window's current font into dc */ HFONT f = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); HGDIOBJ prev = SelectObject(dc, f); GetTextExtentPoint32(dc, txt, (int)txtLen, &sz); SelectObject(dc, prev); ReleaseDC(hwnd, dc); return SizeI(sz.cx, sz.cy); }
bool PdfCreator::AddImagePage(const char *data, size_t len, float imgDpi) { CrashIf(!ctx || !doc); if (!ctx || !doc) return false; const WCHAR *ext = GfxFileExtFromData(data, len); if (str::Eq(ext, L".jpg") || str::Eq(ext, L".jp2")) { Size size = BitmapSizeFromData(data, len); fz_image *image = nullptr; fz_try(ctx) { image = (str::Eq(ext, L".jpg") ? pack_jpeg : pack_jp2)(ctx, data, len, SizeI(size.Width, size.Height)); } fz_catch(ctx) { return false; } bool ok = AddImagePage(image, imgDpi); fz_drop_image(ctx, image); return ok; }
static RenderedBitmap* LoadRenderedBitmap(const WCHAR* filePath) { OwnedData data(file::ReadFile(filePath)); if (!data.data) { return nullptr; } Bitmap* bmp = BitmapFromData(data.data, data.size); if (!bmp) { return nullptr; } HBITMAP hbmp; RenderedBitmap* rendered = nullptr; if (bmp->GetHBITMAP((ARGB)Color::White, &hbmp) == Ok) { rendered = new RenderedBitmap(hbmp, SizeI(bmp->GetWidth(), bmp->GetHeight())); } delete bmp; return rendered; }
static void GeomTest() { PointD ptD(12.4, -13.6); utassert(ptD.x == 12.4 && ptD.y == -13.6); PointI ptI = ptD.ToInt(); utassert(ptI.x == 12 && ptI.y == -14); ptD = ptI.Convert<double>(); utassert(PointD(12, -14) == ptD); utassert(PointD(12.4, -13.6) != ptD); SizeD szD(7.7, -3.3); utassert(szD.dx == 7.7 && szD.dy == -3.3); SizeI szI = szD.ToInt(); utassert(szI.dx == 8 && szI.dy == -3); szD = szI.Convert<double>(); utassert(SizeD(8, -3) == szD); utassert(!szD.IsEmpty() && !szI.IsEmpty()); utassert(SizeI().IsEmpty() && SizeD().IsEmpty()); struct SRIData { int x1s, x1e, y1s, y1e; int x2s, x2e, y2s, y2e; bool intersect; int i_xs, i_xe, i_ys, i_ye; int u_xs, u_xe, u_ys, u_ye; } testData[] = { { 0,10, 0,10, 0,10, 0,10, true, 0,10, 0,10, 0,10, 0,10 }, /* complete intersect */ { 0,10, 0,10, 20,30,20,30, false, 0, 0, 0, 0, 0,30, 0,30 }, /* no intersect */ { 0,10, 0,10, 5,15, 0,10, true, 5,10, 0,10, 0,15, 0,10 }, /* { | } | */ { 0,10, 0,10, 5, 7, 0,10, true, 5, 7, 0,10, 0,10, 0,10 }, /* { | | } */ { 0,10, 0,10, 5, 7, 5, 7, true, 5, 7, 5, 7, 0,10, 0,10 }, { 0,10, 0,10, 5, 15,5,15, true, 5,10, 5,10, 0,15, 0,15 }, }; for (size_t i = 0; i < dimof(testData); i++) { struct SRIData *curr = &testData[i]; RectI rx1(curr->x1s, curr->y1s, curr->x1e - curr->x1s, curr->y1e - curr->y1s); RectI rx2 = RectI::FromXY(curr->x2s, curr->y2s, curr->x2e, curr->y2e); RectI isect = rx1.Intersect(rx2); if (curr->intersect) { utassert(!isect.IsEmpty()); utassert(isect.x == curr->i_xs && isect.y == curr->i_ys); utassert(isect.x + isect.dx == curr->i_xe && isect.y + isect.dy == curr->i_ye); } else { utassert(isect.IsEmpty()); } RectI urect = rx1.Union(rx2); utassert(urect.x == curr->u_xs && urect.y == curr->u_ys); utassert(urect.x + urect.dx == curr->u_xe && urect.y + urect.dy == curr->u_ye); /* if we swap rectangles, the results should be the same */ std::swap(rx1, rx2); isect = rx1.Intersect(rx2); if (curr->intersect) { utassert(!isect.IsEmpty()); utassert(isect.x == curr->i_xs && isect.y == curr->i_ys); utassert(isect.x + isect.dx == curr->i_xe && isect.y + isect.dy == curr->i_ye); } else { utassert(isect.IsEmpty()); } urect = rx1.Union(rx2); utassert(RectI::FromXY(curr->u_xs, curr->u_ys, curr->u_xe, curr->u_ye) == urect); utassert(!rx1.Contains(PointI(-2, -2))); utassert(rx1.Contains(rx1.TL())); utassert(!rx1.Contains(PointI(rx1.x, INT_MAX))); utassert(!rx1.Contains(PointI(INT_MIN, rx1.y))); } }
static inline SizeI GetTabSize(HWND hwnd) { int dx = DpiScaleX(hwnd, std::max(gGlobalPrefs->prereleaseSettings.tabWidth, MIN_TAB_WIDTH)); int dy = DpiScaleY(hwnd, TABBAR_HEIGHT); return SizeI(dx, dy); }
void GameManager::onResize(const int w,const int h) { Screen::setScreenSize(SizeI(w,h)); }
static inline SizeI GetTabSize(WindowInfo *win) { return SizeI((int)(TAB_WIDTH * win->uiDPIFactor), (int)((TABBAR_HEIGHT) * win->uiDPIFactor)); }
Score::Score():value(0), refreshCoord(true), yPos(1){ digitSize = SizeI(56, 56); digitDiagonal = new Point2f[maxCountDigits * 2]; }
SizeI GetBitmapSize(HBITMAP hbmp) { BITMAP bmpInfo; GetObject(hbmp, sizeof(BITMAP), &bmpInfo); return SizeI(bmpInfo.bmWidth, bmpInfo.bmHeight); }