home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 2000 April & May / AMIGA_2000_04.iso / patches / mesa3.1 / mesa-glut.lha / src-glut.aos / glutCreateWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-24  |  5.6 KB  |  194 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  1.1
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * glutCreateWindow.c
  23.  *
  24.  * Version 1.0  27 Jun 1998
  25.  * by Jarno van der Linden
  26.  * jarno@kcbbs.gen.nz
  27.  *
  28.  * Version 1.1  02 Aug 1998
  29.  * by Jarno van der Linden
  30.  * jarno@kcbbs.gen.nz
  31.  *
  32.  * - Quantizer plugin support added
  33.  *
  34.  */
  35.  
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <inline/intuition.h>
  39. #include <inline/gadtools.h>
  40. #include <inline/layers.h>
  41. #include <libraries/gadtools.h>
  42. #include <GL/amigamesa.h>
  43. #include "glutstuff.h"
  44.  
  45. extern VOID CloseWindowSafely(struct Window *win);
  46.  
  47. struct NewMenu defmenu[] =
  48. {
  49.   {NM_TITLE, "Left Menu", 0, 0, 0, 0,},
  50.   {NM_TITLE, "Middle Menu", 0, 0, 0, 0,},
  51.   {NM_TITLE, "Right Menu", 0, 0, 0, 0,},
  52.   {NM_END, NULL, 0, 0, 0, 0,}
  53. };
  54.  
  55. int glutCreateSubWindow(int win, int x, int y, int width, int height) {
  56.   struct GlutWindow *gw;
  57.   int newWinID = -1;
  58.  
  59.   IGNORE_IN_GAME_MODE(newWinID);
  60.  
  61.   if((gw = stuffGetWin(win))) {
  62.     glutInitWindowPosition(gw->wincurx + x, gw->wincury + y);
  63.     glutInitWindowSize(width, height);
  64.  
  65.     if ((newWinID = glutCreateWindow("subwindow")))
  66.       stuffLinkInSubWin(gw, stuffGetWin(newWinID));
  67.     else {
  68.       DEBUGOUT(1, "failed to open sub-window\n");
  69.       newWinID = -1;
  70.     }
  71.     
  72.     DEBUGOUT(2, "%d = glutCreateSubWindow(%d, %d, %d, %d, %d)\n", newWinID, win, x, y, width, height);
  73.   }
  74.   else
  75.     DEBUGOUT(1, "cannot subwindows parent\n");
  76.  
  77.   return newWinID;
  78. }
  79.  
  80. int glutCreateWindow(const char *title)
  81. {
  82.   struct GlutWindow *gw;
  83.  
  84.   if ((gw = AllocVecPooled(glutPool, sizeof(struct GlutWindow)))) {
  85.     struct Window *win;
  86.     struct Screen *screen;
  87.     WORD zoom[4];
  88.  
  89.     screen = LockPubScreen(glutstuff.pubscreenname);
  90.     zoom[0] = glutstuff.initposx;
  91.     zoom[1] = glutstuff.initposy;
  92.     zoom[2] = glutstuff.initwidth;
  93.     zoom[3] = glutstuff.initheight;
  94.  
  95.     win = gw->window = OpenWindowTags(NULL,
  96.                 WA_Title, (ULONG)title,
  97.                 WA_PubScreen, (ULONG)screen,
  98.                 WA_Left, glutstuff.initposx,
  99.                 WA_Top, glutstuff.initposy,
  100.                 WA_InnerWidth, glutstuff.initwidth,
  101.                 WA_InnerHeight, glutstuff.initheight,
  102.                 WA_MinWidth, 32,
  103.                 WA_MinHeight, 32,
  104.                 WA_MaxWidth, ~0,
  105.                 WA_MaxHeight, ~0,
  106.                 WA_Flags, WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_NOCAREREFRESH | WFLG_CLOSEGADGET | WFLG_DEPTHGADGET | WFLG_SIZEBBOTTOM | ((glutstuff.doublemode) ? WFLG_SIMPLE_REFRESH : WFLG_NOCAREREFRESH),
  107.                 WA_Activate, FALSE,                /* only by makecurrent */
  108.                 WA_Zoom, (ULONG)zoom,
  109.                 TAG_END);
  110.     UnlockPubScreen(NULL, screen);
  111.  
  112.     if (win) {
  113.       win->UserPort = glutstuff.msgport;
  114.  
  115. #ifdef USE_CLIP_LAYER_
  116.       gw->clipreg = clipWindowToBorders(win);
  117. #endif
  118.  
  119.       if ((gw->context = amigaMesaCreateContextTags(AMA_Window, win,
  120.                             AMA_RGBMode, (glutstuff.rgbamode ? (glutstuff.rgbamode < 0 ? GL_FALSE : GL_TRUE) : glutstuff.rgba),
  121.                             AMA_AlphaChannel, glutstuff.alpha,
  122.                             AMA_Stereo, (glutstuff.stereomode ? (glutstuff.stereomode < 0 ? GL_FALSE : GL_TRUE) : glutstuff.stereo),
  123.                             AMA_DoubleBuffer, (glutstuff.doublemode ? (glutstuff.doublemode < 0 ? GL_FALSE : GL_TRUE) : glutstuff.db),
  124.                             AMA_PaletteMode, glutstuff.palmode,
  125.                             AMA_RastPort, win->RPort,
  126.                             AMA_Screen, win->WScreen,
  127.                             AMA_Left, win->BorderLeft,
  128.                             AMA_Bottom, win->BorderBottom,
  129.                             AMA_Width, glutstuff.initwidth,
  130.                             AMA_Height, glutstuff.initheight,
  131.                             TAG_END))) {
  132.     if (ModifyIDCMP(win, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MENUPICK | IDCMP_MOUSEBUTTONS | IDCMP_INTUITICKS | IDCMP_CHANGEWINDOW)) {
  133.       dNewList(&gw->SubWindows);
  134.       dNewList(&gw->WindowTimers);
  135.  
  136.       win->UserData = (APTR)gw;
  137.       gw->vi = GetVisualInfo(win->WScreen, TAG_END);
  138.  
  139.       if ((gw->menu = CreateMenus(defmenu, TAG_END))) {
  140.         LayoutMenus(gw->menu, gw->vi, TAG_END);
  141.         SetMenuStrip(win, gw->menu);
  142.       }
  143.       else
  144.         DEBUGOUT(1, "failed to create menu\n");
  145.  
  146.       gw->cursor = GLUT_CURSOR_INHERIT;
  147.       gw->mousex = -1;
  148.       gw->mousey = -1;
  149.  
  150.       gw->winx = gw->wincurx = win->LeftEdge;
  151.       gw->winy = gw->wincury = win->TopEdge;
  152.       gw->winwidth = gw->wincurwidth = InnerWidth(win);
  153.       gw->winheight = gw->wincurheight = InnerHeight(win);
  154.  
  155.       gw->needreshapegui = TRUE;
  156.       gw->needpositiongui = TRUE;
  157.       gw->needredisplay = TRUE;
  158.       gw->needvisibility = TRUE;
  159.       gw->visible = TRUE;
  160.       gw->needleftmenu = TRUE;
  161.       gw->needmiddlemenu = TRUE;
  162.       gw->needrightmenu = TRUE;
  163.  
  164.       stuffLinkInWin(gw);
  165.  
  166.       if (glutstuff.depth)
  167.         glEnable(GL_DEPTH_TEST);
  168.  
  169.     //ActivateWindow(win);
  170.     //glutstuff.activeWindow = gw;
  171.       DEBUGOUT(2, "%d = glutCreateWindow(`%s')\n", gw->WinID, title);
  172.  
  173.       return gw->WinID;
  174.     }
  175.  
  176.     DEBUGOUT(1, "failed to modify internal window-state\n");
  177.     amigaMesaDestroyContext(gw->context);
  178.       }
  179.       else
  180.         DEBUGOUT(1, "failed to create context\n");
  181.  
  182.       CloseWindowSafely(win);
  183.     }
  184.     else
  185.       DEBUGOUT(1, "failed to open window\n");
  186.  
  187.     FreeVecPooled(glutPool, (ULONG *)gw);
  188.   }
  189.   else
  190.     DEBUGOUT(1, "failed to allocate window\n");
  191.  
  192.   return 0;
  193. }
  194.