I'm new to MFC. I know how to draw a line and how to scribble in MFC. I use CDC and some functions such as LineTo() and MoveTo() to do this. Moreover, I've got FillRect() and Rectangle().Now I want to drag my rectangle or any polygon in the view.It's like you drag a icon on your desktop.
I think the first step is to get the region.Then erase the old polygon and when the mouse move draw a same polygon which depends on the point where the mouse go.
So I search region in MSDN and I got Region class and CRgn class.But before I look into these two class I want to know whether I'm in the right direction.
I need more suggestions on how to learn MFC. Actually,all I need is to finish my homework which is mainly about draw polygons and drag them and link them by line. And I hope I can finish this homework all by myself and MSDN. Can MSDN help me do that?
The CDC::Polyline function will draw a polygon much faster than using LineTo and MoveTo.
You do not need region and do not need to erase the old polygon. Instead, you need to draw everything in the view OnDraw. Any change you want to make with the mouse should change the array of coordinates that represent the polygon and then call Invalidate. In other words, do not draw in the mouse message handlers. Calling Invalidate in the mouse message handlers will cause OnDraw to be called later and it should repaint the entire view.
Related
Scratch allows selection of the color using the set pen color. Does anyone know if its possible to program to set the color to transparent so that what ever is drawn can effectively be erased? What would the color number be for that?
Update
The idea was to cover a picture (background) with a colour drawn over the top. Now give the player a little creature that erases the colour on top, they have a certain amount of moves or time to guess what the picture is. The less moves/time they use the more points the player will be awarded.
But the problem seems to be that in the paint a sprite part of scratch erase is an option, but not in the pen programming.
If I cant solve it using erase apprach, my alternative is to make a lot of sprites covering the picture and hide them when the creature touches them. But it seems less fun for the player as the uncovered patterns will be more predictable.
Unfortunately, this isn't really possible. If you have a backdrop that's all one color, you could set the pen color to be the same as the backdrop and color over what you already have (giving the illusion of erasing), but other than that there really isn't a good way.
Your only other option is to use the clear block and then re-draw everything except the piece you want to erase.
If you want to give more context about your specific project, I might be able to help you work out a solution (I've done quite a lot with pen blocks over the years).
Like PullJosh said, it isn't really possible but you can make a sprite called Cover and make it a circle of any color you want. Then, it can clone it's sprite over the sprite you want to hide. Then you can attach a script to the clones:
https://i.stack.imgur.com/S6h4c.png (ctrl + click)
I would like to implement red lines moving oh H/V rulers similar to what I see in windows paint brush (8.1) indicating current mouse position. See the example (red line at 560):
What would be the best way to do it. Direct2D Animation? layers? any other simple trick? The thing here is of cause doing it efficiently without repainting the whole area on mouse move.
I currently using MFC/direct2d so I paint myself the area with field and rulers inside the view, so I have full control on graphics here.
There are many ways to attack this problem. The simplest is to rely on your OnPaint function to paint the line in a location based on a member variable. In your OnMouseMove handler, call InvalidateRect on the current location of the line based on the saved variable, update the variable, and call InvalidateRect a second time for the new line position.
The BeginPaint call that is generated in the CPaintDC constructor will set a clipping region based on the invalidation rectangles you provided. Even if your OnPaint tries to paint the entire window, only those parts that have been invalidated will be redrawn. If this is too inefficient, you can cache the ruler in a bitmap and use GetClipBox to determine which part of the bitmap to blit to the screen.
I want to draw a thick point or a dot in the client area of an mfc alpplication. Is there a function to do so? Alternatively I could even draw an extremely small circle and fill it with a colour to make it appear as a dot- but again how do I fill an object? especially a curved one?
Then I also want to put some text next to it- so what function could i use to "write" in the client area?
GetDC()->SetPixel(x, y, RGB(1,2,3))
Where GetDC() will return the current CWnd's device context, (x,y) are the coordinates, and RGB() is the red/greed/blue color.
Look at GetDC()->Ellipse() for a circle, etc. and GetDC()->TextOut() for displaying text.
It would be good to become familiar with device contexts in general, see:
MFC CDC Members
My goal is to create something like the arrow from car that indicates the speed of the car. My problem is that I do not know what is the best practice for moving the green arrow. I have an image arrow.png and I guess I need to manipulate with the place that the picture is shown and with the rotation of the image.
Can someone point to me some guidelines ?
My basic idea is to have a relative layout for the background and to have one image view that will change the position, but the part changing position is little unclear to me. And I do not think that is good idea to play with layout params and margins...
I would probably extend ImageView then override your onDraw method and use canvas.rotate() to rotate the arrow depending on your app state.
I am making a game in Cocos2d. I want there to be a dotted line that follows the user's finger. I want the line to be straight. The problem is, how do I check to see how many 'dots' will fit in the distance between the ball and where the user is touching? And make it follow in a STRAIGHT line between the ball's position and the finger's position? So here's a re-clarification:
The ball sits still on the left side of the screen, and is halfway up the screen. The user drags their finger, and a dotted line is drawn between the ball's position and the touch's position. I have a 'dot' image to be used, and I would like it to be used as the dots in the line. So it will have to recreate the sprite as many times as it will fit in the area between the two points. Please tell me if you want me to clarify further, Thanks!!
I would make a CCNode object called dottedLine or something.
The dot image would be a sprite that gets added as a child of the node (multiple times).
I would work out the path from ball to finger touch using Trigonometry/Pythagoras theorem.
For creating the line:
From point 0, the ball, i would add 15-20 pixels towards the touch point along the path, and place a dot, I'd repeat this until I reached the end of the line.
Every dot that was placed I would increment a counter, and set that number as the integer tag of that sprite for use in an update method.
Every time the cctouchesmoved method gets called, i'd call an update method on the dottedLine object.
This method would check the distance between the ball and touch point, divide it by the number of dots currently children of the object and remove or add any that are needed. Recreating the sprites every time you move your finger would be messy and wasteful, so reusing your dots and just setting them new positions as the path between ball and touch point changes would probably be best.
I'm not going to provide you code, i think i've explained more than enough of the working out for you to do some googling and work this out.