// Runs geocode hostip callback static int _run_geocode(/*@unused@*/ Ihandle *ih) { float lat,lon; char city[100]; // Check if controls have been created if( (lbl_status==NULL) || (list_method==NULL) || (edt_lat==NULL) || (edt_lon==NULL) ) { LOG(LOGERR,_("Function called without GUI!")); return IUP_DEFAULT; } LOG(LOGVERBOSE,_("Running geocode subfunction.")); IupSetAttribute(run_task,"RUN","NO"); IupSetAttribute(list_method,"VISIBLE","YES"); IupSetAttribute(list_method,"VALUE","0"); if(!location_geocode_hostip(&lat,&lon,city,100)) { IupSetAttribute(lbl_status,"APPEND",_("Unable to download data")); return IUP_DEFAULT; } IupSetfAttribute(lbl_status,"APPEND",_("city: %s"),city); IupSetfAttribute(lbl_status,"APPEND",_("lat/lon: %.2f,%.2f"),lat,lon); IupSetAttribute(lbl_status,"APPEND",_("Go to http://www.hostip.info/ to correct")); IupSetfAttribute(edt_lat,"VALUE","%f",lat); IupSetfAttribute(edt_lon,"VALUE","%f",lon); return IUP_DEFAULT; }
int iupdrvOpen(int *argc, char ***argv) { char* value; if (!gtk_init_check(argc, argv)) return IUP_ERROR; #if defined(IUPGTK_DEBUG) g_log_set_default_handler(iupgtk_log, NULL); #endif IupSetGlobal("DRIVER", "GTK"); IupStoreGlobal("SYSTEMLANGUAGE", pango_language_to_string(gtk_get_default_language())); /* driver system version */ IupSetfAttribute(NULL, "GTKVERSION", "%d.%d.%d", gtk_major_version, gtk_minor_version, gtk_micro_version); IupSetfAttribute(NULL, "GTKDEVVERSION", "%d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); gtkSetGlobalAttrib(); gtkSetGlobalColors(); IupSetGlobal("SHOWMENUIMAGES", "YES"); value = getenv("UBUNTU_MENUPROXY"); /* for now only in Ubuntu */ if (value && (iupStrEqualNoCase(value, "libappmenu.so") || iupStrEqualNoCase(value, "1"))) IupSetGlobal("GLOBALMENU", "Yes"); return IUP_NOERROR; }
static void iScrollBoxLayoutUpdate(Ihandle* ih) { int dx = ih->currentwidth, dy = ih->currentheight; /* already updated the canvas layout, so just have to update the scrollbars and child. */ /* if child is greater than scrollbox, has scrollbars but this affects the oposite direction */ if (ih->firstchild->currentwidth > ih->currentwidth) dy -= iupdrvGetScrollbarSize(); if (ih->firstchild->currentheight > ih->currentheight) dx -= iupdrvGetScrollbarSize(); IupSetfAttribute(ih, "DX", "%d", dx); IupSetfAttribute(ih, "DY", "%d", dy); if (ih->firstchild) { iScrollBoxUpdatePosition(ih, IupGetFloat(ih, "POSX"), IupGetFloat(ih, "POSY")); iupLayoutUpdate(ih->firstchild); } }
static int iValSetTypeAttrib(Ihandle* ih, const char *value) { int min_w, min_h; /* valid only before map */ if (ih->handle) return 0; iupdrvValGetMinSize(ih, &min_w, &min_h); if (iupStrEqualNoCase(value, "VERTICAL")) { /* val natural vertical size is MinWx100 */ IupSetfAttribute(ih, "RASTERSIZE", "%dx%d", min_w, 100); ih->data->type = IVAL_VERTICAL; } else /* "HORIZONTAL" */ { /* val natural horizontal size is 100xMinH */ IupSetfAttribute(ih, "RASTERSIZE", "%dx%d", 100, min_h); ih->data->type = IVAL_HORIZONTAL; } return 0; /* do not store value in hash table */ }
int iupdrvOpen(int *argc, char ***argv) { GtkStyle* style; if (!gtk_init_check(argc, argv)) return IUP_ERROR; IupSetGlobal("DRIVER", "GTK"); IupStoreGlobal("SYSTEMLANGUAGE", pango_language_to_string(gtk_get_default_language())); /* driver system version */ IupSetfAttribute(NULL, "GTKVERSION", "%d.%d.%d", gtk_major_version, gtk_minor_version, gtk_micro_version); IupSetfAttribute(NULL, "GTKDEVVERSION", "%d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); gtkSetDrvGlobalAttrib(); style = gtk_style_new(); iupgtkUpdateGlobalColors(style); IupSetGlobal("_IUP_RESET_GLOBALCOLORS", "YES"); /* will update the global colors when the first dialog is mapped */ g_object_unref(style); return IUP_NOERROR; }
// Address lookup function static int _address_lookup(/*@unused@*/ Ihandle *ih) { char *result = IupGetAttribute(edt_address,"VALUE"); float lat,lon; char city[100]; int rescode; if( result == NULL ) return IUP_DEFAULT; IupSetAttribute(list_method,"VISIBLE","YES"); IupSetAttribute(list_method,"VALUE","0"); IupSetAttribute(lbl_status,"VALUE",""); IupSetfAttribute(lbl_status,"APPEND", _("Downloading info, this may be slow...")); rescode=location_address_lookup(result,&lat,&lon,city,100); // Destroy address box if( hbox_address ) IupDestroy(hbox_address); hbox_address = btn_address = edt_address = NULL; if( dialog_location ) IupRefresh(dialog_location); if(!rescode) { IupSetAttribute(lbl_status,"APPEND",_("Unable to download data")); return IUP_DEFAULT; } IupSetfAttribute(lbl_status,"APPEND",_("city: %s"),city); IupSetfAttribute(lbl_status,"APPEND",_("lat/lon: %.2f,%.2f"),lat,lon); IupSetfAttribute(edt_lat,"VALUE","%f",lat); IupSetfAttribute(edt_lon,"VALUE","%f",lon); return IUP_DEFAULT; }
Ihandle* IupImage (int width, int height, const unsigned char *pixmap) { Ihandle *n = iupTreeCreateNode(NULL); type(n) = IMAGE_; IupSetfAttribute(n,IUP_WIDTH,"%u", width); IupSetfAttribute(n,IUP_HEIGHT,"%u", height); IupSetAttribute(n,"BPP","8"); IupSetAttribute(n,"CHANNELS","1"); image_data(n) = (char *) malloc (width*height); if (image_data(n) && pixmap) memcpy (image_data(n),pixmap,width*height); return n; }
int save_image_cb(void) { if(gc.image == NULL) { IupSetfAttribute(gc.msgbar, "TITLE", "There's no image to save"); return IUP_DEFAULT; } image_copy = imgCopy(gc.image); IupSetfAttribute(gc.msgbar, "TITLE", "State of the image saved"); return IUP_DEFAULT; }
int time_cb(void) { float value = IupGetFloat(progressbar1, "VALUE"); value += increment; if (value > 1) value = 0; /* start over */ IupSetfAttribute(progressbar1, "VALUE", "%g", (double)value); value = IupGetFloat(progressbar2, "VALUE"); value += increment*50; if (value > 50) value = 0; /* start over */ IupSetfAttribute(progressbar2, "VALUE", "%g", (double)value); return IUP_DEFAULT; }
static void iScrollBoxLayoutUpdate(Ihandle* ih) { int w, h; IupGetIntInt(ih, "DRAWSIZE", &w, &h); IupSetfAttribute(ih, "DX", "%d", w); IupSetfAttribute(ih, "DY", "%d", h); if (ih->firstchild) { iScrollBoxUpdatePosition(ih, IupGetFloat(ih, "POSX"), IupGetFloat(ih, "POSY")); iupLayoutUpdate(ih->firstchild); } }
int resize_cb(Ihandle *ih, int w, int h) { /* update page size, it is always the client size of the canvas */ IupSetfAttribute(ih, "DX", "%d", w); IupSetfAttribute(ih, "DY", "%d", h); if (!cdcanvas) return IUP_DEFAULT; /* update CD canvas size */ cdCanvasActivate(cdcanvas); return IUP_DEFAULT; }
static void print_value(Ihandle *ih, double a) { char *type = IupGetAttribute(ih, "TYPE"); switch(type[0]) { case 'V': IupSetfAttribute(lbl_v, "TITLE", "VALUE=%.2f", a); break; case 'H': IupSetfAttribute(lbl_h, "TITLE", "VALUE=%.2f", a); break; } }
int load_image_cb(void) { if(image_copy == NULL) { IupSetfAttribute(gc.msgbar, "TITLE", "There's no copy of image saved"); return IUP_DEFAULT; } gc.image = imgCopy(image_copy); repaint_cb(gc.canvas); IupSetfAttribute(gc.msgbar, "TITLE", "Last state saved is loaded"); return IUP_DEFAULT; }
// List method changes static int _list_method_cb(/*@unused@*/ Ihandle *ih, /*@unused@*/ char *text, int pos, int state) { if( state == 0 ) return IUP_DEFAULT; if( !run_task ) run_task = IupSetAtt(NULL,IupTimer(),"TIME","100",NULL); switch(pos) { case 1: LOG(LOGVERBOSE,_("Running geocode with hostip")); IupSetAttribute(lbl_status,"VALUE",""); IupSetfAttribute(lbl_status,"APPEND", _("Downloading info, this may be slow...")); (void)IupSetCallback(run_task,"ACTION_CB",(Icallback)_run_geocode); IupSetAttribute(run_task,"RUN","YES"); IupSetAttribute(list_method,"VISIBLE","NO"); break; case 2: LOG(LOGVERBOSE,_("Running geocode with geobytes")); IupSetAttribute(lbl_status,"VALUE",""); IupSetfAttribute(lbl_status,"APPEND", _("Downloading info, this may be slow...")); (void)IupSetCallback(run_task,"ACTION_CB",(Icallback)_run_geobytes); IupSetAttribute(run_task,"RUN","YES"); IupSetAttribute(list_method,"VISIBLE","NO"); break; case 3: { edt_address = IupSetAtt(NULL,IupText(NULL), "VALUE","Enter Address...", "EXPAND","HORIZONTAL",NULL); (void)IupSetCallback(edt_address,"GETFOCUS_CB",(Icallback)_address_clear); btn_address = IupSetAtt(NULL,IupButton(_("Lookup"),NULL),NULL); (void)IupSetCallback(btn_address,"ACTION",(Icallback)_address_lookup); hbox_address = IupHbox(edt_address,btn_address,NULL); if( (vbox_method!=NULL) && (hbox_address!=NULL) && (lbl_status!=NULL) ) (void)IupInsert(vbox_method,lbl_status,hbox_address); else { LOG(LOGERR,_("Location search controls not created!")); return IUP_DEFAULT; } IupSetAttribute(list_method,"VISIBLE","NO"); (void)IupMap(hbox_address); IupRefresh(hbox_address); break; } }; return IUP_DEFAULT; }
void iupmotCBcaret (Widget w, XtPointer client_data, XtPointer call_data) { IFnii cb; Iwidgetdata *d = NULL; Ihandle *n; XmTextVerifyCallbackStruct* textverify = (XmTextVerifyCallbackStruct*)call_data; if (iupmot_incallback) return; XtVaGetValues (w, XmNuserData, &d, NULL); if (!d) return; n = d->ihandle; if (n == NULL) return; cb = (IFnii) IupGetCallback(n, "CARET_CB"); if (cb) { int old_col, old_row, col, row=1; long int pos; pos = textverify->newInsert; if (type(n) == TEXT_ || (type(n) == LIST_ && iupCheck(n, "EDITBOX")==YES)) { col = pos+1; } else /* MULTILINE_ */ { long int linText, colText; char *str = XmTextGetString((Widget)handle(n)); iupmotLincol( str, pos, &linText, &colText ); row = linText; col = colText; } old_col = IupGetInt(n, "_IUPMOT_CARETCOL"); old_row = IupGetInt(n, "_IUPMOT_CARETROW"); if (row != old_row || col != old_col) { IupSetfAttribute(n, "_IUPMOT_CARETCOL", "%d", col); IupSetfAttribute(n, "_IUPMOT_CARETROW", "%d", row); iupmot_incallback = TRUE; if (cb(n, row, col) == IUP_CLOSE) iupmot_exitmainloop = 1; iupmot_incallback = FALSE; } } }
static int map_cb(Ihandle *ih) { cdCanvas *canvas = cdCreateCanvas(CD_IUP, ih); /* World size is fixed */ wdCanvasWindow(canvas, 0, WORLD_W, 0, WORLD_H); /* handle scrollbar in world coordinates, so we only have to update DX/DY */ IupSetAttribute(ih, "XMIN", "0"); IupSetAttribute(ih, "YMIN", "0"); IupSetfAttribute(ih, "XMAX", "%d", WORLD_W); IupSetfAttribute(ih, "YMAX", "%d", WORLD_H); return IUP_DEFAULT; }
static void iScrollBoxSetChildrenCurrentSizeMethod(Ihandle* ih, int shrink) { /* update child to its own natural size */ if (ih->firstchild) { iupBaseSetCurrentSize(ih->firstchild, ih->firstchild->naturalwidth, ih->firstchild->naturalheight, shrink); IupSetfAttribute(ih, "XMAX", "%d", ih->firstchild->currentwidth); IupSetfAttribute(ih, "YMAX", "%d", ih->firstchild->currentheight); } else { IupSetAttribute(ih, "XMAX", "0"); IupSetAttribute(ih, "YMAX", "0"); } }
/* carrega uma nova cena */ int load_cb(void) { char* filename = get_file_name(); /* chama o dialogo de abertura de arquivo */ char buffer[30]; if (filename==NULL) return 0; /* Le a cena especificada */ scene = sceLoad( filename ); if( scene == NULL ) return IUP_DEFAULT; camera = sceGetCamera( scene ); eye = camGetEye( camera ); width = camGetScreenWidth( camera ); height = camGetScreenHeight( camera ); yc=0; if (image) imgDestroy(image); image = imgCreate( width, height ); IupSetfAttribute(label, "TITLE", "%3dx%3d", width, height); sprintf(buffer,"%3dx%3d", width, height); IupSetAttribute(canvas,IUP_RASTERSIZE,buffer); IupSetFunction (IUP_IDLE_ACTION, (Icallback) idle_cb); start_time = clock(); IupGLMakeCurrent(canvas); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glEnd(); glFlush(); IupGLSwapBuffers(canvas); /* change the back buffer with the front buffer */ return IUP_DEFAULT; }
static void iMatrixAuxUpdateVisibleSize(Ihandle* ih, int m) { char* D; ImatLinColData *p; int canvas_size; if (m == IMAT_PROCESS_LIN) { D = "DY"; p = &(ih->data->lines); canvas_size = ih->data->h; } else { D = "DX"; p = &(ih->data->columns); canvas_size = ih->data->w; } /* Matrix useful area is the current size minus the title area */ p->visible_size = canvas_size - p->sizes[0]; if (p->visible_size > p->total_size) p->visible_size = p->total_size; if (p->total_size) IupSetfAttribute(ih, D, "%f", (double)p->visible_size/(double)p->total_size); else IupSetAttribute(ih, D, "1.0"); }
int binary_cb(void) { Image* tmp = gc.image; if (tmp != NULL){ IupSetfAttribute(gc.msgbar, "TITLE", "Grey scale image ..."); gc.image = imgGrey(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); tmp = gc.image; gc.image = imgBinary(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); IupSetfAttribute(gc.msgbar, "TITLE", "Binary image ..."); } return IUP_DEFAULT; }
static int enteritem_cb(Ihandle *ih, int lin, int col) { IupSetAttribute(ih,"MARKED", NULL); /* clear all marks */ IupSetAttributeId2(ih,"MARK", lin, 0, "1"); IupSetfAttribute(ih,"REDRAW", "L%d", lin); return IUP_DEFAULT; }
int count_cb(void) { int num; if(gc.image == NULL || imgGetDimColorSpace(gc.image) != 1) { IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary"); return IUP_DEFAULT; } num = imgCount(gc.image); IupSetfAttribute(gc.msgbar, "TITLE", "Objects in this picture: %d", num); return IUP_DEFAULT; }
static int param_action(Ihandle* dialog, int param_index, void* user_data) { switch(param_index) { case IUP_GETPARAM_OK: printf("IupGetParam - OK\n"); break; case IUP_GETPARAM_INIT: { Ihandle* param = (Ihandle*)IupGetAttributeId(dialog, "PARAM", param_index); IupSetfAttribute(param, "MAXSTR", "%d", 30); printf("IupGetParam - Map\n"); break; } case IUP_GETPARAM_CANCEL: printf("IupGetParam - Cancel\n"); break; case IUP_GETPARAM_HELP: printf("IupGetParam - Help\n"); break; // case 1: // return 0; default: { Ihandle* param = (Ihandle*)IupGetAttributeId(dialog, "PARAM", param_index); printf("PARAM%d = %s\n", param_index, IupGetAttribute(param, "VALUE")); break; } } return 1; }
/* calcula uma linha da imagem a cada camada de idle */ int idle_cb(void) { int x; /* Faz uma linha de pixels por vez */ if (yc<height) { IupGLMakeCurrent(canvas); glBegin(GL_POINTS); for( x = 0; x < width; ++x ) { Color pixel; Vector ray; ray = camGetRay( camera, x, yc ); pixel = rayTrace( scene, eye, ray, 0 ); imageSetPixel( image, x, yc, pixel ); glColor3f((float)pixel.red,(float)pixel.green,(float)pixel.blue); glVertex2i(x,yc); } glEnd(); glFlush(); IupGLSwapBuffers(canvas); /* change the back buffer with the front buffer */ yc++; } else { IupSetFunction (IUP_IDLE_ACTION, (Icallback) NULL); /* a imagem ja' esta' completa */ finish_time = clock(); duration = (double)(finish_time - start_time)/CLOCKS_PER_SEC; IupSetfAttribute(label, "TITLE", "tempo=%.3lf s", duration); } return IUP_DEFAULT; }
/* carrega uma nova cena */ int load_cb(void) { char* filename = get_file_name(); /* chama o dialogo de abertura de arquivo */ char buffer[30]; if (filename==NULL) return 0; /* Le a cena especificada */ scene = sceLoad( filename ); if( scene == NULL ) return IUP_DEFAULT; sceGetCamera( scene, &camera ); camGetEye( camera, eye ); camGetScreenWidth( camera, &width ); camGetScreenHeight( camera, &height ); yc=0; if (image) imgDestroy(image); image = imgCreate( width, height ); IupSetfAttribute(label, "TITLE", "%3dx%3d", width, height); sprintf(buffer,"%3dx%3d", width, height); IupSetAttribute(canvas,IUP_RASTERSIZE,buffer); IupSetFunction (IUP_IDLE_ACTION, (Icallback) idle_cb); start_time = clock(); return IUP_DEFAULT; }
int app_open_cb(Ihandle* self) { imFile* ifile; /* file input */ int ret, error; unsigned char* gl_data = (unsigned char*)IupGetAttribute(self, "APP_GL_DATA"); char filename[1024] = ".\\*.*"; /* get a file name */ ret = IupGetFile(filename); if (ret == -1) return IUP_DEFAULT; ifile = imFileOpen(filename, &error); if (!ifile) { IupMessage("Error", "Error reading image file."); return IUP_DEFAULT; } { int width = 0, height = 0, file_color_mode, color_space; Ihandle* dialog = IupGetDialog(self); imFileReadImageInfo(ifile, 0, &width, &height, &file_color_mode, NULL); /* alocates the buffers */ if (gl_data) free(gl_data); gl_data = malloc(width*height*3); IupSetAttribute(dialog, "APP_GL_DATA", gl_data); IupSetfAttribute(dialog, "APP_GL_WIDTH", "%d", width); IupSetfAttribute(dialog, "APP_GL_HEIGHT", "%d", height); imFileReadImageData(ifile, gl_data, 1, IM_PACKED); color_space = imColorModeSpace(file_color_mode); if (color_space == IM_MAP || color_space == IM_GRAY || color_space == IM_BINARY) { long palette[256]; int palette_count; imFileGetPalette(ifile, palette, &palette_count); ConvertMapToGLData(gl_data, width*height, 3, palette, palette_count); } } imFileClose(ifile); return IUP_DEFAULT; }
/* Calculate the size, in pixels, of the invisible columns/lines, the left/above of the first column/line. In fact the start position of the visible area. Depends on the first visible column/line. -> m : choose will operate on lines or columns [IMAT_PROCESS_LIN|IMAT_PROCESS_COL] */ void iupMatrixAuxUpdateScrollPos(Ihandle* ih, int m) { float pos; int i, sb, scroll_pos; char* POS; ImatLinColData *p; if (m == IMAT_PROCESS_LIN) { p = &(ih->data->lines); sb = IUP_SB_VERT; POS = "POSY"; } else { p = &(ih->data->columns); sb = IUP_SB_HORIZ; POS = "POSX"; } /* "first" was changed, so update "last" and the scroll pos */ if (p->total_size <= p->visible_size) { /* the matrix is fully visible */ p->first = p->num_noscroll; p->first_offset = 0; p->last = p->num==p->num_noscroll? p->num_noscroll: p->num-1; if (ih->data->canvas.sb & sb) IupSetAttribute(ih, POS, "0"); return; } /* must check if it is a valid position */ scroll_pos = 0; for(i = p->num_noscroll; i < p->first; i++) scroll_pos += p->sizes[i]; scroll_pos += p->first_offset; if (scroll_pos + p->visible_size > p->total_size) { /* invalid condition, must recalculate so it is valid */ scroll_pos = p->total_size - p->visible_size; /* position first and first_offset, according to scroll pos */ iupMatrixAuxAdjustFirstFromScrollPos(p, scroll_pos); } pos = (float)scroll_pos/(float)p->total_size; /* update last */ iupMatrixAuxUpdateLast(p); /* update scroll pos */ if (ih->data->canvas.sb & sb) IupSetfAttribute(ih, POS, "%g", (double)pos); }
static int click(Ihandle *self, int lin, int col) { printf("click_cb(%d, %d)\n", lin, col); IupSetAttribute(self,"MARKED", NULL); /* clear all marks */ IupSetAttributeId2(self,"MARK", lin, 0, "1"); IupSetfAttribute(self,"REDRAW", "L%d", lin); return IUP_DEFAULT; }
static int time_cb(void) { float value = IupGetFloat(gauge, "VALUE"); value += increment; if (value > 1) value = 0; /* start over */ IupSetfAttribute(gauge, "VALUE", "%f", (double)value); return IUP_DEFAULT; }
static int iScrollBoxMotion_CB(Ihandle *ih, int x, int y, char* status) { if (iup_isbutton1(status) && iupAttribGet(ih, "_IUP_DRAG_SB")) { int start_x = iupAttribGetInt(ih, "_IUP_START_X"); int start_y = iupAttribGetInt(ih, "_IUP_START_Y"); int dx = x - start_x; int dy = y - start_y; int posx = iupAttribGetInt(ih, "_IUP_START_POSX"); int posy = iupAttribGetInt(ih, "_IUP_START_POSY"); IupSetfAttribute(ih, "POSX", "%d", posx-dx); /* drag direction is oposite to scrollbar */ IupSetfAttribute(ih, "POSY", "%d", posy-dy); iScrollBoxScroll_CB(ih, 0, IupGetFloat(ih, "POSX"), IupGetFloat(ih, "POSY")); } return IUP_DEFAULT; }