home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Id: Awindow.c 3.00 1998/09/21 19:17:47 NielsF Exp NielsF $
- */
-
- /*
- * (c) Copyright 1993, Silicon Graphics, Inc.
- * ALL RIGHTS RESERVED
- * Permission to use, copy, modify, and distribute this software for
- * any purpose and without fee is hereby granted, provided that the above
- * copyright notice appear in all copies and that both the copyright notice
- * and this permission notice appear in supporting documentation, and that
- * the name of Silicon Graphics, Inc. not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission.
- *
- * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
- * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
- * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
- * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
- * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
- * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
- * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
- * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
- * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
- */
-
- /*
- * $Log: Awindow.c $
- * Revision 3.0 1998/09/21 19:17:47 NielsF
- * bumped to mesa 3.0
- *
- * $Log: Awindow.c $
- * Revision 1.8 1997/06/25 19:17:47 StefanZ
- * bumped to mesa 2.2
- *
- * Revision 1.5 1996/10/07 00:18:11 StefanZ
- * Mesa 2.0 Fixed
- *
- * Revision 1.4 1996/08/14 22:53:16 StefanZ
- * rev 1.3 tk fixes was from George 'Wulf' Krämer
- *
- * Revision 1.3 1996/08/14 22:23:31 StefanZ
- * Modified due to api change in amigaMesa
- * Implemented div. Input modifier and changed windowhandling
- *
- * Revision 1.2 1996/06/02 00:03:03 StefanZ
- * Started to use RCS to keep track of code.
- *
- */
-
- /*
- * History:
- *
- * 1.0 960315 Now almost evetything is implemented
- * 1.1 960425 Fixed problem with double closeclicks (Thanx to Daniel Jönsson)
- * 1.2 960731 Modified due to api change in amigaMesa
- * 1.3 Implemented div. Input modifier and changed windowhandling (Georg 'Wulf' Krämer)
- *
- * TODO:
- * Exposefunc
- *
- *
- */
-
- #include <signal.h>
-
- #include <inline/exec.h>
- #include <inline/dos.h>
- #include <inline/graphics.h>
- #include <inline/layers.h>
- #include <inline/intuition.h>
-
- #include <devices/inputevent.h>
- #include <intuition/intuition.h>
-
- #include "awindow.h"
-
- /**********************************************************************/
-
- struct Library *DOSBase = NULL;
- struct Library *GfxBase = NULL;
- struct Library *IntuitionBase = NULL;
- struct Library *LayersBase = NULL;
-
- void tkShutDown(int code) {
- tkCloseWindow();
- exit(0);
- }
-
- void tkConstructor(void) {
- if(!(DOSBase = OpenLibrary("dos.library", 39))) {
- if ((DOSBase = OpenLibrary("dos.library", 0))) {
- Printf("Can't open dos.library version 39\n");
- CloseLibrary(DOSBase);
- }
- exit(10);
- }
- if(!(IntuitionBase = OpenLibrary("intuition.library", 39))) {
- Printf("Can't open intuition.library version 39\n");
- exit(10);
- }
- if(!(GfxBase = OpenLibrary("graphics.library", 39))) {
- Printf("Can't open graphics.library version 39\n");
- exit(10);
- }
- if(!(LayersBase = OpenLibrary("layers.library", 39))) {
- Printf("Can't open layers.library version 39\n");
- exit(10);
- }
-
- signal(SIGINT, tkShutDown);
- signal(SIGTERM, tkShutDown);
- }
-
- void tkDestructor(void) {
- if(DOSBase) {
- CloseLibrary(DOSBase);
- DOSBase = 0;
- }
- if(IntuitionBase) {
- CloseLibrary(IntuitionBase);
- IntuitionBase = 0;
- }
- if(GfxBase) {
- CloseLibrary(GfxBase);
- GfxBase = 0;
- }
- if(LayersBase) {
- CloseLibrary(LayersBase);
- LayersBase = 0;
- }
- }
-
- #if 0
- asm (" .text; .stabs \"___CTOR_LIST__\",22,0,0,_constructor");
- asm (" .text; .stabs \"___DTOR_LIST__\",22,0,0,_destructor");
- #endif
-
- /**********************************************************************/
-
- /* Some Bitmasks for amigaevents */
- #define ControlMask (IEQUALIFIER_CONTROL)
- #define ShiftMask (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)
- #define MousePressedMask (SELECTDOWN | MENUDOWN | MIDDLEDOWN)
-
- /**********************************************************************/
-
- struct tkWindow actWindow = {
- 0, 0, 100, 100,
- TK_INDEX, 0,
- 0,
-
- NULL,
- NULL,
- NULL
- #ifdef USE_CLIP_LAYER
- ,NULL
- #endif
- };
-
- static GLboolean tkPopupEnable = TRUE;
-
- float colorMaps[] = {
- 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000,
- 0.000000, 1.000000, 0.333333, 0.776471, 0.443137, 0.556863,
- 0.443137, 0.556863, 0.219608, 0.666667, 0.666667, 0.333333,
- 0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
- 0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
- 0.666667, 0.333333, 0.039216, 0.078431, 0.117647, 0.156863,
- 0.200000, 0.239216, 0.278431, 0.317647, 0.356863, 0.400000,
- 0.439216, 0.478431, 0.517647, 0.556863, 0.600000, 0.639216,
- 0.678431, 0.717647, 0.756863, 0.800000, 0.839216, 0.878431,
- 0.917647, 0.956863, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000,
- 1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000,
- 0.333333, 0.443137, 0.776471, 0.556863, 0.443137, 0.219608,
- 0.556863, 0.666667, 0.666667, 0.333333, 0.666667, 0.333333,
- 0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
- 0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
- 0.039216, 0.078431, 0.117647, 0.156863, 0.200000, 0.239216,
- 0.278431, 0.317647, 0.356863, 0.400000, 0.439216, 0.478431,
- 0.517647, 0.556863, 0.600000, 0.639216, 0.678431, 0.717647,
- 0.756863, 0.800000, 0.839216, 0.878431, 0.917647, 0.956863,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
- 0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
- 0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
- 0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
- 0.854902, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 0.333333, 0.443137,
- 0.443137, 0.219608, 0.776471, 0.556863, 0.556863, 0.666667,
- 0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
- 0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
- 0.666667, 0.333333, 0.666667, 0.333333, 0.039216, 0.078431,
- 0.117647, 0.156863, 0.200000, 0.239216, 0.278431, 0.317647,
- 0.356863, 0.400000, 0.439216, 0.478431, 0.517647, 0.556863,
- 0.600000, 0.639216, 0.678431, 0.717647, 0.756863, 0.800000,
- 0.839216, 0.878431, 0.917647, 0.956863, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
- 0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
- 0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
- 0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
- };
-
- float tkRGBMap[8][3] =
- {
- {0, 0, 0},
- {1, 0, 0},
- {0, 1, 0},
- {1, 1, 0},
- {0, 0, 1},
- {1, 0, 1},
- {0, 1, 1},
- {1, 1, 1}
- };
-
- /**********************************************************************/
- /* Local prototypes */
-
- #ifdef USE_CLIP_LAYER
- static struct Region *clipWindow(struct Window *win, LONG minX, LONG minY, LONG maxX, LONG maxY);
- static struct Region *clipWindowToBorders(struct Window *win);
- #endif
-
- static void (*ExposeFunc) (int, int) = NULL;
- static void (*ReshapeFunc) (GLsizei, GLsizei) = NULL;
- static void (*DisplayFunc) (void) = NULL;
- static GLenum(*KeyDownFunc) (int, GLenum) = NULL;
- static GLenum(*MouseDownFunc) (int, int, GLenum) = NULL;
- static GLenum(*MouseUpFunc) (int, int, GLenum) = NULL;
- static GLenum(*MouseMoveFunc) (int, int, GLenum) = NULL;
- static void (*IdleFunc) (void) = NULL;
-
- /**********************************************************************/
-
- #ifdef USE_CLIP_LAYER
- /*
- * clipWindow()
- * Clip a window to a specified rectangle (given by upper left and
- * lower right corner.) the removed region is returned so that it
- * may be re-installed later.
- */
- static struct Region *clipWindow(struct Window *win, LONG minX, LONG minY, LONG maxX, LONG maxY)
- {
- struct Region *new_region;
- struct Rectangle my_rectangle;
-
- /* set up the limits for the clip */
- my_rectangle.MinX = minX;
- my_rectangle.MinY = minY;
- my_rectangle.MaxX = maxX;
- my_rectangle.MaxY = maxY;
-
- /* get a new region and OR in the limits. */
- if ((new_region = NewRegion())) {
- if (!OrRectRegion(new_region, &my_rectangle)) {
- DisposeRegion(new_region);
- new_region = NULL;
- }
- }
-
- /*
- * Install the new region, and return any existing region.
- * If the above allocation and region processing failed, then
- * new_region will be NULL and no clip region will be installed.
- */
- return (InstallClipRegion(win->WLayer, new_region));
- }
-
- /*
- * clipWindowToBorders()
- * clip a window to its borders.
- * The removed region is returned so that it may be re-installed later.
- */
- struct Region *clipWindowToBorders(struct Window *win)
- {
- return (clipWindow(win, win->BorderLeft, win->BorderTop, win->Width - win->BorderRight - 1, win->Height - win->BorderBottom - 1));
- }
- #endif
-
- /******************************************************************************/
-
- ULONG atk_setIDCMPs(void)
- {
- ULONG mask;
-
- mask = IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE;
- if (ReshapeFunc)
- mask |= IDCMP_NEWSIZE;
- if (KeyDownFunc)
- mask |= (IDCMP_RAWKEY | IDCMP_VANILLAKEY);
- if (MouseDownFunc || MouseUpFunc)
- mask |= IDCMP_MOUSEBUTTONS;
- if (MouseMoveFunc)
- mask |= IDCMP_MOUSEMOVE;
-
- return (mask);
- }
-
- /* TODO (*ExposeFunc)(int, int) */
-
- void atk_modifyIDCMP(void)
- {
- if (actWindow.window)
- ModifyIDCMP(actWindow.window, atk_setIDCMPs());
- }
-
- int atk_FixKeyRAW(char c)
- {
- int key;
-
- switch (c) {
- case CURSORLEFT:
- key = TK_LEFT;
- break;
- case CURSORUP:
- key = TK_UP;
- break;
- case CURSORRIGHT:
- key = TK_RIGHT;
- break;
- case CURSORDOWN:
- key = TK_DOWN;
- break;
- default:
- key = GL_FALSE;
- break;
- }
- return (key);
- }
-
- /******************************************************************************/
- /* cursor.c */
- /******************************************************************************/
-
- void tkNewCursor(GLint id, GLubyte * shapeBuf, GLubyte * maskBuf, GLenum fgColor,
- GLenum bgColor, GLint hotX, GLint hotY) {}
- void tkSetCursor(GLint id) {}
-
- /******************************************************************************/
- /* */
- /******************************************************************************/
-
- void tkErrorPopups(GLboolean bEnable)
- {
- tkPopupEnable = bEnable;
- }
-
- /******************************************************************************/
- /* window.c */
- /******************************************************************************/
-
- void tkCloseWindow(void)
- {
- if (actWindow.context) {
- amigaMesaDestroyContext(actWindow.context);
- actWindow.context = NULL;
- }
- #ifdef USE_CLIP_LAYER
- if (actWindow.clipreg) {
- actWindow.clipreg = InstallClipRegion(actWindow.window->WLayer, actWindow.clipreg);
- DisposeRegion(actWindow.clipreg);
- actWindow.clipreg = NULL;
- }
- #endif
- if (actWindow.window) {
- CloseWindow(actWindow.window);
- actWindow.window = NULL;
- }
- }
-
- void tkInitDisplayModePolicy(GLenum type)
- {
- actWindow.dmPolicy = type;
- }
-
- GLenum tkInitDisplay(void)
- {
- return GL_TRUE;
- }
-
- void tkInitDisplayMode(GLenum type)
- {
- actWindow.type = type;
- }
-
- GLenum tkInitDisplayModeID(GLint ID)
- {
- if(!actWindow.window)
- return GL_FALSE;
- else {
- actWindow.ID = ID;
- return GL_TRUE;
- }
- }
-
- void tkInitPosition(int x, int y, int width, int height)
- {
- actWindow.left = x;
- actWindow.top = y;
- actWindow.width = width;
- actWindow.height = height;
- }
-
- GLenum tkInitWindow(char *title)
- {
- GLenum Result = GL_FALSE, RGB_Flag = GL_TRUE, DB_Flag = GL_FALSE;
-
- if (!(actWindow.screen = LockPubScreen("Mesa")))
- actWindow.screen = LockPubScreen(NULL);
- if (actWindow.screen) {
- if (actWindow.type & TK_INDEX)
- RGB_Flag = GL_FALSE;
- if (actWindow.type & TK_DOUBLE)
- DB_Flag = GL_TRUE;
-
- /* open the window on the public actWindow.screen */
- actWindow.window = OpenWindowTags(NULL,
- WA_Left, actWindow.left,
- WA_Top, actWindow.left,
- WA_InnerWidth, actWindow.width,
- WA_InnerHeight, actWindow.height,
- WA_ReportMouse, TRUE,
- WA_RMBTrap, TRUE, /* Detect right mouse events, no Menus */
- WA_MinWidth, 100, WA_MinHeight, 30,
- WA_MaxWidth, -1, WA_MaxHeight, -1,
- WA_IDCMP, atk_setIDCMPs(),
- WA_Flags, WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_REPORTMOUSE | WFLG_CLOSEGADGET | WFLG_DEPTHGADGET | WFLG_SIZEBBOTTOM | ((DB_Flag) ? WFLG_SIMPLE_REFRESH : WFLG_NOCAREREFRESH),
- WA_Title, (ULONG)title,
- WA_PubScreen, (ULONG)actWindow.screen,
- TAG_END);
- /*
- * Unlock the actWindow.screen. The window now acts as a lock on
- * the actWindow.screen, and we do not need the actWindow.screen after the
- * window has been closed.
- */
- UnlockPubScreen(NULL, actWindow.screen);
-
- if (actWindow.window) {
- amigaMesaBuffer buffer = NULL;
-
- #ifdef USE_CLIP_LAYER
- actWindow.clipreg = clipWindowToBorders(actWindow.window);
- #endif
-
- actWindow.context = amigaMesaCreateContextTags(AMA_Window, (ULONG)actWindow.window,
- AMA_RastPort, (ULONG)actWindow.window->RPort,
- AMA_Screen, (ULONG)actWindow.window->WScreen,
- AMA_DoubleBuffer, DB_Flag,
- AMA_RGBMode, RGB_Flag,
- AMA_Left, actWindow.window->BorderLeft,
- AMA_Bottom, actWindow.window->BorderBottom,
- AMA_Width, actWindow.width,
- AMA_Height, actWindow.height,
- TAG_DONE, 0);
- amigaMesaGetContextTags(actWindow.context, AMA_Buffer, &buffer, TAG_DONE, 0);
- if (buffer)
- amigaMesaMakeCurrent(actWindow.context, buffer);
-
- tkSetRGBMap(256, colorMaps);
-
- Result = GL_TRUE;
- }
- else
- Printf("Failed to open a tkWindow.\n");
- }
-
- return Result;
- }
-
- /*
- * You cannot just call DestroyWindow() here. The programs do not expect
- * tkQuit() to return; DestroyWindow() just sends a WM_DESTROY message
- */
-
- void tkQuit(void)
- {
- tkCloseWindow();
- exit(0);
- }
-
- void tkSwapBuffers(void)
- {
- amigaMesaSwapBuffers(actWindow.context);
- }
-
- /******************************************************************************/
- /* events.c */
- /******************************************************************************/
-
- void tkExec(void)
- {
- struct IntuiMessage *msg, cmsg;
- BOOL wanttoquit = FALSE;
- BOOL press = FALSE;
- int key, id;
-
- /* Redraw handling changed by Wulf 11. Aug. 96 to ensure the
- * same handling under all systems
- */
- GLenum Redraw = GL_FALSE;
-
- if (ReshapeFunc)
- (*ReshapeFunc) (InnerWidth(actWindow.window), InnerHeight(actWindow.window));
-
- if (DisplayFunc)
- (*DisplayFunc) ();
-
- while (!wanttoquit) {
- if ((msg = (struct IntuiMessage *)GetMsg(actWindow.window->UserPort))) {
- cmsg = *msg;
-
- ReplyMsg((struct Message *)msg);
-
- /* after ReplyMsg, you are nolonger allowed to use msg ! */
- switch (cmsg.Class) {
- case IDCMP_NEWSIZE:
- /* Sizes should be adjusted by border, but painting isn't adjusted :-( */
- actWindow.width = InnerWidth(cmsg.IDCMPWindow);
- actWindow.height = InnerHeight(cmsg.IDCMPWindow);
- #ifdef USE_CLIP_LAYER
- if (actWindow.clipreg) /* Get rid of last clipping region */
- DisposeRegion(InstallClipRegion(cmsg.IDCMPWindow->WLayer, NULL));
- clipWindowToBorders(cmsg.IDCMPWindow);
- #endif
- if (ReshapeFunc)
- (*ReshapeFunc) (actWindow.width, actWindow.height);
- Redraw = GL_TRUE; /* very likely to make everything new */
- break;
- case IDCMP_RAWKEY:
- key = atk_FixKeyRAW(cmsg.Code);
- if (key && KeyDownFunc) {
- GLenum mask;
-
- mask = 0;
- if (cmsg.Qualifier & ControlMask)
- mask |= TK_CONTROL;
- if (cmsg.Qualifier & ShiftMask)
- mask |= TK_SHIFT;
- Redraw = (*KeyDownFunc) (key, mask);
- }
- break;
- case IDCMP_VANILLAKEY:
- if (KeyDownFunc) {
- GLenum mask;
-
- mask = 0;
- if (cmsg.Qualifier & ControlMask)
- mask |= TK_CONTROL;
- if (cmsg.Qualifier & ShiftMask)
- mask |= TK_SHIFT;
- key = cmsg.Code;
- Redraw = (*KeyDownFunc) (key, mask);
- }
- break;
- case IDCMP_MOUSEMOVE:
- if (MouseMoveFunc) {
- int x = cmsg.MouseX, y = cmsg.MouseY;
-
- Redraw = (*MouseMoveFunc) (x, y, press);
- }
- break;
- case IDCMP_MOUSEBUTTONS:
- /* Buttonhandling changed Wulf 11.08.96 */
- {
- GLenum mask = 0;
- int x = cmsg.MouseX, y = cmsg.MouseY;
-
- switch (cmsg.Code) {
- case SELECTDOWN:
- case SELECTUP:
- mask |= TK_LEFTBUTTON;
- break;
- case MIDDLEDOWN:
- case MIDDLEUP:
- mask |= TK_MIDDLEBUTTON;
- break;
- case MENUDOWN:
- case MENUUP:
- mask |= TK_RIGHTBUTTON;
- break;
- }
- if (cmsg.Qualifier & ControlMask)
- mask |= TK_CONTROL;
- if (cmsg.Qualifier & ShiftMask)
- mask |= TK_SHIFT;
- if ((cmsg.Code & MousePressedMask)) {
- press = mask;
- if (MouseDownFunc)
- Redraw = (*MouseDownFunc) (x, y, mask);
- }
- else {
- if (MouseUpFunc)
- Redraw = (*MouseUpFunc) (x, y, mask);
- press = 0;
- }
- }
- break;
- case IDCMP_REFRESHWINDOW: /* received only in DB-mode, non-DB-modes are NoCareRefresh */
- BeginRefresh(cmsg.IDCMPWindow);
- tkSwapBuffers(); /* put current contents into damaged region */
- EndRefresh(cmsg.IDCMPWindow, TRUE);
- if (ExposeFunc)
- (*ExposeFunc) (actWindow.width, actWindow.height);
- break;
- case IDCMP_CLOSEWINDOW:
- wanttoquit = TRUE;
- break;
- default:
- break;
- }
- }
- /* TODO Fill this with tests and call apropriate functions */
- if (IdleFunc) {
- (*IdleFunc) ();
- Redraw = GL_TRUE;
- }
- if ((Redraw == GL_TRUE) && DisplayFunc) { /* Redraw handling changed by Wulf 11. Aug. 96 */
- (*DisplayFunc) ();
- Redraw = GL_FALSE;
- }
- if (!wanttoquit && !IdleFunc) {
- WaitPort(actWindow.window->UserPort);
- }
- }
- tkQuit(); /* do not return after quit */
- }
-
- void tkExposeFunc(void (*Func) (int, int))
- {
- ExposeFunc = Func;
- atk_modifyIDCMP();
- }
-
- void tkReshapeFunc(void (*Func) (GLsizei, GLsizei))
- {
- ReshapeFunc = Func;
- atk_modifyIDCMP();
- }
-
- void tkDisplayFunc(void (*Func) (void))
- {
- DisplayFunc = Func;
- }
-
- void tkKeyDownFunc(GLenum(*Func) (int, GLenum))
- {
- KeyDownFunc = Func;
- atk_modifyIDCMP();
- }
-
- void tkMouseDownFunc(GLenum(*Func) (int, int, GLenum))
- {
- MouseDownFunc = Func;
- atk_modifyIDCMP();
- }
-
- void tkMouseUpFunc(GLenum(*Func) (int, int, GLenum))
- {
- MouseUpFunc = Func;
- atk_modifyIDCMP();
- }
-
- void tkMouseMoveFunc(GLenum(*Func) (int, int, GLenum))
- {
- MouseMoveFunc = Func;
- atk_modifyIDCMP();
- }
-
- void tkIdleFunc(void (*Func) (void))
- {
- IdleFunc = Func;
- }
-
- /******************************************************************************/
- /* getset.c */
- /******************************************************************************/
-
- GLint tkGetColorMapSize(void)
- {
- /*
- * AmigaMesa simulates 8bit-Index in any case,
- * so we have 256 colors allways
- */
- return (256);
- }
-
- void tkGetMouseLoc(int *x, int *y)
- {
- *x = actWindow.window->MouseX;
- *y = actWindow.window->MouseY;
- }
-
- void tkGetSystem(TKenum type, void *ptr)
- {
- switch (type) {
- case TK_AOS_SCREEN:
- *((struct Screen **)ptr) = actWindow.screen;
- break;
- case TK_AOS_WINDOW:
- *((struct Window **)ptr) = actWindow.window;
- break;
- case TK_AOS_CONTEXT:
- *((struct amigamesa_context **)ptr) = actWindow.context;
- break;
- default:
- *((int **)ptr) = 0;
- break;
- }
- }
-
- void tkSetFogRamp(int density, int startIndex)
- {
- int fogValues, colorValues;
- int i, j, k;
- float intensity;
-
- fogValues = 1 << density;
- colorValues = 1 << startIndex;
- for (i = 0; i < colorValues; i++) {
- for (j = 0; j < fogValues; j++) {
- k = i * fogValues + j;
- intensity = (i * fogValues + j * colorValues) / 255.0;
- tkSetOneColor(k, intensity, intensity, intensity);
- }
- }
- }
-
- void tkSetGreyRamp(void)
- {
- int i;
- float intensity;
-
- for (i = 0; i < 255; i++) {
- intensity = i / 255.0;
- tkSetOneColor(i, intensity, intensity, intensity);
- }
- }
-
- void tkSetOneColor(int index, float r, float g, float b)
- {
- amigaMesaSetOneColor(actWindow.context, index, r, g, b);
- }
-
- void tkSetOverlayMap(int size, float *rgb)
- {
- Printf("tkSetOverlayMap(%d,%f) TODO\n", size, *rgb);
- }
-
- void tkSetRGBMap(int Size, float *Values)
- {
- int i;
-
- if (Size > 256)
- Size = 256;
-
- for (i = 0; i < Size; i++) {
- tkSetOneColor(i, Values[ i],
- Values[Size + i],
- Values[Size * 2 + i]);
- }
- }
-
- GLenum tkSetWindowLevel(GLenum level)
- {
- Printf("tkSetWindowLevel(%d) TODO\n", level);
- return GL_FALSE;
- }
-
- /******************************************************************************/
- /* */
- /******************************************************************************/
-
- GLint tkGetDisplayModeID(void)
- {
- return actWindow.ID;
- }
-
- GLint tkGetDisplayModePolicy(void)
- {
- return actWindow.dmPolicy;
- }
-
- GLenum tkGetDisplayMode(void)
- {
- return actWindow.type;
- }
-
- #undef USE_CLIP_LAYER
-