void* iupdrvImageCreateImageRaw(int width, int height, int bpp, iupColor* colors, int colors_count, unsigned char *imgdata) { int y, x; Pixmap pixmap; GC gc; pixmap = XCreatePixmap(iupmot_display, RootWindow(iupmot_display,iupmot_screen), width, height, iupdrvGetScreenDepth()); if (!pixmap) return NULL; gc = XCreateGC(iupmot_display,pixmap,0,NULL); /* Pixmap is top-bottom */ /* imgdata is bottom up */ if (bpp == 8) { Pixel color2pixel[256]; int i; for (i=0;i<colors_count;i++) color2pixel[i] = iupmotColorGetPixel(colors[i].r, colors[i].g, colors[i].b); for (y=0;y<height;y++) { int lineoffset = (height-1 - y)*width; /* imgdata is bottom up */ for(x=0;x<width;x++) { unsigned long p = color2pixel[imgdata[lineoffset+x]]; XSetForeground(iupmot_display,gc,p); XDrawPoint(iupmot_display,pixmap,gc,x,y); } } } else { /* planes are separated in imgdata */ int planesize = width*height; unsigned char *r = imgdata, *g = imgdata+planesize, *b = imgdata+2*planesize; for (y=0;y<height;y++) { int lineoffset = (height-1 - y)*width; /* imgdata is bottom up */ for(x=0;x<width;x++) { unsigned long p = iupmotColorGetPixel(r[lineoffset+x], g[lineoffset+x], b[lineoffset+x]); XSetForeground(iupmot_display,gc,p); XDrawPoint(iupmot_display,pixmap,gc,x,y); } } } XFreeGC(iupmot_display,gc); return (void*)pixmap; }
void iupDrawSelectRect(IdrawCanvas* dc, int x, int y, int w, int h) { XSetFunction(iupmot_display, dc->pixmap_gc, GXxor); XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(255, 255, 255)); XFillRectangle(iupmot_display, dc->pixmap, dc->pixmap_gc, x, y, w, h); XSetFunction(iupmot_display, dc->pixmap_gc, GXcopy); }
void iupDrawPolygon(IdrawCanvas* dc, int* points, int count, unsigned char r, unsigned char g, unsigned char b, int style) { int i; XPoint* pnt = (XPoint*)malloc(count*sizeof(XPoint)); /* XPoint uses short for coordinates */ for (i = 0; i < count; i++) { pnt[i].x = (short)points[2*i]; pnt[i].y = (short)points[2*i+1]; } XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(r, g, b)); if (style==IUP_DRAW_FILL) XFillPolygon(iupmot_display, dc->pixmap, dc->pixmap_gc, pnt, count, Complex, CoordModeOrigin); else { XGCValues gcval; if (style==IUP_DRAW_STROKE_DASH) gcval.line_style = LineOnOffDash; else gcval.line_style = LineSolid; XChangeGC(iupmot_display, dc->pixmap_gc, GCLineStyle, &gcval); XDrawLines(iupmot_display, dc->pixmap, dc->pixmap_gc, pnt, count, CoordModeOrigin); } free(pnt); }
static int motToggleSetBgColorAttrib(Ihandle* ih, const char* value) { if (ih->data->type == IUP_TOGGLE_TEXT) { char* parent_value = iupAttribGetInheritNativeParent(ih, "BGCOLOR"); if (!parent_value) { /* if not defined at a native parent, then change the toggle button color to the given color instead using the default */ if (iupdrvBaseSetBgColorAttrib(ih, value)) /* let XmChangeColor do its job */ { parent_value = IupGetGlobal("DLGBGCOLOR"); XtVaSetValues(ih->handle, XmNbackground, iupmotColorGetPixelStr(parent_value), NULL); /* reset just the background */ if (ih->data->is_radio) XtVaSetValues(ih->handle, XmNselectColor, iupmotColorGetPixel(0, 0, 0), NULL); XtVaSetValues(ih->handle, XmNunselectColor, iupmotColorGetPixelStr(value), NULL); return 1; } } else { /* ignore given value, must use only from parent */ if (iupdrvBaseSetBgColorAttrib(ih, parent_value)) { if (ih->data->is_radio) XtVaSetValues(ih->handle, XmNselectColor, iupmotColorGetPixel(0, 0, 0), NULL); XtVaSetValues(ih->handle, XmNunselectColor, iupmotColorGetPixelStr(parent_value), NULL); return 1; } } return 0; } else { if (ih->data->flat) { /* ignore given value, must use only from parent */ value = iupBaseNativeParentGetBgColor(ih); if (iupdrvBaseSetBgColorAttrib(ih, value)) return 1; } return iupdrvBaseSetBgColorAttrib(ih, value); } }
void iupDrawLine(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { XGCValues gcval; if (style==IUP_DRAW_STROKE_DASH) gcval.line_style = LineOnOffDash; else gcval.line_style = LineSolid; XChangeGC(iupmot_display, dc->pixmap_gc, GCLineStyle, &gcval); XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(r, g, b)); XDrawLine(iupmot_display, dc->pixmap, dc->pixmap_gc, x1, y1, x2, y2); }
static void motDragStart(Widget dragSource, XButtonEvent* evt, String* params, Cardinal* num_params) { Widget dragContext; Arg args[20]; int num_args = 0; Atom *dragTypesList; Cardinal dragTypesListCount; Ihandle* ih = NULL; XtVaGetValues(dragSource, XmNuserData, &ih, NULL); dragTypesList = (Atom*)iupAttribGet(ih, "_IUPMOT_DRAG_TARGETLIST"); dragTypesListCount = (Cardinal)iupAttribGetInt(ih, "_IUPMOT_DRAG_TARGETLIST_COUNT"); if (!dragTypesList) return; /* specify resources for DragContext for the transfer */ num_args = 0; iupMOT_SETARG(args, num_args, XmNexportTargets, dragTypesList); iupMOT_SETARG(args, num_args, XmNnumExportTargets, dragTypesListCount); iupMOT_SETARG(args, num_args, XmNdragOperations, iupAttribGetBoolean(ih, "DRAGSOURCEMOVE")? XmDROP_MOVE|XmDROP_COPY: XmDROP_COPY); iupMOT_SETARG(args, num_args, XmNconvertProc, motDragConvertProc); iupMOT_SETARG(args, num_args, XmNinvalidCursorForeground, iupmotColorGetPixel(255, 0, 0)); iupMOT_SETARG(args, num_args, XmNclientData, ih); /* creates a XmDragContext */ dragContext = XmDragStart(dragSource, (XEvent*)evt, args, num_args); if(dragContext) { IFnii cbDragBegin; XtAddCallback(dragContext, XmNdropFinishCallback, (XtCallbackProc)motDropFinishCallback, (XtPointer)ih); cbDragBegin = (IFnii)IupGetCallback(ih, "DRAGBEGIN_CB"); if(cbDragBegin) { if (cbDragBegin(ih, evt->x, evt->y) == IUP_IGNORE) XmDragCancel(dragContext); } } (void)params; (void)num_params; }
static int motValSetBgColorAttrib(Ihandle* ih, const char* value) { Pixel color; unsigned char r, g, b; if (!iupStrToRGB(value, &r, &g, &b)) return 0; r = (r*8)/10; g = (g*8)/10; b = (b*8)/10; color = iupmotColorGetPixel(r, g, b); if (color != (Pixel)-1) { Widget w = XtNameToWidget(ih->handle, "*Scrollbar"); XtVaSetValues(w, XmNtroughColor, color, NULL); } return iupdrvBaseSetBgColorAttrib(ih, value); }
void iupDrawArc(IdrawCanvas* dc, int x1, int y1, int x2, int y2, double a1, double a2, unsigned char r, unsigned char g, unsigned char b, int style) { XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(r, g, b)); if (style==IUP_DRAW_FILL) { XSetArcMode(iupmot_display, dc->pixmap_gc, ArcPieSlice); XFillArc(iupmot_display, dc->pixmap, dc->pixmap_gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1, iupRound(a1 * 64), iupRound((a2 - a1) * 64)); } else { XGCValues gcval; if (style==IUP_DRAW_STROKE_DASH) gcval.line_style = LineOnOffDash; else gcval.line_style = LineSolid; XChangeGC(iupmot_display, dc->pixmap_gc, GCLineStyle, &gcval); XDrawArc(iupmot_display, dc->pixmap, dc->pixmap_gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1, iupRound(a1 * 64), iupRound((a2 - a1) * 64)); } }
void iupDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, unsigned char r, unsigned char g, unsigned char b, const char* font) { int num_line; XFontStruct* xfont = (XFontStruct*)iupmotGetFontStruct(font); XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(r, g, b)); XSetFont(iupmot_display, dc->pixmap_gc, xfont->fid); num_line = iupStrLineCount(text); if (num_line == 1) XDrawString(iupmot_display, dc->pixmap, dc->pixmap_gc, x, y+xfont->ascent, text, len); else { int i, line_height, len; const char *p, *q; line_height = xfont->ascent + xfont->descent; p = text; for (i = 0; i < num_line; i++) { q = strchr(p, '\n'); if (q) len = (int)(q - p); /* Cut the string to contain only one line */ else len = (int)strlen(p); /* use the remaining characters */ /* Draw the line */ XDrawString(iupmot_display, dc->pixmap, dc->pixmap_gc, x, y + xfont->ascent, p, len); /* Advance the string */ if (q) p = q + 1; /* Advance a line */ y += line_height; } } }
void* iupdrvImageCreateImage(Ihandle *ih, const char* bgcolor, int make_inactive) { int y, x, bpp, bgcolor_depend = 0, width = ih->currentwidth, height = ih->currentheight; unsigned char *imgdata = (unsigned char*)iupAttribGetStr(ih, "WID"); Pixmap pixmap; unsigned char bg_r=0, bg_g=0, bg_b=0; GC gc; Pixel color2pixel[256]; bpp = iupAttribGetInt(ih, "BPP"); iupStrToRGB(bgcolor, &bg_r, &bg_g, &bg_b); if (bpp == 8) { int i, colors_count = 0; iupColor colors[256]; iupImageInitColorTable(ih, colors, &colors_count); for (i=0;i<colors_count;i++) { if (colors[i].a == 0) { colors[i].r = bg_r; colors[i].g = bg_g; colors[i].b = bg_b; colors[i].a = 255; bgcolor_depend = 1; } if (make_inactive) iupImageColorMakeInactive(&(colors[i].r), &(colors[i].g), &(colors[i].b), bg_r, bg_g, bg_b); color2pixel[i] = iupmotColorGetPixel(colors[i].r, colors[i].g, colors[i].b); } } pixmap = XCreatePixmap(iupmot_display, RootWindow(iupmot_display,iupmot_screen), width, height, iupdrvGetScreenDepth()); if (!pixmap) return NULL; gc = XCreateGC(iupmot_display,pixmap,0,NULL); for (y=0;y<height;y++) { for(x=0;x<width;x++) { unsigned long p; if (bpp == 8) p = color2pixel[imgdata[y*width+x]]; else { int channels = (bpp==24)? 3: 4; unsigned char *pixel_data = imgdata + y*width*channels + x*channels; unsigned char r = *(pixel_data), g = *(pixel_data+1), b = *(pixel_data+2); if (bpp == 32) { unsigned char a = *(pixel_data+3); if (a != 255) { /* flat alpha */ r = iupALPHABLEND(r, bg_r, a); g = iupALPHABLEND(g, bg_g, a); b = iupALPHABLEND(b, bg_b, a); bgcolor_depend = 1; } } if (make_inactive) iupImageColorMakeInactive(&r, &g, &b, bg_r, bg_g, bg_b); p = iupmotColorGetPixel(r, g, b); } XSetForeground(iupmot_display,gc,p); XDrawPoint(iupmot_display,pixmap,gc,x,y); } } XFreeGC(iupmot_display,gc); if (bgcolor_depend || make_inactive) iupAttribSet(ih, "_IUP_BGCOLOR_DEPEND", "1"); return (void*)pixmap; }
static int motToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char* value; int num_args = 0; Arg args[40]; if (radio) ih->data->radio = 1; value = iupAttribGet(ih, "IMAGE"); if (value) { ih->data->type = IUP_TOGGLE_IMAGE; iupmotSetArg(args[num_args++], XmNlabelType, XmPIXMAP); } else { ih->data->type = IUP_TOGGLE_TEXT; iupmotSetArg(args[num_args++], XmNlabelType, XmSTRING); } /* Core */ iupmotSetArg(args[num_args++], XmNmappedWhenManaged, False); /* not visible when managed */ iupmotSetArg(args[num_args++], XmNx, 0); /* x-position */ iupmotSetArg(args[num_args++], XmNy, 0); /* y-position */ iupmotSetArg(args[num_args++], XmNwidth, 10); /* default width to avoid 0 */ iupmotSetArg(args[num_args++], XmNheight, 10); /* default height to avoid 0 */ /* Primitive */ if (iupStrBoolean(iupAttribGetStr(ih, "CANFOCUS"))) iupmotSetArg(args[num_args++], XmNtraversalOn, True); else iupmotSetArg(args[num_args++], XmNtraversalOn, False); iupmotSetArg(args[num_args++], XmNhighlightThickness, 2); iupmotSetArg(args[num_args++], XmNnavigationType, XmTAB_GROUP); /* Label */ iupmotSetArg(args[num_args++], XmNrecomputeSize, False); /* no automatic resize from text */ iupmotSetArg(args[num_args++], XmNmarginHeight, 0); /* default padding */ iupmotSetArg(args[num_args++], XmNmarginWidth, 0); iupmotSetArg(args[num_args++], XmNmarginTop, 0); /* no extra margins */ iupmotSetArg(args[num_args++], XmNmarginLeft, 0); iupmotSetArg(args[num_args++], XmNmarginBottom, 0); iupmotSetArg(args[num_args++], XmNmarginRight, 0); if (radio) { iupmotSetArg(args[num_args++], XmNtoggleMode, XmTOGGLE_BOOLEAN); iupmotSetArg(args[num_args++], XmNindicatorType, XmONE_OF_MANY_ROUND); if (!iupAttribGet(radio, "_IUPMOT_LASTTOGGLE")) { /* this is the first toggle in the radio, and the last toggle with VALUE=ON */ iupAttribSetStr(ih, "VALUE","ON"); } } else { if (ih->data->type == IUP_TOGGLE_TEXT && iupAttribGetInt(ih, "3STATE")) iupmotSetArg(args[num_args++], XmNtoggleMode, XmTOGGLE_INDETERMINATE); else iupmotSetArg(args[num_args++], XmNtoggleMode, XmTOGGLE_BOOLEAN); iupmotSetArg(args[num_args++], XmNindicatorType, XmN_OF_MANY); } if (ih->data->type == IUP_TOGGLE_IMAGE) { iupmotSetArg(args[num_args++], XmNindicatorOn, XmINDICATOR_NONE); iupmotSetArg(args[num_args++], XmNalignment, XmALIGNMENT_CENTER); iupmotSetArg(args[num_args++], XmNshadowThickness, 2); } else { iupmotSetArg(args[num_args++], XmNspacing, 3); iupmotSetArg(args[num_args++], XmNindicatorOn, XmINDICATOR_CHECK_BOX); iupmotSetArg(args[num_args++], XmNalignment, XmALIGNMENT_BEGINNING); if (radio) { iupmotSetArg(args[num_args++], XmNindicatorSize, 13); iupmotSetArg(args[num_args++], XmNselectColor, iupmotColorGetPixel(0, 0, 0)); } else iupmotSetArg(args[num_args++], XmNindicatorSize, 15); iupmotSetArg(args[num_args++], XmNshadowThickness, 0); iupmotSetArg(args[num_args++], XmNdetailShadowThickness, 2); } ih->handle = XtCreateManagedWidget( iupDialogGetChildIdStr(ih), /* child identifier */ xmToggleButtonWidgetClass, /* widget class */ iupChildTreeGetNativeParentHandle(ih), /* widget parent */ args, num_args); if (!ih->handle) return IUP_ERROR; ih->serial = iupDialogGetChildId(ih); /* must be after using the string */ XtAddCallback(ih->handle, XmNhelpCallback, (XtCallbackProc)iupmotHelpCallback, (XtPointer)ih); XtAddEventHandler(ih->handle, EnterWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, LeaveWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, FocusChangeMask, False, (XtEventHandler)iupmotFocusChangeEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, KeyPressMask, False, (XtEventHandler)iupmotKeyPressEvent, (XtPointer)ih); XtAddCallback(ih->handle, XmNvalueChangedCallback, (XtCallbackProc)motToggleValueChangedCallback, (XtPointer)ih); /* Disable Drag Source */ iupmotDisableDragSource(ih->handle); /* initialize the widget */ XtRealizeWidget(ih->handle); if (ih->data->type == IUP_TOGGLE_TEXT) iupmotSetString(ih->handle, XmNlabelString, ""); return IUP_NOERROR; }