void localToTarget(float &x, float& y, IFlashDisplayObject* target) { if ( target == 0 ){ //по определению localToGlobal(x, y); //Несколько частных случаев для ускорения работы (getCommonAncestor дорогой) }else if ( target == this ){ return; }else if ( target == parent ){ return localToParent(x, y); }else if ( target->getParent() == parent ){ localToParent(x, y); target->parentToLocal(x, y); }else{ IFlashDisplayObject* commonAncestor = getCommonAncestor(target); if ( !commonAncestor ){ localToGlobal(x, y); target->globalToLocal(x, y); }else{ IFlashDisplayObject* current = this; while ( current != commonAncestor ){ current->localToParent(x, y); current = current->getParent(); } __ancestorToLocal(x, y, current, target); } } };
QPoint MapWidget::getCellUnderMouse(QPointF const & mouse) const { QPointF global = localToGlobal(mouse); return QPoint( floor(global.x() / (((float)mTileSize.width()) * mScale)), floor(global.y() / (((float)mTileSize.height()) * mScale))); }
SkRect LayerAndroid::subtractLayers(const SkRect& visibleRect) const { SkRect result; if (m_recordingPicture) { SkRect globalRect = bounds(); globalRect.offset(-getPosition()); // localToGlobal adds in position SkMatrix globalMatrix; localToGlobal(&globalMatrix); globalMatrix.mapRect(&globalRect); SkIRect roundedGlobal; globalRect.round(&roundedGlobal); SkIRect iVisibleRect; visibleRect.round(&iVisibleRect); SkRegion visRegion(iVisibleRect); visRegion.op(roundedGlobal, SkRegion::kDifference_Op); result.set(visRegion.getBounds()); #if DEBUG_NAV_UI SkDebugf("%s visibleRect=(%g,%g,r=%g,b=%g) globalRect=(%g,%g,r=%g,b=%g)" "result=(%g,%g,r=%g,b=%g)", __FUNCTION__, visibleRect.fLeft, visibleRect.fTop, visibleRect.fRight, visibleRect.fBottom, globalRect.fLeft, globalRect.fTop, globalRect.fRight, globalRect.fBottom, result.fLeft, result.fTop, result.fRight, result.fBottom); #endif } else result = visibleRect; for (int i = 0; i < countChildren(); i++) result = getChild(i)->subtractLayers(result); return result; }
int SDLHardwareRenderDevice::render(Sprite *r) { if (r == NULL) { return -1; } if ( !localToGlobal(r) ) { return -1; } // negative x and y clip causes weird stretching // adjust for that here if (m_clip.x < 0) { m_clip.w -= abs(m_clip.x); m_dest.x += abs(m_clip.x); m_clip.x = 0; } if (m_clip.y < 0) { m_clip.h -= abs(m_clip.y); m_dest.y += abs(m_clip.y); m_clip.y = 0; } m_dest.w = m_clip.w; m_dest.h = m_clip.h; SDL_Rect src = m_clip; SDL_Rect dest = m_dest; SDL_SetRenderTarget(renderer, texture); return SDL_RenderCopy(renderer, static_cast<SDLHardwareImage *>(r->getGraphics())->surface, &src, &dest); }
ofRectangle BasicScreenObject::getScreenBoundingBox(){ Renderer* r = (Renderer*)getRoot(); ofVec2f screenpos[4]; screenpos[0] = r->getCamera()->worldToScreen(localToGlobal(0, 0, 0)); screenpos[1] = r->getCamera()->worldToScreen(localToGlobal(width, 0, 0)); screenpos[2] = r->getCamera()->worldToScreen(localToGlobal(width, height, 0)); screenpos[3] = r->getCamera()->worldToScreen(localToGlobal(0, height, 0)); screenpos[0].y=ofGetHeight()-screenpos[0].y; screenpos[1].y=ofGetHeight()-screenpos[1].y; screenpos[2].y=ofGetHeight()-screenpos[2].y; screenpos[3].y=ofGetHeight()-screenpos[3].y; float smallestx = FLT_MAX; float smallesty = FLT_MAX; float biggestx = -FLT_MAX; float biggesty = -FLT_MAX; for(int i=0; i < 4; i++){ ofVec2f spos = screenpos[i]; if(spos.x>biggestx){ biggestx = spos.x; } if(spos.x<smallestx){ smallestx = spos.x; } if(spos.y>biggesty){ biggesty = spos.y; } if(spos.y<smallesty){ smallesty = spos.y; } } ofRectangle boundingbox; boundingbox.x = smallestx; boundingbox.y = smallesty; boundingbox.width = biggestx-smallestx; boundingbox.height= biggesty-smallesty; return boundingbox; }
MapAbstraction::MapRobotObjectPtr LocalMapLayer::getReferenceFrame(GeoObjectID id) const { Q_ASSERT(hasReferenceFrame(id)); MapAbstraction::MapObjectPtr defrosted(mRobotReferenceFrames.value(id)->Clone()); MapAbstraction::MapRobotObjectPtr robot = defrosted.staticCast<MapAbstraction::MapRobotObject>(); QPointF local(robot->coords().longitude(), robot->coords().latitude()); robot->setCoords(MapLibraryHelpers::transformCoords(localToGlobal(local))); return robot; }
Tnode* initxlocalroot(char *name, u32int addr) { uchar score[VtScoreSize]; Block *b; localToGlobal(addr, score); b = dataBlock(score, BtDir, RootTag); if(b == nil) return stringnode("read data block %#ux: %r", addr); return initxblock(b, smprint("'%s' fs root", name), xlocalrootgen, nil); }
static void rootMetaInit(Entry *e) { u32int addr; u32int tag; DirEntry de; MetaBlock mb; MetaEntry me; memset(&de, 0, sizeof(de)); de.elem = vtStrDup("root"); de.entry = 0; de.gen = 0; de.mentry = 1; de.mgen = 0; de.size = 0; de.qid = qid++; de.uid = vtStrDup("adm"); de.gid = vtStrDup("adm"); de.mid = vtStrDup("adm"); de.mtime = time(0); de.mcount = 0; de.ctime = time(0); de.atime = time(0); de.mode = ModeDir | 0555; tag = tagGen(); addr = blockAlloc(BtData, tag); /* build up meta block */ memset(buf, 0, bsize); mbInit(&mb, buf, bsize, bsize/100); me.size = deSize(&de); me.p = mbAlloc(&mb, me.size); assert(me.p != nil); dePack(&de, &me); mbInsert(&mb, 0, &me); mbPack(&mb); blockWrite(PartData, addr); deCleanup(&de); /* build up entry for meta block */ entryInit(e); e->flags |= VtEntryLocal; e->size = bsize; e->tag = tag; localToGlobal(addr, e->score); }
static u32int rootInit(Entry *e) { ulong addr; u32int tag; tag = tagGen(); addr = blockAlloc(BtDir, tag); memset(buf, 0, bsize); /* root meta data is in the third entry */ entryPack(e, buf, 2); entryInit(e); e->flags |= VtEntryDir; entryPack(e, buf, 0); entryInit(e); entryPack(e, buf, 1); blockWrite(PartData, addr); entryInit(e); e->flags |= VtEntryLocal|VtEntryDir; e->size = VtEntrySize*3; e->tag = tag; localToGlobal(addr, e->score); addr = blockAlloc(BtDir, RootTag); memset(buf, 0, bsize); entryPack(e, buf, 0); blockWrite(PartData, addr); return addr; }
Rectangle<int> ComponentPeer::localToGlobal (const Rectangle<int>& relativePosition) { return relativePosition.withPosition (localToGlobal (relativePosition.getPosition())); }
Point<int> ComponentPeer::localToGlobal (Point<int> p) { return localToGlobal (p.toFloat()).roundToInt(); }
static int bumpEpoch(Fs *fs, int doarchive) { uint8_t oscore[VtScoreSize]; uint32_t oldaddr; Block *b, *bs; Entry e; Source *r; Super super; /* * Duplicate the root block. * * As a hint to flchk, the garbage collector, * and any (human) debuggers, store a pointer * to the old root block in entry 1 of the new root block. */ r = fs->source; b = cacheGlobal(fs->cache, r->score, BtDir, RootTag, OReadOnly); if(b == nil) return 0; memset(&e, 0, sizeof e); e.flags = VtEntryActive | VtEntryLocal | VtEntryDir; memmove(e.score, b->score, VtScoreSize); e.tag = RootTag; e.snap = b->l.epoch; b = blockCopy(b, RootTag, fs->ehi+1, fs->elo); if(b == nil){ fprint(2, "%s: bumpEpoch: blockCopy: %R\n", argv0); return 0; } if(0) fprint(2, "%s: snapshot root from %d to %d\n", argv0, oldaddr, b->addr); entryPack(&e, b->data, 1); blockDirty(b); /* * Update the superblock with the new root and epoch. */ if((bs = superGet(fs->cache, &super)) == nil) return 0; fs->ehi++; memmove(r->score, b->score, VtScoreSize); r->epoch = fs->ehi; super.epochHigh = fs->ehi; oldaddr = super.active; super.active = b->addr; if(doarchive) super.next = oldaddr; /* * Record that the new super.active can't get written out until * the new b gets written out. Until then, use the old value. */ localToGlobal(oldaddr, oscore); blockDependency(bs, b, 0, oscore, nil); blockPut(b); /* * We force the super block to disk so that super.epochHigh gets updated. * Otherwise, if we crash and come back, we might incorrectly treat as active * some of the blocks that making up the snapshot we just created. * Basically every block in the active file system and all the blocks in * the recently-created snapshot depend on the super block now. * Rather than record all those dependencies, we just force the block to disk. * * Note that blockWrite might actually (will probably) send a slightly outdated * super.active to disk. It will be the address of the most recent root that has * gone to disk. */ superWrite(bs, &super, 1); blockRemoveLink(bs, globalToLocal(oscore), BtDir, RootTag, 0); blockPut(bs); return 1; }
Fs * fsOpen(char *file, VtSession *z, int32_t ncache, int mode) { int fd, m; uint8_t oscore[VtScoreSize]; Block *b, *bs; Disk *disk; Fs *fs; Super super; switch(mode){ default: vtSetError(EBadMode); return nil; case OReadOnly: m = OREAD; break; case OReadWrite: m = ORDWR; break; } fd = open(file, m); if(fd < 0){ vtSetError("open %s: %r", file); return nil; } bwatchInit(); disk = diskAlloc(fd); if(disk == nil){ vtSetError("diskAlloc: %R"); close(fd); return nil; } fs = vtMemAllocZ(sizeof(Fs)); fs->mode = mode; fs->name = vtStrDup(file); fs->blockSize = diskBlockSize(disk); fs->elk = vtLockAlloc(); fs->cache = cacheAlloc(disk, z, ncache, mode); if(mode == OReadWrite && z) fs->arch = archInit(fs->cache, disk, fs, z); fs->z = z; b = cacheLocal(fs->cache, PartSuper, 0, mode); if(b == nil) goto Err; if(!superUnpack(&super, b->data)){ blockPut(b); vtSetError("bad super block"); goto Err; } blockPut(b); fs->ehi = super.epochHigh; fs->elo = super.epochLow; //fprint(2, "%s: fs->ehi %d fs->elo %d active=%d\n", argv0, fs->ehi, fs->elo, super.active); fs->source = sourceRoot(fs, super.active, mode); if(fs->source == nil){ /* * Perhaps it failed because the block is copy-on-write. * Do the copy and try again. */ if(mode == OReadOnly || strcmp(vtGetError(), EBadRoot) != 0) goto Err; b = cacheLocalData(fs->cache, super.active, BtDir, RootTag, OReadWrite, 0); if(b == nil){ vtSetError("cacheLocalData: %R"); goto Err; } if(b->l.epoch == fs->ehi){ blockPut(b); vtSetError("bad root source block"); goto Err; } b = blockCopy(b, RootTag, fs->ehi, fs->elo); if(b == nil) goto Err; localToGlobal(super.active, oscore); super.active = b->addr; bs = cacheLocal(fs->cache, PartSuper, 0, OReadWrite); if(bs == nil){ blockPut(b); vtSetError("cacheLocal: %R"); goto Err; } superPack(&super, bs->data); blockDependency(bs, b, 0, oscore, nil); blockPut(b); blockDirty(bs); blockRemoveLink(bs, globalToLocal(oscore), BtDir, RootTag, 0); blockPut(bs); fs->source = sourceRoot(fs, super.active, mode); if(fs->source == nil){ vtSetError("sourceRoot: %R"); goto Err; } } //fprint(2, "%s: got fs source\n", argv0); vtRLock(fs->elk); fs->file = fileRoot(fs->source); fs->source->file = fs->file; /* point back */ vtRUnlock(fs->elk); if(fs->file == nil){ vtSetError("fileRoot: %R"); goto Err; } //fprint(2, "%s: got file root\n", argv0); if(mode == OReadWrite){ fs->metaFlush = periodicAlloc(fsMetaFlush, fs, 1000); fs->snap = snapInit(fs); } return fs; Err: fprint(2, "%s: fsOpen error\n", argv0); fsClose(fs); return nil; }
static u32int ventiRoot(char *host, char *s) { int i, n; uchar score[VtScoreSize]; u32int addr, tag; DirEntry de; MetaBlock mb; MetaEntry me; Entry e; VtRoot root; if(!parseScore(score, s)) vtFatal("bad score '%s'", s); if((z = vtDial(host, 0)) == nil || !vtConnect(z, nil)) vtFatal("connect to venti: %R"); tag = tagGen(); addr = blockAlloc(BtDir, tag); ventiRead(score, VtRootType); if(!vtRootUnpack(&root, buf)) vtFatal("corrupted root: vtRootUnpack"); n = ventiRead(root.score, VtDirType); /* * Fossil's vac archives start with an extra layer of source, * but vac's don't. */ if(n <= 2*VtEntrySize){ if(!entryUnpack(&e, buf, 0)) vtFatal("bad root: top entry"); n = ventiRead(e.score, VtDirType); } /* * There should be three root sources (and nothing else) here. */ for(i=0; i<3; i++){ if(!entryUnpack(&e, buf, i) || !(e.flags&VtEntryActive) || e.psize < 256 || e.dsize < 256) vtFatal("bad root: entry %d", i); fprint(2, "%V\n", e.score); } if(n > 3*VtEntrySize) vtFatal("bad root: entry count"); blockWrite(PartData, addr); /* * Maximum qid is recorded in root's msource, entry #2 (conveniently in e). */ ventiRead(e.score, VtDataType); if(!mbUnpack(&mb, buf, bsize)) vtFatal("bad root: mbUnpack"); meUnpack(&me, &mb, 0); if(!deUnpack(&de, &me)) vtFatal("bad root: dirUnpack"); if(!de.qidSpace) vtFatal("bad root: no qidSpace"); qid = de.qidMax; /* * Recreate the top layer of source. */ entryInit(&e); e.flags |= VtEntryLocal|VtEntryDir; e.size = VtEntrySize*3; e.tag = tag; localToGlobal(addr, e.score); addr = blockAlloc(BtDir, RootTag); memset(buf, 0, bsize); entryPack(&e, buf, 0); blockWrite(PartData, addr); return addr; }
ofVec3f BasicScreenObject::localToGlobal(float _x, float _y, float _z){ ofVec3f local(_x, _y, _z); return localToGlobal(local); }