[BACK]Return to plotp.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / plot

Annotation of OpenXM_contrib2/asir2000/plot/plotp.c, Revision 1.14

1.3       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.4       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.14    ! saito      48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.13 2005/12/21 23:18:16 noro Exp $
1.3       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "ox.h"
                     53: #include "ifplot.h"
1.2       noro       54: #include <math.h>
1.1       noro       55:
                     56: #if defined(sun) && !defined(__svr4__)
                     57: #define EXP10(a) exp10(a)
                     58: #else
                     59: #define EXP10(a) pow(10.0,a)
                     60: #endif
                     61:
1.5       noro       62: #if defined(VISUAL)
                     63: static POINT oldpos;
                     64: #endif
                     65:
1.14    ! saito      66: unsigned long GetColor(Display *, char *);
        !            67:
        !            68: unsigned long GetColor(Display *dis, char *color_name)
        !            69: {
        !            70:        Colormap cmap;
        !            71:        XColor near_color, true_color;
        !            72:
        !            73:        cmap = DefaultColormap( dis, 0 );
        !            74:        XAllocNamedColor( dis, cmap, color_name, &near_color, &true_color );
        !            75:        return( near_color.pixel );
        !            76: }
        !            77:
        !            78: void area_print(DISPLAY *display, int **mask, struct canvas *can, int GXcode)
        !            79: {
        !            80:        int ix, iy;
        !            81:        XImage *image;
        !            82:        unsigned long color, black, white;
        !            83:        int wc;
        !            84:
        !            85:        flush();
        !            86:        black = GetColor(display, "black");
        !            87:        white = GetColor(display, "white");
        !            88:        image = XGetImage(display, can->pix, 0, 0, can->width, can->height,
        !            89:                -1, ZPixmap);
        !            90:        for(iy = 0; iy < can->height; iy++){
        !            91:                for(ix = 0; ix < can->width; ix++){
        !            92:                        color = XGetPixel(image, ix, iy);
        !            93:                        if (color == white) wc = -1;
        !            94:                        else if (color == black) wc = 0;
        !            95:                        else wc = 1;
        !            96:                        if ( wc != 0 ) {//XPutPixel(image,ix,iy,black);
        !            97:                                if ( mask[iy][ix] == 0 ) XPutPixel(image, ix, iy, black);
        !            98:                                else {
        !            99:                                        switch (GXcode) {
        !           100:                                        case 3: /* copy case */
        !           101:                                                if (mask[iy][ix] == 1 ) XPutPixel(image, ix, iy, can->color);
        !           102:                                                else XPutPixel(image, ix, iy, BackPixel);
        !           103:                                                break;
        !           104:                                        case 1: /* and case */
        !           105:                                                if ((mask[iy][ix] == 1) && (wc == 1))
        !           106:                                                        XPutPixel(image, ix, iy, can->color);
        !           107:                                                else XPutPixel(image, ix, iy, BackPixel);
        !           108:                                                break;
        !           109:                                        case 7: /* or case */
        !           110:                                                if ((mask[iy][ix] == 1) || (wc == 1))
        !           111:                                                        XPutPixel(image, ix, iy, can->color);
        !           112:                                                else XPutPixel(image, ix, iy, BackPixel);
        !           113:                                                break;
        !           114:                                        case 6: /* xor case */
        !           115:                                                if ((mask[iy][ix] == 1) ^ (wc == 1))
        !           116:                                                        XPutPixel(image, ix, iy, can->color);
        !           117:                                                else XPutPixel(image, ix, iy, BackPixel);
        !           118:                                                break;
        !           119:                                        }
        !           120:                                }
        !           121:                        }
        !           122:                }
        !           123:        }
        !           124:        XPutImage(display,can->pix,drawGC,image,0,0,0,0,can->width, can->height);
        !           125:        count_and_flush();
        !           126:        flush();
        !           127: }
        !           128:
