[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.15

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.15    ! saito      48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.14 2011/08/10 04:51:58 saito 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.15    ! saito      66: #if defined(INTERVAL)
1.14      saito      67: unsigned long GetColor(Display *, char *);
                     68:
                     69: unsigned long GetColor(Display *dis, char *color_name)
                     70: {
                     71:        Colormap cmap;
                     72:        XColor near_color, true_color;
                     73:
                     74:        cmap = DefaultColormap( dis, 0 );
                     75:        XAllocNamedColor( dis, cmap, color_name, &near_color, &true_color );
                     76:        return( near_color.pixel );
                     77: }
                     78:
                     79: void area_print(DISPLAY *display, int **mask, struct canvas *can, int GXcode)
                     80: {
                     81:        int ix, iy;
                     82:        XImage *image;
                     83:        unsigned long color, black, white;
                     84:        int wc;
                     85:
                     86:        flush();
                     87:        black = GetColor(display, "black");
                     88:        white = GetColor(display, "white");
                     89:        image = XGetImage(display, can->pix, 0, 0, can->width, can->height,
                     90:                -1, ZPixmap);
                     91:        for(iy = 0; iy < can->height; iy++){
                     92:                for(ix = 0; ix < can->width; ix++){
                     93:                        color = XGetPixel(image, ix, iy);
                     94:                        if (color == white) wc = -1;
                     95:                        else if (color == black) wc = 0;
                     96:                        else wc = 1;
                     97:                        if ( wc != 0 ) {//XPutPixel(image,ix,iy,black);
                     98:                                if ( mask[iy][ix] == 0 ) XPutPixel(image, ix, iy, black);
                     99:                                else {
                    100:                                        switch (GXcode) {
                    101:                                        case 3: /* copy case */
                    102:                                                if (mask[iy][ix] == 1 ) XPutPixel(image, ix, iy, can->color);
                    103:                                                else XPutPixel(image, ix, iy, BackPixel);
                    104:                                                break;
                    105:                                        case 1: /* and case */
                    106:                                                if ((mask[iy][ix] == 1) && (wc == 1))
                    107:                                                        XPutPixel(image, ix, iy, can->color);
                    108:                                                else XPutPixel(image, ix, iy, BackPixel);
                    109:                                                break;
                    110:                                        case 7: /* or case */
                    111:                                                if ((mask[iy][ix] == 1) || (wc == 1))
                    112:                                                        XPutPixel(image, ix, iy, can->color);
                    113:                                                else XPutPixel(image, ix, iy, BackPixel);
                    114:                                                break;
                    115:                                        case 6: /* xor case */
                    116:                                                if ((mask[iy][ix] == 1) ^ (wc == 1))
                    117:                                                        XPutPixel(image, ix, iy, can->color);
                    118:                                                else XPutPixel(image, ix, iy, BackPixel);
                    119:                                                break;
                    120:                                        }
                    121:                                }
                    122:                        }
                    123:                }
                    124:        }
                    125:        XPutImage(display,can->pix,drawGC,image,0,0,0,0,can->width, can->height);
                    126:        count_and_flush();
                    127:        flush();
                    128: }
1.15    ! saito     129: #endif
1.14      saito     130:
1.9       noro      131: void if_print(DISPLAY *display,double **tab,struct canvas *can)
1.1       noro      132: {
                    133:        int ix,iy,width,height;
                    134:        double *px,*px1,*px2;
                    135:        DRAWABLE pix;
                    136:
                    137:        if ( can->mode == MODE_CONPLOT ) {
                    138:                con_print(display,tab,can); return;
                    139:        }
                    140:        flush();
                    141:        width = can->width; height = can->height; pix = can->pix;
                    142:        for( ix=0; ix<width-1; ix++ )
                    143:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    144:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                    145:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                    146:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
1.12      noro      147:                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1       noro      148:                                count_and_flush();
                    149:                        }
                    150:        flush();
                    151: }
                    152:
1.8       noro      153: #define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7)))
                    154:
1.9       noro      155: void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes)
1.8       noro      156: {
                    157:        int ix,iy,width,height;
                    158:        double *px,*px1,*px2;
                    159:        unsigned char *array;
                    160:        int scan_len;
                    161:
                    162:        if ( can->mode == MODE_CONPLOT ) {
                    163:                memory_con_print(tab,can,bytes); return;
                    164:        }
                    165:        width = can->width; height = can->height;
                    166:
                    167:        /* scan_len = byte length of the scan line */
                    168:        scan_len = (width+7)/8;
                    169:        MKBYTEARRAY(*bytes,scan_len*height);
                    170:        array = BDY(*bytes);
                    171:        for( ix=0; ix<width-1; ix++ )
                    172:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    173:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                    174:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                    175:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                    176:                                MEMORY_DRAWPOINT(array,scan_len,ix,height-iy-1);
                    177:                        }
                    178: }
                    179:
