LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sane Cross-platform alternative to GTK2 ? (https://www.linuxquestions.org/questions/programming-9/sane-cross-platform-alternative-to-gtk2-4175505833/)

Xeratul 05-22-2014 11:17 PM

Sane Cross-platform alternative to GTK2 ?
 
Hello,

I would like to move one software from ncurses to some graphical frontend.

GTK would be a nice move, but man,... have you ever seen the output of :
apt-get install --no-install-recommends libgtk2.0-dev


It is not normal that so much will be installed on a machine.

I am worried, seriously, that no one care about this. A bloated applications is for no one of interest, heavy dependencies: no one care at all, slow applications such as gimp or inkscape: no one care. Seriously, there should be some group of people to clean up the messy devel.

Thank you and greetings

dugan 05-22-2014 11:27 PM

FLTK?

Xeratul 05-23-2014 04:33 AM

Quote:

Originally Posted by dugan (Post 5175606)
FLTK?

Code:

u# apt-get install  libfltk1.3-dev
Reading package lists... Done
Building dependency tree     
Reading state information... Done
The following package was automatically installed and is no longer required:
  libxcb-dri2-0
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  fltk1.3-doc fluid libfltk-cairo1.3 libfltk-forms1.3 libfltk-gl1.3
  libfltk-images1.3 libfltk1.3 libgl1-mesa-dev libglu1-mesa libglu1-mesa-dev
  mesa-common-dev
Suggested packages:
  libjpeg-dev
The following NEW packages will be installed:
  fltk1.3-doc fluid libfltk-cairo1.3 libfltk-forms1.3 libfltk-gl1.3
  libfltk-images1.3 libfltk1.3 libfltk1.3-dev libgl1-mesa-dev libglu1-mesa
  libglu1-mesa-dev mesa-common-dev
0 upgraded, 12 newly installed, 0 to remove and 1 not upgraded.
Need to get 13.3 MB of archives.
After this operation, 46.9 MB of additional disk space will be used.
Do you want to continue [Y/n]?


Well, it is much better than GTK, much much better, but still it is quite a lot !

a4z 05-23-2014 04:49 AM

the truth is:
Quote:

ls -lh
total 5.7M
-rw-r--r-- 1 slk141 users 2.3M May 15 13:21 libfltk.a
-rwxr-xr-x 1 slk141 users 1.2M May 15 13:21 libfltk.so.1.3
-rw-r--r-- 1 slk141 users 4.1K May 15 13:20 libfltk_cairo.a
-rw-r--r-- 1 slk141 users 48K May 15 13:21 libfltk_forms.a
-rwxr-xr-x 1 slk141 users 672K May 15 13:21 libfltk_forms.so.1.3
-rw-r--r-- 1 slk141 users 205K May 15 13:21 libfltk_gl.a
-rwxr-xr-x 1 slk141 users 633K May 15 13:21 libfltk_gl.so.1.3
-rw-r--r-- 1 slk141 users 101K May 15 13:21 libfltk_images.a
-rwxr-xr-x 1 slk141 users 658K May 15 13:21 libfltk_images.so.1.3
and this are the static and shared libraries from my slack build

the debian build seems to include the whole documentation, (that's why I have a extra pack for this)

you will not find anything smaller than FLTK,
in fact, you can include the source into your distribution and ship it like that, the build time is acceptable, something you can/will not do with gtk or qt

Drakevr 05-23-2014 04:52 AM

You shouldn't consider GTK2 as it is deprecated and unmaintained.

If you want GTK you should choose GTK3 that is better supported and the current target of development.
Now if you DON'T want to use GTK there are some good alternatives like FLTK dugan said or Enlightenment Foundation Libraries[0] (EFL) or even Qt[1] that with the new owners and current developments has gotten a huge traction especially against GTKx


[0] http://enlightenment.org
[1] http://qt-project.org

Xeratul 05-23-2014 05:06 AM

Quote:

Originally Posted by Drakevr (Post 5175705)
You shouldn't consider GTK2 as it is deprecated and unmaintained.

If you want GTK you should choose GTK3 that is better supported and the current target of development.
Now if you DON'T want to use GTK there are some good alternatives like FLTK dugan said or Enlightenment Foundation Libraries[0] (EFL) or even Qt[1] that with the new owners and current developments has gotten a huge traction especially against GTKx


[0] http://enlightenment.org
[1] http://qt-project.org

For me it does not matter really to have a gtk.

I would like something nice and graphical for the users (because they dont like ncurses / dos like apps).
As portable / cross-platform as possible, and as tiny and dependencies-free as possible.

One dll to add into the directory would be ideal, such as pdcurses.dll and that's all !!

Drakevr 05-23-2014 05:24 AM

Qt is too much of a beast for that then, do take a look at EFL though they really are portable! they already run in probably any single system you own and then some while being really lightweight both size and performance wise.

dugan 05-23-2014 09:43 AM

Quote:

Originally Posted by Xeratul (Post 5175693)
Well, it is much better than GTK, much much better, but still it is quite a lot !

How could you possibly say that's "a lot"? I see the X development packages (which you'll need for obvious reasons), and I see the various packages that FLTK itself was split up into. What did you expect? If you're going by the number of Debian packages you need for development, then you're being silly.

Quote:

One dll to add into the directory would be ideal, such as pdcurses.dll and that's all !!
Talk about moving the goalposts. That is a completely unrelated question.

First, have you forgotten that you can statically link executables?

Second, the number of packages you need to start development (on Debian) has nothing to do with the number of DLLs you'll need to distribute with your compiled application on Windows. With Qt on Windows, you distribute about 3 DLLs with your compiled, dynamically linked Qt application. Just put them in the same directory as the executable.

You didn't think that a compiled FLTK application (on Windows) would need a libglu1-mesa DLL and a libglu1-mesa-dev DLL, did you?

ntubski 05-23-2014 10:38 AM

A lesser known alternative: http://www.tecgraf.puc-rio.br/iup/. It will require 0 Debian packages to install! ... because it isn't packaged by Debian.

briselec 05-23-2014 07:47 PM

What's the reason for wanting a graphical interface? I'm thinking if it's currently using ncurses you probably don't need a widget library. Have you considered SDL?

Xeratul 05-27-2014 10:10 AM

Thanks there are quite some interesting ones, alternatives. Which one you favor?


Look I just checked what does gtk making using pkg-config, creating there following Include, needed to compile hello.c with gcc. I like very much. So much non needed stuffs. Man, where is simplicity?

Quote:

gcc hello.c -o hello -pthread -I/usr/include/gtk-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0
code:

Code:


#include <gtk/gtk.h>


int main( int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *fixed;

  GtkWidget *button1;
  GtkWidget *button2;
  GtkWidget *button3;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "GtkFixed");
  gtk_window_set_default_size(GTK_WINDOW(window), 290, 200);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

  fixed = gtk_fixed_new();
  gtk_container_add(GTK_CONTAINER(window), fixed);

  button1 = gtk_button_new_with_label("Button");
  gtk_fixed_put(GTK_FIXED(fixed), button1, 150, 50);
  gtk_widget_set_size_request(button1, 80, 35);

  button2 = gtk_button_new_with_label("Button");
  gtk_fixed_put(GTK_FIXED(fixed), button2, 15, 15);
  gtk_widget_set_size_request(button2, 80, 35);

  button3 = gtk_button_new_with_label("Button");
  gtk_fixed_put(GTK_FIXED(fixed), button3, 100, 100);
  gtk_widget_set_size_request(button3, 80, 35);

  g_signal_connect_swapped(G_OBJECT(window), "destroy",
      G_CALLBACK(gtk_main_quit), NULL);

  gtk_widget_show_all(window);

  gtk_main();

  return 0;
}