1.9       noro      129: void if_print(DISPLAY *display,double **tab,struct canvas *can)
1.1       noro      130: {
                    131:        int ix,iy,width,height;
                    132:        double *px,*px1,*px2;
                    133:        DRAWABLE pix;
                    134:
                    135:        if ( can->mode == MODE_CONPLOT ) {
                    136:                con_print(display,tab,can); return;
                    137:        }
                    138:        flush();
                    139:        width = can->width; height = can->height; pix = can->pix;
                    140:        for( ix=0; ix<width-1; ix++ )
                    141:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    142:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                    143:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                    144:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
1.12      noro      145:                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1       noro      146:                                count_and_flush();
                    147:                        }
                    148:        flush();
                    149: }
                    150:
1.8       noro      151: #define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7)))
                    152:
1.9       noro      153: void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes)
1.8       noro      154: {
                    155:        int ix,iy,width,height;
                    156:        double *px,*px1,*px2;
                    157:        unsigned char *array;
                    158:        int scan_len;
                    159:
                    160:        if ( can->mode == MODE_CONPLOT ) {
                    161:                memory_con_print(tab,can,bytes); return;
                    162:        }
                    163:        width = can->width; height = can->height;
                    164:
                    165:        /* scan_len = byte length of the scan line */
                    166:        scan_len = (width+7)/8;
                    167:        MKBYTEARRAY(*bytes,scan_len*height);
                    168:        array = BDY(*bytes);
                    169:        for( ix=0; ix<width-1; ix++ )
                    170:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    171:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                    172:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                    173:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                    174:                                MEMORY_DRAWPOINT(array,scan_len,ix,height-iy-1);
                    175:                        }
                    176: }
                    177:
1.9       noro      178: void con_print(DISPLAY *display,double **tab,struct canvas *can)
1.1       noro      179: {
                    180:        int ix,iy,iz,width,height,pas,pai,len;
                    181:        double zstep,z;
                    182:        double *px,*px1,*px2;
                    183:        DRAWABLE pix;
                    184:        POINT *pa,*pa1;
                    185:        struct pa *parray;
                    186:
                    187:
                    188:        width = can->width; height = can->height; pix = can->pix;
                    189:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    190:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    191:        pas = width;
                    192:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    193:        initmarker(can,"Drawing...");
                    194:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    195:                marker(can,DIR_Z,iz);
                    196:                pai = 0;
                    197:                for( ix=0; ix<width-1; ix++ )
                    198:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    199:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    200:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    201:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    202:                                        if ( pai == pas ) {
                    203:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    204:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    205:                                                pas += pas;
                    206:                                        }
                    207:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    208:                                }
                    209:                can->pa[iz].length = pai;
                    210:                if ( pai ) {
                    211:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    212:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    213:                        can->pa[iz].pos = pa1;
                    214:                }
                    215:        }
                    216:        flush();
                    217:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    218:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
1.12      noro      219:                        DRAWPOINT(display,pix,cdrawGC,XC(pa[ix]),YC(pa[ix]));
1.1       noro      220:                        count_and_flush();
                    221:                }
                    222:        flush();
1.8       noro      223: }
                    224:
1.9       noro      225: void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes)
1.8       noro      226: {
                    227:        int ix,iy,iz,width,height,pas,pai,len;
                    228:        double zstep,z;
                    229:        double *px,*px1,*px2;
                    230:        POINT *pa,*pa1;
                    231:        struct pa *parray;
                    232:        unsigned char *array;
                    233:        int scan_len;
                    234:
                    235:        width = can->width; height = can->height;
                    236:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    237:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    238:        pas = width;
                    239:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    240:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    241:                pai = 0;
                    242:                for( ix=0; ix<width-1; ix++ )
                    243:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    244:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    245:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    246:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    247:                                        if ( pai == pas ) {
                    248:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    249:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    250:                                                pas += pas;
                    251:                                        }
                    252:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    253:                                }
                    254:                can->pa[iz].length = pai;
                    255:                if ( pai ) {
                    256:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    257:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    258:                        can->pa[iz].pos = pa1;
                    259:                }
                    260:        }
                    261:        /* scan_len = byte length of the scan line */
                    262:        scan_len = (width+7)/8;
                    263:        MKBYTEARRAY(*bytes,scan_len*height);
                    264:        array = BDY(*bytes);
                    265:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    266:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                    267:                        MEMORY_DRAWPOINT(array,scan_len,XC(pa[ix]),YC(pa[ix]));
                    268:                }
