Android UI in C++ - c++

I know this is kind of reinventing the wheel, but how hard would it be to implement an android user interface with C++? Is it hard to create things like buttons, and to handle touch screen events like button clicks? Is this feasible and if so, how would you go about doing it?

Take a look at Necessitas, its a Qt port for android which seems to work pretty well.
It might still be in Alpha or Beta stage though, so it will depends on how "serious" your project is. But that proves for sure that one can use plain C++ to build a complete application, not only libraries.

You can always use the JNI to go back up into java to get UI components on the screen. If you set it up to be little more than an API, you can simulate actually doing it in native code. NVidea has some good samples on how to do this: http://developer.nvidia.com/tegra-resources This library code isn't doing it for UI components, but is for various other things (sound, resources, etc). and the idea should work for UI components too.
Also, this project supposedly supports the entire sdk in c++, and I would imagine it's doing it the same way. I don't know how up to date it is, as I haven't actually used it: http://code.google.com/p/android-cpp-sdk/

You can use JNIpp to create wrapper for activity and all UI classes you are interested in.
Take a look at HelloJNIpp sample, it features native Activity, native custom drawn View and a button.
Spoiler:
void MainActivity::OnCreate(const jni::LObject& bundle) {
Activity::OnCreate(bundle);
SetContentView(R::GetLayout("main"));
FindViewById(R::GetID("changeColor"))->
SetOnClickListener(*this,&MainActivity::ChangeColor);
}

Related

Qt c++ application scraping

I would like to interact with an opened qt window (wrote in c++) using code. The code would act like a user and will be completely independent of the code of the qt window. Something like web scraping but with qt (which is much more complicated).The first thing I’m attempting to do is to mimic a click on a push button.
My first intuition was to add some c++ code to the existing code at runtime and execute something like « pushButton.click(); ». After some few searches I tried to use dynamic shared library. The library would implement the code of the button I want to click on, and would be dynamically added to the existing c++ code. This solution could work but seems to be very complicate and not portable. Furthermore I would like the solution to be very independent of the window code.
Of course the qt code of the window will be accessible from the scraping code side.
Are some other solutions more practical ?
EDIT:
GammaRay seems to work fine. I manage to perform a click on a pushButton using the GUI. However, GammaRay doesn't seem to provide a command line interface form. As we can read in the official documentation:
The GammaRay client is available in two forms:
as a standalone application as depicted in the following screenshot
as Qt Creator plugin (for Qt Automotive Suite only)
Is there any possibility to perform a click using GammaRay and without GUI? Are some other solutions work using code only?
The purpose of GammaRay is introspection and not automation. I recommend to use Squish (https://www.froglogic.com/de/squish/editions/qt-gui-test-automation/), depending on the required licenses the price is not so high.
If you don't want to spent the money, then you have to create your own IPC Interface with Remote Commands.

Best Practise for GUI development for vanilla C++ application

I want to know about developing of gui to vanilla C++ application. I have experience in mostly in command line application. My experience in C++ gui till now is cout and cin. I have some experience in WPF (just to mention that I do have some gui experience) I hope this will describe my level of experience with gui. Now,I want to develop an application which needs separate GUI with possibility of 3D display. Of course, one of the choice for GUI API is Qt.Also,after reading lots of stuff on internet, i think code separation would be really helpful in future.
So, here goes my question: Is it possible if I keep my logic as generic as possible (not using winapi or qt in my logic) and make only GUI part API specific (say winapi or qt). Or I will need to add some code in my logic section, say for synchronization between logic and GUI. One can say signal and slot from qt is possible but as far as i know signals and slots are qt specific. they are not standard C++.
In summery,my question is can i make my logic in standard C++ (to stay platform/ framework independent) and only design platform specific GUI? If yes, could you please suggest a link or tutorial or book. A sample code or implementation would be 'a wish come true'. Also, some insights in code separation tactics would be quite helpful.
Regards!!
EDIT::
I will elaborate my problem. I have an application which has separate GUI and Logic section. The gui uses WinAPI and as the communication mode used is windows messages, previous user has created a HWND object in Logic which communicates to GUI. So, there is a HWND in Logic and HWND in GUI. I don't find this approach satisfying. One of the reason is that Logic part will be edited by non-programmers in later stage (not much. just modification of constants or changing implementation of function without changing para or return value). So, I just want to keep logic part in standard format (as much as possible). So once again, could anyone help me in designing business logic in C++ and GUI in any API.
After reading some threads, I found that answering own question is not a bad practice. So I will share the answer I have got.
There is no standard way to build a C++ gui application without using external dependencies. The synchronization between gui and logic part is always framework specific. So, if I want to develop a C++ gui application, I cannot put logic part in standard C++. It must have some code from external framework which will communicate the logic part and gui part. Having said that, I have found my way in by following method. I am going to put my logic part inside a static lib and then I will attach this lib to gui part. It will increase coding in gui section, but it will keep the base functions in standard c++. This way (a function lib in standard C++ and machine operation in framework specific code) will work for me. I hope I am on right track. :)
You can to a large extent write completely separate logic and GUI code in Qt. However you will be able to create a much more useful GUI if you allow the logic and GUI code to interact. Qt has it's own classes for a lot of things (QString, QVector<> etc.) but you're free to ignore these for the most part and use the standard library instead if you'd prefer.
However, I do not think that it is worth trying to separate Qt from the logic code entirely because, as mentioned before, you will be able to build a much better GUI if they interact. For a simple example you could write a very simple Qt GUI with just a window and a button; press that button and some logic code is run. However with more interaction you could use signals and slots to update a progress bar on the GUI to let the user know how far the logic code had got. Also Qt is very portable, allowing you to build your program for Windows, Mac and at least some Linux distros.
Also for your 3D display requirement I recently found myself trying to do a similar thing and found this example very useful - http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html.
I think that by default, you should aim to separate business logic from presentation (GUI) code. In web development, the most commonly used pattern is MVC, and it's principles apply equally to native applications.
However, this separation might be more difficult to achieve in native applications. Mainly because there are no frameworks such as Symfony, which have already solved these architectural problems, and make it easy to keep UI and business code separate by following the established conventions. I have't used Qt but from what I know it's mainly a GUI toolkit - models, views and controllers are not as well-defined and integrated.
Depending on the nature of the needed interface, a simple OpenGL GUI might suffice. This is what I did for a simple uni project. The project needed to display a shapefile colored according to statistics in an XML file. I created a number of GUI widgets - button, label etc, and a custom map widget which encapsulates "business logic". Perhaps I should have "cleansed" the map widget, making it as generic as possible, and move all business logic to a separate library, but considering the business layer was very thin I thought the added complexity would outweigh the benefits.
Another factor is your skill-set - current, and areas which you want to improve. I was more interested in OpenGL and freeglut, then in learning Qt. If I had known Qt, I would have used that.
I have done some projects with vanilla C++ and a QT GUI. The idea of not mixing any QT code into the pure C++ stuff is always good but takes a lot of fun out of it. Usually you end up with a much more elaborate GUI than you expected and would often like to connect it better/easier to your code. Signals and Slots are a really great way to let the GUI interact with your code, but then you start mixing...
TLDR: Think really hard about why you don't want to mix your code with e.g. QT. It would not meand mixing GUI and Logic, no way, but your life could be a lot easier using QT classes like QStrings, QProcesses or QThreads...
If you manage to do all the interactions using QTs Signal & Slot mechanism, at some point you might even change you native QT GUI to a QT Quick (QML) one, which is highly customizable, has nice looks and animations and whatnot.
This is just my opinion.

