void CCxImageCtrl::SetScrollSize(int cx, int cy) { ////////////////////////////////////////////////////////////////////////// m_nCurHeight = cy; int nScrollMax; if (cy < m_dwHeight&&!GetStretchMode()) { nScrollMax = m_dwHeight - cy; } else nScrollMax = 0; if(m_nVScrollPos<0) m_nVScrollPos = 0; if(m_nVScrollPos>nScrollMax) m_nVScrollPos = nScrollMax; SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS; si.nMin = 0; si.nMax = nScrollMax; si.nPage = si.nMax/5; si.nPos = m_nVScrollPos; SetScrollInfo(SB_VERT, &si, TRUE); ////////////////////////////////////////////////////////////////////////// m_nCurWidth = cx; if (cx < m_dwWidth&&!GetStretchMode()) { nScrollMax = m_dwWidth - cx; } else nScrollMax = 0; if(m_nHScrollPos<0) m_nHScrollPos = 0; if(m_nHScrollPos>nScrollMax) m_nHScrollPos = nScrollMax; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS; si.nMin = 0; si.nMax = nScrollMax; si.nPage = si.nMax/5; si.nPos = m_nHScrollPos; SetScrollInfo(SB_HORZ, &si, TRUE); ////////////////////////////////////////////////////////////////////////// Invalidate(FALSE); }
bool VImageState::Build(VWindowBase *pOwner, TiXmlElement *pNode, const char *szPath, bool bWrite) { if (!pNode) return false; // button texture name const char *szTexture = XMLHelper::Exchange_String(pNode,"texture",NULL,bWrite); if (szTexture) // only assign when defined to preserve normal state SetTexture(VGUIManager::LoadTexture(szTexture,szPath)); // texture coordinates and stretch mode float *texCoordData = (float*)(&texCoord.m_vMin); XMLHelper::Exchange_Floats(pNode,"texcoords",texCoordData,4,bWrite); const char *szStretchMode = XMLHelper::Exchange_String(pNode,"stretchmode",NULL,bWrite); if (szStretchMode) m_eStretchMode = GetStretchMode(szStretchMode); // button color XMLHelper::Exchange_Color(pNode,"color",m_iColor,bWrite); XMLHelper::Exchange_Transparency(pNode,"transparency",m_eTranspType,bWrite); // other states bool bFiltering = false; XMLHelper::Exchange_Bool(pNode,"filtering",bFiltering,bWrite); if (bFiltering) m_iAdditionalStateFlags |= RENDERSTATEFLAG_FILTERING; // mouse over cursor const char *szCursor = XMLHelper::Exchange_String(pNode,"cursor",NULL,bWrite); if (szCursor) // only assign when defined to preserve normal state m_spCursor = pOwner->GetMenuManager()->LoadCursorResource(szCursor,szPath); return true; }
void CCxImageCtrl::ImageToClient(CPoint &point) { if (!m_hImage.IsValid()) return; if (GetStretchMode()) { CRect rect; GetClientRect(&rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; double fx = point.x*width/(double)m_hImage.GetWidth(); double fy = point.y*height/(double)m_hImage.GetHeight(); point.x = (long)fx; point.y = (long)fy; } else { double fx = point.x*GetZoomValue(); double fy = point.y*GetZoomValue(); fx -= m_nHScrollPos; fy -= m_nVScrollPos; point.x = (long)fx; point.y = (long)fy; } }
void CCxImageCtrl::ClientToImage(CPoint &point) { if (!m_hImage.IsValid()) return; if (GetStretchMode()) { CRect rect; GetClientRect(&rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; double fx = point.x*m_hImage.GetWidth()/(double)width; double fy = point.y*m_hImage.GetHeight()/(double)height; point.x = (long)fx; point.y = (long)fy; } else { double fx =(double)(m_nHScrollPos + point.x); double fy =(double)(m_nVScrollPos + point.y); fx /= GetZoomValue(); fy /= GetZoomValue(); point.x = (long)fx; point.y = (long)fy; } }
void CCxImageCtrl::OnPaint() { CPaintDC dc(this); // device context for painting CRect ClipRect; GetClientRect(&ClipRect); if(m_hImage.IsValid()) { if(GetStretchMode()) { m_hImage.Stretch(dc,ClipRect); if(m_bCaptureWasSet&&GetState()==CCxImageCtrl::IS_Crop) { dc.Draw3dRect(CRect(m_RefPoint,m_CropActivePoint),RGB(255, 0, 0), RGB(0, 255, 0)); } } else { CRect renderRect(-m_nHScrollPos,-m_nVScrollPos,m_dwWidth-m_nHScrollPos,m_dwHeight-m_nVScrollPos); m_hImage.Draw(dc,renderRect); if(m_bCaptureWasSet&&GetState()==CCxImageCtrl::IS_Crop) { dc.Draw3dRect(CRect(m_RefPoint,m_CropActivePoint),RGB(255, 0, 0), RGB(0, 255, 0)); } dc.SetBkColor(0xEEEEEE); dc.ExcludeClipRect(renderRect); dc.FillRect(ClipRect,&m_brHatch); } } // Do not call CWnd::OnPaint() for painting messages }