1.13      noro      269: }
                    270:
                    271: void memory_print(struct canvas *can,BYTEARRAY *bytes)
                    272: {
                    273:        int len,scan_len,i;
                    274:        POINT *pa;
                    275:        char *array;
                    276:
                    277:        /* scan_len = byte length of the scan line */
                    278:        scan_len = (can->width+7)/8;
                    279:        MKBYTEARRAY(*bytes,scan_len*can->height);
                    280:        array = BDY(*bytes);
                    281:
                    282:        len = can->pa[0].length;
                    283:        pa = can->pa[0].pos;
                    284:        for ( i = 0; i < len; i++ ) {
                    285:                MEMORY_DRAWPOINT(array,scan_len,pa[i].x,pa[i].y);
                    286:        }
1.1       noro      287: }
                    288:
1.9       noro      289: void qif_print(DISPLAY *display,char **tab,struct canvas *can)
1.1       noro      290: {
                    291:        int ix,iy,width,height;
                    292:        char *px;
                    293:        DRAWABLE pix;
                    294:
                    295:        flush();
                    296:        width = can->width; height = can->height; pix = can->pix;
                    297:        for( ix = 0; ix < width; ix++ )
                    298:                for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                    299:                        if ( *px ) {
1.12      noro      300:                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1       noro      301:                                count_and_flush();
                    302:                        }
                    303:        flush();
                    304: }
                    305:
1.9       noro      306: void plot_print(DISPLAY *display,struct canvas *can)
1.1       noro      307: {
1.9       noro      308:        int len;
1.1       noro      309:        POINT *pa;
1.5       noro      310:
                    311: #if defined(VISUAL)
                    312:        len = can->pa[0].length;
                    313:        pa = can->pa[0].pos;
1.6       noro      314:
                    315:        Polyline(can->pix,pa,len);
                    316: //     for ( i = 0; i < len-1; i++ ) {
                    317: //             DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
                    318: //     }
1.5       noro      319: #else
1.1       noro      320:        XDrawLines(display,can->pix,drawGC,
                    321:                can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
                    322:        XFlush(display);
1.5       noro      323: #endif
                    324: }
                    325:
1.9       noro      326: void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color)
1.5       noro      327: {
                    328: #if defined(VISUAL)
                    329:        HDC dc;
                    330:
1.6       noro      331:        SetPixel(can->pix,x,y,(COLORREF)color);
1.5       noro      332:        dc = GetDC(can->hwnd);
1.6       noro      333:        SetPixel(dc,x,y,(COLORREF)color);
1.5       noro      334:        ReleaseDC(can->hwnd,dc);
                    335: #else
1.12      noro      336:        set_drawcolor(color);
                    337:        DRAWPOINT(display,can->pix,cdrawGC,x,y);
                    338:        DRAWPOINT(display,can->window,cdrawGC,x,y);
1.5       noro      339:        XFlush(display);
                    340: #endif
                    341: }
                    342:
