Animated graphics implementation dialog based MFC - c++

Could anyone suggest me a particular way to implement animation in my Dialog-based mfc program? The animation that I am intending to add is like a construction digger machine graphic that would read the values of the machine parameters and change the shape of the graphic accordingly. Most of the information is read from a text file in terms of the parameters, so I just need to be able to get the animation working.
Thanks for your help in advance.

Well, GDI is easy but ugly and quite slow, GDI+ is also easy, but nicer although generally slower. OpenGL or DirectX are much, much faster but quite hard to program. Other libraries, such as cairo, are also available.
I'd suggest to start with the easiest (maybe GDI+) and see if it is fast enough for you.
Do do that, just Invalidate() the control where you are drawing in a timer, (or when you receive new data), and paint the whole graphic in the OnPaint() function. A basic improvement is to Invalidate() only the region where the new data affects the picture.
If then you notice that your code is not fast enough, come back and ask how to improve it. A concrete example will make it easier to get a more useful answer.

there are lot of articles. Most of them based on drawing in device context
http://www.codeproject.com/KB/GDI/flickerfree.aspx
http://www.codeguru.com/cpp/g-m/bitmap/article.php/c4879
http://www.codersource.net/mfc/mfc-gdi-plus/animation-control-mfc.aspx

Related

How to solve slow scrolling in QT android app

I am trying to make a simple QT android app, but basically my problem is that on my main screen I have about 250 little images that i want to scroll. But I really need the scrolling to be fluent and fast. First I tried it using QML but it wasnt really fast, then I tried to make the app in qt designer and use widgets but that was very slow. Then I tried using openGL but on android I can only use openGL ES and I cant find so much examples because every example that I find is much more advanced than I need.
But basically my main question is, what do you think is the best way to solve my problem and if its openGL which way of using it is the best that could solve it?
Thank you.
Neither approach should have problems when scrolling when compared to a native application on the same device. Check the following:
Make sure to measure performance only in release-builds, with QML debugging disabled and no debugger attached.
Maybe your device simply can't keep up with so many images in one view - then it's not a Qt problem. Compare with a 'native' java-App to see if this is the case.
Check if you implemented everything correctly; e.g. check if theres anything running in your main-loop or some events happenening repeatedly which consumes CPU time
And some more general advice:
Downscale your images to the appropriate view-size before giving them to the UI, as they might have to be re-scaled on every frame-update and/or consume graphics memory otherwise. E.g. dont set the source to a 1024x1024 image when it's going to show in a 64x64 view
Remove transparency from the images if they are going to display on solid-colored background anyway.
Dont overlay the images with other widgets/controls
If you're still getting a 'slow' UI, maybe try to merge all or multiple images and their surrounding UI/Controls into one or more bigger images
Very long views are not user-friendly. Maybe implement a pager or tab-view etc. to divide your list into multiple views. This way you can also decrease load-time
Dont try to implement an interface in openGL yourself. It's unlikely you'll make a better one than you already get with QtWidgets and QtQuick.

How to perform 'cheap' scale of the entire screen in D2D?

I am working on a touch screen application (WinRT) and currently draw some graphics to the screen. Because it is touch, I want to enable pinch-to-zoom for scaling the entire content. For a better experience, I only want to redraw the graphics, once the pinch gesture is complete. For the intermediate scalings, I would like to reuse the current bitmap, and perform (if possible) a gpu-only scaling (enlarge bitmap).
Basically, I want to do exactly what iOS and Windows Phone have been doing for years now.
How can I implement this in Direct2D?
As a bonus, If you know a good ressource for reading on Direct2D, please tell me. The MSDN documentation is really poor and I have to hunt different blogs and magazine articles to learn :(
What I tried so far:
m_target->SetTransform(
D2D1::Matrix3x2F::Scale(
D2D1::Size(1.5f, 1.5f),
D2D1::Point2F(500.0f, 500.0f))
);
However, if I do this for interactive elements (like page zoom-in/zoom-out), all objects are rendered (which is also slow).
Another option could be to draw into a BITMAP and use that as the base for the transforms. However, I am not sure if this is a good approach.
Note: I am currently debugging on a Desktop but want to target tablets. I have to consider that tablets are orders of magnitude slower. That's why I try to optimize this functionality.
Thanks!

How to implement zooming in GDI-drawn MFC's CScrollView

I'm drawing some graphics and text with GDI in my CScrollView. I need to implement the zooming functionality. I only need the zoom out functionality, no need to zoom in more than what is normally rendered.
Here are my best ideas:
Use MM_ANISOTROPIC mapping mode with SetWindowExt/SetViewportExt... The problem with this approach is that it does not scale text. Is there any way to force MFC to scale the text as well? Only thing I can think of is to set text font size according to the selected zoom value, but I'm not sure whether this will look well after all...
Draw to memory DC, and use StretchBlt to blit to the client area of appropriate size (set with SetScrollSizes...). This will solve the text scaling issue.
Also it is desirable to have antialiasing effect in the process. I think both methods above should accomplish this per se, but I don't know which will look better. Also I will have to implement printing/print-preview functionality later (using MFC's standard implementation from doc/view architecture), so I need the method to be compatible with that.
Need your advice please. Which way to go and why. Maybe other options exist too?..
You really don't want to mess with the mapping mode when you use MFC -- MFC itself already uses it for (at least) the print preview functionality.
I'd see if SetWorldTransform will work for you. At least with vector/TrueType fonts, it will scale the text along with everything else. Note that before SetWorldTransform will work, you need to call SetGraphicsMode with GM_ADVANCED.
I ended up using the second method I proposed in the question, but used DIBs instead of DDBs (and StretchDIBits() instead of StretchBlt()) because it proved to cause less problems, especially when using big bitmaps, and when printing.

Qt - Real time drawing

I want to show a car's path in a window in real time, how to do that, and what classes I have to use. Is there anything like drawing area, in Qt.
Any Help will be appreciated.
You'll need to read up on QGraphicsview. There are several helpful examples that show every bit of what functionality is present here. The implementation itself... I guess it's just a bunch of QLines on a QGraphicsScene. The realtime part is handled by calling repaint or paintevent or whatever it's called periodically, or setting up a complex animation.
The Qwt library on top of Qt is pretty good for this.

I have a wxwidgets that I want to add some cool effects. Using GDI would be impossibly hard. Could I use flash or something else?

I have an application that I want add some cool animations to show state changes. However, wxwidgets would be difficult because I'd have to program these animations in straight gdi. What's the best way to add these effect windows? Should I open a flash window and run a flash sequence or is maybe some other technology? Does .net have something I could code into a dll and run from my wxwidgets binary? I need something that is super easy to draw and set up the animation.
It's hard to say what the best approach would be to achieve "cool effects", but in most cases you would want a double-buffered drawing surface. That's what I've used in similar-sounding situations.
In wxWidgets, you would want wxBufferedDC.
You could prepare animation as a bunch of images (wxImage loaded from PNG, GIF, JPG or whatever files), and then use a timer and paint them on a control. Maybe it sounds like too much, you I believe you could do it in 50-70 lines of code.
Perhaps you just could make a single widget that has a custom paint-event that hand-draws the various widgets inside it? Then you could draw them at the appropriate locations/sizes without having to involve wxwidgets at all, it would just be a bunch of line-draw/rectangle-draw/text-draw commands to update the display for each frame of animation.