void ContentHostBase::Composite(EffectChain& aEffectChain, float aOpacity, const gfx::Matrix4x4& aTransform, const Point& aOffset, const Filter& aFilter, const Rect& aClipRect, const nsIntRegion* aVisibleRegion, TiledLayerProperties* aLayerProperties) { NS_ASSERTION(aVisibleRegion, "Requires a visible region"); if (!mTextureHost || !mTextureHost->Lock()) { return; } RefPtr<TexturedEffect> effect = CreateTexturedEffect(mTextureHost, aFilter); aEffectChain.mPrimaryEffect = effect; nsIntRegion tmpRegion; const nsIntRegion* renderRegion; if (PaintWillResample()) { // If we're resampling, then the texture image will contain exactly the // entire visible region's bounds, and we should draw it all in one quad // to avoid unexpected aliasing. tmpRegion = aVisibleRegion->GetBounds(); renderRegion = &tmpRegion; } else { renderRegion = aVisibleRegion; } nsIntRegion region(*renderRegion); nsIntPoint origin = GetOriginOffset(); region.MoveBy(-origin); // translate into TexImage space, buffer origin might not be at texture (0,0) // Figure out the intersecting draw region TextureSource* source = mTextureHost; MOZ_ASSERT(source); gfx::IntSize texSize = source->GetSize(); nsIntRect textureRect = nsIntRect(0, 0, texSize.width, texSize.height); textureRect.MoveBy(region.GetBounds().TopLeft()); nsIntRegion subregion; subregion.And(region, textureRect); if (subregion.IsEmpty()) { // Region is empty, nothing to draw mTextureHost->Unlock(); return; } nsIntRegion screenRects; nsIntRegion regionRects; // Collect texture/screen coordinates for drawing nsIntRegionRectIterator iter(subregion); while (const nsIntRect* iterRect = iter.Next()) { nsIntRect regionRect = *iterRect; nsIntRect screenRect = regionRect; screenRect.MoveBy(origin); screenRects.Or(screenRects, screenRect); regionRects.Or(regionRects, regionRect); } TileIterator* tileIter = source->AsTileIterator(); TileIterator* iterOnWhite = nullptr; if (tileIter) { tileIter->BeginTileIteration(); } if (mTextureHostOnWhite) { iterOnWhite = mTextureHostOnWhite->AsTileIterator(); MOZ_ASSERT(!tileIter || tileIter->GetTileCount() == iterOnWhite->GetTileCount(), "Tile count mismatch on component alpha texture"); if (iterOnWhite) { iterOnWhite->BeginTileIteration(); } } bool usingTiles = (tileIter && tileIter->GetTileCount() > 1); do { if (iterOnWhite) { MOZ_ASSERT(iterOnWhite->GetTileRect() == tileIter->GetTileRect(), "component alpha textures should be the same size."); } nsIntRect texRect = tileIter ? tileIter->GetTileRect() : nsIntRect(0, 0, texSize.width, texSize.height); // Draw texture. If we're using tiles, we do repeating manually, as texture // repeat would cause each individual tile to repeat instead of the // compound texture as a whole. This involves drawing at most 4 sections, // 2 for each axis that has texture repeat. for (int y = 0; y < (usingTiles ? 2 : 1); y++) { for (int x = 0; x < (usingTiles ? 2 : 1); x++) { nsIntRect currentTileRect(texRect); currentTileRect.MoveBy(x * texSize.width, y * texSize.height); nsIntRegionRectIterator screenIter(screenRects); nsIntRegionRectIterator regionIter(regionRects); const nsIntRect* screenRect; const nsIntRect* regionRect; while ((screenRect = screenIter.Next()) && (regionRect = regionIter.Next())) { nsIntRect tileScreenRect(*screenRect); nsIntRect tileRegionRect(*regionRect); // When we're using tiles, find the intersection between the tile // rect and this region rect. Tiling is then handled by the // outer for-loops and modifying the tile rect. if (usingTiles) { tileScreenRect.MoveBy(-origin); tileScreenRect = tileScreenRect.Intersect(currentTileRect); tileScreenRect.MoveBy(origin); if (tileScreenRect.IsEmpty()) continue; tileRegionRect = regionRect->Intersect(currentTileRect); tileRegionRect.MoveBy(-currentTileRect.TopLeft()); } gfx::Rect rect(tileScreenRect.x, tileScreenRect.y, tileScreenRect.width, tileScreenRect.height); effect->mTextureCoords = Rect(Float(tileRegionRect.x) / texRect.width, Float(tileRegionRect.y) / texRect.height, Float(tileRegionRect.width) / texRect.width, Float(tileRegionRect.height) / texRect.height); GetCompositor()->DrawQuad(rect, aClipRect, aEffectChain, aOpacity, aTransform, aOffset); } } } if (iterOnWhite) { iterOnWhite->NextTile(); } } while (usingTiles && tileIter->NextTile()); if (tileIter) { tileIter->EndTileIteration(); } if (iterOnWhite) { iterOnWhite->EndTileIteration(); } mTextureHost->Unlock(); }
/* Generate grid ---------------------------------------------------------------------------------*/ void TableSkin::ThinkGrid( PointList& points, RectList& rects, const Pos &p ) { Tiler tiler( points, rects, p); tiler.SetClipRect( GetClipRect() ); // TOP/LEFT DIVIDERS // BOTTOM/RIGHT DIVIDERS // DIVIDERS int i, n = _x_dividers.Size(); int j, m = _y_dividers.Size(); if ( Exists(BODY+VDIV) ) for( i=1; i<n-1; ++i ) { int begin = (_x_dividers[i-1] + _x_dividers[i])/2; int end = (_x_dividers[i] + _x_dividers[i+1])/2; int shift = _x_dividers[i] - (end+begin-1)/2; Rect top_bound = Rect( begin, _rLU.GetY1(), end-begin, _rLU.GetH() ); Rect mid_bound = Rect( begin, _rLU.GetY2(), end-begin, _rLD.GetY1()-_rLU.GetY2()); Rect btm_bound = Rect( begin, _rLD.GetY1(), end-begin, _rLD.GetH() ); tiler.Orient(VERTICAL); if ( Exists(HEAD+VDIV) ) { IGraphics &g = ImageDicer::GetImage(HEAD+VDIV); tiler.RectCut( g.GetRect(), top_bound, Tiler::HALIGNCENTER|Tiler::VALIGNTOP, shift ); } IGraphics &g = ImageDicer::GetImage(BODY+VDIV); tiler.RectFill1D( g.GetRect(), mid_bound, Tiler::HALIGNCENTER, shift ); if ( Exists(TAIL+VDIV) ) { IGraphics &g = ImageDicer::GetImage(TAIL+VDIV); tiler.RectCut( g.GetRect(), btm_bound, Tiler::HALIGNCENTER|Tiler::VALIGNBOTTOM, shift ); } } if ( Exists(BODY+HDIV) ) for( j=1; j<m-1; ++j ) { int begin = (_y_dividers[j-1] + _y_dividers[j])/2; int end = (_y_dividers[j] + _y_dividers[j+1])/2; int shift = _y_dividers[j] - (end+begin-1)/2; Rect top_bound = Rect( _rLU.GetX1(), begin, _rLU.GetW(), end-begin ); Rect mid_bound = Rect( _rLU.GetX2(), begin, _rRU.GetX1()-_rLU.GetX2(), end-begin); Rect btm_bound = Rect( _rRU.GetX1(), begin, _rRU.GetW(), end-begin ); tiler.Orient(HORIZONTAL); if ( Exists(HEAD+HDIV) ) { IGraphics &g = ImageDicer::GetImage(HEAD+HDIV); tiler.RectCut( g.GetRect(), top_bound, Tiler::VALIGNCENTER|Tiler::HALIGNLEFT, shift ); } IGraphics &g = ImageDicer::GetImage(BODY+HDIV); tiler.RectFill1D( g.GetRect(), mid_bound, Tiler::VALIGNCENTER, shift ); if ( Exists(TAIL+HDIV) ) { IGraphics &g = ImageDicer::GetImage(TAIL+HDIV); tiler.RectCut( g.GetRect(), btm_bound, Tiler::VALIGNCENTER|Tiler::HALIGNRIGHT, shift ); } } if ( Exists(CROSSING) ) { for( i=1; i<n-1; ++i) for( j=1; j<m-1; ++j) { int xb = (_x_dividers[i-1] + _x_dividers[i])/2; int yb = (_y_dividers[j-1] + _y_dividers[j])/2; int xe = (_x_dividers[i+1] + _x_dividers[i])/2; int ye = (_y_dividers[j+1] + _y_dividers[j])/2; int xs = _x_dividers[i] - (xe+xb-1)/2; int ys = _y_dividers[j] - (ye+yb-1)/2; Rect r = Rect( xb, yb, xe-xb, ye-yb ); IGraphics &g = ImageDicer::GetImage(CROSSING); tiler.Orient(VERTICAL); tiler.RectCut( g.GetRect(), r, Tiler::VALIGNCENTER|Tiler::HALIGNCENTER, xs, ys); } } }
void Batched::DrawQuad(glm::vec2 pos, glm::vec2 size, Texture& tex) { innerDraw(pos, size, 0, tex, Rect(0,0,1,1)); }
// 描画 void Stage::Draw(){ // 床 Rect(0 - offsetX, 500, MAP_SIZE, 300).draw(Palette::Green); // ブロック描画 BlockDraw(); }
void OpenGLeGuiGraphics::_beginDraw() { gcn::Rectangle area(0, 0, mWidth, mHeight); gcn::Graphics::pushClipArea(area); m_renderbackend->pushClipArea(Rect(0, 0, mWidth, mHeight), false); }
void GUISlider::Draw(Common::Bitmap *ds) { Rect bar; Rect handle; int thickness; if (MinValue >= MaxValue) MaxValue = MinValue + 1; Value = Math::Clamp(Value, MinValue, MaxValue); // it's a horizontal slider if (IsHorizontal()) { thickness = Height / 3; bar.Left = X + 1; bar.Top = Y + Height / 2 - thickness; bar.Right = X + Width - 1; bar.Bottom = Y + Height / 2 + thickness + 1; handle.Left = (int)(((float)(Value - MinValue) / (float)(MaxValue - MinValue)) * (float)(Width - 4) - 2) + bar.Left + 1; handle.Top = bar.Top - (thickness - 1); handle.Right = handle.Left + 4; handle.Bottom = bar.Bottom + (thickness - 1); if (HandleImage > 0) { // store the centre of the pic rather than the top handle.Top = bar.Top + (bar.Bottom - bar.Top) / 2 + 1; handle.Left += 2; } handle.Top += HandleOffset; handle.Bottom += HandleOffset; } // vertical slider else { thickness = Width / 3; bar.Left = X + Width / 2 - thickness; bar.Top = Y + 1; bar.Right = X + Width / 2 + thickness + 1; bar.Bottom = Y + Height - 1; handle.Top = (int)(((float)(MaxValue - Value) / (float)(MaxValue - MinValue)) * (float)(Height - 4) - 2) + bar.Top + 1; handle.Left = bar.Left - (thickness - 1); handle.Bottom = handle.Top + 4; handle.Right = bar.Right + (thickness - 1); if (HandleImage > 0) { // store the centre of the pic rather than the left handle.Left = bar.Left + (bar.Right - bar.Left) / 2 + 1; handle.Top += 2; } handle.Left += HandleOffset; handle.Right += HandleOffset; } color_t draw_color; if (BgImage > 0) { // tiled image as slider background int x_inc = 0; int y_inc = 0; if (IsHorizontal()) { x_inc = get_adjusted_spritewidth(BgImage); // centre the image vertically bar.Top = Y + (Height / 2) - get_adjusted_spriteheight(BgImage) / 2; } else { y_inc = get_adjusted_spriteheight(BgImage); // centre the image horizontally bar.Left = X + (Width / 2) - get_adjusted_spritewidth(BgImage) / 2; } int cx = bar.Left; int cy = bar.Top; // draw the tiled background image do { draw_gui_sprite(ds, BgImage, cx, cy, true); cx += x_inc; cy += y_inc; // done as a do..while so that at least one of the image is drawn } while ((cx + x_inc <= bar.Right) && (cy + y_inc <= bar.Bottom)); } else { // normal grey background draw_color = ds->GetCompatibleColor(16); ds->FillRect(Rect(bar.Left + 1, bar.Top + 1, bar.Right - 1, bar.Bottom - 1), draw_color); draw_color = ds->GetCompatibleColor(8); ds->DrawLine(Line(bar.Left, bar.Top, bar.Left, bar.Bottom), draw_color); ds->DrawLine(Line(bar.Left, bar.Top, bar.Right, bar.Top), draw_color); draw_color = ds->GetCompatibleColor(15); ds->DrawLine(Line(bar.Right, bar.Top + 1, bar.Right, bar.Bottom), draw_color); ds->DrawLine(Line(bar.Left, bar.Bottom, bar.Right, bar.Bottom), draw_color); } if (HandleImage > 0) { // an image for the slider handle if (spriteset[HandleImage] == NULL) HandleImage = 0; handle.Left -= get_adjusted_spritewidth(HandleImage) / 2; handle.Top -= get_adjusted_spriteheight(HandleImage) / 2; draw_gui_sprite(ds, HandleImage, handle.Left, handle.Top, true); handle.Right = handle.Left + get_adjusted_spritewidth(HandleImage); handle.Bottom = handle.Top + get_adjusted_spriteheight(HandleImage); } else { // normal grey tracker handle draw_color = ds->GetCompatibleColor(7); ds->FillRect(Rect(handle.Left, handle.Top, handle.Right, handle.Bottom), draw_color); draw_color = ds->GetCompatibleColor(15); ds->DrawLine(Line(handle.Left, handle.Top, handle.Right, handle.Top), draw_color); ds->DrawLine(Line(handle.Left, handle.Top, handle.Left, handle.Bottom), draw_color); draw_color = ds->GetCompatibleColor(16); ds->DrawLine(Line(handle.Right, handle.Top + 1, handle.Right, handle.Bottom), draw_color); ds->DrawLine(Line(handle.Left + 1, handle.Bottom, handle.Right, handle.Bottom), draw_color); } _cachedHandle = handle; }
void SetupWindow::postInit() { int width = 620; const int height = 450; if (config.getIntValue("screenwidth") >= 730) width += 100; setContentSize(width, height); setMinWidth(310); setMinHeight(210); static const char *buttonNames[] = { // TRANSLATORS: setup button N_("Apply"), // TRANSLATORS: setup button N_("Cancel"), // TRANSLATORS: setup button N_("Store"), // TRANSLATORS: setup button N_("Reset Windows"), nullptr }; int x = width; const int buttonPadding = getOption("buttonPadding", 5); for (const char ** curBtn = buttonNames; *curBtn; ++ curBtn) { Button *const btn = new Button(this, gettext(*curBtn), *curBtn, this); mButtons.push_back(btn); x -= btn->getWidth() + buttonPadding; btn->setPosition(x, height - btn->getHeight() - buttonPadding); add(btn); // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) mResetWindows = btn; } mPanel->setDimension(Rect(5, 5, width - 10, height - 40)); mPanel->enableScrollButtons(true); mTabs.push_back(new Setup_Video(this)); mTabs.push_back(new Setup_Visual(this)); mTabs.push_back(new Setup_Audio(this)); mTabs.push_back(new Setup_Perfomance(this)); mTabs.push_back(new Setup_Touch(this)); mTabs.push_back(new Setup_Input(this)); mTabs.push_back(new Setup_Joystick(this)); mTabs.push_back(new Setup_Colors(this)); mTabs.push_back(new Setup_Chat(this)); mTabs.push_back(new Setup_Players(this)); mTabs.push_back(new Setup_Relations(this)); mTabs.push_back(new Setup_Theme(this)); mTabs.push_back(new Setup_Other(this)); FOR_EACH (std::list<SetupTab*>::const_iterator, i, mTabs) { SetupTab *const tab = *i; mPanel->addTab(tab->getName(), tab); }
void ResStarlingAtlas::loadAtlas(CreateResourceContext& context) { std::string xml_path = context.walker.getPath("file"); file::buffer fb; file::read(xml_path.c_str(), fb); pugi::xml_document doc; doc.load_buffer_inplace(&fb.data[0], fb.data.size()); pugi::xml_node starling_xml = doc.first_child(); pugi::xml_node root = doc.root().first_child(); const std::string& img = root.attribute("imagePath").as_string(); char head[255]; char tail[255]; path::split(xml_path.c_str(), head, tail); _imagePath = std::string(head) + img; _texture = IVideoDriver::instance->createTexture(); pugi::xml_node meta = context.walker.getMeta(); if (!meta.empty()) { int textureWidth = meta.attribute("tw").as_int(); int textureHeight = meta.attribute("th").as_int(); _texture->init(0, textureWidth, textureHeight, TF_R8G8B8A8); } else { unsigned char buff[64]; unsigned int size = 0; { file::autoClose ac(file::open(_imagePath.c_str(), "rb")); size = file::read(ac.getHandle(), buff, sizeof(buff)); } int width = 0; int height = 0; ImageType type; if (getImageInfo(buff, size, img.c_str(), type, width, height)) { _texture->init(0, width, height, TF_R8G8B8A8); } else { spMemoryTexture mt = new MemoryTexture; ImageData im; file::buffer bf; file::read(_imagePath.c_str(), bf); mt->init(bf, true, _texture->getFormat()); im = mt->lock(); _texture->init(mt->lock(), false); } } float iw = 1.0f / _texture->getWidth(); float ih = 1.0f / _texture->getHeight(); ResAnim* resAnim = 0; pugi::xml_node sub = starling_xml.first_child(); animationFrames frames; while (sub) { const char* name = sub.attribute("name").value(); char id[255]; strcpy(id, name); //int frame_index = atoi(index); //todo optimize attributes int x = sub.attribute("x").as_int(); int y = sub.attribute("y").as_int(); int width = sub.attribute("width").as_int(); int height = sub.attribute("height").as_int(); int frameX = sub.attribute("frameX").as_int(); int frameY = sub.attribute("frameY").as_int(); int frameWidth = sub.attribute("frameWidth").as_int(width); int frameHeight = sub.attribute("frameHeight").as_int(height); if (!resAnim || resAnim->getName() != id) { if (resAnim) { resAnim->init(frames, (int)frames.size()); resAnim->setParent(this); context.resources->add(resAnim); frames.clear(); } resAnim = new ResAnim(this); setNode(resAnim, context.walker.getNode()); resAnim->setName(id); } AnimationFrame frame; RectF srcRect(x * iw, y * ih, width * iw, height * ih); RectF destF = Rect(-frameX, -frameY, width, height).cast<RectF>(); Diffuse df; df.base = _texture; frame.init(resAnim, df, srcRect, destF, Vector2((float)frameWidth, (float)frameHeight)); frames.push_back(frame); sub = sub.next_sibling(); } if (resAnim) { resAnim->init(frames, (int)frames.size()); resAnim->setParent(this); context.resources->add(resAnim); } }
bool LOSPFontLoader::load(Font* font, std::string const& path) { font->free(); std::ifstream f; OpenGameFileR(f, path, std::ios::binary); if(!f) return false; long bitmapWidth = 0, bitmapHeight = 0; f.read((char *)&bitmapWidth, 4); f.read((char *)&bitmapHeight, 4); if(!f) return false; bool full = false; if(bitmapWidth < 0) { bitmapWidth = -bitmapWidth; full = true; } font->m_bitmap = create_bitmap_ex(8, bitmapWidth, bitmapHeight); if(!font->m_bitmap) return false; font->m_supportColoring = true; int max = 224; if(full) { max = 256; } else font->m_chars.assign(32, Font::CharInfo(Rect(0, 0, 1, 1), 0)); for(int i = 0; i < max; ++i) { int x, y, w, h; f.read((char *)&x, 4); f.read((char *)&y, 4); f.read((char *)&w, 4); f.read((char *)&h, 4); if(!f) return false; font->m_chars.push_back(Font::CharInfo(Rect(x, y, x + w, y + h), 0)); } if(!full) font->m_chars[11] = font->m_chars[(unsigned char)'^']; for(int y = 0; y < bitmapWidth; ++y) { for(int x = 0; x < bitmapHeight; ++x) { char v; if(!f.get(v)) return false; int c = (unsigned char)v; putpixel(font->m_bitmap, x, y, c); } } font->buildSubBitmaps(); return true; }
void LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion) { PROFILER_LABEL("LayerManagerComposite", "Render", js::ProfileEntry::Category::GRAPHICS); if (mDestroyed) { NS_WARNING("Call on destroyed layer manager"); return; } // At this time, it doesn't really matter if these preferences change // during the execution of the function; we should be safe in all // permutations. However, may as well just get the values onces and // then use them, just in case the consistency becomes important in // the future. bool invertVal = gfxPrefs::LayersEffectInvert(); bool grayscaleVal = gfxPrefs::LayersEffectGrayscale(); float contrastVal = gfxPrefs::LayersEffectContrast(); bool haveLayerEffects = (invertVal || grayscaleVal || contrastVal != 0.0); // Set LayerScope begin/end frame LayerScopeAutoFrame frame(PR_Now()); // Dump to console if (gfxPrefs::LayersDump()) { this->Dump(); } else if (profiler_feature_active("layersdump")) { std::stringstream ss; Dump(ss); profiler_log(ss.str().c_str()); } // Dump to LayerScope Viewer if (LayerScope::CheckSendable()) { // Create a LayersPacket, dump Layers into it and transfer the // packet('s ownership) to LayerScope. auto packet = MakeUnique<layerscope::Packet>(); layerscope::LayersPacket* layersPacket = packet->mutable_layers(); this->Dump(layersPacket); LayerScope::SendLayerDump(Move(packet)); } /** Our more efficient but less powerful alter ego, if one is available. */ RefPtr<Composer2D> composer2D; composer2D = mCompositor->GetWidget()->GetComposer2D(); // We can't use composert2D if we have layer effects if (!mTarget && !haveLayerEffects && gfxPrefs::Composer2DCompositionEnabled() && composer2D && composer2D->HasHwc() && composer2D->TryRenderWithHwc(mRoot, mCompositor->GetWidget(), mGeometryChanged)) { LayerScope::SetHWComposed(); if (mFPS) { double fps = mFPS->mCompositionFps.AddFrameAndGetFps(TimeStamp::Now()); if (gfxPrefs::LayersDrawFPS()) { printf_stderr("HWComposer: FPS is %g\n", fps); } } mCompositor->EndFrameForExternalComposition(Matrix()); mLastFrameMissedHWC = false; return; } else if (!mTarget && !haveLayerEffects) { mLastFrameMissedHWC = !!composer2D; } { PROFILER_LABEL("LayerManagerComposite", "PreRender", js::ProfileEntry::Category::GRAPHICS); if (!mCompositor->GetWidget()->PreRender(this)) { return; } } ParentLayerIntRect clipRect; Rect bounds(mRenderBounds.x, mRenderBounds.y, mRenderBounds.width, mRenderBounds.height); Rect actualBounds; CompositorBench(mCompositor, bounds); if (mRoot->GetClipRect()) { clipRect = *mRoot->GetClipRect(); Rect rect(clipRect.x, clipRect.y, clipRect.width, clipRect.height); mCompositor->BeginFrame(aInvalidRegion, &rect, bounds, nullptr, &actualBounds); } else { gfx::Rect rect; mCompositor->BeginFrame(aInvalidRegion, nullptr, bounds, &rect, &actualBounds); clipRect = ParentLayerIntRect(rect.x, rect.y, rect.width, rect.height); } if (actualBounds.IsEmpty()) { mCompositor->GetWidget()->PostRender(this); return; } // Allow widget to render a custom background. mCompositor->GetWidget()->DrawWindowUnderlay(this, IntRect(actualBounds.x, actualBounds.y, actualBounds.width, actualBounds.height)); RefPtr<CompositingRenderTarget> previousTarget; if (haveLayerEffects) { previousTarget = PushGroupForLayerEffects(); } else { mTwoPassTmpTarget = nullptr; } // Render our layers. RootLayer()->Prepare(ViewAs<RenderTargetPixel>(clipRect, PixelCastJustification::RenderTargetIsParentLayerForRoot)); RootLayer()->RenderLayer(clipRect.ToUnknownRect()); if (!mRegionToClear.IsEmpty()) { nsIntRegionRectIterator iter(mRegionToClear); const IntRect *r; while ((r = iter.Next())) { mCompositor->ClearRect(Rect(r->x, r->y, r->width, r->height)); } } if (mTwoPassTmpTarget) { MOZ_ASSERT(haveLayerEffects); PopGroupForLayerEffects(previousTarget, clipRect.ToUnknownRect(), grayscaleVal, invertVal, contrastVal); } // Allow widget to render a custom foreground. mCompositor->GetWidget()->DrawWindowOverlay( this, LayoutDeviceIntRect(actualBounds.x, actualBounds.y, actualBounds.width, actualBounds.height)); // Debugging RenderDebugOverlay(actualBounds); { PROFILER_LABEL("LayerManagerComposite", "EndFrame", js::ProfileEntry::Category::GRAPHICS); mCompositor->EndFrame(); mCompositor->SetDispAcquireFence(mRoot, mCompositor->GetWidget()); // Call after EndFrame() } if (composer2D) { composer2D->Render(mCompositor->GetWidget()); } mCompositor->GetWidget()->PostRender(this); RecordFrame(); }
Rect CPetLoadSave::getSlotBounds(int index) { return Rect(323, 376 + index * 16, 473, 392 + index * 16); }
void LayerManagerComposite::PopGroupForLayerEffects(RefPtr<CompositingRenderTarget> aPreviousTarget, IntRect aClipRect, bool aGrayscaleEffect, bool aInvertEffect, float aContrastEffect) { MOZ_ASSERT(mTwoPassTmpTarget); // This is currently true, so just making sure that any new use of this // method is flagged for investigation MOZ_ASSERT(aInvertEffect || aGrayscaleEffect || aContrastEffect != 0.0); mCompositor->SetRenderTarget(aPreviousTarget); EffectChain effectChain(RootLayer()); Matrix5x4 effectMatrix; if (aGrayscaleEffect) { // R' = G' = B' = luminance // R' = 0.2126*R + 0.7152*G + 0.0722*B // G' = 0.2126*R + 0.7152*G + 0.0722*B // B' = 0.2126*R + 0.7152*G + 0.0722*B Matrix5x4 grayscaleMatrix(0.2126f, 0.2126f, 0.2126f, 0, 0.7152f, 0.7152f, 0.7152f, 0, 0.0722f, 0.0722f, 0.0722f, 0, 0, 0, 0, 1, 0, 0, 0, 0); effectMatrix = grayscaleMatrix; } if (aInvertEffect) { // R' = 1 - R // G' = 1 - G // B' = 1 - B Matrix5x4 colorInvertMatrix(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 1, 1, 1, 0); effectMatrix = effectMatrix * colorInvertMatrix; } if (aContrastEffect != 0.0) { // Multiplying with: // R' = (1 + c) * (R - 0.5) + 0.5 // G' = (1 + c) * (G - 0.5) + 0.5 // B' = (1 + c) * (B - 0.5) + 0.5 float cP1 = aContrastEffect + 1; float hc = 0.5*aContrastEffect; Matrix5x4 contrastMatrix( cP1, 0, 0, 0, 0, cP1, 0, 0, 0, 0, cP1, 0, 0, 0, 0, 1, -hc, -hc, -hc, 0); effectMatrix = effectMatrix * contrastMatrix; } effectChain.mPrimaryEffect = new EffectRenderTarget(mTwoPassTmpTarget); effectChain.mSecondaryEffects[EffectTypes::COLOR_MATRIX] = new EffectColorMatrix(effectMatrix); gfx::Rect clipRectF(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height); mCompositor->DrawQuad(Rect(Point(0, 0), Size(mTwoPassTmpTarget->GetSize())), clipRectF, effectChain, 1., Matrix4x4()); }
float LayerManagerComposite::ComputeRenderIntegrity() { // We only ever have incomplete rendering when progressive tiles are enabled. Layer* root = GetRoot(); if (!gfxPlatform::GetPlatform()->UseProgressivePaint() || !root) { return 1.f; } FrameMetrics rootMetrics = LayerMetricsWrapper::TopmostScrollableMetrics(root); if (!rootMetrics.IsScrollable()) { // The root may not have any scrollable metrics, in which case rootMetrics // will just be an empty FrameMetrics. Instead use the actual metrics from // the root layer. rootMetrics = LayerMetricsWrapper(root).Metrics(); } ParentLayerIntRect bounds = RoundedToInt(rootMetrics.GetCompositionBounds()); IntRect screenRect(bounds.x, bounds.y, bounds.width, bounds.height); float lowPrecisionMultiplier = 1.0f; float highPrecisionMultiplier = 1.0f; #ifdef MOZ_WIDGET_ANDROID // Use the transform on the primary scrollable layer and its FrameMetrics // to find out how much of the viewport the current displayport covers nsTArray<Layer*> rootScrollableLayers; GetRootScrollableLayers(rootScrollableLayers); if (rootScrollableLayers.Length() > 0) { // This is derived from the code in // AsyncCompositionManager::TransformScrollableLayer Layer* rootScrollable = rootScrollableLayers[0]; const FrameMetrics& metrics = LayerMetricsWrapper::TopmostScrollableMetrics(rootScrollable); Matrix4x4 transform = rootScrollable->GetEffectiveTransform(); transform.PostScale(metrics.GetPresShellResolution(), metrics.GetPresShellResolution(), 1); // Clip the screen rect to the document bounds Rect documentBounds = transform.TransformBounds(Rect(metrics.GetScrollableRect().x - metrics.GetScrollOffset().x, metrics.GetScrollableRect().y - metrics.GetScrollOffset().y, metrics.GetScrollableRect().width, metrics.GetScrollableRect().height)); documentBounds.RoundOut(); screenRect = screenRect.Intersect(IntRect(documentBounds.x, documentBounds.y, documentBounds.width, documentBounds.height)); // If the screen rect is empty, the user has scrolled entirely into // over-scroll and so we can be considered to have full integrity. if (screenRect.IsEmpty()) { return 1.0f; } // Work out how much of the critical display-port covers the screen bool hasLowPrecision = false; if (!metrics.GetCriticalDisplayPort().IsEmpty()) { hasLowPrecision = true; highPrecisionMultiplier = GetDisplayportCoverage(metrics.GetCriticalDisplayPort(), transform, screenRect); } // Work out how much of the display-port covers the screen if (!metrics.GetDisplayPort().IsEmpty()) { if (hasLowPrecision) { lowPrecisionMultiplier = GetDisplayportCoverage(metrics.GetDisplayPort(), transform, screenRect); } else { lowPrecisionMultiplier = highPrecisionMultiplier = GetDisplayportCoverage(metrics.GetDisplayPort(), transform, screenRect); } } } // If none of the screen is covered, we have zero integrity. if (highPrecisionMultiplier <= 0.0f && lowPrecisionMultiplier <= 0.0f) { return 0.0f; } #endif // MOZ_WIDGET_ANDROID nsIntRegion screenRegion(screenRect); nsIntRegion lowPrecisionScreenRegion(screenRect); Matrix4x4 transform; ComputeRenderIntegrityInternal(root, screenRegion, lowPrecisionScreenRegion, transform); if (!screenRegion.IsEqual(screenRect)) { // Calculate the area of the region. All rects in an nsRegion are // non-overlapping. float screenArea = screenRect.width * screenRect.height; float highPrecisionIntegrity = screenRegion.Area() / screenArea; float lowPrecisionIntegrity = 1.f; if (!lowPrecisionScreenRegion.IsEqual(screenRect)) { lowPrecisionIntegrity = lowPrecisionScreenRegion.Area() / screenArea; } return ((highPrecisionIntegrity * highPrecisionMultiplier) + (lowPrecisionIntegrity * lowPrecisionMultiplier)) / 2; } return 1.f; }
Rect MenuItem::rect() const { return Rect( _position.x - _contentSize.width * _anchorPoint.x, _position.y - _contentSize.height * _anchorPoint.y, _contentSize.width, _contentSize.height); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto size = Director::getInstance()->getWinSize(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24); // position the label on the center of the screen label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer //this->addChild(label, 1); // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer //this->addChild(sprite, 0); //ControlButton *button = standardButtonWithTitle("fengzhu"); //button->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); //this->addChild(button); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("common.plist"); //auto my_sp = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("common_backBtn.png")); //my_sp->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); //this->addChild(my_sp); auto backBtn = INSTANCE(ButtonUtils)->createButton("common_setBtn.png",Size(75,81),""); backBtn->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); //this->addChild(backBtn); //INSTANCE(AnimateManager)->showScaleAnimate(backBtn); for (int i = 0;i< 10;i++) { //log("%d",INSTANCE(GameUtils)->getRandom(5)); } scheduleUpdate(); //auto eventNode = Node::create(); auto eventNode = Sprite::create("CloseNormal.png"); this->addChild(eventNode); eventNode->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); eventNode->setColor(Color3B::WHITE); //eventNode->setContentSize(Size(backBtn->getContentSize())); log("%f,%f",eventNode->getContentSize().width,eventNode->getContentSize().height); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [](Touch* touch,Event* event){ auto target = static_cast<Sprite*>(event->getCurrentTarget()); Vec2 locationInNode = target->convertToNodeSpace(touch->getLocation()); Size s = target->getContentSize(); Rect rect = Rect(0, 0, s.width, s.height); if (rect.containsPoint(locationInNode)) { log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y); target->setOpacity(180); return true; } return false; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, eventNode); //auto containerForSprite1 = Node::create(); //auto sprite1 = Sprite::create("CyanSquare.png"); //sprite1->setPosition(origin+Vec2(size.width/2, size.height/2) + Vec2(-80, 80)); //containerForSprite1->addChild(sprite1); //addChild(containerForSprite1, 10); //auto sprite2 = Sprite::create("MagentaSquare.png"); //sprite2->setPosition(origin+Vec2(size.width/2, size.height/2)); //addChild(sprite2, 20); //auto sprite3 = Sprite::create("YellowSquare.png"); //sprite3->setPosition(Vec2(0, 0)); //sprite2->addChild(sprite3, 1); //// Make sprite1 touchable //auto listener1 = EventListenerTouchOneByOne::create(); //listener1->setSwallowTouches(true); //listener1->onTouchBegan = [](Touch* touch, Event* event){ // auto target = static_cast<Sprite*>(event->getCurrentTarget()); // // Vec2 locationInNode = target->convertToNodeSpace(touch->getLocation()); // Size s = target->getContentSize(); // Rect rect = Rect(0, 0, s.width, s.height); // // if (rect.containsPoint(locationInNode)) // { // log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y); // target->setOpacity(180); // return true; // } // return false; //}; //listener1->onTouchMoved = [](Touch* touch, Event* event){ // auto target = static_cast<Sprite*>(event->getCurrentTarget()); // target->setPosition(target->getPosition() + touch->getDelta()); //}; //listener1->onTouchEnded = [=](Touch* touch, Event* event){ // auto target = static_cast<Sprite*>(event->getCurrentTarget()); // log("sprite onTouchesEnded.. "); // target->setOpacity(255); // if (target == sprite2) // { // containerForSprite1->setLocalZOrder(100); // } // else if(target == sprite1) // { // containerForSprite1->setLocalZOrder(0); // } //}; //_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite1); //_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1->clone(), sprite2); //_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1->clone(), sprite3); return true; }
void Xulyanh::Cat_anh() { Mat thresh = this->ThresholdImage(); int xmin = 10000, ymin = 10000, xmax = -1, ymax = -1; //tìm xmin for (int i = 0; i <thresh.cols; i++) { for (int j = 0; j < thresh.rows; j++) { Scalar colour = thresh.at<uchar>(Point(i, j)); if (colour.val[0] == 0) { xmin = i; break; } } if (xmin != 10000) { break; } } //tìm ymin for (int i = 0; i <thresh.rows; i++) { for (int j = 0; j < thresh.cols; j++) { Scalar colour = thresh.at<uchar>(Point(j, i)); if (colour.val[0] == 0) { ymin = i; break; } } if (ymin != 10000) { break; } } //tìm xmax for (int i = thresh.cols - 1; i >= 0; i--) { for (int j = 0; j < thresh.rows; j++) { Scalar colour = thresh.at<uchar>(Point(i, j)); if (colour.val[0] == 0) { xmax = i; break; } } if (xmax != -1) { break; } } //tìm ymax for (int i = thresh.rows - 1; i >= 0; i--) { for (int j = 0; j < thresh.cols; j++) { Scalar colour = thresh.at<uchar>(Point(j, i)); if (colour.val[0] == 0) { ymax = i; break; } } if (ymax != -1) { break; } } Mat number = thresh(Rect(xmin, ymin, xmax - xmin+1, ymax - ymin+1)); // chia cắt các dòng trong ảnh int x_current, y_current = 0; std::vector<Mat> listdongMat; bool dongtrang = false; //chia dòng for (int i = 0; i< number.rows; i++) { int j; for (j = 0; j < number.cols; j++) { Scalar colour = number.at<uchar>(Point(j, i)); if (colour.val[0] == 0) { if (dongtrang == true)//nếu đang là dòng trắng mà gặp dòng den { y_current = i; } dongtrang = false; break; } } //nếu trong dòng này toàn màu trắng thì cắt ra if (j == number.cols&&dongtrang == false) { Mat _temp = number(Rect(0, y_current, number.cols, i - y_current)); listdongMat.push_back(_temp); dongtrang = true; } if (i == number.rows - 1 && dongtrang == false) { Mat _temp = number(Rect(0, y_current, number.cols, number.rows - y_current)); listdongMat.push_back(_temp); } } std::vector<Mat> listNumber; for (int z = 0; z < listdongMat.size(); z++) { dongtrang = true; //chia các chữ số trong các ảnh đã cắt dòng for (int i = 0; i < listdongMat[z].cols; i++) { int j; for (j = 0; j < listdongMat[z].rows; j++) { Scalar colour = listdongMat[z].at<uchar>(Point(i, j)); if (colour.val[0] == 0)//nếu là màu đen { if (dongtrang) { x_current = i; dongtrang = false; } break; } } if (j == listdongMat[z].rows&&dongtrang == false) { dongtrang = true; Mat temp = listdongMat[z](Rect(x_current, 0, i - x_current, listdongMat[z].rows)); listNumber.push_back(temp); } if (i == listdongMat[z].cols-1&&!dongtrang) { dongtrang = true; Mat temp = listdongMat[z](Rect(x_current, 0, i - x_current+1, listdongMat[z].rows)); listNumber.push_back(temp); } } } //cắt những đoạn thừa trong ảnh for (int i = 0; i < listNumber.size(); i++) { for (int j = 0; j < listNumber[i].rows; j++) { int z; for (z = 0; z < listNumber[i].cols; z++) { Scalar colour = listNumber[i].at<uchar>(Point(z, j)); if (colour.val[0] == 0)//nếu là màu đen { y_current = j; break; } } if (z != listNumber[i].cols) { break; } } int y_current1; for (int j = listNumber[i].rows - 1; j >= 0; j--) { int z; for (z = 0; z < listNumber[i].cols; z++) { Scalar colour = listNumber[i].at<uchar>(Point(z, j)); if (colour.val[0] == 0)//nếu là màu đen { y_current1 = j; break; } } if (z != listNumber[i].cols) { break; } } Mat temp = listNumber[i](Rect(0, y_current, listNumber[i].cols, y_current1 - y_current + 1)); this->listNumberCurrent.push_back(temp); } }
/** * Calculate the size of all the component controls stacked vertically. * For Avkon Forms the controls overlap by 2 pixels (hard coded) */ EXPORT_C TSize CEikCapCArray::MinimumSize() { TSize size(0,0); CEikCaptionedControl *firstCapCC = Count() > 0 ? (*this)[0] : NULL; if (firstCapCC && firstCapCC->iIsFormControl) { // we're inside form // Minimumsize needs to be called even though we wouldnt use the result (at least it calculates the number of lines) // TP HACK START (made because MinimumSize() is not good name for situations where content dimensions are desired) TInt height = 0; TInt width = 0; TRect parentRect = Rect(); TSize lineSize; // absolute size, minimumSize = maximumSize = LAF size for(TInt i=0; i<Count(); i++) { TInt gap = 0; // not possible to get this from LAF. (should be 0.5u or something) CEikCaptionedControl *line = (*this)[i]; TAknWindowLineLayout layout; const CEikDialogPage *dialogPage = firstCapCC->DialogPage(); CEikDialogPage::TFormLayoutSelection ret = CEikDialogPage::ESingle; if ( dialogPage ) ret = dialogPage->FormLayout(); if (ret == CEikDialogPage::ESingle) { lineSize = line->MinimumSize(); // ensures NumberOfLines() is valid. } else if (ret == CEikDialogPage::EDouble) { lineSize = line->MinimumSize(); // ensures NumberOfLines() is valid. } height += lineSize.iHeight + gap; width = lineSize.iWidth; } size = TSize(width,height); } else { TInt wholeWidth=0; const TInt count=Count(); const TInt topMargin=iDensePacking ? KAknNoTopMargin : KAknTopMargin; const TInt bottomMargin = iDensePacking ? KAknNoTopMargin : KAknTopMargin ; const TInt verticalSpacing=iDensePacking ? KVerticalSpacingSquash : KVerticalSpacing; TInt deltaHeight=0; CEikCapCArrayExtension *extension = ExtensionOrNull(); if (!extension) return TSize(30,30); // OOM for (TInt ii=0; ii<count; ++ii) { CEikCaptionedControl* line=(*this)[ii]; TSize thisSize=line->MinimumSize(); TInt thisDeltaHeight=thisSize.iHeight+verticalSpacing; if (deltaHeight<thisDeltaHeight) deltaHeight=thisDeltaHeight; const TInt thisCaptionWidth=line->iCaptionWidth; if (!(line->LatentGroupLineFollows())) { size.iHeight+=deltaHeight; deltaHeight=0; } if (!thisCaptionWidth) { if (wholeWidth<thisSize.iWidth) wholeWidth=thisSize.iWidth; } else { thisSize.iWidth-=thisCaptionWidth; if (extension->iCaptionWidth<thisCaptionWidth) extension->iCaptionWidth=thisCaptionWidth; if (size.iWidth<thisSize.iWidth) size.iWidth=thisSize.iWidth; } } size.iWidth+=extension->iCaptionWidth; if (size.iWidth<wholeWidth) size.iWidth=wholeWidth; // If the total height is zero don't bother adding a top margin if ( size.iHeight > 0 ) { size.iHeight+=( topMargin + bottomMargin ) ; size.iHeight+=2 ; // (we have included one too many '-2's) } } return size; }
Rect MoMo::GetPhysicsBound(){ Rect rect; rect = Rect(TILE_SIZE*0.5f-phyWidth*0.5f, TILE_SIZE*0.5f-phyHeight*0.5f, phyWidth, phyHeight); return RectApplyAffineTransform(rect, getNodeToParentAffineTransform()); }
bool ActionSpellTownPortal(Heroes & hero) { const Kingdom & kingdom = hero.GetKingdom(); std::vector<s32> castles; Display & display = Display::Get(); Cursor & cursor = Cursor::Get(); LocalEvent & le = LocalEvent::Get(); cursor.Hide(); cursor.SetThemes(cursor.POINTER); for(KingdomCastles::const_iterator it = kingdom.GetCastles().begin(); it != kingdom.GetCastles().end(); ++it) if(*it && !(*it)->GetHeroes().Guest()) castles.push_back((**it).GetIndex()); if(castles.empty()) { Dialog::Message("", _("No avaialble town. Spell Failed!!!"), Font::BIG, Dialog::OK); return false; } const u16 window_w = 280; const u16 window_h = 200; Dialog::FrameBorder* frameborder = new Dialog::FrameBorder(); frameborder->SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); frameborder->Redraw(); const Rect & area = frameborder->GetArea(); const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); background.Blit(Rect(0, 0, window_w, window_h), area); u16 result = Dialog::ZERO; CastleIndexListBox listbox(area, result); listbox.RedrawBackground(area); listbox.SetScrollButtonUp(ICN::LISTBOX, 3, 4, Point(area.x + 256, area.y + 55)); listbox.SetScrollButtonDn(ICN::LISTBOX, 5, 6, Point(area.x + 256, area.y + 145)); listbox.SetScrollSplitter(AGG::GetICN(ICN::LISTBOX, 10), Rect(area.x + 261, area.y + 78, 14, 64)); listbox.SetAreaMaxItems(5); listbox.SetAreaItems(Rect(area.x + 10, area.y + 60, 250, 100)); listbox.SetListContent(castles); listbox.Redraw(); ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL); btnGroups.Draw(); cursor.Show(); display.Flip(); while(result == Dialog::ZERO && le.HandleEvents()) { result = btnGroups.QueueEventProcessing(); listbox.QueueEventProcessing(); if(!cursor.isVisible()) { listbox.Redraw(); cursor.Show(); display.Flip(); } } delete frameborder; // store if(result == Dialog::OK) return HeroesTownGate(hero, world.GetCastle(listbox.GetCurrent())); return false; }
Setup_Relations::Setup_Relations(const Widget2 *const widget) : SetupTab(widget), PlayerRelationsListener(), mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)), mPlayerTableModel(new PlayerTableModel(this)), mPlayerTable(new GuiTable(this, mPlayerTableModel)), mPlayerTitleTable(new GuiTable(this, mPlayerTableTitleModel)), mPlayerScrollArea(new ScrollArea(this, mPlayerTable)), // TRANSLATORS: relation dialog button mDefaultTrading(new CheckBox(this, _("Allow trading"), player_relations.getDefault() & PlayerRelation::TRADE)), // TRANSLATORS: relation dialog button mDefaultWhisper(new CheckBox(this, _("Allow whispers"), player_relations.getDefault() & PlayerRelation::WHISPER)), // TRANSLATORS: relation dialog button mDeleteButton(new Button(this, _("Delete"), ACTION_DELETE, this)), mIgnoreActionChoicesModel(new IgnoreChoicesListModel), mIgnoreActionChoicesBox(new DropDown(widget, mIgnoreActionChoicesModel)) { // TRANSLATORS: relation dialog name setName(_("Relations")); mPlayerTable->setOpaque(Opaque_false); mPlayerTableTitleModel->fixColumnWidth(NAME_COLUMN, NAME_COLUMN_WIDTH); mPlayerTableTitleModel->fixColumnWidth(RELATION_CHOICE_COLUMN, RELATION_CHOICE_COLUMN_WIDTH); mPlayerTitleTable->setBackgroundColor(getThemeColor( ThemeColorId::TABLE_BACKGROUND)); mPlayerTitleTable->setSelectableGui(false); for (int i = 0; i < COLUMNS_NR; i++) { mPlayerTableTitleModel->set(0, i, new Label( this, gettext(table_titles[i]))); } mPlayerTitleTable->setLinewiseSelection(true); mPlayerScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mPlayerTable->setActionEventId(ACTION_TABLE); mPlayerTable->setLinewiseSelection(true); mPlayerTable->addActionListener(this); // TRANSLATORS: relation dialog label Label *const ignore_action_label = new Label(this, _("When ignoring:")); mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY); mIgnoreActionChoicesBox->addActionListener(this); int ignore_strategy_index = 0; // safe default if (player_relations.getPlayerIgnoreStrategy()) { ignore_strategy_index = player_relations.getPlayerIgnoreStrategyIndex( player_relations.getPlayerIgnoreStrategy()->mShortName); if (ignore_strategy_index < 0) ignore_strategy_index = 0; } mIgnoreActionChoicesBox->setSelected(ignore_strategy_index); mIgnoreActionChoicesBox->adjustHeight(); reset(); // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mPlayerTitleTable, 6); place(0, 1, mPlayerScrollArea, 6, 4).setPadding(2); place(0, 5, mDeleteButton); place(3, 5, ignore_action_label, 1); place(4, 5, mIgnoreActionChoicesBox, 2).setPadding(2); place(3, 6, mDefaultTrading, 3); place(3, 7, mDefaultWhisper, 3); player_relations.addListener(this); setDimension(Rect(0, 0, 500, 350)); }
void Window_BattleCommand::UpdateCursorRect() { if (index >= 0) SetCursorRect(Rect(0, (index - top_row) * 16, contents->GetWidth(), 16)); else SetCursorRect(Rect()); }
Rect Deserializer::ReadRect() { float data[4]; Read(data, sizeof data); return Rect(data); }
// ブロック描画関数 void Stage::BlockDraw(){ for (int i = 0; i < BLOCK_NUM; ++i){ block[i] = Rect(randX[i] - offsetX, randY[i] , 50, 50).draw(Palette::Brown); } }
static void vgascreenputc(VGAscr* scr, char* buf, Rectangle *flushr) { Point p; int h, w, pos; Rectangle r; // drawdebug = 1; if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)]) xp = xbuf; h = scr->memdefont->height; switch(buf[0]){ case '\n': if(curpos.y+h >= window.max.y){ vgascroll(scr); *flushr = window; } curpos.y += h; vgascreenputc(scr, "\r", flushr); break; case '\r': xp = xbuf; curpos.x = window.min.x; break; case '\t': p = memsubfontwidth(scr->memdefont, " "); w = p.x; if(curpos.x >= window.max.x-4*w) vgascreenputc(scr, "\n", flushr); pos = (curpos.x-window.min.x)/w; pos = 4-(pos%4); *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h); memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S); curpos.x += pos*w; break; case '\b': if(xp <= xbuf) break; xp--; r = Rect(*xp, curpos.y, curpos.x, curpos.y+h); memimagedraw(scr->gscreen, r, back, back->r.min, nil, ZP, S); combinerect(flushr, r); curpos.x = *xp; break; case '\0': break; default: p = memsubfontwidth(scr->memdefont, buf); w = p.x; if(curpos.x >= window.max.x-w) vgascreenputc(scr, "\n", flushr); *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y+h); memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S); memimagestring(scr->gscreen, curpos, conscol, ZP, scr->memdefont, buf); combinerect(flushr, r); curpos.x += w; } // drawdebug = 0; }
void CMultiPicWnd::OnTimer(UINT_PTR nIDEvent) { if (nIDEvent == TIMER_FADE_REFRESH) { KillTimer(TIMER_FADE_REFRESH); m_bTransitioning = TRUE; Redraw(); } else if (nIDEvent == TIMER_CHANGE) { if (m_mode == MOD_Normal) { if (m_frames.size() > 1) { if (IsWindowVisible()) { m_curPic++; if (m_curPic >= INT(m_frames.size())) m_curPic = 0; m_picDrawer.LoadFile(m_frames[m_curPic].path.c_str()); m_picDrawer.GetDrawParams().zoomLockMode = GdiPlusPicDrawer::ZLM_FullImage; m_bMemDCInvalidated = TRUE; Redraw(); } } } else if (m_mode == MOD_ShowParts) { if (m_frames.size() > 1) { m_curPic++; if (m_curPic >= INT(m_frames.size())) m_curPic = 0; m_picDrawer.LoadFile(m_frames[m_curPic].path.c_str()); } CRect rc; GetClientRect(&rc); if (m_picDrawer.GetZoomForLockMode(Rect(rc.left, rc.top, rc.Width(), rc.Height()), GdiPlusPicDrawer::ZLM_FullImage) < 1.0) { GdiPlusPicDrawer::DrawParams& params = m_picDrawer.GetDrawParams(); params.zoomLockMode = GdiPlusPicDrawer::ZLM_NoLock; params.reqZoom = 1.0; params.positionX = rand() * 100 / RAND_MAX; params.positionY = rand() * 100 / RAND_MAX; m_bMemDCInvalidated = TRUE; Redraw(); } else { if (m_picDrawer.GetDrawParams().zoomLockMode != GdiPlusPicDrawer::ZLM_FullImage) { m_picDrawer.GetDrawParams().zoomLockMode = GdiPlusPicDrawer::ZLM_FullImage; m_bMemDCInvalidated = TRUE; Redraw(); } } } } CWnd::OnTimer(nIDEvent); }
Setup_Quick::Setup_Quick(const Widget2 *const widget) : SetupTabScroll(widget), mMoveTypeList(new NamesModel), mCrazyMoveTypeList(new NamesModel) { // TRANSLATORS: quick tab in settings setName(_("Quick")); LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); new SetupQuickItem("", this, "moveTypeEvent", &GameModifiers::getMoveTypeString, &GameModifiers::changeMoveType); new SetupQuickItem("", this, "crazyMoveTypeEvent", &GameModifiers::getCrazyMoveTypeString, &GameModifiers::changeCrazyMoveType); new SetupQuickItem("", this, "moveToTargetTypeEvent", &GameModifiers::getMoveToTargetTypeString, &GameModifiers::changeMoveToTargetType); new SetupQuickItem("", this, "followModeEvent", &GameModifiers::getFollowModeString, &GameModifiers::changeFollowMode); new SetupQuickItem("", this, "attackWeaponTypeEvent", &GameModifiers::getAttackWeaponTypeString, &GameModifiers::changeAttackWeaponType); new SetupQuickItem("", this, "attackTypeEvent", &GameModifiers::getAttackTypeString, &GameModifiers::changeAttackType); new SetupQuickItem("", this, "magicAttackTypeEvent", &GameModifiers::getMagicAttackTypeString, &GameModifiers::changeMagicAttackType); new SetupQuickItem("", this, "pvpAttackTypeEvent", &GameModifiers::getPvpAttackTypeString, &GameModifiers::changePvpAttackType); new SetupQuickItem("", this, "quickDropCounterEvent", &GameModifiers::getQuickDropCounterString, &GameModifiers::changeQuickDropCounter); new SetupQuickItem("", this, "pickUpTypeEvent", &GameModifiers::getPickUpTypeString, &GameModifiers::changePickUpType); new SetupQuickItem("", this, "mapDrawTypeEvent", &GameModifiers::getMapDrawTypeString, &GameModifiers::changeMapDrawType); new SetupQuickItem("", this, "imitationModeEvent", &GameModifiers::getImitationModeString, &GameModifiers::changeImitationMode); new SetupQuickItem("", this, "CameraModeEvent", &GameModifiers::getCameraModeString, &GameModifiers::changeCameraMode); new SetupQuickItem("", this, "awayModeEvent", &GameModifiers::getAwayModeString, &GameModifiers::changeAwayMode); new SetupQuickItem("", this, "targetingTypeEvent", &GameModifiers::getTargetingTypeString, &GameModifiers::changeTargetingType); setDimension(Rect(0, 0, 550, 350)); }
void Batched::DrawQuad(glm::vec2 pos, glm::vec2 size, float rotation, Texture& tex) { innerDraw(pos, size, rotation, tex, Rect(0,0,1,1)); }
int PlayerWin::run() { INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); // set QUICK_V3_ROOT const char *QUICK_V3_ROOT = getenv("QUICK_V3_ROOT"); if (!QUICK_V3_ROOT || strlen(QUICK_V3_ROOT) == 0) { MessageBox("Please run \"setup_win.bat\", set quick-cocos2d-x root path.", "quick-cocos2d-x player error"); return 1; } SimulatorConfig::getInstance()->setQuickCocos2dxRootPath(QUICK_V3_ROOT); // load project config from command line args vector<string> args; for (int i = 0; i < __argc; ++i) { wstring ws(__wargv[i]); string s; s.assign(ws.begin(), ws.end()); args.push_back(s); } _project.parseCommandLine(args); if (_project.getProjectDir().length() <= 0) { _project.resetToWelcome(); } // set framework path if (!_project.isLoadPrecompiledFramework()) { FileUtils::getInstance()->addSearchPath(SimulatorConfig::getInstance()->getQuickCocos2dxRootPath() + "quick/"); } // create the application instance _app = new AppDelegate(); _app->setProjectConfig(_project); // set window icon HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PLAYER)); // create console window if (_project.isShowConsole()) { AllocConsole(); _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { SendMessage(_hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwndConsole, WM_SETICON, ICON_SMALL, (LPARAM)icon); ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } // set environments SetCurrentDirectoryA(_project.getProjectDir().c_str()); FileUtils::getInstance()->setSearchRootPath(_project.getProjectDir().c_str()); FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str()); // check screen DPI HDC screen = GetDC(0); int dpi = GetDeviceCaps(screen, LOGPIXELSX); ReleaseDC(0, screen); // set scale with DPI // 96 DPI = 100 % scaling // 120 DPI = 125 % scaling // 144 DPI = 150 % scaling // 192 DPI = 200 % scaling // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor // // enable DPI-Aware with DeclareDPIAware.manifest // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness float screenScale = 1.0f; //if (dpi >= 120 && dpi < 144) //{ // screenScale = 1.25f; //} //else if (dpi >= 144 && dpi < 192) //{ // screenScale = 1.5f; //} //else if (dpi >= 192) //{ // screenScale = 2.0f; //} CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale); // create opengl view Size frameSize = _project.getFrameSize(); float frameScale = 1.0f; if (_project.isRetinaDisplay()) { frameSize.width *= screenScale; frameSize.height *= screenScale; } else { frameScale = screenScale; } const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height); const bool isResize = _project.isResizeWindow(); auto glview = GLViewImpl::createWithRect("quick-cocos2d-x", frameRect, frameScale, isResize); _hwnd = glview->getWin32Window(); SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon); SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); FreeResource(icon); auto director = Director::getInstance(); director->setOpenGLView(glview); //director->setScreenScale(screenScale); // set window position if (_project.getProjectDir().length()) { setZoom(_project.getFrameScale()); Vec2 pos = _project.getWindowOffset(); if (pos.x != 0 && pos.y != 0) { glfwSetWindowPos(glview->getWindow(), pos.x, pos.y); } } // init player services initServices(); loadLuaConfig(); registerKeyboardEvent(); // register event handlers auto eventDispatcher = director->getEventDispatcher(); eventDispatcher->addCustomEventListener("APP.WINDOW_CLOSE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowClose, this)); eventDispatcher->addCustomEventListener("APP.WINDOW_RESIZE_EVENT", CC_CALLBACK_1(PlayerWin::onWindowResize, this)); eventDispatcher->addCustomEventListener("APP.VIEW_SCALE", CC_CALLBACK_1(PlayerWin::onWindowScale, this)); // prepare _project.dump(); auto app = Application::getInstance(); glfwSetWin32WindowProc(&PlayerWin::windowProc); HWND hwnd = _hwnd; HWND hwndConsole = _hwndConsole; const ProjectConfig &project = _project; director->getScheduler()->schedule([hwnd, hwndConsole, project](float dt) { CC_UNUSED_PARAM(dt); ShowWindow(hwnd, SW_RESTORE); GLFWwindow *window = dynamic_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView())->getWindow(); glfwShowWindow(window); }, this, 0.0f, 0, 0.001f, false, "SHOW_WINDOW_CALLBACK"); if (project.isAppMenu() && GetMenu(hwnd)) { // update window size RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); } ShowWindow(_hwnd, SW_MINIMIZE); // startup message loop return app->run(); }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CMainContainer::Draw(const TRect& /*aRect*/) const { CWindowGc& gc = SystemGc(); gc.Clear(Rect()); }
void CSelectBox::DrawControl(CDC &dc, CRect rcUpdate) { int nWidth = m_rc.Width(); int nHeight = m_rc.Height(); int nItemWidth = nWidth / m_nXCount; int nItemHeight = nHeight / m_nYCount; int nXPos = (nWidth - nItemWidth * m_nXCount) / 2; int nYPos = (nHeight - nItemHeight * m_nYCount) / 2; if(!m_bUpdate) { UpdateMemDC(dc, nWidth, nHeight * 3); m_memDC.BitBlt(0, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY); int nXPosTemp = nXPos; int nYPosTemp = nYPos; Graphics graphics(m_memDC); Pen pen(m_clrFrame, 1); for(int i = 0; i <= m_nYCount; i++) { graphics.DrawLine(&pen, nXPos, nYPosTemp, nXPos + nItemWidth * m_nXCount, nYPosTemp); nYPosTemp += nItemHeight; } for(int i = 0; i <= m_nXCount; i++) { graphics.DrawLine(&pen, nXPosTemp, nYPos, nXPosTemp, nYPos + nItemHeight * m_nYCount); nXPosTemp += nItemWidth; } if(m_bImage) { for(size_t i = 0; i < m_vecpImage.size(); i++) { if(m_vecpImage[i] != NULL) { graphics.DrawImage(m_vecpImage[i], Rect(nXPos + nItemWidth * (i % m_nXCount) + 1, nYPos + nItemHeight * (i / m_nXCount) + 1, nItemWidth - 1, nItemHeight - 1), 0, 0, m_vecsizeImage[i].cx, m_vecsizeImage[i].cy, UnitPixel); } } } else { for(size_t i = 0; i < m_vecclr.size(); i++) { SolidBrush brush(m_vecclr[i]); graphics.FillRectangle(&brush, nXPos + nItemWidth * (i % m_nXCount) + 1, nYPos + nItemHeight * (i / m_nXCount) + 1, nItemWidth - 1, nItemHeight - 1); } } m_memDC.BitBlt(0, nHeight, nWidth, nHeight, &m_memDC, 0, 0, SRCCOPY); m_memDC.BitBlt(0, nHeight * 2, nWidth, nHeight, &m_memDC, 0, 0, SRCCOPY); //选择 SolidBrush brush(m_clrHover); nYPosTemp = nYPos + nHeight; if(m_bImage) { for(size_t i = 0; i < m_vecpImage.size(); i++) { graphics.FillRectangle(&brush, nXPos + nItemWidth * (i % m_nXCount) + 1, nYPosTemp + nItemHeight * (i / m_nXCount) + 1, nItemWidth - 1, nItemHeight - 1); } } else { for(size_t i = 0; i < m_vecclr.size(); i++) { graphics.FillRectangle(&brush, nXPos + nItemWidth * (i % m_nXCount) + 1, nYPosTemp + nItemHeight * (i / m_nXCount) + 1, nItemWidth - 1, nItemHeight - 1); } } int nLineWidth = m_bImage ? 2 : 1; //选中 pen.SetColor(m_clrSelect); pen.SetWidth(nLineWidth); nYPosTemp = nYPos + nHeight * 2; for(int i = 0; i < m_nYCount; i++) { nXPosTemp = nXPos; for(int j = 0; j < m_nXCount; j++) { Rect rect(nXPosTemp + nLineWidth, nYPosTemp + nLineWidth, nItemWidth - 1 - nLineWidth, nItemHeight - 1 - nLineWidth); //绘制矩形 graphics.DrawRectangles(&pen, &rect, 1); nXPosTemp += nItemWidth; } nYPosTemp += nItemHeight; } } dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width()+1, m_rc.Height()+1, &m_memDC, 0, 0, SRCCOPY); if(m_nXSelect != -1 && m_nYSelect != -1) { dc.BitBlt(m_rc.left + nXPos + m_nXSelect * nItemWidth, m_rc.top + nYPos + m_nYSelect * nItemHeight, nItemWidth, nItemHeight, &m_memDC, m_nXSelect * nItemWidth, nHeight * 2 + m_nYSelect * nItemHeight, SRCCOPY); } if(m_nXHover != -1 && m_nYHover != -1) { dc.BitBlt(m_rc.left + nXPos + m_nXHover * nItemWidth, m_rc.top + nYPos + m_nYHover * nItemHeight, nItemWidth, nItemHeight, &m_memDC, m_nXHover * nItemWidth, nHeight + m_nYHover * nItemHeight, SRCCOPY); } }