1.9       noro      343: void draw_line(DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color)
1.5       noro      344: {
                    345: #if defined(VISUAL)
                    346:        HDC dc;
1.6       noro      347:        HPEN pen,oldpen;
1.5       noro      348:
1.6       noro      349:        if ( color ) {
                    350:                pen = CreatePen(PS_SOLID,1,color);
                    351:                oldpen = SelectObject(can->pix,pen);
                    352:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                    353:                SelectObject(can->pix,oldpen);
                    354:
                    355:                dc = GetDC(can->hwnd);
                    356:                oldpen = SelectObject(dc,pen);
                    357:                DRAWLINE(display,dc,drawGC,x,y,u,v);
                    358:                SelectObject(dc,oldpen);
                    359:                ReleaseDC(can->hwnd,dc);
                    360:
                    361:                DeleteObject(pen);
                    362:        } else {
                    363:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                    364:                dc = GetDC(can->hwnd);
                    365:                DRAWLINE(display,dc,drawGC,x,y,u,v);
                    366:                ReleaseDC(can->hwnd,dc);
                    367:        }
1.5       noro      368: #else
1.12      noro      369:        set_drawcolor(color);
                    370:        DRAWLINE(display,can->pix,cdrawGC,x,y,u,v);
                    371:        DRAWLINE(display,can->window,cdrawGC,x,y,u,v);
1.10      noro      372:        XFlush(display);
                    373: #endif
                    374: }
                    375:
                    376: void draw_character_string(DISPLAY *display,struct canvas *can,int x,int y,char *str,int color)
                    377: {
                    378: #if defined(VISUAL)
                    379:        HDC dc;
1.11      noro      380:        COLORREF oldcolor;
1.10      noro      381:
                    382:        if ( color ) {
1.11      noro      383:                oldcolor = SetTextColor(can->pix,color);
1.10      noro      384:                DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
1.11      noro      385:                SetTextColor(can->pix,oldcolor);
1.10      noro      386:
                    387:                dc = GetDC(can->hwnd);
1.11      noro      388:                oldcolor = SetTextColor(dc,color);
1.10      noro      389:                DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
1.11      noro      390:                SetTextColor(dc,oldcolor);
1.10      noro      391:                ReleaseDC(can->hwnd,dc);
                    392:        } else {
                    393:                DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
                    394:                dc = GetDC(can->hwnd);
                    395:                DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
                    396:                ReleaseDC(can->hwnd,dc);
                    397:        }
                    398: #else
1.12      noro      399:        set_drawcolor(color);
                    400:        DRAWSTRING(display,can->pix,cdrawGC,x,y,str,strlen(str));
                    401:        DRAWSTRING(display,can->window,cdrawGC,x,y,str,strlen(str));
1.5       noro      402:        XFlush(display);
                    403: #endif
1.1       noro      404: }
                    405:
                    406: #define D 5
                    407:
1.9       noro      408: void pline(DISPLAY *display,struct canvas *can,DRAWABLE d)
1.1       noro      409: {
1.9       noro      410:        double w,w1,e,n;
1.1       noro      411:        int x0,y0,x,y,xadj,yadj;
                    412:        char buf[BUFSIZ];
                    413:        double adjust_scale();
                    414:
1.5       noro      415:        /* XXX : should be cleaned up */
                    416:        if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
                    417:                return;
                    418:        if ( can->mode == MODE_INTERACTIVE )
1.1       noro      419:                return;
                    420:
                    421:        xadj = yadj = 0;
                    422:        if ( (can->xmin < 0) && (can->xmax > 0) ) {
1.6       noro      423:                x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
1.1       noro      424:                DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
                    425:        } else if ( can->xmin >= 0 )
                    426:                x0 = 0;
                    427:        else
1.6       noro      428:                x0 = can->width-D;
1.1       noro      429:        if ( (can->ymin < 0) && (can->ymax > 0) ) {
1.6       noro      430:                y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
1.1       noro      431:                DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
                    432:        } else if ( can->ymin >= 0 )
1.6       noro      433:                y0 = can->height;
1.1       noro      434:        else
                    435:                y0 = D;
1.6       noro      436:
                    437:        /* scale on x-axis */
1.1       noro      438:        w = can->xmax-can->xmin;
                    439:        w1 = w * DEFAULTWIDTH/can->width;
                    440:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    441:        for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
1.9       noro      442:                x = (int)(can->width*(n*e-can->xmin)/w);
1.1       noro      443:                DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                    444:                sprintf(buf,"%g",n*e);
1.6       noro      445:                DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
1.1       noro      446:        }
1.6       noro      447:
                    448:        /* scale on y-axis */