1.9       noro      180: void con_print(DISPLAY *display,double **tab,struct canvas *can)
1.1       noro      181: {
                    182:        int ix,iy,iz,width,height,pas,pai,len;
                    183:        double zstep,z;
                    184:        double *px,*px1,*px2;
                    185:        DRAWABLE pix;
                    186:        POINT *pa,*pa1;
                    187:        struct pa *parray;
                    188:
                    189:
                    190:        width = can->width; height = can->height; pix = can->pix;
                    191:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    192:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    193:        pas = width;
                    194:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    195:        initmarker(can,"Drawing...");
                    196:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    197:                marker(can,DIR_Z,iz);
                    198:                pai = 0;
                    199:                for( ix=0; ix<width-1; ix++ )
                    200:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    201:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    202:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    203:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    204:                                        if ( pai == pas ) {
                    205:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    206:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    207:                                                pas += pas;
                    208:                                        }
                    209:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    210:                                }
                    211:                can->pa[iz].length = pai;
                    212:                if ( pai ) {
                    213:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    214:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    215:                        can->pa[iz].pos = pa1;
                    216:                }
                    217:        }
                    218:        flush();
                    219:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    220:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
1.12      noro      221:                        DRAWPOINT(display,pix,cdrawGC,XC(pa[ix]),YC(pa[ix]));
1.1       noro      222:                        count_and_flush();
                    223:                }
                    224:        flush();
1.8       noro      225: }
                    226:
1.9       noro      227: void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes)
1.8       noro      228: {
                    229:        int ix,iy,iz,width,height,pas,pai,len;
                    230:        double zstep,z;
                    231:        double *px,*px1,*px2;
                    232:        POINT *pa,*pa1;
                    233:        struct pa *parray;
                    234:        unsigned char *array;
                    235:        int scan_len;
                    236:
                    237:        width = can->width; height = can->height;
                    238:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    239:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    240:        pas = width;
                    241:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    242:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    243:                pai = 0;
                    244:                for( ix=0; ix<width-1; ix++ )
                    245:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    246:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    247:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    248:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    249:                                        if ( pai == pas ) {
                    250:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    251:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    252:                                                pas += pas;
                    253:                                        }
                    254:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    255:                                }
                    256:                can->pa[iz].length = pai;
                    257:                if ( pai ) {
                    258:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    259:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    260:                        can->pa[iz].pos = pa1;
                    261:                }
                    262:        }
                    263:        /* scan_len = byte length of the scan line */
                    264:        scan_len = (width+7)/8;
                    265:        MKBYTEARRAY(*bytes,scan_len*height);
                    266:        array = BDY(*bytes);
                    267:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    268:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                    269:                        MEMORY_DRAWPOINT(array,scan_len,XC(pa[ix]),YC(pa[ix]));
                    270:                }
1.13      noro      271: }
                    272:
                    273: void memory_print(struct canvas *can,BYTEARRAY *bytes)
                    274: {
                    275:        int len,scan_len,i;
                    276:        POINT *pa;
                    277:        char *array;
                    278:
                    279:        /* scan_len = byte length of the scan line */
                    280:        scan_len = (can->width+7)/8;
                    281:        MKBYTEARRAY(*bytes,scan_len*can->height);
                    282:        array = BDY(*bytes);
                    283:
                    284:        len = can->pa[0].length;
                    285:        pa = can->pa[0].pos;
                    286:        for ( i = 0; i < len; i++ ) {
                    287:                MEMORY_DRAWPOINT(array,scan_len,pa[i].x,pa[i].y);
                    288:        }
1.1       noro      289: }
                    290:
1.9       noro      291: void qif_print(DISPLAY *display,char **tab,struct canvas *can)
1.1       noro      292: {
                    293:        int ix,iy,width,height;
                    294:        char *px;
                    295:        DRAWABLE pix;
                    296:
                    297:        flush();
                    298:        width = can->width; height = can->height; pix = can->pix;
                    299:        for( ix = 0; ix < width; ix++ )
                    300:                for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                    301:                        if ( *px ) {
1.12      noro      302:                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1       noro      303:                                count_and_flush();
                    304:                        }
                    305:        flush();
                    306: }
                    307:
