home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / DISP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  4.2 KB  |  179 lines

  1. /*
  2.     disp.c
  3.  
  4.     % Display object hardware-independent code.
  5.  
  6.     5/16/88  by Ted.
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.     11/15/88 ted:    put in new ptd_SetInner function
  15.     12/16/88 jmd    made ddisp_GetWidth/Height into functions
  16.     01/15/89 ted:    made ddisp_GetFont omalloc its own font structure.
  17.      4/04/89 ted    Added FreeFont function.
  18.      8/22/89 ted    Made disp_OpenFont use ocalloc.
  19. */
  20.  
  21. #include "oakhead.h"
  22. #include "disppriv.h"
  23.  
  24. /* -------------------------------------------------------------------------- */
  25.  
  26. boolean disp_Ok()
  27. /*
  28.     This disp_Ok function assumes that no valid display will:
  29.         Have an invalid id number.
  30.         Have a NULL dig data pointer.
  31.         Have a NULL info structure pointer.
  32.         Have an invalid display map.
  33. */
  34. {
  35.     OEXTERN int num_dmgrs;
  36.  
  37.     if (curr_dmgr->id > 0 && curr_dmgr->id <= num_dmgrs &&
  38.         curr_dmgr->disp.dig.data != NULL &&
  39.         curr_dmgr->disp.info != NULL &&
  40.         pmap_Ok(disp_dispmap())) {
  41.         return(TRUE);
  42.     }
  43.     return(FALSE);
  44. }
  45. /* -------------------------------------------------------------------------- */
  46.  
  47. int disp_GetHeight()
  48. /*
  49.     Get the height of the display in characters
  50. */
  51. {
  52.     owl_Assert(disp_Ok(), OE_GH_DISP);
  53.     return((int)(disp_GetPixHeight() / ofont_GetHeight(disp_GetDefFont())));
  54. }
  55. /* -------------------------------------------------------------------------- */
  56.  
  57. int disp_GetWidth()
  58. /*
  59.     Get the width of the display in characters
  60. */
  61. {
  62.     owl_Assert(disp_Ok(), OE_GW_DISP);
  63.     return((int)(disp_GetPixWidth() / ofont_GetWidth(disp_GetDefFont())));
  64. }
  65. /* -------------------------------------------------------------------------- */
  66.  
  67. ofont_type disp_OpenFont(fontreq)
  68.     fontreq_struct *fontreq;
  69. /*
  70.     Request a reference to the font the device interface can supply that
  71.     is closest to the desired width, height, and other attributes.
  72. */
  73. {
  74.     ofont_type font;
  75.  
  76.     owl_Assert(disp_Ok(), OE_GF_DISP);
  77.  
  78.     if ((font = (ofont_type) ocalloc(OA_FONT, sizeof(struct ofont_struct), sizeof(byte)))
  79.         == NULL) {
  80.         return(NULL);
  81.     }
  82.     if (!disp_Control(DC_OPENFONT, fontreq, font)) {
  83.         ofree(OA_FONT, font);
  84.         font = NULL;
  85.     }
  86.     return(font);
  87. }
  88. /* -------------------------------------------------------------------------- */
  89.  
  90. void disp_CloseFont(font)
  91.     ofont_type font;
  92. /*
  93.     Release a font previously requested from disp_GetFont().
  94. */
  95. {
  96.     disp_Control(DC_CLOSEFONT, font, NULL);
  97.     ofree(OA_FONT, (VOID *) font);
  98. }
  99. /* -------------------------------------------------------------------------- */
  100.  
  101. void disp_SetAttrColors(attr, bg, fg)
  102.     byte attr;
  103.     opixval bg;
  104.     opixval fg;
  105. {
  106.     setattr_struct pvs;
  107.  
  108.     pvs.attr = attr;
  109.     pvs.bg = bg;
  110.     pvs.fg = fg;
  111.     disp_Control(DC_SETATTRCOLS, &pvs, NULL);
  112. }
  113. /* -------------------------------------------------------------------------- */
  114.  
  115. opixval disp_GetAttrFgColor(attr)
  116.     byte attr;
  117. {
  118.     opixval fg;
  119.  
  120.     fg = 0;
  121.     disp_getattrfg(&attr, &fg);
  122.     return(fg);
  123. }
  124. /* -------------------------------------------------------------------------- */
  125.  
  126. opixval disp_GetAttrBgColor(attr)
  127.     byte attr;
  128. {
  129.     opixval bg;
  130.  
  131.     bg = 0;
  132.     disp_getattrbg(&attr, &bg);
  133.     return(bg);
  134. }
  135. /* -------------------------------------------------------------------------- */
  136.  
  137. void disp_SetColMapEntry(icol, red, green, blue)
  138.     opixval icol;
  139.     olevel red;
  140.     olevel green;
  141.     olevel blue;
  142. /*
  143. */
  144. {
  145.     ocolmap_struct(1) color;
  146.  
  147.     color.firstpix = icol;
  148.     color.nentries = 1;
  149.     color.rgbs[0].rgb[ORED] = red;
  150.     color.rgbs[0].rgb[OGREEN] = green;
  151.     color.rgbs[0].rgb[OBLUE] = blue;
  152.  
  153.     disp_Control(DC_SETCOLMAP, &color, NULL);
  154. }
  155. /* -------------------------------------------------------------------------- */
  156.  
  157. boolean ptd_SetInner(ptd, inptd, inboxp)
  158.     ptd_struct *ptd;
  159.     ptd_struct *inptd;
  160.     opbox *inboxp;
  161. /*
  162.     Make inptd a copy of ptd but with its relboxp pointing to inboxp.
  163.     Clip inboxp within the ptd window's inner box.
  164.     Returns TRUE if the new relbox is not empty.
  165.  
  166.     Sets inptd->relboxp even if it fails.
  167.     Leaves ptd unaltered.
  168. */
  169. {
  170.     memmove(inptd, ptd, sizeof(ptd_struct));
  171.     opbox_copy(inboxp, ptd->relboxp);
  172.     inptd->relboxp = inboxp;
  173.     return(opwh_clipbox(win_GetPixWidth(ptd->win),
  174.                         win_GetPixHeight(ptd->win),
  175.                         inboxp) != 0);
  176. }
  177. /* -------------------------------------------------------------------------- */
  178.  
  179.