1.1       noro      449:        w = can->ymax-can->ymin;
                    450:        w1 = w * DEFAULTHEIGHT/can->height;
                    451:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    452:        for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
1.9       noro      453:                y = (int)(can->height*(1-(n*e-can->ymin)/w));
1.1       noro      454:                DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                    455:                sprintf(buf,"%g",n*e);
1.6       noro      456:                if ( can->xmax <= 0 ) {
                    457: #if !defined(VISUAL)
1.1       noro      458:                        xadj = TEXTWIDTH(sffs,buf,strlen(buf));
1.6       noro      459: #else
                    460:                        SIZE size;
                    461:
                    462:                        GetTextExtentPoint32(d,buf,strlen(buf),&size);
                    463:                        xadj = size.cx;
                    464: #endif
                    465:                }
                    466:                DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
1.1       noro      467:        }
                    468: }
                    469:
1.9       noro      470: double adjust_scale(double e,double w)
1.1       noro      471: {
                    472:        switch ( (int)floor(w/e) ) {
                    473:                case 1:
                    474:                        return e/4; break;
                    475:                case 2: case 3:
                    476:                        return e/2; break;
                    477:                case 4: case 5: case 6: case 7:
                    478:                        return e; break;
                    479:                        break;
                    480:                case 8: case 9: case 10: default:
                    481:                        return 2*e; break;
                    482:        }
                    483: }
                    484:
1.9       noro      485: void initmarker(struct canvas *can,char *message)
1.1       noro      486: {
1.5       noro      487: #if defined(VISUAL)
                    488:        can->real_can->percentage = 0;
                    489:        can->real_can->prefix = message;
                    490: #else
1.1       noro      491:        XawScrollbarSetThumb(can->xdone,0.0,0.0);
                    492:        XawScrollbarSetThumb(can->ydone,1.0,0.0);
                    493:        XFlush(display);
1.5       noro      494: #endif
1.1       noro      495: }
                    496:
1.9       noro      497: void marker(struct canvas *can,int dir,int p)
1.1       noro      498: {
1.5       noro      499: #if defined(VISUAL)
                    500:        if ( dir == DIR_X )
1.9       noro      501:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->width*100);
1.5       noro      502:        else if ( dir == DIR_Y )
1.9       noro      503:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->height*100);
1.5       noro      504:        else
1.9       noro      505:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->nzstep*100);
1.5       noro      506: #else
1.1       noro      507:        if ( dir == DIR_X ) {
                    508:                XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
                    509:                count_and_flush();
                    510:        } else if ( dir == DIR_Y ) {
                    511:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
                    512:                count_and_flush();
                    513:        } else {
                    514:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
                    515:                flush();
                    516:        }
1.5       noro      517: #endif
1.1       noro      518: }
                    519:
1.9       noro      520: void define_cursor(WINDOW w,CURSOR cur)
1.1       noro      521: {
1.5       noro      522: #if !defined(VISUAL)
1.1       noro      523:        XDefineCursor(display,w,cur); flush();
1.5       noro      524: #endif
1.1       noro      525: }
                    526:
                    527: static int flush_count;
                    528: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
                    529: #define MAX_COUNT 64
                    530: #else
                    531: #define MAX_COUNT 32
                    532: #endif
                    533:
1.9       noro      534: void count_and_flush() {
1.5       noro      535: #if !defined(VISUAL)
1.1       noro      536:        if ( ++flush_count == MAX_COUNT )
                    537:                flush();
1.5       noro      538: #endif
1.1       noro      539: }
                    540:
1.9       noro      541: void flush() {
1.5       noro      542: #if !defined(VISUAL)
1.1       noro      543:        flush_count = 0;
                    544:        XFlush(display);
1.5       noro      545: #endif
1.1       noro      546: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>