Home > OS >  How to add an image in a Xforms interface in language C
How to add an image in a Xforms interface in language C

Time:01-12

I have to do an a GUI for a project and for better ergonomics i want to add images or pictures to it. For the project i have to do it in C or C and I'm using Xforms to create the GUI.

There is my code for the moment:

#include <stdio.h>
#include <forms.h>

#define WIDTH 800
#define LENGTH 480


FL_FORM *menu;
FL_IMAGE *skiold;
FL_OBJECT *lower_bar;
FL_OBJECT *deco;

/* ------------- */
/* main fonction */
/* ------------- */
int main(int argc, char *argv[])
{
    fl_initialize(&argc, argv, 0, 0, 0);

    menu = fl_bgn_form(FL_FLAT_BOX, WIDTH, LENGTH);
    fl_set_form_background_color(menu, FL_WHITE);

    lower_bar = fl_add_box(FL_FLAT_BOX, 0, 400, 800, 80, "");
    fl_set_object_color(lower_bar, FL_DARKER_COL1, FL_DARKER_COL1);
    deco = fl_add_text(FL_NORMAL_TEXT, 250, 420, 300, 50, "PRINCIPAL MENU");
    fl_set_object_lsize(deco, 30);
    fl_set_object_color(deco, FL_DARKER_COL1, FL_DARKER_COL1);

    /*skiold = flimage_load("logo_skiold.png")*/

    fl_end_form();
    fl_show_form(menu, FL_PLACE_MOUSE, FL_FULLBORDER, "Emulateur");
    fl_do_forms();
    fl_hide_form(menu);
    fl_finish();

    return 0;
}

From what I saw in the documentation, I just had to create a variable of type FL_IMAGE and load it after. But when I compile it, it returns that it doesn't recognize the type FL_IMAGE.

So, I don't know if this is a problem of libraries, if there are others methods or if this is just impossible.

CodePudding user response:

The INSTALL doc file states that for building libflimage and its headers you must configure and make and make install as root. Then you have also a libflimage.so and an flimage.h to include.

Note: I've noy yet tested all this with your source. I've only done the build/install and got also libflimage.so and an flimage.h available

ADDENDUM Now I testes ad all is Ok, the image is displayed but a canvas is needed:

// gcc prova.c -lforms -lflimage -o prova
#include <stdio.h>
#include <forms.h>
#include <flimage.h>

#define WIDTH 800
#define LENGTH 480
    
FL_FORM *menu;
FL_IMAGE *skiold;
FL_OBJECT *lower_bar;
FL_OBJECT *deco;
FL_OBJECT *canv;

/* ------------- */
/* main fonction */
/* ------------- */
int main(int argc, char *argv[])
{
    fl_initialize(&argc, argv, 0, 0, 0);

    menu = fl_bgn_form(FL_FLAT_BOX, WIDTH, LENGTH);
    fl_set_form_background_color(menu, FL_WHITE);
    canv = fl_add_canvas(FL_NORMAL_CANVAS, 0, 0, 100, 100,"");

    lower_bar = fl_add_box(FL_FLAT_BOX, 0, 400, 800, 80, "");
    fl_set_object_color(lower_bar, FL_DARKER_COL1, FL_DARKER_COL1);
    deco = fl_add_text(FL_NORMAL_TEXT, 250, 420, 300, 50, "PRINCIPAL MENU");
    fl_set_object_lsize(deco, 30);
    fl_set_object_color(deco, FL_DARKER_COL1, FL_DARKER_COL1);

    flimage_enable_png();
    //skiold = flimage_load("logo_skiold.png")    
    skiold = flimage_load("/path/to/mypng/mypng.png");

    fl_end_form();
    fl_show_form(menu, FL_PLACE_MOUSE, FL_FULLBORDER, "Emulateur");
    flimage_display(skiold,  FL_ObjWin(canv));
    fl_do_forms(); 
    fl_hide_form(menu);
    fl_finish();

    return 0;
}
  • Related