home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 4 / CD_Magazyn_EXEC_nr_4.iso / Recent / dev / c / apputil.lha / apputil / windows.c < prev   
Encoding:
C/C++ Source or Header  |  2000-11-05  |  2.3 KB  |  99 lines

  1. /*
  2.  * windows.c
  3.  * =========
  4.  * Window utility functions.
  5.  *
  6.  * Copyright (C) 1999-2000 HÃ¥kan L. Younes (lorens@hem.passagen.se)
  7.  */
  8.  
  9. #include <intuition/imageclass.h>
  10.  
  11. #include <proto/graphics.h>
  12. #include <proto/intuition.h>
  13.  
  14. #include "apputil.h"
  15.  
  16.  
  17. VOID SetupWindowPosition(struct Screen *scr,
  18.              WORD scrWidth, WORD scrHeight,
  19.              WORD winWidth, WORD winHeight,
  20.              WORD *left, WORD *top,
  21.              WORD *zoomLeft, WORD *zoomTop) {
  22.   ULONG modeID;
  23.   struct Rectangle rect;
  24.  
  25.   if (*left == -1) {
  26.     *left = 0;
  27.     *top = 0;
  28.     modeID = GetVPModeID(&(scr->ViewPort));
  29.     if (modeID != INVALID_ID && QueryOverscan(modeID, &rect, OSCAN_TEXT)) {
  30.       if (scr->LeftEdge < 0) {
  31.     *left = -scr->LeftEdge;
  32.       }
  33.       if (scr->TopEdge < 0) {
  34.     *top = -scr->TopEdge;
  35.       }
  36.       *left += (rect.MaxX - rect.MinX + 1 - winWidth) / 2;
  37.       *top += (rect.MaxY - rect.MinY + 1 - winHeight) / 2;
  38.     }
  39.     *zoomLeft = *left;
  40.     *zoomTop = *top;
  41.   } else {
  42.     if (scr->Width != scrWidth) {
  43.       *left = (*left * scr->Width) / scrWidth;
  44.       *zoomLeft = (*left * scr->Width) / scrWidth;
  45.     }
  46.     if (scr->Height != scrHeight) {
  47.       *top = (*top * scr->Height) / scrHeight;
  48.       *zoomTop = (*zoomTop * scr->Height) / scrHeight;
  49.     }
  50.   }
  51. }
  52.  
  53.  
  54. VOID TitleBarExtent(struct Screen *scr, STRPTR title,
  55.             WORD *width, WORD *height) {
  56.   if (width != NULL) {
  57.     struct DrawInfo *dri;
  58.     struct Image *img;
  59.  
  60.     *width = TextLength(&scr->RastPort, title, (ULONG)strlen(title)) +
  61.       2 * INTERWIDTH;
  62.     dri = GetScreenDrawInfo(scr);
  63.     img = (struct Image *)NewObject(NULL, "sysiclass",
  64.                     SYSIA_DrawInfo, dri,
  65.                     SYSIA_Which, CLOSEIMAGE,
  66.                     TAG_DONE);
  67.     if (img != NULL) {
  68.       *width += img->Width;
  69.       DisposeObject(img);
  70.     } else {
  71.       *width += 20;
  72.     }
  73.     img = (struct Image *)NewObject(NULL, "sysiclass",
  74.                     SYSIA_DrawInfo, dri,
  75.                     SYSIA_Which, ZOOMIMAGE,
  76.                     TAG_DONE);
  77.     if (img != NULL) {
  78.       *width += img->Width;
  79.       DisposeObject(img);
  80.     } else {
  81.       *width += 24;
  82.     }
  83.     img = (struct Image *)NewObject(NULL, "sysiclass",
  84.                     SYSIA_DrawInfo, dri,
  85.                     SYSIA_Which, DEPTHIMAGE,
  86.                     TAG_DONE);
  87.     if (img != NULL) {
  88.       *width += img->Width;
  89.       DisposeObject(img);
  90.     } else {
  91.       *width += 24;
  92.     }
  93.   }
  94.  
  95.   if (height != NULL) {
  96.     *height = scr->WBorTop + scr->Font->ta_YSize + 1;
  97.   }
  98. }
  99.