static void show_menu(Ihandle* ih) { int x, y; Ihandle* menu_file = IupMenu( IupSetAttributes(IupItem("Item with Image", "item_cb"), "IMAGE=image_tec"), IupSetAttributes(IupItem("Toggle using VALUE", NULL), "VALUE=ON, KEY=K_V"), IupSetAttributes(IupItem("Auto &Toggle", "item_cb"), "AUTOTOGGLE=YES, VALUE=OFF, IMAGE=image_test, IMPRESS=image_test_pressed"), IupSeparator(), IupItem("E&xit (Close)", NULL), NULL); Ihandle* menu = IupMenu( IupSetAttributes(IupSubmenu("Submenu", menu_file), "KEY=K_S, IMAGE=image_tec"), IupItem("Item", "item_cb"), IupSetAttributes(IupItem("Item", "item_cb"), "VALUE=ON"), IupSetAttributes(IupItem("Item", "item_cb"), "KEY=K_I, IMAGE=image_tec"), NULL); x = IupGetInt(ih, "X"); y = IupGetInt(ih, "Y"); y += IupGetInt2(ih, "RASTERSIZE"); IupPopup(menu, x, y); IupDestroy(menu); }
static int motion_cb(Ihandle *ih,int x,int y,char* status) { (void)status; if (move) { double dif_x, dif_y; double dx, dy, dz; double x1, y1, z1; double x2, y2, z2; double angle, norma; int height = IupGetInt2(ih, "RASTERSIZE"); double mv[16]; double pm[16]; int vp[4]; IupGLMakeCurrent(ih); glGetDoublev(GL_MODELVIEW_MATRIX, mv); glGetDoublev(GL_PROJECTION_MATRIX, pm); glGetIntegerv(GL_VIEWPORT, vp); dif_x = x - pos_x; dif_y = y - pos_y; if (dif_x == 0 && dif_y == 0) return IUP_DEFAULT; pos_x = x; pos_y = y; angle = sqrt(dif_x*dif_x + dif_y*dif_y); gluUnProject(pos_x, INVERT_Y(pos_y), 0.0, mv, pm, vp, &x1, &y1, &z1); gluUnProject((double)(dif_y + pos_x), (double)(dif_x + INVERT_Y(pos_y)), 0.0, mv, pm, vp, &x2, &y2, &z2); dx = x2-x1; dy = y2-y1; dz = z2-z1; norma = sqrt(dx*dx + dy*dy + dz*dz); dx /= norma; dy /= norma; dz /= norma; glMatrixMode(GL_MODELVIEW); glTranslated(0.5, 0.5, 0.5); glRotated (angle, dx, dy, dz); glTranslated(-0.5, -0.5, -0.5); glGetDoublev(GL_MODELVIEW_MATRIX, model_view_matrix); use_model_matrix = 1; draw_cube(); IupGLSwapBuffers(ih); } return IUP_DEFAULT; }
static int motion_cb(Ihandle *ih,int x,int y,char* status) { (void)status; if (move) { double dif_x, dif_y; double dx, dy, dz; double x1, y1, z1; double x2, y2, z2; double angle, norma; int height = IupGetInt2(ih, "RASTERSIZE"); IupGLMakeCurrent(ih); dif_x = x - pos_x; dif_y = y - pos_y; pos_x = x; pos_y = y; angle = sqrt(dif_x*dif_x + dif_y*dif_y); unproject (pos_x, INVERT_Y(pos_y), &x1, &y1, &z1); unproject ((double)(dif_y+pos_x), (double)(dif_x+INVERT_Y(pos_y)), &x2, &y2, &z2); dx = x2-x1; dy = y2-y1; dz = z2-z1; norma = sqrt(dx*dx + dy*dy + dz*dz); dx /= norma; dy /= norma; dz /= norma; glTranslated(0.5, 0.5, 0.5); glRotated (angle, dx, dy, dz); glTranslated(-0.5, -0.5, -0.5); draw_cube(); glFlush(); IupGLSwapBuffers(ih); } return IUP_DEFAULT; }
int iupDataEntry(int maxlin, int* maxcol, int* maxscr, char* title, char** text, char** data) { int i, bt; Ihandle *ok, *cancel, *dlg, *vb, *hb, **txt, **lbl, *button_box, *dlg_box; txt = (Ihandle **)calloc(maxlin, sizeof(Ihandle*)); if (txt == NULL) return -2; lbl = (Ihandle **)calloc(maxlin+1, sizeof(Ihandle*)); vb = IupVbox(NULL); for (i=0; i<maxlin; i++) { txt[i] = IupText(NULL); IupSetAttribute(txt[i],"VALUE",data[i]); IupSetfAttribute(txt[i],"VISIBLECOLUMNS","%dx", maxscr[i]); IupSetfAttribute(txt[i],"NC", "%d", maxcol[i]); IupSetAttribute(txt[i],"EXPAND","HORIZONTAL"); hb = IupHbox(lbl[i] = IupLabel(text[i]), txt[i], NULL); IupSetAttribute(hb,"MARGIN","0x0"); IupSetAttribute(hb,"ALIGNMENT","ACENTER"); IupAppend(vb, hb); } lbl[i] = NULL; IupInsert(vb, NULL, IupNormalizerv(lbl)); ok = IupButton("OK", NULL); IupSetAttribute(ok, "PADDING", "20x0"); IupSetCallback(ok, "ACTION", (Icallback)CB_button_OK); cancel = IupButton(iupStrMessageGet("IUP_CANCEL"), NULL); IupSetAttribute(cancel, "PADDING", "20x0"); IupSetCallback(cancel, "ACTION", (Icallback)CB_button_CANCEL); button_box = IupHbox( IupFill(), ok, cancel, NULL); IupSetAttribute(button_box,"MARGIN","0x0"); IupSetAttribute(button_box, "NORMALIZESIZE", "HORIZONTAL"); dlg_box = IupVbox( IupFrame(vb), button_box, NULL); IupSetAttribute(dlg_box,"MARGIN","10x10"); IupSetAttribute(dlg_box,"GAP","5"); dlg = IupDialog(dlg_box); IupSetAttribute(dlg,"TITLE",title); IupSetAttribute(dlg,"MINBOX","NO"); IupSetAttribute(dlg,"MAXBOX","NO"); IupSetAttributeHandle(dlg,"DEFAULTENTER", ok); IupSetAttributeHandle(dlg,"DEFAULTESC", cancel); IupSetAttribute(dlg,"PARENTDIALOG",IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg,"ICON", IupGetGlobal("ICON")); IupMap(dlg); IupSetfAttribute(dlg,"MAXSIZE", "65535x%d", IupGetInt2(dlg, "RASTERSIZE")); IupSetAttribute(dlg,"MINSIZE", IupGetAttribute(dlg, "RASTERSIZE")); IupPopup(dlg,IUP_CENTER,IUP_CENTER); for (i=0; i<maxlin; i++) { data[i] = (char *)iupStrDup(IupGetAttribute(txt[i], "VALUE")); } free(txt); bt = IupGetInt(dlg, "STATUS"); IupDestroy(dlg); return bt; }
static int winDialogSetFullScreenAttrib(Ihandle* ih, const char* value) { if (iupStrBoolean(value)) { if (!iupAttribGet(ih, "_IUPWIN_FS_STYLE")) { int width, height; LONG off_style, new_style; BOOL visible = ShowWindow (ih->handle, SW_HIDE); /* remove the decorations */ off_style = WS_BORDER | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU; new_style = GetWindowLong(ih->handle, GWL_STYLE); iupAttribSetStr(ih, "_IUPWIN_FS_STYLE", (char*)new_style); new_style &= (~off_style); SetWindowLong(ih->handle, GWL_STYLE, new_style); /* save the previous decoration attributes */ iupAttribStoreStr(ih, "_IUPWIN_FS_MAXBOX", iupAttribGet(ih, "MAXBOX")); iupAttribStoreStr(ih, "_IUPWIN_FS_MINBOX", iupAttribGet(ih, "MINBOX")); iupAttribStoreStr(ih, "_IUPWIN_FS_MENUBOX",iupAttribGet(ih, "MENUBOX")); iupAttribStoreStr(ih, "_IUPWIN_FS_RESIZE", iupAttribGet(ih, "RESIZE")); iupAttribStoreStr(ih, "_IUPWIN_FS_BORDER", iupAttribGet(ih, "BORDER")); iupAttribStoreStr(ih, "_IUPWIN_FS_TITLE", IupGetAttribute(ih, "TITLE")); /* must use IupGetAttribute to check from the native implementation */ /* save the previous position and size */ iupAttribStoreStr(ih, "_IUPWIN_FS_X", IupGetAttribute(ih, "X")); /* must use IupGetAttribute to check from the native implementation */ iupAttribStoreStr(ih, "_IUPWIN_FS_Y", IupGetAttribute(ih, "Y")); iupAttribStoreStr(ih, "_IUPWIN_FS_SIZE", IupGetAttribute(ih, "RASTERSIZE")); /* remove the decorations attributes */ iupAttribSetStr(ih, "MAXBOX", "NO"); iupAttribSetStr(ih, "MINBOX", "NO"); iupAttribSetStr(ih, "MENUBOX", "NO"); IupSetAttribute(ih, "TITLE", NULL); iupAttribSetStr(ih, "RESIZE", "NO"); iupAttribSetStr(ih, "BORDER", "NO"); /* full screen size */ iupdrvGetFullSize(&width, &height); SetWindowPos(ih->handle, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); /* layout will be updated in WM_SIZE */ if (visible) ShowWindow(ih->handle, SW_SHOW); } } else { LONG style = (LONG)iupAttribGet(ih, "_IUPWIN_FS_STYLE"); if (style) { BOOL visible = ShowWindow(ih->handle, SW_HIDE); /* restore the decorations attributes */ iupAttribStoreStr(ih, "MAXBOX", iupAttribGet(ih, "_IUPWIN_FS_MAXBOX")); iupAttribStoreStr(ih, "MINBOX", iupAttribGet(ih, "_IUPWIN_FS_MINBOX")); iupAttribStoreStr(ih, "MENUBOX",iupAttribGet(ih, "_IUPWIN_FS_MENUBOX")); IupSetAttribute(ih, "TITLE", iupAttribGet(ih, "_IUPWIN_FS_TITLE")); /* TITLE is not stored in the HashTable */ iupAttribStoreStr(ih, "RESIZE", iupAttribGet(ih, "_IUPWIN_FS_RESIZE")); iupAttribStoreStr(ih, "BORDER", iupAttribGet(ih, "_IUPWIN_FS_BORDER")); /* restore the decorations */ SetWindowLong(ih->handle, GWL_STYLE, style); /* restore position and size */ SetWindowPos(ih->handle, HWND_TOP, iupAttribGetInt(ih, "_IUPWIN_FS_X"), iupAttribGetInt(ih, "_IUPWIN_FS_Y"), IupGetInt(ih, "_IUPWIN_FS_SIZE"), IupGetInt2(ih, "_IUPWIN_FS_SIZE"), 0); /* layout will be updated in WM_SIZE */ if (visible) ShowWindow(ih->handle, SW_SHOW); /* remove auxiliar attributes */ iupAttribSetStr(ih, "_IUPWIN_FS_MAXBOX", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_MINBOX", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_MENUBOX",NULL); iupAttribSetStr(ih, "_IUPWIN_FS_TITLE", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_RESIZE", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_BORDER", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_X", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_Y", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_SIZE", NULL); iupAttribSetStr(ih, "_IUPWIN_FS_STYLE", NULL); } } return 1; }
static int motDialogSetFullScreenAttrib(Ihandle* ih, const char* value) { if (iupStrBoolean(value)) { if (!iupAttribGet(ih, "_IUPMOT_FS_STYLE")) { int visible = iupdrvDialogIsVisible(ih); if (visible) iupAttribSetStr(ih, "_IUPMOT_FS_STYLE", "VISIBLE"); else iupAttribSetStr(ih, "_IUPMOT_FS_STYLE", "HIDDEN"); /* save the previous decoration attributes */ /* during fullscreen these attributes can be consulted by the application */ iupAttribStoreStr(ih, "_IUPMOT_FS_MAXBOX", iupAttribGet(ih, "MAXBOX")); iupAttribStoreStr(ih, "_IUPMOT_FS_MINBOX", iupAttribGet(ih, "MINBOX")); iupAttribStoreStr(ih, "_IUPMOT_FS_MENUBOX",iupAttribGet(ih, "MENUBOX")); iupAttribStoreStr(ih, "_IUPMOT_FS_RESIZE", iupAttribGet(ih, "RESIZE")); iupAttribStoreStr(ih, "_IUPMOT_FS_BORDER", iupAttribGet(ih, "BORDER")); iupAttribStoreStr(ih, "_IUPMOT_FS_TITLE", IupGetAttribute(ih, "TITLE")); /* must use IupGetAttribute to check from the native implementation */ /* remove the decorations attributes */ iupAttribSetStr(ih, "MAXBOX", "NO"); iupAttribSetStr(ih, "MINBOX", "NO"); iupAttribSetStr(ih, "MENUBOX", "NO"); IupSetAttribute(ih, "TITLE", NULL); iupAttribSetStr(ih, "TITLE", NULL); /* remove from the hash table if we are during IupMap */ iupAttribSetStr(ih, "RESIZE", "NO"); iupAttribSetStr(ih, "BORDER", "NO"); /* use WM fullscreen support */ if (!motDialogSetFullScreen(ih, 1)) { /* or configure fullscreen manually */ int decor; int width, height; /* hide before changing decorations */ if (visible) { iupAttribSetStr(ih, "_IUPMOT_SHOW_STATE", NULL); /* To avoid a SHOW_CB notification */ XtUnmapWidget(ih->handle); } /* save the previous position and size */ iupAttribStoreStr(ih, "_IUPMOT_FS_X", IupGetAttribute(ih, "X")); /* must use IupGetAttribute to check from the native implementation */ iupAttribStoreStr(ih, "_IUPMOT_FS_Y", IupGetAttribute(ih, "Y")); iupAttribStoreStr(ih, "_IUPMOT_FS_SIZE", IupGetAttribute(ih, "RASTERSIZE")); /* save the previous decoration */ XtVaGetValues(ih->handle, XmNmwmDecorations, &decor, NULL); iupAttribSetStr(ih, "_IUPMOT_FS_DECOR", (char*)decor); /* remove the decorations */ XtVaSetValues(ih->handle, XmNmwmDecorations, (XtArgVal)0, NULL); motDialogSetWindowManagerStyle(ih); /* get full screen size */ iupdrvGetFullSize(&width, &height); /* set position and size */ XtVaSetValues(ih->handle, XmNwidth, (XtArgVal)width, XmNheight, (XtArgVal)height, XmNx, (XtArgVal)0, XmNy, (XtArgVal)0, NULL); /* layout will be updated in motDialogConfigureNotify */ if (visible) XtMapWidget(ih->handle); } } } else { char* fs_style = iupAttribGet(ih, "_IUPMOT_FS_STYLE"); if (fs_style) { /* can only switch back from full screen if window was visible */ /* when fullscreen was set */ if (iupStrEqualNoCase(fs_style, "VISIBLE")) { iupAttribSetStr(ih, "_IUPMOT_FS_STYLE", NULL); /* restore the decorations attributes */ iupAttribStoreStr(ih, "MAXBOX", iupAttribGet(ih, "_IUPMOT_FS_MAXBOX")); iupAttribStoreStr(ih, "MINBOX", iupAttribGet(ih, "_IUPMOT_FS_MINBOX")); iupAttribStoreStr(ih, "MENUBOX",iupAttribGet(ih, "_IUPMOT_FS_MENUBOX")); IupSetAttribute(ih, "TITLE", iupAttribGet(ih, "_IUPMOT_FS_TITLE")); /* TITLE is not stored in the HashTable */ iupAttribStoreStr(ih, "RESIZE", iupAttribGet(ih, "_IUPMOT_FS_RESIZE")); iupAttribStoreStr(ih, "BORDER", iupAttribGet(ih, "_IUPMOT_FS_BORDER")); if (!motDialogSetFullScreen(ih, 0)) { int border, caption, menu, x, y; int visible = iupdrvDialogIsVisible(ih); if (visible) XtUnmapWidget(ih->handle); /* restore the decorations */ XtVaSetValues(ih->handle, XmNmwmDecorations, (XtArgVal)(int)iupAttribGet(ih, "_IUPMOT_FS_DECOR"), NULL); motDialogSetWindowManagerStyle(ih); /* the dialog decoration will not be considered yet in the next XtVaSetValues */ /* so compensate the decoration when restoring the position and size */ iupdrvDialogGetDecoration(ih, &border, &caption, &menu); x = iupAttribGetInt(ih, "_IUPMOT_FS_X") - (border); y = iupAttribGetInt(ih, "_IUPMOT_FS_Y") - (border+caption+menu); /* restore position and size */ XtVaSetValues(ih->handle, XmNx, (XtArgVal)x, XmNy, (XtArgVal)y, XmNwidth, (XtArgVal)(IupGetInt(ih, "_IUPMOT_FS_SIZE") - (2*border)), XmNheight, (XtArgVal)(IupGetInt2(ih, "_IUPMOT_FS_SIZE") - (2*border+caption)), NULL); /* layout will be updated in motDialogConfigureNotify */ if (visible) XtMapWidget(ih->handle); /* remove auxiliar attributes */ iupAttribSetStr(ih, "_IUPMOT_FS_X", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_Y", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_SIZE", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_DECOR", NULL); } /* remove auxiliar attributes */ iupAttribSetStr(ih, "_IUPMOT_FS_MAXBOX", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_MINBOX", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_MENUBOX",NULL); iupAttribSetStr(ih, "_IUPMOT_FS_RESIZE", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_BORDER", NULL); iupAttribSetStr(ih, "_IUPMOT_FS_TITLE", NULL); } } } return 1; }