#include "InterfaceManager.h" #include "GameManager.h" static GLint LoadTexture(int Num) { PicHandle Picture; Rect PictureSize; GWorldPtr World, origGWorld; GDHandle origGDev; Ptr Pixels; GLuint Texture; OSErr error; GetGWorld(&origGWorld, &origGDev); Picture = GetPicture(Num); if (Picture == NULL || ResError() != noErr) return 0; PictureSize = (**Picture).picFrame; Pixels = NewPtrClear(PictureSize.right * PictureSize.bottom * 4); if (Pixels == NULL) return 0; error = QTNewGWorldFromPtr(&World, k32ARGBPixelFormat, &PictureSize, NULL, NULL, 0, Pixels, (PictureSize.right * 4)); if (error != noErr || World == NULL) return 0; SetGWorld(World, NULL); DrawPicture(Picture, &PictureSize); ReleaseResource((Handle) Picture); glGenTextures(1, &Texture); glBindTexture(GL_TEXTURE_2D, Texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, PictureSize.right, PictureSize.bottom, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, Pixels); SetGWorld(origGWorld, origGDev); DisposePtr(Pixels); DisposeGWorld(World); return Texture; } static pascal OSStatus MouseEventHandler(EventHandlerCallRef nextEvent, EventRef theEvent, void * userData) { #pragma unused(nextEvent) VGame * g; Point screenMouseLoc; GLfloat worldMouseLoc[2]; Rect gameWindowBounds; g = (VGame *) userData; if (g->Status != MENU) return eventNotHandledErr; if (GetEventKind(theEvent) == kEventMouseDown && g->Interface.TitleMovement < TITLEMOVE) { g->Interface.SplashUp = 0; g->Interface.SplashAlpha = 0.0; g->Interface.TitleAlpha = 1.0; g->Interface.TitleMovement = TITLEMOVE; return eventNotHandledErr; } g->Interface.TitleOver.Play = 0; g->Interface.TitleOver.Prefs = 0; g->Interface.TitleOver.Quit = 0; GetEventParameter(theEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &screenMouseLoc); if (!g->w.IsFullScreen) { GetWindowBounds(g->w.TheWindow, kWindowContentRgn, &gameWindowBounds); screenMouseLoc.h -= gameWindowBounds.left; screenMouseLoc.v -= gameWindowBounds.top; } gameWindowBounds = WindowSize(&g->w); worldMouseLoc[0] = ((screenMouseLoc.h * 800.0) / (float) gameWindowBounds.right); worldMouseLoc[1] = (600.0 - ((screenMouseLoc.v * 600.0) / (float) gameWindowBounds.bottom)); /* Hard coded interface element bounds... */ if (worldMouseLoc[0] > ((TITLEMOVE - 0.05) * 1000.0) && worldMouseLoc[0] < (((TITLEMOVE - 0.05) + (0.013 * 4)) * 1000.0) && worldMouseLoc[1] > (0.09 * 1000.0) && worldMouseLoc[1] < (0.11 * 1000.0)) { switch (GetEventKind(theEvent)) { case kEventMouseDown: SwitchMode(g, PLAYING); break; case kEventMouseMoved: g->Interface.TitleOver.Play = 1; break; } } else if (worldMouseLoc[0] > ((TITLEMOVE - 0.05) * 1000.0) && worldMouseLoc[0] < (((TITLEMOVE - 0.05) + (0.013 * 5)) * 1000.0) && worldMouseLoc[1] > (0.05 * 1000.0) && worldMouseLoc[1] < (0.07 * 1000.0)) { switch (GetEventKind(theEvent)) { case kEventMouseDown: if (g->Status == PLAYING && g->w.IsFullScreen) { CreateWindowedContext(&g->w); ShowCursor(); if (g->Paused) { glClear(GL_DEPTH_BUFFER_BIT); DrawWorld(&g->world, 1.0); aglSwapBuffers(g->w.Windowed); } } OpenSettingsWindow(GetSettings()); break; case kEventMouseMoved: g->Interface.TitleOver.Prefs = 1; break; } } else if (worldMouseLoc[0] > ((TITLEMOVE - 0.05) * 1000.0) && worldMouseLoc[0] < (((TITLEMOVE - 0.05) + (0.013 * 4)) * 1000.0) && worldMouseLoc[1] > (0.01 * 1000.0) && worldMouseLoc[1] < (0.03 * 1000.0)) { switch (GetEventKind(theEvent)) { case kEventMouseDown: QuitApplicationEventLoop(); break; case kEventMouseMoved: g->Interface.TitleOver.Quit = 1; break; } } return eventNotHandledErr; } void InitInterface(VInterface * i, VWindow * w, void * game) { VGame * g; EventTypeSpec eventTypes[2]; g = (VGame *)game; i->w = w; i->SplashTexture = LoadTexture(128); i->SplashDisp = glGenLists(1); i->SplashAlpha = 0; i->SplashUp = true; i->TitleAlpha = 0; i->TitleMovement = -TITLEMOVE; i->Title = "INFILTRATION"; i->TitleDone = false; i->TitleOver.Play = false; i->TitleOver.Prefs = false; i->TitleOver.Quit = false; glNewList(i->SplashDisp, GL_COMPILE); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, i->SplashTexture); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_QUADS); glTexCoord3i(0, 0, 0); glVertex2i(0, 512); glTexCoord3i(1, 0, 0); glVertex2i(512, 512); glTexCoord3i(1, 1, 0); glVertex2i(512, 0); glTexCoord3i(0, 1, 0); glVertex2i(0, 0); glEnd(); glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEndList(); eventTypes[0].eventClass = kEventClassMouse; eventTypes[0].eventKind = kEventMouseDown; eventTypes[1].eventClass = kEventClassMouse; eventTypes[1].eventKind = kEventMouseMoved; InstallApplicationEventHandler(NewEventHandlerUPP(MouseEventHandler), 2, eventTypes, g, NULL); } void DrawInterface(VInterface * i) { Rect TheSize; TheSize = WindowSize(i->w); OffsetRect(&TheSize, -TheSize.left, -TheSize.top); if(i->SplashAlpha) { glColor4f(1.0, 1.0, 1.0, i->SplashAlpha); glPushMatrix(); glScalef((800.0 / TheSize.right), (600.0 / TheSize.bottom), 0.0); glTranslatef(((TheSize.right / 2) - 256), ((TheSize.bottom / 2) - 256), 0); glCallList(i->SplashDisp); glPopMatrix(); } if(i->TitleAlpha) { glEnable(GL_LINE_SMOOTH); glColor4f(1, 0.25, 0, i->TitleAlpha); glPushMatrix(); glLineWidth(5); glScalef(4600.0, 6000.0, 1); glTranslatef(0.01, 0.027, 0); DrawCStringWithVectorFont(i->Title); glPopMatrix(); glPushMatrix(); glLineWidth(2); glScalef(1000, 1000, 1); if(i->TitleOver.Prefs) glColor4f(1, 0, 0, 1); else glColor4f(0, 0.8, 0, 1); glPushMatrix(); glTranslatef(-0.05 + i->TitleMovement, 0.05, 0); DrawCStringWithVectorFont("PREFS"); glPopMatrix(); if(i->TitleOver.Quit) glColor4f(1, 0, 0, 1); else glColor4f(0, 0.8, 0, 1); glPushMatrix(); glTranslatef(0.7 - i->TitleMovement, 0.01, 0); DrawCStringWithVectorFont("QUIT"); glPopMatrix(); if(i->TitleOver.Play) glColor4f(1, 0, 0, 1); else glColor4f(0, 0.8, 0, 1); glPushMatrix(); glTranslatef(0.7 - i->TitleMovement, 0.09, 0); DrawCStringWithVectorFont("PLAY"); glPopMatrix(); glLineWidth(1); glPopMatrix(); glDisable(GL_LINE_SMOOTH); } } void RunInterface(VInterface * i, float interval) { if(i->SplashUp) { i->SplashAlpha += (FADESPEED1 / interval); if(i->SplashAlpha >= 1) i->SplashUp = false; } else { if(i->SplashAlpha < 0) i->SplashAlpha = 0; else i->SplashAlpha -= (FADESPEED2 / interval); if(i->TitleAlpha < 1 - 0.00001) i->TitleAlpha += (FADESPEED3 / interval); else if(i->TitleAlpha > 1 + 0.00001) i->TitleAlpha = 1; if(i->TitleMovement < TITLEMOVE - 0.00001) i->TitleMovement += (0.000090 / interval); else if(i->TitleMovement > TITLEMOVE + 0.00001) i->TitleMovement = TITLEMOVE; } }