dugan 05-27-2014 10:54 AM

Quote:

Code:

gcc hello.c -o hello -pthread -I/usr/include/gtk-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0

Quote:

So much non needed stuffs.
Such as? ;)

And dude, learn CMake.

Just put the following CMakeLists.txt file in the same directory as hello.c:

Code:

cmake_minimum_required (VERSION 2.6)
project (Hello)
find_package(GTK2)
include_directories (${GTK2_INCLUDE_DIRS})
add_executable(hello hello.c)
target_link_libraries(hello ${GTK2_LIBRARIES})

Then:

Code:

mkdir build
cd build
cmake ..
make
./hello

Quote:

Thanks there are quite some interesting ones, alternatives. Which one you favor?
Me? Qt.

Xeratul 05-30-2014 11:15 AM

"Me? Qt"

what about X11?

It is simple and portable on Windows as well.



Would you know how to create an inputbox in x11?

// hello.c

Code:

/* The authors of this work have released all rights to it and placed it
in the public domain under the Creative Commons CC0 1.0 waiver
(http://creativecommons.org/publicdomain/zero/1.0/).

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Retrieved from: http://en.literateprograms.org/Hello_World_(C,_Xlib)?oldid=19143
*/


#include<X11/Xlib.h>

#include<stdio.h>
#include<stdlib.h>

