void CUILevelMap::Init (shared_str name, CInifile& gameLtx, LPCSTR sh_name) { inherited::Init(name, gameLtx, sh_name); Fvector4 tmp = gameLtx.r_fvector4(MapName(),"global_rect"); m_GlobalRect.set(tmp.x, tmp.y, tmp.z, tmp.w); #ifdef DEBUG float kw = m_GlobalRect.width () / BoundRect().width (); float kh = m_GlobalRect.height () / BoundRect().height (); if(FALSE==fsimilar(kw,kh,EPS_L)){ Msg(" --incorrect global rect definition for map [%s] kw=%f kh=%f",*MapName(),kw,kh); Msg(" --try x2=%f or y2=%f",m_GlobalRect.x1+kh*BoundRect().width(), m_GlobalRect.y1+kw*BoundRect().height()); } #endif // Msg("Succesfully loaded map %s. Zoom=%f",*name, kw); /* if(gameLtx.line_exist(MapName(),"anomalies_texture")){ LPCSTR texture = gameLtx.r_string (MapName(),"anomalies_texture"); Fvector4 tmp = gameLtx.r_fvector4(MapName(),"anomalies_texture_rect"); //lt,wh Frect rect; rect.set (tmp.x,tmp.y,tmp.x+tmp.z,tmp.y+tmp.w); m_anomalies_map = xr_new<CUIStatic>(); m_anomalies_map->Init (texture,0.0f,0.0f,0.0f,0.0f); m_anomalies_map->GetUIStaticItem().SetOriginalRect(rect); m_anomalies_map->SetStretchTexture (true); m_anomalies_map->SetAutoDelete (false); } */ }
float CUIGlobalMap::CalcOpenRect(const Fvector2& center_point, Frect& map_desired_rect, float tgt_zoom) { Fvector2 new_center_pt; // calculate desired rect in new zoom map_desired_rect.set (0.0f,0.0f, BoundRect().width()*tgt_zoom,BoundRect().height()*tgt_zoom); // calculate center point in new zoom (center_point is in identity global map space) new_center_pt.set (center_point.x*tgt_zoom,center_point.y*tgt_zoom); // get vis width & height Frect vis_abs_rect = m_mapWnd->ActiveMapRect(); float vis_w = vis_abs_rect.width(); float vis_h = vis_abs_rect.height(); // calculate center delta from vis rect Fvector2 delta_pos; delta_pos.set (new_center_pt.x-vis_w*0.5f,new_center_pt.y-vis_h*0.5f); // correct desired rect map_desired_rect.sub (delta_pos.x,delta_pos.y); // clamp pos by vis rect const Frect& r = map_desired_rect; Fvector2 np = r.lt; if (r.x2<vis_w) np.x += vis_w-r.x2; if (r.y2<vis_h) np.y += vis_h-r.y2; if (r.x1>0.0f) np.x = 0.0f; if (r.y1>0.0f) np.y = 0.0f; np.sub (r.lt); map_desired_rect.add (np.x,np.y); // calculate max way dist float dist = 0.f; Frect s_rect,t_rect; s_rect.div (GetWndRect(),GetCurrentZoom(),GetCurrentZoom()); t_rect.div (map_desired_rect,tgt_zoom,tgt_zoom); Fvector2 cpS,cpT; s_rect.getcenter (cpS); t_rect.getcenter (cpT); dist = cpS.distance_to(cpT); return dist; }
void CRectSelection::OnDraw( CImage* pImage, COLORREF color ) { CRect tmpSelection = m_rect; CorrectDragRect( &tmpSelection ); BoundRect( pImage, &tmpSelection ); for( int x=tmpSelection.left; x<tmpSelection.right; x++ ) { for( int y=tmpSelection.top; y<tmpSelection.bottom; y++ ) { if( x == tmpSelection.left || x == tmpSelection.right - 1 || y == tmpSelection.top || y == tmpSelection.bottom - 1) { pImage->SetPixel( x, y, color ); } } } }
/************************************************************************ ComputeZoomDisp Computes and sets values for the lpDisplay. ************************************************************************/ void ComputeZoomDisp() { LPDISPLAY lpMyDisplay; RECT area; int fileH, fileW, dispH, dispW; int x, y; LPIMAGE lpMyImage; if (!hZoomWindow) return; lpMyDisplay = (LPDISPLAY)GetDisplayPtr(hZoomWindow); lpMyImage = (LPIMAGE)GetImagePtr (hZoomWindow ); if (!lpMyDisplay) return; GetClientRect(hZoomWindow, &area); dispH = area.bottom - area.top; dispW = area.right - area.left; x = 0; y = 0; // set lpDisplay lpMyDisplay->DispRect.left = x; lpMyDisplay->DispRect.right = x+dispW-1; lpMyDisplay->DispRect.top =y ; lpMyDisplay->DispRect.bottom = y+dispH-1; fileW = lpMyImage->npix; fileH = lpMyImage->nlin; lpMyDisplay->FileRect.left = x; lpMyDisplay->FileRect.top = y; lpMyDisplay->FileRect.right = x + fileW - 1; lpMyDisplay->FileRect.bottom = y + fileH - 1; lpMyDisplay->FileRate = FGET(fileW, dispW); BoundRect( &lpMyDisplay->FileRect, 0, 0, lpMyImage->npix-1, lpMyImage->nlin-1 ); }
// try to positioning clipRect center to vNewPoint void CUICustomMap::SetActivePoint(const Fvector &vNewPoint) { Fvector2 pos; pos.set(vNewPoint.x,vNewPoint.z); Frect bound = BoundRect(); if( FALSE==bound.in(pos) )return; Fvector2 pos_on_map = ConvertRealToLocalNoTransform(pos); Frect map_abs_rect; GetAbsoluteRect(map_abs_rect); Fvector2 pos_abs; pos_abs.set(map_abs_rect.lt); pos_abs.add(pos_on_map); Frect clip_abs_rect = GetClipperRect(); Fvector2 clip_center; clip_abs_rect.getcenter(clip_center); clip_center.sub(pos_abs); MoveWndDelta (clip_center); SetHeadingPivot (pos_on_map, Fvector2().set(0,0), false); }
BOOL CRectSelection::OnLButtonUp( DragState dragState, CPoint point, CImage* pImage, std::vector<CSelection*>& selections ) { if( dragState == DRAGGING ) { CorrectDragRect( &m_rect ); BoundRect( pImage, &m_rect ); if( m_rect.Width() >= 4 && m_rect.Height() >= 4 ) { selections.push_back( this ); } } else if( dragState == FIXED ) { if( m_rect.Width() >= 4 && m_rect.Height() >= 4 ) { selections.push_back( this ); } } return TRUE; }
void ComputeFileRect( HWND hWnd, int x, int y, LFIXED FileRate ) /************************************************************************/ { int fx, fy, DispWidth, DispHeight, dx, dy; LFIXED DispRate; LPIMAGE lpImage; LPDISPLAY lpDisplay; // A NULL FileRate is a signal that FileRect was just initialized // and doesn't need recalculating if ( !FileRate) return; lpImage = GetImagePtr(hWnd); lpDisplay = GetDisplayPtr(hWnd); // FileRect will be recomputed from FileRate and a center point (x,y) DispWidth = RectWidth( &lpDisplay->DispRect ); DispHeight = RectHeight( &lpDisplay->DispRect ); DispRate = FGET(FUNITY, lpDisplay->FileRate); dx = FMUL(lpImage->npix, DispRate); dy = FMUL(lpImage->nlin, DispRate); // FileRate == 1 is a special case for handling iconic state // otherwise handle normally if ( FileRate == TINYRATE) // Display all of image - iconic state { fx = lpImage->npix; fy = lpImage->nlin; lpDisplay->ViewPercentage = 0; } else { // if image fits or is smaller than display surface // use maximum FileRect, otherwise use current FileRate if (dx <= DispWidth) fx = lpImage->npix; else fx = FMUL( DispWidth, FileRate ); if (dy <= DispHeight) fy = lpImage->nlin; else fy = FMUL( DispHeight, FileRate ); } if (x == -1 && y == -1) // special signal to use old XY { x = lpDisplay->FileRect.left; y = lpDisplay->FileRect.top; } else { x -= ( fx / 2 ); y -= ( fy / 2 ); } if ( x < 0 ) x = 0; if ( y < 0 ) y = 0; if ( x + fx - 1 >= lpImage->npix ) x = lpImage->npix - fx; if ( y + fy - 1 >= lpImage->nlin ) y = lpImage->nlin - fy; lpDisplay->FileRect.left = x; lpDisplay->FileRect.top = y; lpDisplay->FileRect.right = x + fx - 1; lpDisplay->FileRect.bottom = y + fy - 1; BoundRect( &lpDisplay->FileRect, 0, 0, lpImage->npix-1, lpImage->nlin-1 ); }
BOOL CImage::CombineObjects(BOOL fNoUndo, BOOL fCreateMask, BOOL fForceIt, ITEMID idDirty, LPRECT lpUpdateRect) { LPOBJECT lpBase, lpObject; int iWidth, iHeight, depth, y, iImageWidth, iImageHeight; LPTR lpDataBuf, lpMaskPtr; RECT rFloaters, rMask, rTemp; BOOL fNewMask; LPMASK lpMask; UNDO_TYPE UndoType; AstralSetRectEmpty(lpUpdateRect); // get rectangle for all floating objects if (!GetFloatingObjectsRect(&rFloaters)) return(FALSE); // Get base object lpBase = GetBase(); // get pixmap information PixmapGetInfo(&lpBase->Pixmap, PMT_EDIT, &iImageWidth, &iImageHeight, &depth, NULL); BoundRect(&rFloaters, 0, 0, iImageWidth-1, iImageHeight-1); iWidth = RectWidth(&rFloaters); iHeight = RectHeight(&rFloaters); // allocate buffer for alpha channel combining if (!(lpDataBuf = Alloc((long)iWidth*depth))) { Message(IDS_EMEMALLOC); return(FALSE); } lpMask = NULL; if (fCreateMask) { lpMask = GetMaskEx(OFF, Control.NoUndo, &fNewMask, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); } // do it to it ProgressBegin(lpMask != NULL ? 2 : 1, idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); if (!fNoUndo) { UndoType = UT_DATA|UT_DELETEOBJECTS; if (lpMask) { if (fNewMask) UndoType |= UT_CREATEMASK; else UndoType |= UT_ALPHA; } if (!ImgEditInit(this, ET_OBJECT, UndoType, lpBase)) { if (!fForceIt) { ProgressEnd(); FreeUp(lpDataBuf); return(FALSE); } } } // do it to it ProgressBegin(1, 0); for (y = rFloaters.top; y <= rFloaters.bottom; ++y) { AstralClockCursor(y-rFloaters.top, iHeight, NO); ImgGetLine(this, NULL, rFloaters.left, y, iWidth, lpDataBuf); PixmapWrite(&lpBase->Pixmap, PMT_EDIT, rFloaters.left, y, iWidth, lpDataBuf, iWidth); } ProgressEnd(); if (lpMask && (lpObject = GetNextObject(lpBase, YES, NO))) { ProgressBegin(1, 0); for (y = rFloaters.top; y <= rFloaters.bottom; ++y) { AstralClockCursor(y-rFloaters.top, iHeight, NO); lpMaskPtr = PixmapPtr(&lpMask->Pixmap, PMT_EDIT, rFloaters.left, y, YES); if (!lpMaskPtr) continue; ImgMaskLoad(this, lpObject, NULL, rFloaters.left, y, iWidth, lpDataBuf, NO, CR_OR, 0, 0); CombineData(lpDataBuf, lpMaskPtr, iWidth, NO, CR_OR); } MaskRectUpdate(lpMask, &rMask); ProgressEnd(); } FreeUp(lpDataBuf); GetObjectMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); lpObject = lpBase; while (lpObject = GetNextObject(lpObject, YES, NO)) { // always let undo stuff initialize this // lpObject->fUndoDeleted = NO; lpObject->fDeleted = YES; } //DeleteObjects((LPOBJECT)lpBase->lpNext, NO); if (!fNoUndo) ImgEditedObject(this, lpBase, idDirty, &rFloaters); else fChanged = YES; //if ( Tool.hRibbon ) // SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); ProgressEnd(); //SetupMiniViews(NULL, NO); return(TRUE); }