Skinning WinAPI Controls

If you've ever seen an application in the Adobe Creative Suite 5 (CS5), you may have noticed that it doesn't look like the native Windows GUI.. They have modified it to have a different look to it.
Where would someone begin to make an application that has a custom skin? CS5 uses the Adobe Source library for it's widget/control management, so I tried downloading and compiling the Adobe Source Library to see if I could make a nice skinned app like Photoshop CS5, but after finally getting it to compile and tested it, I realized the library was only for managing widgets and not skinning the GUI, like CS5 has.
Where would I begin to make a nice skinned program like Adobe Cs5 applications? Can anyone point me in the right direction?
Do I simply use the WM_PAINT Message from WinAPI and render my own widgets using openGL or something?
Use QT and QML. It doesn't have a steep learning curve. You define your GUI with JavaScript and add lots of effects and enjoy using PNGs in every single thing you can imagine. Then you do your application logic with C++. In fact you can do some fairly advanced things other than UI with QML but it's better to seperate concerns as always.
I use it at work for a product to be released. Overriding WM_PAINT is not the only way in Windows but I strongly recommend QT instead of Win32 API when it comes to custom drawn UI. At least to my experience, it is way easier than my adventures with Win32 API.
If you want to implement custom controls by yourself, you need to implement own WM_PAINT and draw with using GDI/GDI+. For toplevel windows and popups you can use Layered windows. But I think you can find a lot of professional custom controls over internet for reasonable price if you don't want to implement by yourself.
I think your choices re creating a modern skinned app are: QT or WPF (via C++/CLI).
If you have an existing Win32 API application and you do not want to rewrite it using a library that supports skinning you might want to have a look at Stardock DirectSkin.
If you decide to rewrite your application I would also recommend Qt. Guitar Pro 6 was rewritten using Qt, read more about their experience here.