int main()
{
        Display *dpy;
        Window rootwin;
        Window win;
        Colormap cmap;
        XEvent e;
        int scr;
        GC gc;


        if(!(dpy=XOpenDisplay(NULL))) {
                fprintf(stderr, "ERROR: could not open display\n");
                exit(1);
        }
        scr = DefaultScreen(dpy);
        rootwin = RootWindow(dpy, scr);
        cmap = DefaultColormap(dpy, scr);

        win=XCreateSimpleWindow(dpy, rootwin, 1, 1, 100, 50, 0,
                        BlackPixel(dpy, scr), BlackPixel(dpy, scr));
        XStoreName(dpy, win, "hello");

        gc=XCreateGC(dpy, win, 0, NULL);
        XSetForeground(dpy, gc, WhitePixel(dpy, scr));
        XSelectInput(dpy, win, ExposureMask|ButtonPressMask);
        XMapWindow(dpy, win);
        while(1) {
                XNextEvent(dpy, &e);
                if(e.type==Expose && e.xexpose.count<1)
                        XDrawString(dpy, win, gc, 10, 10, "Hello World!", 12);
                else if(e.type==ButtonPress) break;
        }

        XCloseDisplay(dpy);

        return 0;
}


Xeratul 06-01-2014 10:32 AM

1 Attachment(s)
Most of technical people are trying to migrate from windows to Linux now a days , but they are facing lot of problems with Linux . they do not even know the forums and blogs of Linux which would be useful for finding answer to their query. The main problem of open source is choosing right one for user need. Because so many open source softwares are available for a single thing. Surely user need some supportive forum or website to find that one . open Peta is also doing that job. The idea of this post coming to my mind from my college friend . One of my colleague asked me about computer graphics program in Linux using C programming language. the questions is

How to draw line, circle , or 2D graphics in Linux Using C or C++?

I was searching Internet and found some softwares for developing graphics applications in Linux. that softwares are listed here

GTK+ – Gnome Tool Kit

QT - The X toolkit

SVGALIB [ #include<vgagl.h> ]

libgraph [ #include<graphics.h> ]

GTK and QT are simple and used for high level Graphical User Interface [ GUI ] development. SVGALIB and libgraph is used for 2D graphics in Linux . the syntax and functions are some what different for beginners [specially the user from windows ] but most of users familiar with windows graphics.h header file in C and C++ , so we can move for libgraph which is exact one for windows graphics user . libgraph is an implementation of the Turbo C graphics API (graphics.h) on GNU/Linux using SDL [ Simple Direct Media Player ]. The library requires SDL for primitive graphics and SDL. First you need to install the following dependency packages using synaptic package manager in Ubuntu Linux to develop the graphics applications properly.


gcc test.c -lgraph -o superbe



Code:


#include<stdio.h>
#include<graphics.h>

int main() {
//int gd=DETECT,gm;

int gd = DETECT,gm, left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;

initgraph(&gd,&gm,NULL);

int i,xx=10;
char str[3]="0";
setbkcolor(WHITE);

setcolor(12); //outline heart
circle(50,50,40);
circle(110,50,40);
line(22,80,80,140);
line(80,140,138,80);

floodfill(50,50,12); //fill heart
floodfill(110,50,12);
floodfill(80,50,12);
floodfill(80,100,12);



// setlinestyle(SOLID_LINE, 0, 2); <---- this is not into LINUX?
line(50,50,200,200);
 /* setting text justification  - horizontally & vertically */
// how to use this into linux?      settextjustify(CENTER_TEXT, CENTER_TEXT);
                /* sets font style, direction and size */
//      settextstyle(i, i % 2, 5);

setcolor(RED);
rectangle(150, 180, 500, 220);
floodfill(201,201,12);
outtextxy(200 , 200 , " I LOVE GRAPHICS.H ON LINUX");



line(50,50,80,80);

line( 0, 0, 100, 100);

setcolor(YELLOW);
  rectangle(left, top -100  , right, bottom -100);
  circle(x, y, radius);

  bar(left + 300, top -100 , right + 300, bottom -100);

setcolor(BLUE);
  line(left - 10, top + 150, left + 410, top + 150);
  ellipse(x, y + 200, 0, 360, 100, 50);
 

      setcolor(BLUE);
      // draw a white color border with rectangle
      rectangle(3 ,3,getmaxx() -3,getmaxy() -3);

 
setcolor(BLUE);    // to set the colour of the text to white
outtextxy(left + 100, top + 325, "My First C Graphics Program");


setcolor(BLUE);    // to set the colour of the text to white
//settextstyle(3,0,2);  // to set the text to my preferred style


outtextxy(40,10,"text goes here");  // the actual text
//settextstyle(0,0,1);  // to return the style to default

  setcolor(CYAN);
moveto(200 , 200 );

char msg[4000];
int j ;

rectangle(150, 380, 500, 440 );
floodfill(181,401,12);
 j = snprintf( msg, 300 , "background: %d, foreground: %d, maxcolors: %d", getbkcolor(), getcolor(), getmaxcolor());
 outtextxy( 180 , 400 , msg );



getch();
closegraph();
return 0;
}




However borland graphics.h might be slow... , no??

Quote:

About

This library is intended to replace the old DOS library that was included Borland C (called BGI, which stands for Borland Graphics Interface). which provides functions for DOS graphics mode. It was extremely slow and it's API wasn't perfect (from modern point of view) but it was very simple to use, so it very well suits for teaching programming basis, where graphics output is needed. Although all it's lacks, it is used even now, because of it's simplicity for teaching purpose.


So, OpenBGI library is intended to replace that old library, by implementing just the same interface but implementing on Microsoft Windows system for use with Visual Studio (6.0, .NET, 2003, 2005, 2008) or MinGW compiler. It has practically the same API as <graphics.h> (that was included in Borland C for DOS) with some extensions (described in Features). That is, it let's simply to switch from old legacy Borland C to modern compilers/IDEs ( Visual Studio 2005 Express Edition, for example) practically without code changing.

There is also some other Windows implementation of that old library (Winbgi, for example), but OpenBGI implementation differs from them in good debug mode support


is this idea much faster? he uses bgi into a dos game
http://www.planetsourcecode.com/vb/s...=7383&lngWId=3




Here a nice screensaver that I quickly made using graphics.h
it works more or less ok.
Code:


#include <stdio.h>
//#include <stdlib.h>
#include <graphics.h>


int srand_counter = 1 ;


int randomi(int max) {
    srand ( time(NULL) * srand_counter );
    srand_counter++;
    return (rand() %max ) ;
}


 
int main (void)
{
  int i, gd, gm;

  int ch = 0 ;
  int main_gameover = 0 ;
 
  gd = DETECT;
  initgraph (&gd, &gm, "");
  setbkcolor (BLACK);
  cleardevice ();
  outtextxy (0, 0, "Screensaver...");



  while( main_gameover == 0){

    setcolor (1 + randomi(15));
    line ( randomi(getmaxx()), randomi(getmaxy()),
    randomi(getmaxx()), randomi(getmaxy()) );

    // ch =  getch ();   
 ch =  kbhit();   

      if ( ch == 'q'  )  main_gameover = 1;
    //  if ( ch == KEY_F(10)  )  main_gameover = 1;
      if ( ch == 'c'  )    cleardevice();

    if ( ch == 'B'  )    {  setbkcolor (BLACK);  cleardevice (); }
    if ( ch == 'a'  )    {  setbkcolor (BLACK);cleardevice (); }

    if ( ch == 'b'  ) {
        setbkcolor (BLUE);
        cleardevice ();
        outtextxy (0, 0, "Pressed B key...");
      }

    }

  closegraph ();
  return 0;
}


dugan 06-01-2014 04:26 PM

Quote:

Originally Posted by Xeratul (Post 5180299)
How to draw line, circle , or 2D graphics in Linux Using C or C++?

If that's all you want, then add OpenGL to your list of things to evaluate.


All times are GMT -5. The time now is 09:21 AM.