1.9       noro      308: void plot_print(DISPLAY *display,struct canvas *can)
1.1       noro      309: {
1.9       noro      310:        int len;
1.1       noro      311:        POINT *pa;
1.5       noro      312:
                    313: #if defined(VISUAL)
                    314:        len = can->pa[0].length;
                    315:        pa = can->pa[0].pos;
1.6       noro      316:
                    317:        Polyline(can->pix,pa,len);
                    318: //     for ( i = 0; i < len-1; i++ ) {
                    319: //             DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
                    320: //     }
1.5       noro      321: #else
1.1       noro      322:        XDrawLines(display,can->pix,drawGC,
                    323:                can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
                    324:        XFlush(display);
1.5       noro      325: #endif
                    326: }
                    327:
1.9       noro      328: void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color)
1.5       noro      329: {
                    330: #if defined(VISUAL)
                    331:        HDC dc;
                    332:
1.6       noro      333:        SetPixel(can->pix,x,y,(COLORREF)color);
1.5       noro      334:        dc = GetDC(can->hwnd);
1.6       noro      335:        SetPixel(dc,x,y,(COLORREF)color);
1.5       noro      336:        ReleaseDC(can->hwnd,dc);
                    337: #else
1.12      noro      338:        set_drawcolor(color);
                    339:        DRAWPOINT(display,can->pix,cdrawGC,x,y);
                    340:        DRAWPOINT(display,can->window,cdrawGC,x,y);
1.5       noro      341:        XFlush(display);
                    342: #endif
                    343: }
                    344:
1.9       noro      345: void draw_line(DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color)
1.5       noro      346: {
                    347: #if defined(VISUAL)
                    348:        HDC dc;
1.6       noro      349:        HPEN pen,oldpen;
1.5       noro      350:
1.6       noro      351:        if ( color ) {
                    352:                pen = CreatePen(PS_SOLID,1,color);
                    353:                oldpen = SelectObject(can->pix,pen);
                    354:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                    355:                SelectObject(can->pix,oldpen);
                    356:
                    357:                dc = GetDC(can->hwnd);
                    358:                oldpen = SelectObject(dc,pen);
                    359:                DRAWLINE(display,dc,drawGC,x,y,u,v);
                    360:                SelectObject(dc,oldpen);
                    361:                ReleaseDC(can->hwnd,dc);
                    362:
                    363:                DeleteObject(pen);
                    364:        } else {
                    365:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                    366:                dc = GetDC(can->hwnd);
                    367:                DRAWLINE(display,dc,drawGC,x,y,u,v);
                    368:                ReleaseDC(can->hwnd,dc);
                    369:        }
1.5       noro      370: #else
1.12      noro      371:        set_drawcolor(color);
                    372:        DRAWLINE(display,can->pix,cdrawGC,x,y,u,v);
                    373:        DRAWLINE(display,can->window,cdrawGC,x,y,u,v);
1.10      noro      374:        XFlush(display);
                    375: #endif
                    376: }
                    377:
                    378: void draw_character_string(DISPLAY *display,struct canvas *can,int x,int y,char *str,int color)
                    379: {
                    380: #if defined(VISUAL)
                    381:        HDC dc;
1.11      noro      382:        COLORREF oldcolor;
1.10      noro      383:
                    384:        if ( color ) {
1.11      noro      385:                oldcolor = SetTextColor(can->pix,color);
1.10      noro      386:                DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
1.11      noro      387:                SetTextColor(can->pix,oldcolor);
1.10      noro      388:
                    389:                dc = GetDC(can->hwnd);
1.11      noro      390:                oldcolor = SetTextColor(dc,color);
1.10      noro      391:                DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
1.11      noro      392:                SetTextColor(dc,oldcolor);
1.10      noro      393:                ReleaseDC(can->hwnd,dc);
                    394:        } else {
                    395:                DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
                    396:                dc = GetDC(can->hwnd);
                    397:                DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
                    398:                ReleaseDC(can->hwnd,dc);
                    399:        }
                    400: #else
1.12      noro      401:        set_drawcolor(color);
                    402:        DRAWSTRING(display,can->pix,cdrawGC,x,y,str,strlen(str));
                    403:        DRAWSTRING(display,can->window,cdrawGC,x,y,str,strlen(str));
1.5       noro      404:        XFlush(display);
                    405: #endif
1.1       noro      406: }
                    407:
                    408: #define D 5
                    409:
