Example #1
0
char* read_file(const char* filename)
{
  int size;
  char* str;
  FILE* file = fopen(filename, "rb");
  if (!file)
  {
    IupMessagef("Error", "Can't open file: %s", filename);
    return NULL;
  }

  /* calculate file size */
  fseek(file, 0, SEEK_END);
  size = ftell(file);
  fseek(file, 0, SEEK_SET);

  /* allocate memory for the file contents + nul terminator */
  str = malloc(size + 1);
  /* read all data at once */
  fread(str, size, 1, file);
  /* set the nul terminator */
  str[size] = 0;

  if (ferror(file))
    IupMessagef("Error", "Fail when reading from file: %s", filename);

  fclose(file);
  return str;
}
Example #2
0
int main(int argc, char **argv)
{
  int ret;
  int integer = 12;
  float real = 1e-3f;
  char text[300]="This is a vector of characters";
  char *fmt =
  {
   "IupScanf Example\n"
   "Text: %300.5%s\n"
   "Real: %20.10%g\n"
   "Integer: %3.10%d\n"
  };
  
  IupOpen(&argc, &argv);

  IupSetLanguage("ENGLISH");

  ret = IupScanf(fmt, text, &real, &integer);
  if (ret == -1)
    IupMessage("IupScanf","Operation canceled");
  else
    IupMessagef("IupScanf","Text: %s\nReal: %f\nInteger: %d\nFields read successfully: %d",text,real,integer,ret);

  IupClose();

  return EXIT_SUCCESS;

}
Example #3
0
void write_file(const char* filename, const char* str, int count)
{
  FILE* file = fopen(filename, "w");
  if (!file)
  {
    IupMessagef("Error", "Can't open file: %s", filename);
    return;
  }

  fwrite(str, 1, count, file);

  if (ferror(file))
    IupMessagef("Error", "Fail when writing to file: %s", filename);

  fclose(file);
}
Example #4
0
static void iupgtk_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
{
  const char* log_lvl = "";
  (void)user_data;

  if (!log_domain)
    log_domain = "";

  switch (log_level & G_LOG_LEVEL_MASK)
  {
  case G_LOG_LEVEL_ERROR:
    log_lvl = "ERROR";
    break;
  case G_LOG_LEVEL_CRITICAL:
    log_lvl = "CRITICAL";
    break;
  case G_LOG_LEVEL_WARNING:
    log_lvl = "WARNING";
    break;
  case G_LOG_LEVEL_MESSAGE:
    log_lvl = "MESSAGE";
    break;
  case G_LOG_LEVEL_INFO:
    log_lvl = "INFO";
    break;
  case G_LOG_LEVEL_DEBUG:
    log_lvl = "DEBUG";
    break;
  }

  IupMessagef("IUPGTK Log", "%s [%s] %s", log_domain, log_lvl, message);
}
Example #5
0
void GetParamTest(void)
{
    int pboolean = 1;
    int pinteger = 3456;
    float preal = 3.543f;
    int pinteger2 = 192;
    float preal2 = 0.5f;
    float pangle = 90;
    char pstring[100] = "string text";
    char pfont[100] = "Courier, 24";
    char pcolor[100] = "255 0 128";
    int plist = 2, poptions = 1;
    char pstring2[200] = "second text\nsecond line";
    char file_name[500] = "test.jpg";

    if (!IupGetParam("Title", param_action, 0,
                     "Bt %u[, MyCancel, Help!]\n"
                     "Boolean 100%%: %b[No,Yes]\n"
                     "Integer: %i\n"
                     "Real 1: %r\n"
                     "Sep1 %t\n"
                     "Integer: %i[0,255]\n"
                     "Real 2: %r[-1.5,1.5,0.05]\n"
                     "Sep2 %t\n"
                     "Angle: %a[0,360]\n"
                     "String: %s\n"
                     "Options: %o|item0|item1|item2|\n"
                     "List: %l|item0|item1|item2|item3|item4|item5|item6|\n"
                     "File: %f[OPEN|*.bmp;*.jpg|CURRENT|NO|NO]\n"
                     "Color: %c{Color Tip}\n"
                     "Font: %n\n"
                     "Sep3 %t\n"
                     "Multiline: %m\n",
                     &pboolean, &pinteger, &preal, &pinteger2, &preal2, &pangle, pstring, &poptions, &plist, file_name, pcolor, pfont, pstring2, NULL))
        return;

    IupMessagef("IupGetParam",
                "Boolean Value: %d\n"
                "Integer: %d\n"
                "Real 1: %g\n"
                "Integer: %d\n"
                "Real 2: %g\n"
                "Angle: %g\n"
                "String: %s\n"
                "Options Index: %d\n"
                "List Index: %d\n"
                "FileName: %s\n"
                "Color: %s\n"
                "Font: %s\n"
                "Multiline: %s",
                pboolean, pinteger, (double)preal, pinteger2, (double)preal2, (double)pangle, pstring, poptions, plist, file_name, pcolor, pfont, pstring2);
}
Example #6
0
int app_about_cb(Ihandle *self)
{
  IupMessagef("About", "IUPGLView 1.0\n"
                       "Tecgraf/PUC-Rio\n"
                       " ---------------- \n"
                       "IUP Version %s\n"
                       "IM Version %s\n"
                       " ---------------- \n"
                       "OpenGL:\n"
                       "  Vendor: %s\n"
                       "  Renderer: %s\n"
                       "  Version: %s\n"
                       , IUP_RELEASE_VERSION, IM_VERSION, 
                         glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION));
  return IUP_DEFAULT;
}
Example #7
0
void GetParamTest(void)
{
  int pboolean = 1;
  int pinteger = 3456;
  float preal = 3.543f;
  int pinteger2 = 192;
  float preal2 = 0.5f;
  float pangle = 90;
  char pstring[100] = "string text";
  int plist = 2;
  char pstring2[200] = "second text\nsecond line";
  char file_name[500] = "test.jpg";
  
  if (!IupGetParam("Title", param_action, 0,
                   "Boolean: %b[No,Yes]\n"
                   "Integer: %i\n"
                   "Real 1: %r\n"
                   "Sep1 %t\n"
                   "Integer: %i[0,255]\n"
                   "Real 2: %r[-1.5,1.5,0.05]\n"
                   "Sep2 %t\n"
                   "Angle: %a[0,360]\n"
                   "String: %s\n"
                   "List: %l|item1|item2|item3|\n" 
                   "File: %f[OPEN|*.bmp;*.jpg|CURRENT|NO|NO]\n"
                   "Sep3 %t\n"
                   "Multiline: %m\n",
                   &pboolean, &pinteger, &preal, &pinteger2, &preal2, &pangle, pstring, &plist, file_name, pstring2, NULL))
    return;
  
  IupMessagef("IupGetParam",
              "Boolean Value: %d\n"
              "Integer: %d\n"
              "Real 1: %g\n"
              "Integer: %d\n"
              "Real 2: %g\n"
              "Angle: %g\n"
              "String: %s\n"
              "List Index: %d\n" 
              "FileName: %s\n"
              "Multiline: %s",
              pboolean, pinteger, (double)preal, pinteger2, (double)preal2, (double)pangle, pstring, plist, file_name, pstring2);
}
Example #8
0
int bt_cb(Ihandle *self)
{
  Ihandle *list = (Ihandle*)IupGetAttribute(self, "_LIST");
  IupMessagef ("List", "Value=%s", IupGetAttribute(list, "VALUE"));
  return IUP_DEFAULT;
}