How do I draw a rounded rectangle without filling it (in MFC)? - windows

Another drawing question for you MFC/GDI gurus out there... :-)
I'm using MFC, and I'm doing some drawing with a CDC object. That works fine.
But now I want to draw a rectangle with rounded corners, the line being a couple of pixels wide. But I dont want any filling to occur! There is a method CDC::RoundRect - I just set the pen I want and get a beautiful rounded rectangle with that pen. But CDC::RoundRect also fills the rectangle with the current brush.
Is there any way to draw just the line, with no filling? Any other method I haven't found? Or can I create some sort of "null brush" that doesn't alter what's in the middle of the rectangle?
I'd be very grateful for some good advice!
/Anders from Sweden

Just select a NULL brush before drawing the rounded rectangle, like
CPen pen;
CBrush* pOldBrush;
CPen* pOldPen;
if (!pen.CreatePenIndirect(&m_logpen))
return;
pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
pOldPen = pDC->SelectObject(&pen);
pDC->RoundRect(m_rect, m_roundness);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);

Related

How does one override "draw" in a CCNode?

I am creating a side scrolling game.
I compute all the points representing what a terrain should look like by doing the following:
The points representing the top of the hill are determined by using a sin function.
The bottom of the hill is just the bottom of the screen.
The left and right edges of the terrain, are the left and right edges of the screen, where the x coords are x=0, and x= screen width.
But I don't know how to draw it on screen, and "fill" it with some other texture. (A predetermined PNG image or something).
How does one override the draw method of a CCNode or CCSprite to accomplish this ?
In the example below I would use a square png image of stars, which I would like to repeat as I scroll the terrain from left to right.
Edit: In the tutorial below, they do all kinds of calculations and wrap a sprite around the hills. But I just want to do something simple, like fill the hills with a simple "noise" texture (no stripes etc), or a solid color. How can I do that?
: http://www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with-cocos2d-2-x-part-1
EDIT: To clarify: I know one can override the draw method. But I don't know what code to put in it to accomplish the problem I described above.
Create a new class that subclasses CCNode or CCSprite, and add a draw method:
- (void) draw {
}
The draw method will automatically execute each frame. Put whatever "drawing" code you like within it.

How can i draw a slanted rectangle in a frame (or picture)?

I have a code that takes a video, split it into frames and then asks me how many rectangles would i like to draw on the frame (only the first frame, kin the code below).
I would like to be able to draw a slanted rectangles too. Is there any command that can help me?
if k==1
result=input('How many rectangles would you like to draw? ');
pos=zeros(result,4);
for i=1:result
handle=imrect;
pos(i,:)=handle.getPosition;
end
end
In your code, imrect is responsible for drawing a rectangle.
You may use impoly to draw some polygons (here slanted rectangles).
The code
imshow('cameraman.tif')
h_poly = impoly;
will give
You can modify the shape by drag/dropping the selection's blue handles.
The positions of the blue handles can be known with
pos = getPosition(h_poly)

BitmapData pattern fill in actionscript 3.0

How do i fill some BitmapData image with other image pattern in as 3.0? For example, i have an white image with black square at the center which would be "square:BitmapData" and the other image with little(2x2) blue circle which i would call "circle:BitmapData". I want to fill that square with this blue circles, is there any way to do this?
UPDATE
Here i found the example of what i need to do:
This is two images (left is like my square, right is like the blue circle)
http://pix.samoucka.ru/img/content/graphics/thewebschedule/8/466.gif
And this is how it would look after filling
http://pix.samoucka.ru/img/content/graphics/thewebschedule/8/467.gif
You can try using copyPixels() and iterating though x and y to tile the whole thing, copyPixels() is very fast.
Or
It might be simpler to create a Sprite and use graphics.beginBitmapFill() then graphics.drawRect() with the correct size, then draw() to the BitmapData in the correct position.
If you need to determine the size and position of the black square, getColorBoundsRect() should do the job.

Is there a fast way to grab an area of an OpenGL-ES scene and render that area as a picture-in-picture?

I have a bunch of game elements being drawn to the screen with OpenGL-ES and I'd like to be able to render a small rectangle in the bottom corner of the screen that shows, say, what's presently being displayed in the top left quarter of the screen.
In that way it's similar to a picture-in-picture from a tv, only the smaller picture would be showing part of the same thing the bigger picture is showing.
I'm comfortable with scaling in OpenGL-ES, but what I don't know how to do is get the proper rectangle of renderbuffer data and use that chunk as the data for an inset frame buffer for the next render pass. I imagine there's some trick along these lines to do this efficiently.
I've tried re-rendering the game elements at a smaller scale for this inset window and it just seems horribly inefficient when the data is already elsewhere and just needs to be scaled down a bit.
I'm not sure I'm asking this clearly or in the right terms, So any and all illumination is welcome and appreciated - especially examples. Thank you!
Have a look at glCopyTexImage2D. It lets you copy a portion of the framebuffer into a texture. So the order of operation would be:
Draw your scene normally
Bind your picture-in-picture texture
glCopyTexImage2D
Draw a quad with that texture in the bottom corner

How to get consistent gradient fill in GDI+ when using a rotated LinearGradientBrush?

I'm using GDI+ in my application, and I need to use a rotated LinearGradientBrush to paint several rects in the exact same way. However, although I'm calling the same code to fill each rect, the results aren't what I expect. Here's the code to create the gradient fill, where rcDraw is the rect containing the area to paint for each rect. These coordinates are in the parent window's coordinates, so they are not identical for the 2 rects.
g_hbrLinear = new LinearGradientBrush( Rect( 0, rcDraw.top, 0, rcDraw.bottom - rcDraw.top ),
clrStart, clrEnd, (REAL) 80, FALSE );
What I see on screen looks like this (http://www.nnanime.com/bugs/LinGradBrush-rotate10.png). You can see that it's as if the fill from the first rect continues into the second one. What I really want is to have the 2 rects look identical. I think I can do that if I paint each rect separately using its own client coordinates, but for the purposes of my app, I need to use the parent window's coordinates.
I guess what I'm asking is, how does GDI+ calculate the "origin" of a fill? Is it always based on 0,0 in the coordinate system you use? Is there a way to shift it? I tried TranslateTransform, but it doesn't seem to shift the fill in a way that I find predictable or understandable.
The rect passed to the linear gradient brush determines the where the left and right colors will sit, and the gradient will be painted within this rectangle.
So, I think you need to create a brush for each rectangle you are painting, where the rectangle you are painting is also passed to the constructor for the linear gradient brush.
My experience with the "transform" of linear gradient brushes matches yours; I haven't been able to understand what it's supposed to do.
You can think of a brush in GDI+ as a function mapping world co-ordinates to a color. What the brush looks like at a given point does not change based on the shape being filled.
It does change with the transform of the Graphics object you're drawing on. So, if you don't want to change the brush, you could temporarily change the transform of the Graphics object so that the rectangle you're drawing has a specific, known size and position in world coordinates. The BeginContainer and EndContainer methods should make this easy.
(There is also the RenderingOrigin property but it only affects hatch brushes, which oddly are unaffected by world transforms.)

Resources