⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ui_mac.c

📁 另一个分形程序
💻 C
字号:
/*	ui_mac.c		Xaos Fractal Viewer	Macintosh Driver 2.0		Written by Dominic Mazzoni (dmazzoni@cs.cmu.edu)	based on the Macintosh Driver (version 1.31) by	Tapio K. Vocadlo of Ottawa, Canada (taps@rmx.com).		XaoS version: 	3.1 beta	Driver version: 2.0		This file contains routines for two mac drivers,	the main Mac driver and the fullscreen mac driver.  Features / Notes:    * Uses the main monitor (the one with the menu bar).    * Supports 8-bit, 16-bit, or 32-bit color.  If the monitor is set to    any other depth, XaoS is told to render 8-bit and Quickdraw does the    translation to the screen    * Fullscreen mode hides and shows the menu bar using new (Mac OS 8.5)    routines that may not work on older systems.    * Menus are native in windowed mode, and XaoS-rendered in fullscreen mode.    * Supports resolution-switching on the fly*/#include "config.h"#include "filter.h"#ifdef _MAC// Cursor rez IDsconst short CURS_PAN = 202;const short CURS_PANACTIVE = 203;const short CURS_ZOOM = 204;	// not usedconst short CURS_ZOOMOUT = 205;	// not used// Splash pict IDconst short kSplashPICT = 128;// Menu IDsconst short apple_menu_id = 8000;const short about_item = 1;#include "version.h"#include "aconfig.h"#include <stdio.h>#include <fcntl.h>#include <string.h>#include <unistd.h>#include "zoom.h"//#include "gif.h"#include "ui.h"#include "ui_helper.h"#include "uiint.h"//#include "palette.h"#include <stdlib.h>#include <QDOffScreen.h>#include <Palettes.h>#include <Menus.h>#include "CommonDialogs.h"static void ui_setdriver (uih_context * c, int d);struct ui_driver mac_driver;struct ui_driver mac_full_driver;struct ui_driver mac_double_driver;static int mac_window_width = 0;static int mac_window_height = 0;static int mac_depth;static int full_screen_mode;static int mac_currentbuff = 0;static int mac_num_colors = 0;static WindowPtr mac_screen;static GWorldPtr mac_offscreen[2];static GDHandle mac_gdev = nil;static int mac_original_gdev_mode;static Boolean mac_palette_changed = true;static Boolean mac_show_grow_icon = true;static Boolean mac_panning = false;static GWorldPtr mac_grow_icon_gworld = nil;static RGBColor mac_text_color = { 0xFFFF, 0xFFFF, 0xFFFF };	// whitevoid SetWindPaletteFromClut (WindowPtr theWindow, CTabHandle theClut);GDHandle GetGameScreen (void);void RestoreGameScreen (void);void DrawNiceGrowIcon (WindowPtr w);void DoMenuCommand (long menuResult);static void mac_free_buffers (char *buffer1, char *buffer2);MenuHandle mac_createrootmenu ();void mac_menu_selected (int menu_id, int item);// SUPPORT ROUTINES ----------------------#define kIndexedGDeviceType			0#define kFixedGDeviceType			1#define kDirectGDeviceType			2// Handle menu command choicevoidDoMenuCommand (long menuResult){  int menuID, menuItem;  Str255 daName;  MenuHandle mh;  menuID = HiWord (menuResult);	/* use macros for efficiency to... */  menuItem = LoWord (menuResult);	/* get menu item number and menu number */  mh = GetMenuHandle (menuID);  if (menuID == apple_menu_id)    {      if (menuItem == about_item)	ui_key ('h');      else	{	  GetMenuItemText (mh, menuItem, daName);	  OpenDeskAcc (daName);	}    }  else if (menuItem > 0)    {      mac_menu_selected (menuID, menuItem);    }  HiliteMenu (0);		/* unhighlight what MenuSelect (or MenuKey) hilited */  FlushEvents (everyEvent, 0);}// Draw the standard grow icon but without the scrollbar lines.voidDrawNiceGrowIcon (WindowPtr w){  // Since DrawGrowIcon includes the scrollbar lines,  // the simple way to draw just the icon is to clip it  // to just the grow box.  Rect clipRect;  RgnHandle rh, rgnClip;  rh = NewRgn ();  GetClip (rh);  clipRect = w->portRect;  clipRect.left = clipRect.right - 15;  clipRect.top = clipRect.bottom - 15;  rgnClip = NewRgn ();  RectRgn (rgnClip, &clipRect);  SetClip (rgnClip);		// restore clip region  DrawGrowIcon (w);  SetClip (rh);			// restore clip region  DisposeRgn (rh);  DisposeRgn (rgnClip);}// Set a window's palette from a 'clut' resource handle.voidSetWindPaletteFromClut (WindowPtr theWindow, CTabHandle theClut){  // From 'Tricks of the Mac Game Programming Gurus', 1st ed., page 104-105,  // chapter 2, "Basic Game Graphics"  PaletteHandle thePalette;  // Create a palette from the clut  thePalette = GetPalette (theWindow);  if (thePalette == nil)    {      // create palette for window      thePalette = NewPalette ((**theClut).ctSize + 1, theClut, pmTolerant +			       pmExplicit, 0x0000);    }  else    {      // modify the window's palette to be the clut.      CTab2Palette (theClut, thePalette, pmTolerant + pmExplicit, 0x0000);    }  // Install palette into window  NSetPalette (theWindow, thePalette, pmAllUpdates);  // Update color environment  ActivatePalette (theWindow);}// Return a GDHandle to a mac_screen that can be drawn on.// If no such mac_screen, return nil.GDHandleGetGameScreen (){  mac_gdev = GetMainDevice ();	// Get device with menu bar, which we will use  mac_depth = (**(**mac_gdev).gdPMap).pixelSize;  return mac_gdev;}// Restore original monitor device pixel depth.voidRestoreGameScreen (){}// Buffer-to-window copy routine.static voiddisplay_refresh (){  PixMapHandle pmap, pmapicon;  GWorldPtr oldPort;  GDHandle oldDev;  Rect r;  if (mac_offscreen[mac_currentbuff] == nil)    return;  if (mac_show_grow_icon)    {      // Draw the grow icon onto the bitmap so it appears all the time.      GetGWorld (&oldPort, &oldDev);      r = mac_offscreen[mac_currentbuff]->portRect;      r.left = r.right - 15;      r.top = r.bottom - 15;      // Save current pixels.      SetGWorld (mac_grow_icon_gworld, nil);      ForeColor (blackColor);      BackColor (whiteColor);      pmap = GetGWorldPixMap (mac_offscreen[mac_currentbuff]);      pmapicon = GetGWorldPixMap (mac_grow_icon_gworld);      // Force color tables to be the same so speed is at maximum.      (*((*pmap)->pmTable))->ctSeed = (*((*pmapicon)->pmTable))->ctSeed;      CopyBits (&((GrafPtr) mac_offscreen[mac_currentbuff])->portBits,		&((GrafPtr) mac_grow_icon_gworld)->portBits, &r,		&mac_grow_icon_gworld->portRect, srcCopy, nil);      // Draw grow icon.                    SetGWorld (mac_offscreen[mac_currentbuff], nil);      //DrawNiceGrowIcon((WindowPtr) mac_offscreen[mac_currentbuff]); // won't work.      OffsetRect (&r, 1, 1);      PenSize (1, 1);      EraseRect (&r);      FrameRect (&r);      InsetRect (&r, 3, 3);      OffsetRect (&r, 1, 1);      FrameRect (&r);      InsetRect (&r, 1, 1);      OffsetRect (&r, -3, -3);      EraseRect (&r);      FrameRect (&r);      SetGWorld (oldPort, oldDev);    }  // An update event occurred, so just copy from our buffer to the mac_screen.  pmap = GetGWorldPixMap (mac_offscreen[mac_currentbuff]);  // Force color tables to be the same so speed is at maximum.  (*((*pmap)->pmTable))->ctSeed =    (*((*((*(mac_gdev))->gdPMap))->pmTable))->ctSeed;  CopyBits (&((GrafPtr) mac_offscreen[mac_currentbuff])->portBits,	    &((GrafPtr) mac_screen)->portBits,	    &mac_offscreen[mac_currentbuff]->portRect, &mac_screen->portRect,	    srcCopy, nil);  // Restore pixels.  if (mac_show_grow_icon)    {      r = mac_offscreen[mac_currentbuff]->portRect;      r.left = r.right - 15;      r.top = r.bottom - 15;      SetGWorld (mac_offscreen[mac_currentbuff], nil);      pmap = GetGWorldPixMap (mac_offscreen[mac_currentbuff]);      pmapicon = GetGWorldPixMap (mac_grow_icon_gworld);      // Force color tables to be the same so speed is at maximum.      (*((*pmap)->pmTable))->ctSeed = (*((*pmapicon)->pmTable))->ctSeed;      CopyBits (&((GrafPtr) mac_grow_icon_gworld)->portBits,		&((GrafPtr) mac_offscreen[mac_currentbuff])->portBits,		&mac_grow_icon_gworld->portRect, &r, srcCopy, nil);      SetGWorld (oldPort, oldDev);    }}// ------------------------------------------------------// XAOS UI API SUPPORT// Display c-string <text> at x,ystatic voidmac_print (int x, int y, CONST char *text){  static short lastY = 32000;  // Clear mac_screen if cursor has moved up or on same line.  if (y <= lastY)    display_refresh ();  //      EraseRect(&mac_screen->portRect);  lastY = y;  MoveTo (x + 3, y + 12);  RGBForeColor (&mac_text_color);  DrawText (text, 0, strlen (text));  ForeColor (blackColor);	// so copybits will work}// Display pixel buffer from fractal engine to window.static voidmac_display (){  PixMapHandle pmap;  if (mac_palette_changed)    {      mac_palette_changed = false;      ActivatePalette (mac_screen);    }  display_refresh ();}// Add color to palette.// r,g,b are 0-255 range color channel values.static intmac_set_color (int r, int g, int b, int init){  PaletteHandle hPalette;  RGBColor srcRGB;  if (init)    {      mac_num_colors = 1;      mac_palette_changed = true;	// signal mac_display to activate new palette    }  if (mac_num_colors == 255)    return (-1);  srcRGB.red = r * 256;  srcRGB.green = g * 256;  srcRGB.blue = b * 256;  hPalette = GetPalette (mac_screen);  SetEntryColor (hPalette, mac_num_colors - 1, &srcRGB);  return (mac_num_colors++);}// Switch current pixel buffer to copy from on next display update.static voidmac_flip_buffers (){  mac_currentbuff ^= 1;}// Deallocate any stuff we allocated at startup.static voidmac_uninitialize (){  int i;  for (i = 0; i < 2; i++)    {      if (mac_offscreen[i] != nil)	DisposeGWorld (mac_offscreen[i]);    }  DisposeWindow (mac_screen);  RestoreGameScreen ();  ShowMenuBar ();}static intmac_init (int fullScreen){  Rect r;  OSErr err, error;  SysEnvRec theWorld;  PixMapHandle pmap;  GWorldPtr oldWorld;  GDHandle oldDev;  CTabHandle clut;  int i;  PicHandle ph;  Rect rSplash;  Rect r2;  MenuHandle appleMenu;  char winTitle[255];  // Init the Mac Toolbox.  //      Test the computer to be sure we can do color.    //      If not we would crash, which would be bad.    //      If we can誸 run, just beep and exit.  //  static Boolean bBeenHere = false;  full_screen_mode = fullScreen;  if (!bBeenHere)    {      error = SysEnvirons (1, &theWorld);      if (theWorld.hasColorQD == false)	{	  SysBeep (1);	  ExitToShell ();	/* If no color QD, we must leave. */	}      /* Initialize all the needed managers. */      InitGraf (&qd.thePort);      InitFonts ();      InitWindows ();      InitMenus ();      TEInit ();      InitDialogs (nil);      InitCursor ();      //      //      To make the Random sequences truly random, we need to make the seed start      //      at a different number.  An easy way to do this is to put the current time      //      and date into the seed.  Since it is always incrementing the starting seed      //      will always be different.  Don誸 for each call of Random, or the sequence      //      will no longer be random.  Only needed once, here in the init.      //      GetDateTime ((unsigned long *) &qd.randSeed);      // Nicely acquire drawing device.      // Do this before the messier init/terminate stuff occurs.      if (!GetGameScreen ())	ExitToShell ();      // -- Mac Toolbox initialized.      bBeenHere = true;      // Install apple menu      appleMenu = NewMenu (apple_menu_id, "\p\024");      MacAppendMenu (appleMenu, "\pXaoS Help

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -