-
July 5th, 2013, 09:27 AM
#1
[RESOLVED] Need help with a grid over a bitmap in a scrollview
Hello... I have a CScrollView that displays a bitmap and I'm trying to draw a grid that I can turn off and on by check box and when the mouse is over a section of the grid that square highlights... I do all the drawing in the ondraw function... But when I have many grid squares it becomes slow to scroll and to highlight the square the mouse is over... I'm not sure the best way to go about this and where to place code to speed it up... The bitmap is only loaded once... But in ondraw the grid has to redraw every time scrolled and when mouse moved over a square.. In onmousemove I call invalidate so the square under mouse changes... Thx for any ideas can give me... Tc always
•SlimGradey•
-
July 5th, 2013, 11:23 AM
#2
Re: Need help with a grid over a bitmap in a scrollview
Could you show your code for drawing and mouse handling?
Victor Nijegorodov
-
July 5th, 2013, 11:25 AM
#3
Re: Need help with a grid over a bitmap in a scrollview
Originally Posted by SlimGradey
... In onmousemove I call invalidate so the square under mouse changes...
Do you call Invalidete() on EVERY mouse move? Or only if you figured out that the highlighted square has changed?
Do you Invalidete() ENTIRE window? Or only two squares (previously and currently highlighted )?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 5th, 2013, 09:46 PM
#4
Re: Need help with a grid over a bitmap in a scrollview
Code:
OnDraw(CDC* pDC)
{
CDC pDC2;
pDC2.CreateCompatibleDC(pDC);
OnPrepareDC(&pDC2);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(pDC,m_width,m_height);
CBitmap *oldBitmap = pDC2.SelectObject(&bitmap);
if(m_MemDC != 0)
pDC2.BitBlt(0,0,m_width,m_height,&m_MemDC,0,0,SRCCOPY);
if(m_ShowGrid)
{
for(int i=0; i<m_width; i+=m_GridSize)
{
for(int b=0; b<m_height; b+=m_GridSize)
{
pDC2.Draw3dRect(i,b,m_GridSize,m_GridSize,RGB(255,255,255),RGB(255,255,255));
CPoint pos;
GetCursorPos(&pos);
ScreenToClient(&pos);
OnPrepareDC(pDC);
pDC->DPtoLP(&pos);
CRect rect;
rect.left=i;
rect.top=b;
rect.right=rect.left+m_GridSize;
rect.bottom=rect.top+m_GridSize;
if(rect.PtInRect(pos))
pDC2.Draw3dRect(i,b,m_GridSize,m_GridSize,RGB(255,0,0),RGB(255,0,0));
}
}
}
pDC->BitBlt(0,0,m_width,m_height,&pDC2,0,0,SRCCOPY);
pDC2.SelectObject(oldBitmap);
}
OnEraseBkgnd(CDC* pDC)
{return true;}
OnMouseMove(UINT nFlags, CPoint point)
{if(m_ShowGrid)Invalidate();
CScrollView::OnMouseMove(nFlags,point);}
Sorry for slow reply, don't have net on my pc and had use cellphone to write this by hand...
m_MemDC is CDC that has a CBitmap selected into it from the image loading function and m_width and m_height is the size of it and m_ShowGrid is a bool that's toggled by a check box and m_GridSize is an int the user can select 8, 16, 32, or 64 for the size of the grid... The bigger the grid squares the less looping drawing it needs to do and runs normal speed if the images not so big...the bigger the image and or smaller the grid makes things go really slow scrolling or tracking the mouse an update the square the mouse is over... Later gonna try adding when user clicks that spot on the grid that square part of the image gets copied to use... Then after that learn how make free hand selections that snaps to the grid every 8pixels then copy that part of the image... Thx alot…
•SlimGradey•
-
July 6th, 2013, 03:37 AM
#5
Re: Need help with a grid over a bitmap in a scrollview
Well, it looks like Vlad was correct guessing about the reason of your problem!
You should call Invaliddte() only if you figured out that the highlighted square has changed!
And onlyfor two squares: previously and currently highlighted.
Victor Nijegorodov
-
July 7th, 2013, 03:22 AM
#6
Re: Need help with a grid over a bitmap in a scrollview
Thx guys... That did the trick... Now its really fast... Now in mousemove I draw the current highlight and invalidate the old highlight...
•SlimGradey•
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|