/* Ver.0.25 */ /* 2012/11/16 */ /* Programed by NONO-Lab */ /* xwmy.c */ #include #include /* unit - pixel */ #define XW_Left 160 /* Window Left */ #define XW_Top 160 /* Window Top */ #define XW_Width 640 /* Window Width */ #define XW_Height 480 /* Window Height */ #define XW_FW 5 /* Window Frame-Width */ #define XW_WCOL "black" /* Window Color */ #define XW_FCOL "royal blue" /* WIndows Frame Color */ #define XW_Color_Black "black" #define XW_Color_Blue "blue" #define XW_Color_Red "red" #define XW_Color_Magenta "magenta" #define XW_Color_Green "green" #define XW_Color_Aqua "aqua" #define XW_Color_Yellow "yellow" #define XW_Color_White "white" #define XW_Color_Cyan "cyan" /* aka Aqua */ #define XW_Color_Gray "gray" #define XW_Color_Orange "orange" /* Global Var. */ double DB_WX1,DB_WY1,DB_WX2,DB_WY2,DB_WXL,DB_WYL; int XW_VX1,XW_VY1,XW_VX2,XW_VY2,XW_VXL,XW_VYL; Display* XW_Disp; Window XW_Window; GC XW_GC; Colormap XW_CM; XSetWindowAttributes XW_ATR; XEvent XW_EV; void XW_Swap_Int(int *a, int *b) { int t; t=*a; *a=*b; *b=t; } unsigned long XW_GetColor(char* cname) { XColor n_col, t_col; XAllocNamedColor(XW_Disp, XW_CM, cname, &n_col, &t_col); return(n_col.pixel); } void XW_View(int x1,int y1,int x2,int y2) { XW_VX1=x1; XW_VY1=y1; XW_VX2=x2; XW_VY2=y2; XW_VXL=x2-x1; XW_VYL=y2-y1; } void XW_Open(void) { XW_Disp = XOpenDisplay(NULL); XW_CM = DefaultColormap(XW_Disp, 0); XW_Window = XCreateSimpleWindow (XW_Disp, DefaultRootWindow(XW_Disp), XW_Left, XW_Top, XW_Width, XW_Height, XW_FW, XW_GetColor(XW_FCOL), XW_GetColor(XW_WCOL)); XW_ATR.backing_store = WhenMapped; XChangeWindowAttributes(XW_Disp, XW_Window, CWBackingStore, &XW_ATR); XSelectInput(XW_Disp, XW_Window, ExposureMask); XMapWindow(XW_Disp, XW_Window); /* Display XW */ do{ XNextEvent(XW_Disp, &XW_EV); } while(XW_EV.type != Expose); XW_GC = XCreateGC(XW_Disp, XW_Window, 0, 0); XMoveWindow(XW_Disp, XW_Window, XW_Left, XW_Top); XW_View(0,0,XW_Width-1,XW_Height-1); XFlush(XW_Disp); } void XW_Close(void) { XDestroyWindow(XW_Disp, XW_Window); XCloseDisplay(XW_Disp); } void XW_Refresh(void) { XFlush(XW_Disp); } void XW_DrawLine(int x1, int y1, int x2, int y2) { XDrawLine(XW_Disp, XW_Window,XW_GC, x1, y1, x2, y2); } void XW_DrawRect(int x1, int y1, int x2, int y2) { int x,y,w,h; if (x1>x2) { XW_Swap_Int(&x1, &x2); } if (y1>y2) { XW_Swap_Int(&y1, &y2); } x=x1; y=y1; w=x2-x1; h=y2-y1; XDrawRectangle(XW_Disp, XW_Window,XW_GC, x, y, w, h); } void XW_SetColor(char* cname) { XSetForeground(XW_Disp,XW_GC, XW_GetColor(cname)); } /* ------------------------------------- */ void DB_Window(double x1,double y1,double x2,double y2) { DB_WX1=x1; DB_WY1=y1; DB_WX2=x2; DB_WY2=y2; DB_WXL=x2-x1; DB_WYL=y2-y1; } void DB_NewView() { int nvxl,nvyl; double gac,tac; gac=1.0 * XW_VXL/XW_VYL; tac=DB_WXL/DB_WYL; nvxl = XW_VXL; nvyl = XW_VYL; if (tac > gac) { nvyl = (int)(XW_VYL * gac / tac); } if (tac < gac) { nvxl = (int)(XW_VXL * tac / gac); } /* NEW VIEW & WINDOW */ XW_View(XW_VX1, XW_VY1, XW_VX1 + nvxl, XW_VY1 + nvyl); DB_Window(DB_WX1, DB_WY1, DB_WX2, DB_WY2); } void DB_WindowNV(double x1,double y1,double x2,double y2) { DB_Window(x1, y1, x2, y2); DB_NewView(); } int DB_XPos(double x) { return (int)(0.5 + XW_VX1 + (x - DB_WX1) /(DB_WX2-DB_WX1) * (XW_VX2-XW_VX1)); } int DB_YPos(double y) { return (int)(0.5 + XW_VY2 - (y - DB_WY1) /(DB_WY2-DB_WY1) * (XW_VY2-XW_VY1)); } void DB_DrawLine(double x1,double y1,double x2,double y2) { XW_DrawLine(DB_XPos(x1),DB_YPos(y1),DB_XPos(x2),DB_YPos(y2)); } void DB_DrawRect(double x1,double y1,double x2,double y2) { XW_DrawRect(DB_XPos(x1),DB_YPos(y1),DB_XPos(x2),DB_YPos(y2)); }