C++ UI framework from scratch?

I want to create a C++ UI framework (something like QT or like ubuntu unity Desktop)
How is programmed , is it using OpenGL or lets take plasma ui of QT (how is this programmed )?
Direct answers , reference links anything will be helpful.
Some interesting opengl based UI I founf on the web
LiquidEngine
http://www.youtube.com/watch?v=k0saaAIjIEY
Libnui
en.wikipedia.org/wiki/Libnui
Some UI frameworks render everything themselves, and work based on some kind of clipping-window-within-the-host-systems-screen. Non-display aspects (such as input event handling) have to be translated to/from the host systems underlying APIs.
Some UI frameworks translate as much as possible to some underlying framework.
wxWidgets can do both. You can choose a native version (e.g. wxMSW if you're on Windows) and most wxWidgets controls will be implemented using native Windows controls. Equally, you can choose the wxUniversal version, where all controls are implemented by the wxWidgets library itself.
The trouble is that typical GUI frameworks are huge. If you want a more manageable example to imitate, you might look at FLTK. I haven't got around to studying it myself, but it has a reputation for being consise.
There are also some GUI toolkits that are specifically aimed at games programming, such as Crazy Eddies GUI. My guess - these are probably as idependent of the underlying API as possible, so that particular applications can implement the mapping to whichever underlying API they happen to target (OpenGL, DirectX, SDL, whatever) and can be the boss of the GUI rather than visa versa.
http://www.wxwidgets.org/
http://www.fltk.org/
http://www.cegui.org.uk/wiki/index.php/Main_Page
"no really, don't write your own wm or toolkit"
The #Xorg-devel guys on irc.freenode.org
doing one anyway means that you have to test against a wide range of more or less buggy WMs and X implementations, and that you have to frequently update to be compatible with the latest Xorg server and X protocol features (like Xinput 2.1)
understandably, the Xorg people are tired to support old, unmaintained toolkits and applications. They already have enough bugs.
The GUI frameworks are very dependant on a windows system, which dictates what is allowed and how windows are created and rendered. For example, pass a specific option to create a borderless or full-screen window.
Since you mentioned opengl and ubuntu, I guess you want to start on a linux platform. You should study xlib, for which you can find reference here.
Since the qt library is open source, you can download it and peek into it's sources.
A UI library isn't developed from scratch. It relies on the OS' windowing system, which relies on the driver from your graphics adapter, which relies on the OS kernel, which relies on... and so on.
To develop any software "from scratch", you can start by writing your own BIOS. Once you're done with that, move on to writing an OS, and then you should be just about ready to write the software you wanted. Good luck.
And this is assuming you're willing to cheat, of course, and use a compiler you didn't write from scratch.
Before you do that, it's worth that you spend one week on thinking:
1, Do you really know how to do it? I doubt that.
2, Do you really need to do it? I doubt that too.

Touch friendly GUI in Windows Mobile

I'm porting an audio processing application written in C++ from Windows to Windows Mobile (version 5+). Basically what I need to port is the GUI. The application is quite complicated and the GUI will need to be able to offer a lot of functionality. I would like to create a touch friendly user interface that also looks good. Which basically means that standard WinMo controls are out the window.
I've looked at libraries such as Fluid and they look like something I would like to use. However, as I said I'm developing i C++. Even though it would be possible to only write the GUI part i some .NET language I rather not. My experience with .NET on Windows Mobile is that it doesn't work very well...
Can anyone either suggest a C/C++ touch friendly GUI library for Windows Mobile or some kind of "best practices" document/how-to on how to use the standard Windows Mobile controls in order to make the touch friendly and also work and look well in later versions of Windows Mobile (in particular version 6.5)?
There are two aspects to your question:
Libraries. For this I would take a look at Qt for CE/WinMo. The C++ alternative is MFC.
GUI Design. About Face and Designing Interfaces (J. Tidwell) are a couple of good books.
Also:
make sure that your UI is finger-friendly, I hate it when I have to use a stylus.
keep in mind that on touch screens you can't have tooltips (no mouse over) and you don't have a mouse pointer. WinMo uses click and long click, but the latter is not easily discoverable.
add joystick UI navigation
don't try to cram too many controls on the tiny screen, use tabs or drill-down menus
I don't know any good C++ libs but you could try SlideUI mobile controls (it is in .NET), but you wouldn’t need any specific knowledge to use it and it's available via design time and easy to use.
http://www.devslide.com/products/slideui
Disclosure: I am affiliated with devslide.