Ejemplo n.º 1
0
void
AdjustScreen(register struct Screen *screen, int *dx, int *dy)
{
  int c640, c320, r400, r200, w, h, max_x, max_y;
  struct Preferences prefs;
  extern struct GfxBase *GfxBase;

  GetPrefs(&prefs, sizeof(prefs));
  c640 = 640 + prefs.ColumnSizeChange;
  c320 = c640 / 2;
  r200 = 200 + prefs.RowSizeChange;
  r400 = r200 * 2;

  max_y = (GfxBase->DisplayFlags & PAL) ? MAX_Y_PAL : MAX_Y_NTSC;
  if (screen->ViewPort.Modes & LACE){
    max_y *= 2;
  }
  max_x = MAX_X;
  if (screen->ViewPort.Modes & HIRES){
    max_x *= 2;
  }
  if (screen->ViewPort.DWidth <= max_x) {
    w = screen->ViewPort.DWidth;
  }else{
    w = max_x;
  }
  if (screen->ViewPort.DHeight <= max_y) {
    h = screen->ViewPort.DHeight;
  }else{
    h = max_y;
  }

  if (screen->ViewPort.Modes & HIRES){
    if (w > c640) {
      screen->ViewPort.DxOffset += (c640 - w) / 2;
    }
    *dx = screen->ViewPort.DxOffset / 2;
  }else{
    if (w > c320) {
      screen->ViewPort.DxOffset += (c320 - w) / 2;
    }
    *dx = screen->ViewPort.DxOffset;
  }
  if (screen->ViewPort.Modes & LACE){
    if (h > r400) {
      screen->ViewPort.DyOffset += (r400 - h) / 2;
    }
    *dy = screen->ViewPort.DyOffset / 2;
  }else{
    if (h > r200) {
      screen->ViewPort.DyOffset += (r200 - h) / 2;
    }
    *dy = screen->ViewPort.DyOffset;
  }

  RemakeDisplay();
}
Ejemplo n.º 2
0
	virtual void MessageReceived(BMessage* msg)
	{
		switch( msg->what ) {
			case OK_MSG:
				if( mTarget.IsValid() ) {
					BMessage		msg(OWQ_ADD);
					if( !mOldPrefs.IsEmpty() ) msg.AddMessage( "old item", &mOldPrefs );
					if( GetPrefs( msg ) == B_OK ) mTarget.SendMessage( &msg );
				}
				Quit();
				break;
			case CANCEL_MSG:
				Quit();
				break;
			case OWQ_CHOOSE_FILE_MSG:
				{
					if( !mFilePanel ) mFilePanel = new BFilePanel(B_OPEN_PANEL, 0, 0, 0,
																	false);
					if( mFilePanel->IsShowing() ) break;
					if( mFilePanel->Window() ) {
						mFilePanel->Window()->SetTitle("Select File" B_UTF8_ELLIPSIS);
					}
					
					mFilePanel->SetTarget(BMessenger(this));
					mFilePanel->SetMessage( new BMessage('entr') );
					mFilePanel->Show();
				}
				break;
			case 'entr':
				{
					entry_ref	ref;
					if( msg->FindRef( "refs", &ref ) == B_OK ) {
						delete mRef;
						mRef = new entry_ref( ref );
					}
				}
				break;
			case OWQ_ON_MSG:
				{
					bool	enable = false;
					if( mOnBox && mOnBox->Value() == B_CONTROL_ON ) enable = true;
					SetControlEnable(enable);
				}
				break;
			case SET_PREFS_MSG:
				SetPrefs( msg );
				break;
			default:
				BWindow::MessageReceived(msg);
				break;
		}
	}