1.9       noro      410: void pline(DISPLAY *display,struct canvas *can,DRAWABLE d)
1.1       noro      411: {
1.9       noro      412:        double w,w1,e,n;
1.1       noro      413:        int x0,y0,x,y,xadj,yadj;
                    414:        char buf[BUFSIZ];
                    415:        double adjust_scale();
                    416:
1.5       noro      417:        /* XXX : should be cleaned up */
                    418:        if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
                    419:                return;
                    420:        if ( can->mode == MODE_INTERACTIVE )
1.1       noro      421:                return;
                    422:
                    423:        xadj = yadj = 0;
                    424:        if ( (can->xmin < 0) && (can->xmax > 0) ) {
1.6       noro      425:                x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
1.1       noro      426:                DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
                    427:        } else if ( can->xmin >= 0 )
                    428:                x0 = 0;
                    429:        else
1.6       noro      430:                x0 = can->width-D;
1.1       noro      431:        if ( (can->ymin < 0) && (can->ymax > 0) ) {
1.6       noro      432:                y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
1.1       noro      433:                DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
                    434:        } else if ( can->ymin >= 0 )
1.6       noro      435:                y0 = can->height;
1.1       noro      436:        else
                    437:                y0 = D;
1.6       noro      438:
                    439:        /* scale on x-axis */
1.1       noro      440:        w = can->xmax-can->xmin;
                    441:        w1 = w * DEFAULTWIDTH/can->width;
                    442:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    443:        for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
1.9       noro      444:                x = (int)(can->width*(n*e-can->xmin)/w);
1.1       noro      445:                DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                    446:                sprintf(buf,"%g",n*e);
1.6       noro      447:                DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
1.1       noro      448:        }
1.6       noro      449:
                    450:        /* scale on y-axis */
1.1       noro      451:        w = can->ymax-can->ymin;
                    452:        w1 = w * DEFAULTHEIGHT/can->height;
                    453:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    454:        for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
1.9       noro      455:                y = (int)(can->height*(1-(n*e-can->ymin)/w));
1.1       noro      456:                DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                    457:                sprintf(buf,"%g",n*e);
1.6       noro      458:                if ( can->xmax <= 0 ) {
                    459: #if !defined(VISUAL)
1.1       noro      460:                        xadj = TEXTWIDTH(sffs,buf,strlen(buf));
1.6       noro      461: #else
                    462:                        SIZE size;
                    463:
                    464:                        GetTextExtentPoint32(d,buf,strlen(buf),&size);
                    465:                        xadj = size.cx;
                    466: #endif
                    467:                }
                    468:                DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
1.1       noro      469:        }
                    470: }
                    471:
1.9       noro      472: double adjust_scale(double e,double w)
1.1       noro      473: {
                    474:        switch ( (int)floor(w/e) ) {
                    475:                case 1:
                    476:                        return e/4; break;
                    477:                case 2: case 3:
                    478:                        return e/2; break;
                    479:                case 4: case 5: case 6: case 7:
                    480:                        return e; break;
                    481:                        break;
                    482:                case 8: case 9: case 10: default:
                    483:                        return 2*e; break;
                    484:        }
                    485: }
                    486:
1.9       noro      487: void initmarker(struct canvas *can,char *message)
1.1       noro      488: {
1.5       noro      489: #if defined(VISUAL)
                    490:        can->real_can->percentage = 0;
                    491:        can->real_can->prefix = message;
                    492: #else
1.1       noro      493:        XawScrollbarSetThumb(can->xdone,0.0,0.0);
                    494:        XawScrollbarSetThumb(can->ydone,1.0,0.0);
                    495:        XFlush(display);
1.5       noro      496: #endif
1.1       noro      497: }
                    498:
1.9       noro      499: void marker(struct canvas *can,int dir,int p)
1.1       noro      500: {
1.5       noro      501: #if defined(VISUAL)
                    502:        if ( dir == DIR_X )
1.9       noro      503:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->width*100);
1.5       noro      504:        else if ( dir == DIR_Y )
1.9       noro      505:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->height*100);
1.5       noro      506:        else
1.9       noro      507:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->nzstep*100);
1.5       noro      508: #else
1.1       noro      509:        if ( dir == DIR_X ) {
                    510:                XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
                    511:                count_and_flush();
                    512:        } else if ( dir == DIR_Y ) {
                    513:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
                    514:                count_and_flush();
                    515:        } else {
                    516:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
                    517:                flush();
                    518:        }
1.5       noro      519: #endif
1.1       noro      520: }
                    521:
1.9       noro      522: void define_cursor(WINDOW w,CURSOR cur)
1.1       noro      523: {
1.5       noro      524: #if !defined(VISUAL)
1.1       noro      525:        XDefineCursor(display,w,cur); flush();
1.5       noro      526: #endif
1.1       noro      527: }
                    528:
                    529: static int flush_count;
                    530: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
                    531: #define MAX_COUNT 64
                    532: #else
                    533: #define MAX_COUNT 32
                    534: #endif
                    535:
1.9       noro      536: void count_and_flush() {
1.5       noro      537: #if !defined(VISUAL)
1.1       noro      538:        if ( ++flush_count == MAX_COUNT )
                    539:                flush();
1.5       noro      540: #endif
1.1       noro      541: }
                    542:
1.9       noro      543: void flush() {
1.5       noro      544: #if !defined(VISUAL)
1.1       noro      545:        flush_count = 0;
                    546:        XFlush(display);
1.5       noro      547: #endif
1.1       noro      548: }

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