home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Libraries / mui / glutmui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  3.9 KB  |  128 lines  |  [TEXT/CWIE]

  1. /*
  2.  * Copyright (c) 1993-1997, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
  36.  */
  37.  
  38. #include "glut.h"
  39. #include "gizmo.h"
  40. #include <stdio.h>
  41.  
  42. int mui_xorg, mui_yorg, mui_xsize, mui_ysize;
  43. static GLint viewport[4];
  44. int mui_singlebuffered = 0;
  45. int menuinuse = 0;
  46.  
  47. static int mbleft = 0;
  48.  
  49. void setmousebuttons(int b, int s)
  50. {
  51.     switch (b) {
  52.     case GLUT_LEFT_BUTTON:
  53.         mbleft = (s == GLUT_DOWN);
  54.         break;
  55.     }
  56. }
  57.  
  58. void mui_drawgeom(void)
  59. {
  60.     glViewport(0, 0, mui_xsize, mui_ysize);
  61.     glMatrixMode(GL_PROJECTION);
  62.     glLoadIdentity();
  63.     gluOrtho2D(0, mui_xsize, 0, mui_ysize);
  64.     glMatrixMode(GL_MODELVIEW);
  65.     glLoadIdentity();
  66.     muiDrawUIList(1);
  67.     if (mui_singlebuffered == 0)
  68.     glutSwapBuffers();
  69. }
  70.  
  71. void mui_keyboard(unsigned char c, int x, int y)
  72. {
  73.     muiHandleEvent(MUI_KEYSTROKE, c, x, mui_ysize-y);
  74.     glutPostRedisplay();
  75. }
  76.  
  77. void mui_mouse(int b, int s, int x, int y)
  78. {
  79.     setmousebuttons(b, s);
  80.     if (b == GLUT_MIDDLE_BUTTON && s == GLUT_DOWN) {
  81.     muiHandleEvent(MUI_DEVICE_DOUBLE_CLICK, 0, x, mui_ysize-y);
  82.     glutPostRedisplay();
  83.     }
  84.     if (b != GLUT_LEFT_BUTTON) { return; }
  85.     muiHandleEvent((s==GLUT_DOWN)?MUI_DEVICE_PRESS:MUI_DEVICE_RELEASE, 0, x, mui_ysize-y);
  86.     glutPostRedisplay();
  87. }
  88.  
  89. static void mui_Reshape(int width, int height)
  90. {
  91.     mui_xorg = glutGet(GLUT_WINDOW_X);
  92.     mui_yorg = glutGet(GLUT_WINDOW_Y);
  93.     mui_xsize = width;
  94.     mui_ysize = height;
  95.     glViewport(0, 0, mui_xsize, mui_ysize);
  96.     glGetIntegerv(GL_VIEWPORT, viewport);
  97.     glutPostRedisplay();
  98. }
  99.  
  100. void mui_glutmotion(int x, int y)
  101. {
  102.     if (mbleft == 0) return;
  103.     muiHandleEvent(MUI_DEVICE_DOWN, 0, x, mui_ysize-y);
  104.     glutPostRedisplay();
  105. }
  106.  
  107. void mui_glutpassivemotion(int x, int y)
  108. {
  109.     muiHandleEvent(MUI_DEVICE_UP, 0, x, mui_ysize-y);
  110.     glutPostRedisplay();
  111. }
  112.  
  113. void mui_menufunc(int state)
  114. {
  115.     menuinuse = state;
  116. }
  117.  
  118. void muiInit(void)
  119. {
  120.     glutKeyboardFunc(mui_keyboard);
  121.     glutMouseFunc(mui_mouse);
  122.     glutReshapeFunc(mui_Reshape);
  123.     glutMotionFunc(mui_glutmotion);
  124.     glutPassiveMotionFunc(mui_glutpassivemotion);
  125.     glutDisplayFunc(mui_drawgeom);
  126.     glutMenuStateFunc(mui_menufunc);
  127. }
  128.