Ejemplo n.º 3
0
TWindow::TWindow(int32 pixelCount)
	:
	BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Magnify"),
		B_TITLED_WINDOW, B_OUTLINE_RESIZE)
{
	GetPrefs(pixelCount);

	// add info view
	BRect infoRect(Bounds());
	infoRect.InsetBy(-1, -1);
	fInfo = new TInfoView(infoRect);
	AddChild(fInfo);

	fFontHeight = FontHeight(fInfo, true);
	fInfoHeight = (fFontHeight * 2) + (3 * 5);

	BRect fbRect(0, 0, (fHPixelCount*fPixelSize), (fHPixelCount*fPixelSize));
	if (InfoIsShowing())
		fbRect.OffsetBy(10, fInfoHeight);
	fFatBits = new TMagnify(fbRect, this);
	fInfo->AddChild(fFatBits);

	fFatBits->SetSelection(fShowInfo);
	fInfo->SetMagView(fFatBits);

	ResizeWindow(fHPixelCount, fVPixelCount);
	UpdateInfoBarOnResize();

	AddShortcut('S', B_COMMAND_KEY, new BMessage(msg_save));
	AddShortcut('C', B_COMMAND_KEY, new BMessage(msg_copy_image));
	AddShortcut('T', B_COMMAND_KEY, new BMessage(msg_show_info));
	AddShortcut('H', B_COMMAND_KEY, new BMessage(msg_add_cross_hair));
	AddShortcut('H', B_SHIFT_KEY, 	new BMessage(msg_remove_cross_hair));
	AddShortcut('G', B_COMMAND_KEY, new BMessage(msg_toggle_grid));
	AddShortcut('F', B_COMMAND_KEY, new BMessage(msg_freeze));
	AddShortcut('I', B_COMMAND_KEY, new BMessage(msg_stick));
	AddShortcut('-', B_COMMAND_KEY, new BMessage(msg_shrink));
	AddShortcut('=', B_COMMAND_KEY, new BMessage(msg_grow));
	AddShortcut('/', B_COMMAND_KEY, new BMessage(msg_make_square));
	AddShortcut(',', B_COMMAND_KEY, new BMessage(msg_shrink_pixel));
	AddShortcut('.', B_COMMAND_KEY, new BMessage(msg_grow_pixel));
}
Ejemplo n.º 4
0
/******* SerialUnit::New() ***********************************/
OOP_Object *PCSerUnit__Root__New(OOP_Class *cl, OOP_Object *obj, struct pRoot_New *msg)
{
    struct HIDDSerialUnitData * data;
    struct TagItem *tag, *tstate;
    ULONG unitnum = 0;

    EnterFunc(bug("SerialUnit::New()\n"));

    tstate = msg->attrList;
    while ((tag = NextTagItem((const struct TagItem **)&tstate)))
    {
        ULONG idx;

#define csd CSD(cl->UserData)
        if (IS_HIDDSERIALUNIT_ATTR(tag->ti_Tag, idx))
#undef csd
        {
            switch (idx)
            {
            case aoHidd_SerialUnit_Unit:
                unitnum = (ULONG)tag->ti_Data;
                break;
            }
        }

    } /* while (tags to process) */

    obj = (OOP_Object *)OOP_DoSuperMethod(cl, obj, (OOP_Msg)msg);

    if (obj)
    {
        struct IntuitionBase * IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
        data = OOP_INST_DATA(cl, obj);

        data->baseaddr = bases[unitnum];

        if (NULL != IntuitionBase) {
            struct Preferences prefs;
            GetPrefs(&prefs,sizeof(prefs));
            data->baudrate      = prefs.BaudRate;
            adapt_data(data, &prefs);
            CloseLibrary((struct Library *)IntuitionBase);
        } else {
            data->datalength = 8;
            data->parity     = FALSE;
            data->baudrate   = 9600; /* will be initialize in set_baudrate() */
        }
        data->unitnum    = unitnum;

        Disable();
        CSD(cl->UserData)->units[data->unitnum] = data;
        Enable();

        D(bug("Unit %d at 0x0%x\n", data->unitnum, data->baseaddr));

        /* Wake up UART */
        serial_outp(data, UART_LCR, 0xBF);
        serial_outp(data, UART_EFR, UART_EFR_ECB);
        serial_outp(data, UART_IER, 0);
        serial_outp(data, UART_EFR, 0);
        serial_outp(data, UART_LCR, 0);

        /* clear the FIFOs */
        serial_outp(data, UART_FCR, (UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT));

        /* clear the interrupt registers */
        (void)serial_inp(data, UART_RX);
        (void)serial_inp(data, UART_IIR);
        (void)serial_inp(data, UART_MSR);

        /* initilize the UART */
        serial_outp(data, UART_LCR, get_lcr(data));

        serial_outp(data, UART_MCR, UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS);
        serial_outp(data, UART_IER, UART_IER_RDI | UART_IER_THRI | UART_IER_RLSI | UART_IER_MSI);

        /* clear the interrupt registers again ... */
        (void)serial_inp(data, UART_LSR);
        (void)serial_inp(data, UART_RX);
        (void)serial_inp(data, UART_IIR);
        (void)serial_inp(data, UART_MSR);

        set_baudrate(data, data->baudrate);
    } /* if (obj) */

    ReturnPtr("SerialUnit::New()", OOP_Object *, obj);
}
Ejemplo n.º 5
0
bool GollyApp::OnInit()
{
   SetAppName(_("Golly"));    // for use in Warning/Fatal dialogs

   // create a stopwatch so we can use Time() to get elapsed millisecs
   stopwatch = new wxStopWatch();
   
   // set variable seed for later rand() calls
   srand(time(0));

   #if defined(__WXMAC__) && !wxCHECK_VERSION(2,7,2)
      // prevent rectangle animation when windows open/close
      wxSystemOptions::SetOption(wxMAC_WINDOW_PLAIN_TRANSITION, 1);
      // prevent position problem in wxTextCtrl with wxTE_DONTWRAP style
      // (but doesn't fix problem with I-beam cursor over scroll bars)
      wxSystemOptions::SetOption(wxMAC_TEXTCONTROL_USE_MLTE, 1);
   #endif

   // get current working directory before calling SetAppDirectory
   wxString initdir = wxFileName::GetCwd();
   if (initdir.Last() != wxFILE_SEP_PATH) initdir += wxFILE_SEP_PATH;

   // make sure current working directory contains application otherwise
   // we can't open Help files
   SetAppDirectory( wxString(argv[0]).mb_str(wxConvLocal) );

   // now set global gollydir for use in GetPrefs and elsewhere
   gollydir = wxFileName::GetCwd();
   if (gollydir.Last() != wxFILE_SEP_PATH) gollydir += wxFILE_SEP_PATH;
   
   // let non-wx modules call Fatal, Warning, BeginProgress, etc
   lifeerrors::seterrorhandler(&wxerrhandler);

   // allow .html files to include common graphic formats,
   // and .icons files to be in any of these formats;
   // note that wxBMPHandler is always installed, so it needs not be added,
   // and we can assume that if HAVE_WX_BMP_HANDLER is not defined, then
   // the handlers have not been auto-detected (and we just install them all).
#if !defined(HAVE_WX_BMP_HANDLER) || defined(HAVE_WX_GIF_HANDLER)
   wxImage::AddHandler(new wxGIFHandler);
#endif
#if !defined(HAVE_WX_BMP_HANDLER) || defined(HAVE_WX_PNG_HANDLER)
   wxImage::AddHandler(new wxPNGHandler);
#endif
#if !defined(HAVE_WX_BMP_HANDLER) || defined(HAVE_WX_TIFF_HANDLER)
   wxImage::AddHandler(new wxTIFFHandler);
#endif

   // wxInternetFSHandler is needed to allow downloading files
   wxFileSystem::AddHandler(new wxInternetFSHandler);
   wxFileSystem::AddHandler(new wxZipFSHandler);

   // get main window location and other user preferences
   GetPrefs();
   
   // create main window (also initializes viewptr, bigview, statusptr)
   mainptr = new MainFrame();
   if (mainptr == NULL) Fatal(_("Failed to create main window!"));
   
   // initialize some stuff before showing main window
   mainptr->SetRandomFillPercentage();
   mainptr->SetMinimumStepExponent();

   wxString banner = _("This is Golly version ");
   banner +=         _(STRINGIFY(VERSION)); 
   banner +=         _(".  Copyright 2012 The Golly Gang.");
   statusptr->SetMessage(banner);

   mainptr->NewPattern();

   // script/pattern files are stored in the pendingfiles array for later processing
   // in OnIdle; this avoids a crash in Win app if a script is run before showing
   // the main window, and also avoids event problems in Win app with a long-running
   // script (eg. user can't hit escape to abort script)
   const wxString START_PERL = wxT("golly-start.pl");
   const wxString START_PYTHON = wxT("golly-start.py");
   wxString startscript = gollydir + START_PERL;
   if (wxFileExists(startscript)) {
      mainptr->pendingfiles.Add(startscript);
   } else {
      // look in user-specific data directory
      startscript = datadir + START_PERL;
      if (wxFileExists(startscript)) {
         mainptr->pendingfiles.Add(startscript);
      }
   }
   startscript = gollydir + START_PYTHON;
   if (wxFileExists(startscript)) {
      mainptr->pendingfiles.Add(startscript);
   } else {
      // look in user-specific data directory
      startscript = datadir + START_PYTHON;
      if (wxFileExists(startscript)) {
         mainptr->pendingfiles.Add(startscript);
      }
   }
   
   // argc is > 1 if command line has one or more script/pattern files
   for (int n = 1; n < argc; n++) {
      wxFileName filename(argv[n]);
      // convert given path to a full path if not one already; this allows users
      // to do things like "../golly bricklayer.py" from within Scripts folder
      if (!filename.IsAbsolute()) filename = initdir + argv[n];
      mainptr->pendingfiles.Add(filename.GetFullPath());
   }

   // show main window
   if (maximize) mainptr->Maximize(true);
   mainptr->Show(true);
   SetTopWindow(mainptr);

   // true means call wxApp::OnRun() which will enter the main event loop;
   // false means exit immediately
   return true;
}