Annotation of pmsdk/samples/linefrac/lfps.c, revision 1.1

1.1     ! root        1: /************************************************************************
        !             2: *
        !             3: *   lfps.c -- Subroutines for PS/DC/BM management for LineFractal.
        !             4: *
        !             5: *   Created by Microsoft Corporation, 1989
        !             6: *
        !             7: ************************************************************************/
        !             8: 
        !             9: #define INCL_WIN
        !            10: #define INCL_GPI
        !            11: #include <os2.h>
        !            12: 
        !            13: #include <mt\stdio.h>
        !            14: #include <mt\stdlib.h>
        !            15: #include <mt\math.h>
        !            16: 
        !            17: #define INCL_GLOBALS
        !            18: #define INCL_THREADS
        !            19: #include "linefrac.h"
        !            20: 
        !            21: #define INCL_LFPS
        !            22: #define INCL_LFDRAW
        !            23: #include "lffuncs.h"
        !            24: 
        !            25: 
        !            26: 
        !            27: 
        !            28: /************************************************************************
        !            29: *
        !            30: *   Global Variables
        !            31: *
        !            32: ************************************************************************/
        !            33: 
        !            34: extern GLOBALDATA global;
        !            35: 
        !            36: 
        !            37: 
        !            38: 
        !            39: /************************************************************************
        !            40: *
        !            41: *   Data structures for opening the PostScript DC.
        !            42: *
        !            43: ************************************************************************/
        !            44: 
        !            45: typedef struct _randomdata
        !            46: {
        !            47:     long data[12];
        !            48: } PSRANDOMDATA;
        !            49: 
        !            50: typedef struct _psdevopendata
        !            51: {
        !            52:     char *device;
        !            53:     char *name;
        !            54:     PSRANDOMDATA *data;
        !            55:     char *type;
        !            56: } PSDEVOPENDATA;
        !            57: 
        !            58: PSRANDOMDATA psrnddata =
        !            59: {
        !            60:     48, 0, 0x65656565, 0, 0, 0, 0, 0, 0, 0, 0, 1
        !            61: };
        !            62: 
        !            63: PSDEVOPENDATA dvdata =
        !            64: {
        !            65:     "ps.txt",
        !            66:     "PSCRIPT",
        !            67:     &psrnddata,
        !            68:     "IBM_Q_STD"
        !            69: };
        !            70: 
        !            71: 
        !            72: 
        !            73: 
        !            74: /************************************************************************
        !            75: *
        !            76: *   LfOpenDC
        !            77: *
        !            78: *   Open a device context for the thread.  Read the DC type from the
        !            79: *   thread structure.
        !            80: *
        !            81: ************************************************************************/
        !            82: 
        !            83: BOOL fhdcInUse = FALSE; /* TRUE --> a direct dc thread is active */
        !            84: HDC hdcPrivate = NULL; /* non NULL --> it's the window DC */
        !            85: 
        !            86: BOOL
        !            87: LfOpenDC(pthr)
        !            88: PTHR  pthr;
        !            89: {
        !            90:     switch (pthr->dcType)
        !            91:     {
        !            92:     case IDM_DCDIRECT:
        !            93:        /* only one direct dc allowed */
        !            94:        if (fhdcInUse)
        !            95:            pthr->hdc = NULL;
        !            96:        else
        !            97:        {
        !            98:            if (!hdcPrivate)
        !            99:                hdcPrivate = WinOpenWindowDC(global.hwnd);
        !           100:            pthr->hdc = hdcPrivate;
        !           101:            fhdcInUse = TRUE;
        !           102:        }
        !           103:        break;
        !           104: 
        !           105:     case IDM_DCMEMORY:
        !           106:        pthr->hdc = DevOpenDC(global.hab, OD_MEMORY, "*", 0L, NULL, NULL);
        !           107:        break;
        !           108: 
        !           109:     case IDM_DCPOSTSCRIPT:
        !           110:        pthr->hdc = DevOpenDC(global.hab, OD_DIRECT, "*", 4L, (PDEVOPENDATA)&dvdata, NULL);
        !           111:        break;
        !           112: 
        !           113:     case IDM_DCPROPRINTER:
        !           114: 
        !           115:     default:
        !           116:        pthr->hdc = NULL;
        !           117:     }
        !           118: 
        !           119:     return (pthr->hdc ? TRUE : FALSE);
        !           120: }
        !           121: 
        !           122: 
        !           123: 
        !           124: 
        !           125: /************************************************************************
        !           126: *
        !           127: *   LfCloseDC
        !           128: *
        !           129: *   Close the device context for the thread.
        !           130: *
        !           131: ************************************************************************/
        !           132: 
        !           133: VOID
        !           134: LfCloseDC(pthr)
        !           135: PTHR  pthr;
        !           136: {
        !           137:     if (pthr->dcType == IDM_DCDIRECT)
        !           138:        fhdcInUse = FALSE;
        !           139:     else
        !           140:     {
        !           141:        if (pthr->hbm)
        !           142:            LfDeleteBitmap(pthr);
        !           143:        if (pthr->hdc)
        !           144:            DevCloseDC(pthr->hdc);
        !           145:     }
        !           146:     pthr->hdc = NULL;
        !           147: }
        !           148: 
        !           149: 
        !           150: 
        !           151: 
        !           152: /************************************************************************
        !           153: *
        !           154: *   LfCreateBitmap
        !           155: *
        !           156: *   Create a bitmap of the format specified in the thread structure.
        !           157: *   If the bitmap is to be automatically sized, then read the window
        !           158: *   size, otherwise use the values in the thread structure.
        !           159: *
        !           160: ************************************************************************/
        !           161: 
        !           162: BOOL
        !           163: LfCreateBitmap(pthr)
        !           164: PTHR  pthr;
        !           165: {
        !           166:     BITMAPINFOHEADER bminfo;
        !           167: 
        !           168:     bminfo.cbFix = sizeof bminfo;
        !           169: 
        !           170:     bminfo.cx = (USHORT) (pthr->rcl.xRight - pthr->rcl.xLeft);
        !           171:     bminfo.cy = (USHORT) (pthr->rcl.yTop   - pthr->rcl.yBottom);
        !           172:     bminfo.cPlanes   = pthr->cPlanes;
        !           173:     bminfo.cBitCount = pthr->cBitCount;
        !           174: 
        !           175:     pthr->hbm = GpiCreateBitmap(pthr->hps, &bminfo, 0L, 0L, 0L);
        !           176: 
        !           177:     return (pthr->hbm ? TRUE : FALSE);
        !           178: }
        !           179: 
        !           180: 
        !           181: 
        !           182: 
        !           183: /************************************************************************
        !           184: *
        !           185: *   LfDeleteBitmap
        !           186: *
        !           187: *   Delete the thread's bitmap and set the bitmap handle to null.
        !           188: *
        !           189: ************************************************************************/
        !           190: 
        !           191: VOID
        !           192: LfDeleteBitmap(pthr)
        !           193: PTHR  pthr;
        !           194: {
        !           195:     GpiDeleteBitmap(pthr->hbm);
        !           196:     pthr->hbm = NULL;
        !           197: }
        !           198: 
        !           199: 
        !           200: 
        !           201: 
        !           202: /************************************************************************
        !           203: *
        !           204: *   LfCreatePS
        !           205: *
        !           206: *   Create a presentation space for the thread.  If the DC type is
        !           207: *   a memory bitmap, then create a bitmap, select it into the PS, and
        !           208: *   initialize it to the desired background color.  Compute the scale
        !           209: *   factors and offsets to use when drawing.
        !           210: *
        !           211: ************************************************************************/
        !           212: 
        !           213: BOOL
        !           214: LfCreatePS(pthr)
        !           215: PTHR  pthr;
        !           216: {
        !           217:     SIZEL size;
        !           218:     BOOL fOK = FALSE;
        !           219: 
        !           220:     if (LfOpenDC(pthr))
        !           221:     {
        !           222:        size.cx = 0L;
        !           223:        size.cy = 0L;
        !           224:        pthr->hps = GpiCreatePS(global.hab, pthr->hdc, &size,
        !           225:                                 PU_PELS|GPIT_MICRO|GPIA_ASSOC);
        !           226:        if (pthr->hps)
        !           227:        {
        !           228:            if (pthr->dcType == IDM_DCDIRECT)
        !           229:            {
        !           230:                pthr->rcl = global.rcl;
        !           231:                GpiSetAttrs(pthr->hps, PRIM_LINE,   LFA_LINEALL,  0L, &pthr->lb);
        !           232:                GpiSetAttrs(pthr->hps, PRIM_MARKER, LFA_MARKALL,  0L, &pthr->mb);
        !           233:                GpiSetAttrs(pthr->hps, PRIM_AREA,   LFA_AREAALL,  0L, &pthr->ab);
        !           234:                GpiSetAttrs(pthr->hps, PRIM_IMAGE,  LFA_IMAGEALL, 0L, &pthr->ib);
        !           235: 
        !           236:            }
        !           237:            else if (pthr->dcType == IDM_DCMEMORY)
        !           238:            {
        !           239:                pthr->rcl.xLeft   = 0L;
        !           240:                pthr->rcl.yBottom = 0L;
        !           241:                pthr->rcl.xRight  = global.bm.cx;
        !           242:                pthr->rcl.yTop    = global.bm.cy;
        !           243:                pthr->cPlanes     = global.bm.cPlanes;
        !           244:                pthr->cBitCount   = global.bm.cBitCount;
        !           245:                if (LfCreateBitmap(pthr))
        !           246:                    if (GpiSetBitmap(pthr->hps, pthr->hbm) != HBM_ERROR)
        !           247:                    {
        !           248:                        GpiSetAttrs(pthr->hps, PRIM_LINE,   LFA_LINEALL,  0L, &pthr->lb);
        !           249:                        GpiSetAttrs(pthr->hps, PRIM_MARKER, LFA_MARKALL,  0L, &pthr->mb);
        !           250:                        GpiSetAttrs(pthr->hps, PRIM_AREA,   LFA_AREAALL,  0L, &pthr->ab);
        !           251:                        GpiSetAttrs(pthr->hps, PRIM_IMAGE,  LFA_IMAGEALL, 0L, &pthr->ib);
        !           252: 
        !           253:                        LfClearRect(pthr, &pthr->rcl);
        !           254:                        if (pthr->fCollectBounds)
        !           255:                            GpiSetDrawControl(pthr->hps, DCTL_BOUNDARY, DCTL_ON);
        !           256:                        fOK = TRUE;
        !           257:                    }
        !           258: 
        !           259:                if (!fOK)
        !           260:                {
        !           261:                    LfDeletePS(pthr);
        !           262:                    return FALSE;
        !           263:                }
        !           264:            }
        !           265:            else
        !           266:            {
        !           267:                pthr->rcl = global.rcl;
        !           268:            }
        !           269: 
        !           270:            pthr->flMiscAttrs |= LFA_XSCALE | LFA_YSCALE | LFA_XOFF | LFA_YOFF;
        !           271: 
        !           272:            return TRUE;
        !           273:        }
        !           274:     }
        !           275:     return FALSE;
        !           276: }
        !           277: 
        !           278: 
        !           279: 
        !           280: 
        !           281: /************************************************************************
        !           282: *
        !           283: *   LfDeletePS
        !           284: *
        !           285: *   Delete the thread's presentation space.  If the DC type is
        !           286: *   a memory bitmap, then unset the bitmap and delete it.
        !           287: *
        !           288: ************************************************************************/
        !           289: 
        !           290: VOID
        !           291: LfDeletePS(pthr)
        !           292: PTHR  pthr;
        !           293: {
        !           294:     if (pthr->hbm)
        !           295:     {
        !           296:        GpiSetBitmap(pthr->hps, NULL);
        !           297:        LfDeleteBitmap(pthr);
        !           298:     }
        !           299:     GpiDestroyPS(pthr->hps);
        !           300:     LfCloseDC(pthr);
        !           301: }
        !           302: 
        !           303: 
        !           304: 
        !           305: 
        !           306: /************************************************************************
        !           307: *
        !           308: *   LfResizePS
        !           309: *
        !           310: *   Destroy the current PS and create a new one the size of the
        !           311: *   current client rectangle.
        !           312: *
        !           313: ************************************************************************/
        !           314: 
        !           315: BOOL
        !           316: LfResizePS(pthr)
        !           317: PTHR pthr;
        !           318: {
        !           319:     if (pthr->hps)
        !           320:     {
        !           321:        pthr->fInterrupted = TRUE;
        !           322:        while (pthr->fBusy)
        !           323:            ;
        !           324:        LfDeletePS(pthr);
        !           325:     }
        !           326: 
        !           327:     return LfCreatePS(pthr);
        !           328: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.