I just started using Direct2D yesterday. I want to use the DrawLine function.
But when i call the function that draws the line, the line will appear but a black background also appears
How can i get rid of the black background?
I tried to clear to NULL but that didn´t help.
I dont know what the problem is because i have nowhere declared a background.
Related
I am using C++ and SDL 2. Is there any function in SDL or any available algorithm to clear only a part of the screen?
I tried using SDL_RenderSetViewPort() in the following way but it didn't work:
SDL_RenderSetViewPort(renderer,&rect);
SDL_RenderClear(renderer);
I thought that the specific texture present in the given rectangle part would be cleared but it didn't.
SDL_SetRenderDrawColor() with the clear color then SDL_RenderFillRect() with the desired region to 'clear'.
I need a GroupBox control for something else that showing it in application's window. That's why I want to disable the frame surrounding it (or at least make it invisible by, for example, drawing it with the color that matches with window's background). Both are harder than I thought though, I've been loking for the solution everywhere and found nothing. I don't want to use anything as straightforward as painting over it in WM_PAINT-case in window procedure because there will be that annoying sparkling when I move the window.
I'm running out of ideas, tried a few things on my own, none worked. Anyone have some tips?
I would like to draw a simple (red) line over an image with gtkmm (in c++).
I have the image : Gtk::Image *image which is displayed in my window.
But I would like the line to change of position (I mean : draw another line) when a function is called. I need your help because I didn't find how to draw over an existing image...
Thank you for your help !
EDIT : A solution for me would be to overlay the image by an image with alpha channel... but I don't know how to to that :-/
You should not actually draw in the image, instead you draw in the window.
First put the image in the window (blitting or some other means) then draw the line.
See e.g. this link on how to draw straight lines.
Connect to the "expose-event" (GTK2) or "draw" (GTK3) signal of the GtkImage. I think you should use the C++ equivalent of g_signal_connect_after (which in in GObject), and not the g_signal_connect one, so you get a chance of drawing after the image has been drawn, so your drawing is on top of it. To draw you need to use cairomm, and Joachim already gave you a link to a cairomm tutorial.
i have been using cleardevice() to clear the graphics ... but it creates several problems
for eg .. i create a background but i have to clear some specific elements , then i have to use another user defined function drawb() which draws the background and simultaneously cleardevice();
creating a lot of problems
line(x,y,x1,y1); //suppose this line is to be erased
//but using cleardevice even clears the background
cleardevice();
drawb(); //to draw board or background
so i want to know an alternative approach(an approach to clear only the line not the background) (if it exists )
Once a line is drawn, there is no real way to remove it (except if you are drawing using XOR mode!). However, there are some thing you could do. You could render everything but the line in a page and store it there. Then, in another page you render everything, including the line. So if you want to undo the line, you just switch the page back.
An example:
setactivepage(0);
// draw stuff, including background
setactivepage(1);
// draw stuff, including background and line
setvisualpage(0); // no line visible
setvisualpage(1); // line visible
Also, if you want to reset the screen with a background, there is no need to do a cleardevice(), since the drawb() overwrites every pixel ayway.
You can first take the image before drawing the line by getimage()
and put that image on the line whenever you want to hide your image
This will not change your background and not flick it. putimage() can put the image.
I'm trying to draw on the screen (the whole screen, on top of every other window) using GDI+.
I've passed NULL to GetDC to get a HDC to the screen, and then used that to create a Graphics object, and used DrawRectangle to draw rectangles on the screen.
Everything works..except...the inside of the rectangle won't update.
Like if I draw it over a command prompt, and move the command prompt, the inside of the rectangle remains black.
I expect to see whats under the rectangle.
Here's the code that's doing the drawing..
Pen BluePen(Color(255, 0, 255, 0), 2);
Graphics graphics(screenDC);
graphics.DrawRectangle(&BluePen, myRect);
Pretty simple, so is there something I have to do to get the inside of the rectangle to update when the screen does? Or to get it truely transparent.
================= EDIT =================
Well I had given up on this, and assumed it wasn't possible, until...I realized the Inspect tool that comes with the Windows SDK does this perfectly.
I would like to recreate something similar to the highlight rectangle, and if I select a window (such as Firefox) and then bring Inspect into focus I can move it around freely with everything being updated perfectly.
There's not even any flickering.
So...does anyone know how Inspect manages to do this?
Also answers in GDI instead of GDI+ are fine...
In windows the screen (and the windows ...) surface(s) are ... volatile, like sandboxes. The "overlapping" of windows and the re-painting of uncovered surfaces is an illusion made by proper event management.
Everything is drawn remain there until something else is drawn over it.
"Uncovering" a surface makes the window representing that surface to receive a WM_PAINT message. It's up to that window procedure to react to that message by re-painting everything is supposed to be under it.
Now, unless you intercept somehow the WM_PAINT message that is sent to the desktop window, you have mostly no chance to know the desktop needs a repaint and hence your paint code will not be called and no repaint will happen. Or better it happens following just the desktop window updating code, that's not aware of your paint.