void CGameMap::ShowFog(){ CRect mapRect(0,0,sizeX-1,sizeY-1); CPoint gridPoint(CConvert::GetGridPointByScreenPoint(CPoint(-64*6,-32*6))); //gridPoint = CConvert::GetGridPointByScreenPoint(CPoint(-64*6,-32*6)); for(int y=0;y<SIZE_Y/32+17;y++){//17為最佳化的值 for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x+=1; gridPoint.y-=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint)){ if(mapTile[gridPoint.y][gridPoint.x].VisionCount()==0 && mapTile[gridPoint.y][gridPoint.x].IsExplored()){ fog.SetTopLeft(screenPoint.x-fog.Width()/2,screenPoint.y); fog.ShowBitmap(); } } } gridPoint.x+=1; for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x-=1; gridPoint.y+=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint)){ if(mapTile[gridPoint.y][gridPoint.x].VisionCount()==0 && mapTile[gridPoint.y][gridPoint.x].IsExplored()){ fog.SetTopLeft(screenPoint.x-fog.Width()/2,screenPoint.y); fog.ShowBitmap(); } } } gridPoint.y+=1; } }
void EditTSCtrl::make3DMouseEvent(Gui3DMouseEvent & gui3DMouseEvent, const GuiEvent & event) { (GuiEvent&)(gui3DMouseEvent) = event; gui3DMouseEvent.mousePoint = event.mousePoint; if(!smCamOrtho) { // get the eye pos and the mouse vec from that... Point3F screenPoint((F32)gui3DMouseEvent.mousePoint.x, (F32)gui3DMouseEvent.mousePoint.y, 1.0f); Point3F wp; unproject(screenPoint, &wp); gui3DMouseEvent.pos = smCamPos; gui3DMouseEvent.vec = wp - smCamPos; gui3DMouseEvent.vec.normalizeSafe(); } else { // get the eye pos and the mouse vec from that... Point3F screenPoint((F32)gui3DMouseEvent.mousePoint.x, (F32)gui3DMouseEvent.mousePoint.y, 0.0f); Point3F np, fp; unproject(screenPoint, &np); gui3DMouseEvent.pos = np; smCamMatrix.getColumn( 1, &(gui3DMouseEvent.vec) ); } }
void CGameMap::ShowMapTile(){ CPoint gridPoint(CConvert::GetGridPointByScreenPoint(CPoint(-64*6,-32*6))); //取得整個地圖的範圍,用於判斷是否再地圖內 CRect mapRect(0,0,sizeX-1,sizeY-1); for(int y=0;y<SIZE_Y/32+17;y++){//17為最佳化的值 for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x+=1; gridPoint.y-=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint) && this->mapTile[gridPoint.y][gridPoint.x].IsExplored()){ this->mapTile[gridPoint.y][gridPoint.x].OnShow(); } } gridPoint.x+=1; for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x-=1; gridPoint.y+=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint) && this->mapTile[gridPoint.y][gridPoint.x].IsExplored()){ this->mapTile[gridPoint.y][gridPoint.x].OnShow(); } } gridPoint.y+=1; } gridPoint = CConvert::GetGridPointByScreenPoint(CPoint(-64*6,-32*6)); for(int y=0;y<SIZE_Y/32+17;y++){//17為最佳化的值 for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x+=1; gridPoint.y-=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint) && this->mapTile[gridPoint.y][gridPoint.x].IsExplored()){ //this->mapTile[gridPoint.y][gridPoint.x].OnShow(); } } gridPoint.x+=1; for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x-=1; gridPoint.y+=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint) && this->mapTile[gridPoint.y][gridPoint.x].IsExplored()){ //this->mapTile[gridPoint.y][gridPoint.x].OnShow(); } } gridPoint.y+=1; } }
void CGameMap::ShowSprites(){ CRect mapRect(0,0,sizeX-1,sizeY-1); CPoint gridPoint(CConvert::GetGridPointByScreenPoint(CPoint(-64*6,-32*6))); //gridPoint = CConvert::GetGridPointByScreenPoint(CPoint(-64*6,-32*6)); for(int y=0;y<SIZE_Y/32+17;y++){//17為最佳化的值 for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x+=1; gridPoint.y-=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint)){ if(!mapTile[gridPoint.y][gridPoint.x].IsExplored()){ continue; } if(mapTile[gridPoint.y][gridPoint.x].VisionCount()==0){//視野外只顯示房子 set<CSprite*>::iterator it; for(it = mapTile[gridPoint.y][gridPoint.x].Sprites().begin();it!= mapTile[gridPoint.y][gridPoint.x].Sprites().end();it++){ if((*it)->IsBuilding() || (*it)->IsResource()){ (*it)->OnShow(); } } }else{//再視野內 this->mapTile[gridPoint.y][gridPoint.x].OnShowSprites(); } } } gridPoint.x+=1; for(int x=0;x<SIZE_X/64+12;x++){ gridPoint.x-=1; gridPoint.y+=1; CPoint screenPoint(CConvert::GetScreenPointByGridPoint(gridPoint)); if(mapRect.PtInRect(gridPoint)){ if(!mapTile[gridPoint.y][gridPoint.x].IsExplored()){ continue; } if(mapTile[gridPoint.y][gridPoint.x].VisionCount()==0){//視野外只顯示房子 set<CSprite*>::iterator it; for(it = mapTile[gridPoint.y][gridPoint.x].Sprites().begin();it!= mapTile[gridPoint.y][gridPoint.x].Sprites().end();it++){ if((*it)->IsBuilding()){ (*it)->OnShow(); } } }else{//再視野內 this->mapTile[gridPoint.y][gridPoint.x].OnShowSprites(); } } } gridPoint.y+=1; } }
Math::Ray Camera::GenerateRay(double x, double y) const{ Math::Point screenPoint(x,y,0); Math::Point cameraPoint = mScreenToCamera(screenPoint); Math::Ray ray(Math::Point(0,0,0), Math::Vector(cameraPoint)); return mCameraToWorld(ray); }
void TransferFunctionAlphaWidget::paintOpacityGraph(QPainter& painter) { QPen pointPen, pointLinePen; pointPen.setColor(QColor(0, 0, 150)); pointLinePen.setColor(QColor(150, 100, 100)); // Go through each point and draw squares and lines IntIntMap opacityMap = mImageTF->getOpacityMap(); QPoint lastScreenPoint; this->mPointRects.clear(); for (IntIntMap::iterator opPoint = opacityMap.begin(); opPoint != opacityMap.end(); ++opPoint) { // Get the screen (plot) position of this point AlphaPoint pt(opPoint->first, opPoint->second); QPoint screenPoint = this->alpha2screen(pt); // draw line from left edge to first point: if (opPoint==opacityMap.begin()) { lastScreenPoint = QPoint(mPlotArea.left(), screenPoint.y()); } // Draw line from previous point painter.setPen(pointLinePen); painter.drawLine(lastScreenPoint, screenPoint); // Draw the rectangle QRect pointRect(screenPoint.x() - mBorder, screenPoint.y() - mBorder, mBorder*2, mBorder*2); if (opPoint->first==mSelectedAlphaPoint.position) { pointPen.setWidth(2); painter.setPen(pointPen); } else { pointPen.setWidth(1); painter.setPen(pointPen); } painter.drawRect(pointRect); this->mPointRects[opPoint->first] = pointRect; // Store the point lastScreenPoint = screenPoint; } // draw a line from the last point to the right end QPoint screenPoint(mPlotArea.right(), lastScreenPoint.y()); painter.setPen(pointLinePen); painter.drawLine(lastScreenPoint, screenPoint); }
void CMouse::InternalOnMouseMove(UINT nFlags, const CPoint& point) { CPoint screenPoint(point); GetWnd().ClientToScreen(&screenPoint); if (!TestDrag(screenPoint) && !m_pMainFrame->IsInteractiveVideo()) { if (!m_bTrackingMouseLeave) { StartMouseLeaveTracker(); } SetCursor(nFlags, screenPoint, point); MVRMove(nFlags, point); } m_pMainFrame->UpdateControlState(CMainFrame::UPDATE_CONTROLS_VISIBILITY); }
void GameTSCtrl::onMouseMove(const GuiEvent &evt) { if(gSnapLine) return; MatrixF mat; Point3F vel; if ( GameGetCameraTransform(&mat, &vel) ) { Point3F pos; mat.getColumn(3,&pos); Point3F screenPoint((F32)evt.mousePoint.x, (F32)evt.mousePoint.y, 1.0f); Point3F worldPoint; if (unproject(screenPoint, &worldPoint)) { Point3F vec = worldPoint - pos; lineTestStart = pos; vec.normalizeSafe(); lineTestEnd = pos + vec * 500; static U32 losMask = VehicleObjectType | StaticShapeObjectType; RayInfo ri; bool hit = gClientContainer.castRay( lineTestStart, lineTestEnd, losMask, &ri); if (!hit) { //Con::printf("no hit!"); if (mCursorObject != NULL) mCursorObject->setHighlighted(false); mCursorObject = NULL; } else { if (ri.object != mCursorObject && mCursorObject != NULL) mCursorObject->setHighlighted(false); mCursorObject = (ShapeBase*)ri.object; mCursorObject->setHighlighted(true); } } } }
void CSelectionPanel::OnShowHPLine(){ set<CSprite*>::iterator it; CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC CBrush *pb,redBrush(RGB(255,0,0)),greenBrush(RGB(0,255,0)); CPen *pp,blackPen(PS_SOLID,1,RGB(0,0,0)); pp = pDC->SelectObject(&blackPen); pb = pDC->SelectObject(&redBrush); for(it = selectedSprites.begin();it!=selectedSprites.end();it++){ CPoint screenPoint(CConvert::GetScreenPointByMapPoint((*it)->MapPoint())); CRect redRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50,5)); pDC->Rectangle(redRect); CRect greenRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50*(*it)->HP()/(*it)->MaxHP(),5)); pDC->SelectObject(&greenBrush); pDC->Rectangle(greenRect); pDC->SelectObject(&redBrush); } pDC->SelectObject(pb); // pDC->SelectObject(pp); CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC //if(isSelected){ // //畫圓圈 // CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC // CBrush *pb,redBrush(RGB(255,0,0)),greenBrush(RGB(0,255,0)); // CPen *pp,nullPen(PS_NULL,0,RGB(0,0,0)); // pb = pDC->SelectObject(&redBrush); // pp = pDC->SelectObject(&nullPen); // CPoint screenPoint(CConvert::GetScreenPointByMapPoint(mapPoint)); // CRect redRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50,5)); // CRect greenRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50*hp/maxHp,5)); // pDC->Rectangle(redRect); // pDC->SelectObject(&greenBrush); // pDC->Rectangle(greenRect); // pDC->SelectObject(pb); // // pDC->SelectObject(pp); // CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC //} }
void GameTSCtrl::onMouseMove(const GuiEvent &evt) { if(gSnapLine) return; MatrixF mat; Point3F vel; if ( GameGetCameraTransform(&mat, &vel) ) { Point3F pos; mat.getColumn(3,&pos); Point3F screenPoint((F32)evt.mousePoint.x, (F32)evt.mousePoint.y, -1.0f); Point3F worldPoint; if (unproject(screenPoint, &worldPoint)) { Point3F vec = worldPoint - pos; lineTestStart = pos; vec.normalizeSafe(); lineTestEnd = pos + vec * 1000; } } }
void CUnit::OnShowSelectedLine(){ //畫圓圈 CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC CPen penBlack; CPen penWhite; CPen* pOldPen; penBlack.CreatePen(PS_SOLID,1,RGB(0,0,0)); penWhite.CreatePen(PS_SOLID,1,RGB(255,255,255)); pOldPen = pDC->SelectObject(&penBlack); CRect rect; CPoint screenPoint(CConvert::GetScreenPointByMapPoint(mapPoint)); rect.SetRect( screenPoint.x-bmp->Width()/2-10, screenPoint.y-25, screenPoint.x+bmp->Width()/2+10, screenPoint.y+5); pDC->Arc(rect,rect.TopLeft(),rect.TopLeft()); rect.MoveToY(rect.top+1); pDC->SelectObject(&penWhite); pDC->Arc(rect,rect.TopLeft(),rect.TopLeft()); pDC->SelectObject(pOldPen); // CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC }
void RecentProjectsList::MouseDown(BPoint where) { uint32 buttons; BPoint point; GetMouse(&point, &buttons); if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) { BMessage* message = Window()->CurrentMessage(); int32 clicks; message->FindInt32("clicks", &clicks); if (clicks > 1) { clicks = 1; message->ReplaceInt32("clicks", clicks); } } BListView::MouseDown(where); if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) { BPoint screenPoint(where); ConvertToScreen(&screenPoint); screenPoint.x -= 5; screenPoint.y -= 5; BStringItem* stringItem = (BStringItem*)ItemAt(IndexOf(where)); if (stringItem == NULL) return; BPopUpMenu menu("context"); menu.AddItem(new BMenuItem(TR("Remove from Recent List"), new BMessage(M_REMOVE_FROM_LIST))); menu.SetTargetForItems(Window()); menu.Go(screenPoint, true, false); } }
void CGameMap::OnMove(){ //////////地圖動作開始////////// if(this->isMovingLeft){//往左移動 this->sx-=16; } if(this->isMovingRight){//往右移動 this->sx+=16; } if(this->isMovingUp){//往上移動 this->sy-=8; } if(this->isMovingDown){//往下移動 this->sy+=8; } //修正螢幕座標 CPoint mapPoint(CConvert::GetMapPointByScreenPoint(CPoint(400,220))); mapPoint.x = mapPoint.x<0? 0: mapPoint.x; mapPoint.x = mapPoint.x>=sizeX*64? sizeX*64-1:mapPoint.x; mapPoint.y = mapPoint.y<0? 0: mapPoint.y; mapPoint.y = mapPoint.y>=sizeY*64? sizeY*64-1:mapPoint.y; CPoint screenPoint(CConvert::GetScreenPointByMapPoint(mapPoint)); sx += screenPoint.x-400; sy += screenPoint.y-220; }
//main render engine function called as multiple threads void cRenderWorker::doWork(void) { // here will be rendering thread QTextStream out(stdout); int width = image->GetWidth(); int height = image->GetHeight(); double aspectRatio = (double) width / height; PrepareMainVectors(); PrepareReflectionBuffer(); if (params->ambientOcclusionEnabled && params->ambientOcclusionMode == params::AOmodeMultipeRays) PrepareAOVectors(); //init of scheduler cScheduler *scheduler = threadData->scheduler; //start point for ray-marching CVector3 start = params->camera; scheduler->InitFirstLine(threadData->id, threadData->startLine); bool lastLineWasBroken = false; //main loop for y for (int ys = threadData->startLine; scheduler->ThereIsStillSomethingToDo(threadData->id); ys = scheduler->NextLine(threadData->id, ys, lastLineWasBroken)) { //skip if line is out of region if (ys < 0) break; if (ys < data->screenRegion.y1 || ys > data->screenRegion.y2) continue; //main loop for x for (int xs = 0; xs < width; xs += scheduler->GetProgressiveStep()) { //break if by coincidence this thread started rendering the same line as some other lastLineWasBroken = false; if (scheduler->ShouldIBreak(threadData->id, ys)) { lastLineWasBroken = true; break; } if (scheduler->GetProgressivePass() > 1 && xs % (scheduler->GetProgressiveStep() * 2) == 0 && ys % (scheduler->GetProgressiveStep() * 2) == 0) continue; //skip if pixel is out of region; if (xs < data->screenRegion.x1 || xs > data->screenRegion.x2) continue; //calculate point in image coordinate system CVector2<int> screenPoint(xs, ys); CVector2<double> imagePoint = data->screenRegion.transpose(data->imageRegion, screenPoint); imagePoint.x *= aspectRatio; //full dome shemisphere cut bool hemisphereCut = false; if (params->perspectiveType == params::perspFishEyeCut && imagePoint.Length() > 0.5 / params->fov) hemisphereCut = true; //calculate direction of ray-marching CVector3 viewVector = CalculateViewVector(imagePoint, params->fov, params->perspectiveType, mRot); //---------------- 1us ------------- //Ray marching CVector3 point; CVector3 startRay = start; sRGBAfloat resultShader; sRGBAfloat objectColour; CVector3 normal; double depth = 1e20; double opacity = 1.0; //raymarching loop (reflections) if (!hemisphereCut) //in fulldome mode, will not render pixels out of the fulldome { sRayRecursionIn recursionIn; sRayMarchingIn rayMarchingIn; CVector3 direction = viewVector; direction.Normalize(); rayMarchingIn.binaryEnable = true; rayMarchingIn.direction = direction; rayMarchingIn.maxScan = params->viewDistanceMax; rayMarchingIn.minScan = params->viewDistanceMin; rayMarchingIn.start = startRay; rayMarchingIn.invertMode = false; recursionIn.rayMarchingIn = rayMarchingIn; recursionIn.calcInside = false; recursionIn.resultShader = resultShader; recursionIn.objectColour = objectColour; sRayRecursionInOut recursionInOut; sRayMarchingInOut rayMarchingInOut; rayMarchingInOut.buffCount = &rayBuffer[0].buffCount; rayMarchingInOut.stepBuff = rayBuffer[0].stepBuff; recursionInOut.rayMarchingInOut = rayMarchingInOut; recursionInOut.rayIndex = 0; sRayRecursionOut recursionOut = RayRecursion(recursionIn, recursionInOut); resultShader = recursionOut.resultShader; objectColour = recursionOut.objectColour; depth = recursionOut.rayMarchingOut.depth; if (!recursionOut.found) depth = 1e20; opacity = recursionOut.fogOpacity; normal = recursionOut.normal; } sRGBfloat pixel2; pixel2.R = resultShader.R; pixel2.G = resultShader.G; pixel2.B = resultShader.B; unsigned short alpha = resultShader.A * 65535; unsigned short opacity16 = opacity * 65535; sRGB8 colour; colour.R = objectColour.R * 255; colour.G = objectColour.G * 255; colour.B = objectColour.B * 255; sRGBfloat normalFloat; if(image->GetImageOptional()->optionalNormal) { CVector3 normalRotated = mRotInv.RotateVector(normal); normalFloat.R = (1.0 + normalRotated.x) / 2.0; normalFloat.G = (1.0 + normalRotated.z) / 2.0; normalFloat.B = 1.0 - normalRotated.y; } for (int xx = 0; xx < scheduler->GetProgressiveStep(); ++xx) { for (int yy = 0; yy < scheduler->GetProgressiveStep(); ++yy) { image->PutPixelImage(screenPoint.x + xx, screenPoint.y + yy, pixel2); image->PutPixelColour(screenPoint.x + xx, screenPoint.y + yy, colour); image->PutPixelAlpha(screenPoint.x + xx, screenPoint.y + yy, alpha); image->PutPixelZBuffer(screenPoint.x + xx, screenPoint.y + yy, (float) depth); image->PutPixelOpacity(screenPoint.x + xx, screenPoint.y + yy, opacity16); if(image->GetImageOptional()->optionalNormal) image->PutPixelNormal(screenPoint.x + xx, screenPoint.y + yy, normalFloat); } } data->statistics.numberOfRenderedPixels++; } } //emit signal to main thread when finished emit finished(); return; }
void CMouse::SetCursor(UINT nFlags, const CPoint& clientPoint) { CPoint screenPoint(clientPoint); GetWnd().ClientToScreen(&screenPoint); SetCursor(nFlags, screenPoint, clientPoint); }
NS_IMETHODIMP nsResizerFrame::HandleEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { NS_ENSURE_ARG_POINTER(aEventStatus); if (nsEventStatus_eConsumeNoDefault == *aEventStatus) { return NS_OK; } nsWeakFrame weakFrame(this); bool doDefault = true; switch (aEvent->message) { case NS_MOUSE_BUTTON_DOWN: { if (aEvent->eventStructType == NS_MOUSE_EVENT && static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) { nsCOMPtr<nsIBaseWindow> window; nsIPresShell* presShell = aPresContext->GetPresShell(); nsIContent* contentToResize = GetContentToResize(presShell, getter_AddRefs(window)); if (contentToResize) { nsIFrame* frameToResize = contentToResize->GetPrimaryFrame(); if (!frameToResize) break; // cache the content rectangle for the frame to resize // GetScreenRectInAppUnits returns the border box rectangle, so // adjust to get the desired content rectangle. nsRect rect = frameToResize->GetScreenRectInAppUnits(); switch (frameToResize->GetStylePosition()->mBoxSizing) { case NS_STYLE_BOX_SIZING_CONTENT: rect.Deflate(frameToResize->GetUsedPadding()); case NS_STYLE_BOX_SIZING_PADDING: rect.Deflate(frameToResize->GetUsedBorder()); default: break; } mMouseDownRect = rect.ToNearestPixels(aPresContext->AppUnitsPerDevPixel()); doDefault = false; } else { // If there is no window, then resizing isn't allowed. if (!window) break; doDefault = false; // ask the widget implementation to begin a resize drag if it can Direction direction = GetDirection(); nsresult rv = aEvent->widget->BeginResizeDrag(aEvent, direction.mHorizontal, direction.mVertical); // for native drags, don't set the fields below if (rv != NS_ERROR_NOT_IMPLEMENTED) break; // if there's no native resize support, we need to do window // resizing ourselves window->GetPositionAndSize(&mMouseDownRect.x, &mMouseDownRect.y, &mMouseDownRect.width, &mMouseDownRect.height); } // we're tracking mTrackingMouseMove = true; // remember current mouse coordinates mMouseDownPoint = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset(); nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED); } } break; case NS_MOUSE_BUTTON_UP: { if (mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT && static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) { // we're done tracking. mTrackingMouseMove = false; nsIPresShell::SetCapturingContent(nsnull, 0); doDefault = false; } } break; case NS_MOUSE_MOVE: { if (mTrackingMouseMove) { nsCOMPtr<nsIBaseWindow> window; nsIPresShell* presShell = aPresContext->GetPresShell(); nsCOMPtr<nsIContent> contentToResize = GetContentToResize(presShell, getter_AddRefs(window)); // check if the returned content really is a menupopup nsMenuPopupFrame* menuPopupFrame = nsnull; if (contentToResize) { nsIFrame* frameToResize = contentToResize->GetPrimaryFrame(); if (frameToResize && frameToResize->GetType() == nsGkAtoms::menuPopupFrame) { menuPopupFrame = static_cast<nsMenuPopupFrame *>(frameToResize); } } // both MouseMove and direction are negative when pointing to the // top and left, and positive when pointing to the bottom and right // retrieve the offset of the mousemove event relative to the mousedown. // The difference is how much the resize needs to be nsIntPoint screenPoint(aEvent->refPoint + aEvent->widget->WidgetToScreenOffset()); nsIntPoint mouseMove(screenPoint - mMouseDownPoint); // Determine which direction to resize by checking the dir attribute. // For windows and menus, ensure that it can be resized in that direction. Direction direction = GetDirection(); if (window || menuPopupFrame) { if (menuPopupFrame) { menuPopupFrame->CanAdjustEdges( (direction.mHorizontal == -1) ? NS_SIDE_LEFT : NS_SIDE_RIGHT, (direction.mVertical == -1) ? NS_SIDE_TOP : NS_SIDE_BOTTOM, mouseMove); } } else if (!contentToResize) { break; // don't do anything if there's nothing to resize } nsIntRect rect = mMouseDownRect; AdjustDimensions(&rect.x, &rect.width, mouseMove.x, direction.mHorizontal); AdjustDimensions(&rect.y, &rect.height, mouseMove.y, direction.mVertical); // Don't allow resizing a window or a popup past the edge of the screen, // so adjust the rectangle to fit within the available screen area. if (window) { nsCOMPtr<nsIScreen> screen; nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1")); if (sm) { nsIntRect frameRect = GetScreenRect(); sm->ScreenForRect(frameRect.x, frameRect.y, 1, 1, getter_AddRefs(screen)); if (screen) { nsIntRect screenRect; screen->GetRect(&screenRect.x, &screenRect.y, &screenRect.width, &screenRect.height); rect.IntersectRect(rect, screenRect); } } } else if (menuPopupFrame) { nsRect frameRect = menuPopupFrame->GetScreenRectInAppUnits(); nsIFrame* rootFrame = aPresContext->PresShell()->FrameManager()->GetRootFrame(); nsRect rootScreenRect = rootFrame->GetScreenRectInAppUnits(); nsRect screenRect = menuPopupFrame->GetConstraintRect(frameRect, rootScreenRect); // round using ToInsidePixels as it's better to be a pixel too small // than be too large. If the popup is too large it could get flipped // to the opposite side of the anchor point while resizing. nsIntRect screenRectPixels = screenRect.ToInsidePixels(aPresContext->AppUnitsPerDevPixel()); rect.IntersectRect(rect, screenRectPixels); } if (contentToResize) { // convert the rectangle into css pixels. When changing the size in a // direction, don't allow the new size to be less that the resizer's // size. This ensures that content isn't resized too small as to make // the resizer invisible. nsRect appUnitsRect = rect.ToAppUnits(aPresContext->AppUnitsPerDevPixel()); if (appUnitsRect.width < mRect.width && mouseMove.x) appUnitsRect.width = mRect.width; if (appUnitsRect.height < mRect.height && mouseMove.y) appUnitsRect.height = mRect.height; nsIntRect cssRect = appUnitsRect.ToInsidePixels(nsPresContext::AppUnitsPerCSSPixel()); nsIntRect oldRect; nsWeakFrame weakFrame(menuPopupFrame); if (menuPopupFrame) { nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget(); if (widget) widget->GetScreenBounds(oldRect); // convert the new rectangle into outer window coordinates nsIntPoint clientOffset = widget->GetClientOffset(); rect.x -= clientOffset.x; rect.y -= clientOffset.y; } SizeInfo sizeInfo, originalSizeInfo; sizeInfo.width.AppendInt(cssRect.width); sizeInfo.height.AppendInt(cssRect.height); ResizeContent(contentToResize, direction, sizeInfo, &originalSizeInfo); MaybePersistOriginalSize(contentToResize, originalSizeInfo); if (weakFrame.IsAlive() && (oldRect.x != rect.x || oldRect.y != rect.y) && (!menuPopupFrame->IsAnchored() || menuPopupFrame->PopupLevel() != ePopupLevelParent)) { menuPopupFrame->MoveTo(rect.x, rect.y, true); } } else { window->SetPositionAndSize(rect.x, rect.y, rect.width, rect.height, true); // do the repaint. } doDefault = false; } } break; case NS_MOUSE_CLICK: if (NS_IS_MOUSE_LEFT_CLICK(aEvent)) { MouseClicked(aPresContext, aEvent); } break; case NS_MOUSE_DOUBLECLICK: if (aEvent->eventStructType == NS_MOUSE_EVENT && static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) { nsCOMPtr<nsIBaseWindow> window; nsIPresShell* presShell = aPresContext->GetPresShell(); nsIContent* contentToResize = GetContentToResize(presShell, getter_AddRefs(window)); if (contentToResize) { nsIFrame* frameToResize = contentToResize->GetPrimaryFrame(); if (frameToResize && frameToResize->GetType() == nsGkAtoms::menuPopupFrame) break; // Don't restore original sizing for menupopup frames until // we handle screen constraints here. (Bug 357725) RestoreOriginalSize(contentToResize); } } break; } if (!doDefault) *aEventStatus = nsEventStatus_eConsumeNoDefault; if (doDefault && weakFrame.IsAlive()) return nsTitleBarFrame::HandleEvent(aPresContext, aEvent, aEventStatus); return NS_OK; }
NS_IMETHODIMP nsResizerFrame::HandleEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { NS_ENSURE_ARG_POINTER(aEventStatus); if (nsEventStatus_eConsumeNoDefault == *aEventStatus) { return NS_OK; } nsWeakFrame weakFrame(this); PRBool doDefault = PR_TRUE; switch (aEvent->message) { case NS_MOUSE_BUTTON_DOWN: { if (aEvent->eventStructType == NS_MOUSE_EVENT && static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) { nsCOMPtr<nsIBaseWindow> window; nsIPresShell* presShell = aPresContext->GetPresShell(); nsIContent* contentToResize = GetContentToResize(presShell, getter_AddRefs(window)); if (contentToResize) { nsIFrame* frameToResize = contentToResize->GetPrimaryFrame(); if (!frameToResize) break; mMouseDownRect = frameToResize->GetScreenRect(); } else { // ask the widget implementation to begin a resize drag if it can Direction direction = GetDirection(); nsresult rv = aEvent->widget->BeginResizeDrag(aEvent, direction.mHorizontal, direction.mVertical); if (rv == NS_ERROR_NOT_IMPLEMENTED && window) { // if there's no native resize support, we need to do window // resizing ourselves window->GetPositionAndSize(&mMouseDownRect.x, &mMouseDownRect.y, &mMouseDownRect.width, &mMouseDownRect.height); } else { // for native drags, don't set the fields below doDefault = PR_FALSE; break; } } // we're tracking mTrackingMouseMove = PR_TRUE; // remember current mouse coordinates mMouseDownPoint = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset(); nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED); doDefault = PR_FALSE; } } break; case NS_MOUSE_BUTTON_UP: { if (mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT && static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) { // we're done tracking. mTrackingMouseMove = PR_FALSE; nsIPresShell::SetCapturingContent(nsnull, 0); doDefault = PR_FALSE; } } break; case NS_MOUSE_MOVE: { if (mTrackingMouseMove) { nsCOMPtr<nsIBaseWindow> window; nsIPresShell* presShell = aPresContext->GetPresShell(); nsCOMPtr<nsIContent> contentToResize = GetContentToResize(presShell, getter_AddRefs(window)); // check if the returned content really is a menupopup nsMenuPopupFrame* menuPopupFrame = nsnull; if (contentToResize) { nsIFrame* frameToResize = contentToResize->GetPrimaryFrame(); if (frameToResize && frameToResize->GetType() == nsGkAtoms::menuPopupFrame) { menuPopupFrame = static_cast<nsMenuPopupFrame *>(frameToResize); } } // both MouseMove and direction are negative when pointing to the // top and left, and positive when pointing to the bottom and right // retrieve the offset of the mousemove event relative to the mousedown. // The difference is how much the resize needs to be nsIntPoint screenPoint(aEvent->refPoint + aEvent->widget->WidgetToScreenOffset()); nsIntPoint mouseMove(screenPoint - mMouseDownPoint); // what direction should we go in? For content resizing, always use // 'bottomend'. For other windows, check the dir attribute. Direction direction; if (window || menuPopupFrame) { direction = GetDirection(); if (menuPopupFrame) { menuPopupFrame->CanAdjustEdges( (direction.mHorizontal == -1) ? NS_SIDE_LEFT : NS_SIDE_RIGHT, (direction.mVertical == -1) ? NS_SIDE_TOP : NS_SIDE_BOTTOM, mouseMove); } } else if (contentToResize) { direction.mHorizontal = GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL ? -1 : 1; direction.mVertical = 1; } else { break; // don't do anything if there's nothing to resize } nsIntRect rect = mMouseDownRect; AdjustDimensions(&rect.x, &rect.width, mouseMove.x, direction.mHorizontal); AdjustDimensions(&rect.y, &rect.height, mouseMove.y, direction.mVertical); // Don't allow resizing a window or a popup past the edge of the screen, // so adjust the rectangle to fit within the available screen area. if (window) { nsCOMPtr<nsIScreen> screen; nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1")); if (sm) { nsIntRect frameRect = GetScreenRect(); sm->ScreenForRect(frameRect.x, frameRect.y, 1, 1, getter_AddRefs(screen)); if (screen) { nsIntRect screenRect; screen->GetRect(&screenRect.x, &screenRect.y, &screenRect.width, &screenRect.height); rect.IntersectRect(rect, screenRect); } } } else if (menuPopupFrame) { nsPoint framePoint = menuPopupFrame->GetScreenRectInAppUnits().TopLeft(); nsIFrame* rootFrame = aPresContext->PresShell()->FrameManager()->GetRootFrame(); nsRect rootScreenRect = rootFrame->GetScreenRectInAppUnits(); nsRect screenRect = menuPopupFrame->GetConstraintRect(framePoint, rootScreenRect); // round using ToInsidePixels as it's better to be a pixel too small // than be too large. If the popup is too large it could get flipped // to the opposite side of the anchor point while resizing. nsIntRect screenRectPixels = screenRect.ToInsidePixels(aPresContext->AppUnitsPerDevPixel()); rect.IntersectRect(rect, screenRectPixels); } if (contentToResize) { nsIntRect cssRect = rect.ToAppUnits(aPresContext->AppUnitsPerDevPixel()) .ToInsidePixels(nsPresContext::AppUnitsPerCSSPixel()); nsAutoString widthstr, heightstr; widthstr.AppendInt(cssRect.width); heightstr.AppendInt(cssRect.height); // for XUL elements, just set the width and height attributes. For // other elements, set style.width and style.height if (contentToResize->IsXUL()) { nsIntRect oldRect; nsWeakFrame weakFrame(menuPopupFrame); if (menuPopupFrame) { nsCOMPtr<nsIWidget> widget; menuPopupFrame->GetWidget(getter_AddRefs(widget)); if (widget) widget->GetScreenBounds(oldRect); } contentToResize->SetAttr(kNameSpaceID_None, nsGkAtoms::width, widthstr, PR_TRUE); contentToResize->SetAttr(kNameSpaceID_None, nsGkAtoms::height, heightstr, PR_TRUE); if (weakFrame.IsAlive() && (oldRect.x != rect.x || oldRect.y != rect.y)) { // XXX This might go very wrong, since menu popups may add // offsets (e.g. from margins) to this position, so the popup's // widget won't end up at the desired position. menuPopupFrame->MoveTo(rect.x, rect.y, PR_TRUE); } } else { nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyleContent = do_QueryInterface(contentToResize); if (inlineStyleContent) { widthstr += NS_LITERAL_STRING("px"); heightstr += NS_LITERAL_STRING("px"); nsCOMPtr<nsIDOMCSSStyleDeclaration> decl; inlineStyleContent->GetStyle(getter_AddRefs(decl)); decl->SetProperty(NS_LITERAL_STRING("width"), widthstr, EmptyString()); decl->SetProperty(NS_LITERAL_STRING("height"), heightstr, EmptyString()); } } } else { window->SetPositionAndSize(rect.x, rect.y, rect.width, rect.height, PR_TRUE); // do the repaint. } doDefault = PR_FALSE; } } break; case NS_MOUSE_CLICK: if (NS_IS_MOUSE_LEFT_CLICK(aEvent)) { MouseClicked(aPresContext, aEvent); } break; } if (!doDefault) *aEventStatus = nsEventStatus_eConsumeNoDefault; if (doDefault && weakFrame.IsAlive()) return nsTitleBarFrame::HandleEvent(aPresContext, aEvent, aEventStatus); else return NS_OK; }
CPoint CConvert::GetScreenPointByGridPoint(CPoint gp){//輸入格子座標得到螢幕座標 CPoint mapPoint(GetMapPointByGridPoint(gp));//格子座標轉成地圖座標 CPoint screenPoint(GetScreenPointByMapPoint(mapPoint));//地圖座標轉成螢幕座標 return screenPoint; }