Example #1
0
// Equivalent of "at".
static void put_char_at(Short row, Short col, Char ch, Boolean bold)
{
  Short cheat, vcheat = DunTopY + (itsy_on ? 0 : 0);//center the map vertically
  RectangleType r;
  Short vc_w = itsy_on ? visible_char_w_itsy : visible_char_w;
  Short vc_h = itsy_on ? visible_char_h_itsy : visible_char_h;

  RctSetRectangle(&r, col * vc_w, row*vc_h+vcheat, vc_w, vc_h);

  if (!my_prefs.black_bg || IsColor)
    WinEraseRectangle(&r, 0);
  else
    WinDrawRectangle(&r, 0);
    
  // calculate pixel position of "row, col" and put char there
  cheat = vc_w - FntCharWidth(ch); // center the variable width characters

  if (cheat <= 1)   cheat = 0;
  else              cheat /= 2;

  if (ch != ' ') {

#ifdef I_AM_COLOR
    //  if (IsColor) {
    //    WinSetTextColor(get_color(ch, col+visible_x, row+visible_y));
    //  }
#endif

    if (!itsy_on && (ch== 'g' || ch== 'j' || ch== 'p' ||ch == 'q' ||ch == 'y'))
      vcheat--; // unfortunately, letters with dangling bits are a pain.
    
    if (!my_prefs.black_bg || IsColor)
      WinDrawChars(&ch, 1, col * vc_w + cheat, row * vc_h+vcheat);
    else
      WinDrawInvertedChars(&ch, 1, col * vc_w + cheat, row * vc_h+vcheat);

    if (bold)  WinInvertRectangle(&r, 0); /* 0 for square corners */
  }
  terminal[row][col] = ch;

}
Example #2
0
/* Display the example font character centred in the given object ID */
void DisplayChar
    (
    FontID      fontID, /* font to print */
    const char  letter, /* letter to display */
    FormType*   form,   /* pointer form to print to */
    UInt16      objID   /* object to print in form */
    )
{
    RectangleType bounds;
    Coord         x;
    Coord         y;
#ifdef HAVE_GRAY_FONT
    Char          orientation;
    orientation   = GrayFntSetOrientation( GRAY_FONT_NORMAL );
#endif

    FrmGetObjectBounds( form, FrmGetObjectIndex( form, objID ), &bounds );
    FntSetFont( fontID );

    /* double our input values for sony */
    HiResAdjustBounds( &bounds, sonyHiRes );

    /* find approximate centered position for character */
    x = bounds.topLeft.x +
        ( bounds.extent.x / 2 ) -
        ( FntCharWidth( letter ) / 2 );
    y = bounds.topLeft.y +
        ( bounds.extent.y / 2 ) -
        ( FntCharHeight() / 2 );

    WinDrawChars( &letter, 1, x, y );

#ifdef HAVE_GRAY_FONT
    GrayFntSetOrientation( orientation );
#endif
}
Example #3
0
void	FntCharsInWidth (Char const * string, Int16 *stringWidthP, 
	Int16 *stringLengthP, Boolean *fitWithinWidth)
{
	Int16 width = 0;
	Int16 charWidth;
	Int16 length = 0;
	Int16 maxLength = *stringLengthP;
	Int16 maxWidth = *stringWidthP;
	Int16 firstChar;
	Int16 lastChar;
	Int16 charSize;
	UInt8 ch;
	Char const * s2;
	FontCharInfoType * info;
	FontPtr	fontP;



	ErrNonFatalDisplayIf(string == NULL, "Null string");
	ErrNonFatalDisplayIf(stringWidthP == NULL, "Null stringWidthP");
	ErrNonFatalDisplayIf(stringLengthP == NULL, "Null stringLengthP");
	ErrNonFatalDisplayIf(fitWithinWidth == NULL, "Null fitWithinWidth");
	
	fontP = UICurrentFontPtr;

	if (((UInt16)fontP->fontType & fntFontMapMask) != fntFontMapMask)
		{
		firstChar = UICurrentFontPtr->firstChar;
		lastChar = UICurrentFontPtr->lastChar;
		info = (FontCharInfoType *) (&UICurrentFontPtr->owTLoc) + 
				UICurrentFontPtr->owTLoc;
	
		
		while (*string != '\0' && *string != linefeedChr && length < maxLength)
			{
			// If the character exist, get its width, otherwise get the width
			// of the Missing Character symbol.
			ch = *string;
	
			if (ch >= firstChar && ch <= lastChar && 
					info[ch - firstChar].width != fntMissingChar)
				charWidth = info[ch - firstChar].width;
			else	
				charWidth = info[lastChar - firstChar +1].width;
	
			if (width + charWidth <= maxWidth)
				{
				width += charWidth;
				length++;
				}
			else
				break;			// can't add any more characters.
				
			string++;
			}
		}

	else
		{
		while (*string != '\0' && *string != linefeedChr && length < maxLength)
			{
			charWidth = GetCharsWidth (string, &charSize);

			if (width + charWidth <= maxWidth)
				{
				width += charWidth;
				length += charSize;
				}
			else
				break;			// can't add any more characters.
				
			string += charSize;
			}
		}
		
	// string is the first character that didn't get included.  A '\0'
	// means the entire string fit, a linefeedChr means the string wrapped
	// (didn't fit), and anything else means the string was too wide.
	// Now, if the string is too wide because of blank characters, then
	// the string shouldn't considered to be truncated.  It's entire visible
	// contents does fit.
	

	// If the character we were adding was a whitespace and
	// all the characters until the end of the string are white spaces
	// then we don't consider the string truncated.
	if (length >= maxLength)		// used up all the characters
		*fitWithinWidth = true;
	else if (*string == linefeedChr)
		*fitWithinWidth = false;
	else if (*string == '\0')
		*fitWithinWidth = true;
	else
		{
		s2 = string;
		
		while (*s2 == ' ' || *s2 == tabChr)
			s2++;
		
		if (*s2 == '\0')
			*fitWithinWidth = true;
		else
			*fitWithinWidth = false;
		}
	

	// Visual optimization.  If the last char was unseen remove it.
	// Drawing it adds nothing of value.
	string--;
	while (length > 0 && 
		(*string == ' ' || *string == linefeedChr || *string == tabChr))
		{
		width -= FntCharWidth(*string);
		string--;
		length--;
		}


	*stringWidthP = width;
	*stringLengthP = length;
}
Example #4
0
void CGameForm::OnDraw() {

	played_cards.Render(true);
	player_hand.Render(true);

	char bid_trump_str[2];
	StrPrintF(bid_trump_str, "%d", gManager->tbl->bid  );

	FormPtr frmP = FrmGetActiveForm();
/*
	RectangleType bounds;
	UInt16 gadgetIndex = FrmGetObjectIndex( frmP, MainBidTrumpGadget );
	FrmGetObjectBounds(frmP, gadgetIndex, &bounds);

	// draw the bid
	char bidval = bid_trump_str[0];
	WinPaintChar( bidval, bounds.topLeft.x, bounds.topLeft.y );

	Card foo(gManager->trk->getTrump(), (Card::face_t)1 );

	// now, draw the suit
	MemHandle hRsc = DmGetResource(bitmapRsc, foo.SuitBitmap(false) );
	ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource");
	BitmapType* bitmapP = (BitmapType*) MemHandleLock(hRsc);

	WinPaintBitmap (bitmapP, bounds.topLeft.x + 6, bounds.topLeft.y);

	MemHandleUnlock(hRsc);
	DmReleaseResource(hRsc);
*/
	// handle MainBidTrumpGadget here also
	MemHandle hRsc;
	BitmapType* bitmapP;

	switch ( gManager->tbl->trump ) {

		case Card::heart:
			hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily );
			break;
		case Card::diamond:
			hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily );
			break;
		case Card::club:
			hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily );
			break;
		case Card::spade:
			hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily );
			break;
	}

	RectangleType bounds;

//	FormPtr frmP = FrmGetActiveForm();
	UInt16 gadgetIndex = FrmGetObjectIndex(frmP, MainBidTrumpGadget);
	FrmGetObjectBounds(frmP, gadgetIndex, &bounds);
	char bidstr[4];
	StrPrintF(bidstr, "%d", gManager->tbl->bid);
	WinPaintChar(bidstr[0], bounds.topLeft.x, bounds.topLeft.y );

	ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource");
	bitmapP = (BitmapType*) MemHandleLock(hRsc);
	WinDrawBitmap (bitmapP, bounds.topLeft.x + FntCharWidth(bidstr[0]) + 1, bounds.topLeft.y);
	MemHandleUnlock(hRsc);
	DmReleaseResource(hRsc);

}
Example #5
0
/*------------------------------------------------------CIRexxApp::FindLaunch-+
|                                                                             |
+----------------------------------------------------------------------------*/
Err CIRexxApp::FindLaunch(FindParamsPtr pFindParams)
{
   //<<<JAL TODO: This is currently dependent on the Rexx category.
   //             I'm not sure if we'll ever need to change/add-to this,
   //             but if we do, then this code will have to be changed
   //             along with the GoTo command.
   Err err;
   LocalID dbID;
   UInt16 cardNo = 0;
   DmOpenRef dbP;
   DmSearchStateType searchState;
   UInt16 recordNum;
   MemHandle hRecord;
   UInt32 pos;
   UInt16 matchLength;
   Boolean match, full;
   RectangleType r;
   UInt32 type;
   UInt32 creator;

   // Open our database (should we search MemoPad and pedit, too?)
   // and do our Find.  We define the semantics of Find, so
   // instead of searching the whole records for the search string,
   // let's just search for scripts with the search string as their "name."
   if (FindDrawHeader(pFindParams, "Rexx Scripts")) {
      goto m_return;
   }
   if ((err = DmGetNextDatabaseByTypeCreator(
       true, &searchState, 'data', CREATORID, true, &cardNo, &dbID)) != errNone) {
      pFindParams->more = false;
      return errNone;
   }
   if ((err = DmDatabaseInfo(0, dbID, 0, 0, 0, 0, 0, 0, 0, 0, 0, &type, &creator)) != errNone ||
      (type != 'data' && creator != CREATORID)) {
      pFindParams->more = false;
      return errNone;
   }
   if ((dbP = DmOpenDatabase(cardNo, dbID, pFindParams->dbAccesMode)) == 0 || 
      DmGetAppInfoID(dbP) == 0) { /* if categories not initialized then CategoryGetName throws fatal error */ 
      pFindParams->more = false;
      return errNone;
   }
   UInt16 category;
   char categoryName[dmCategoryLength];
   for (category = 0; category < dmRecNumCategories; ++category) {
       CategoryGetName(dbP, category, categoryName);
       if (!StrCaselessCompare(categoryName, "REXX")) { break; }
   }
   if (category == dmRecNumCategories) { goto m_return; }
   // set it to dmAllCategories?

   UInt32 romVersion;
   FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);

   full = false;
   recordNum = pFindParams->recordNum;
   while (true) {

      // Because applications can take a long time to finish a Find when
      // the result may already be on the screen, or for other reasons,
      // users like to be able to stop the Find.  So, stop it if any event
      // is pending, i.e., if the user does something with the device.
      // Because actually checking if an event is pending slows the
      // search itself, just check it every so many records.
      if ((recordNum & 0x000f) == 0 && EvtSysEventAvail(true)) {
         pFindParams->more = true;
         break;
      }
      if (!(hRecord = DmQueryNextInCategory(dbP, &recordNum, category))) {
         pFindParams->more = false;
         break;
      }

      Char * p = (char *)MemHandleLock(hRecord);
      UInt32 isInternational;
      err = FtrGet(sysFtrCreator, sysFtrNumIntlMgr, &isInternational);
      if (err == errNone && isInternational) {
         match = TxtFindString(p, pFindParams->strToFind, &pos, &matchLength);
      } else {
         match = TxtGlueFindString(p, pFindParams->strToFind, &pos, &matchLength);
      }
      if (match) {
         // Add the match to the find paramter block.
         // If there is no room to display the match
         // then the following function will return true.
         full = FindSaveMatch(pFindParams, recordNum, (UInt16)pos, 0, 0, cardNo, dbID);
         if (!full) {
            // Get the bounds of the region where we will draw the results, and
            // display the title of the description neatly in that area.
            FindGetLineBounds(pFindParams, &r);
            Int16 x = r.topLeft.x + 1;
            Int16 y = r.topLeft.y;
            Int16 w = r.extent.x - 2;
            Char * cr = StrChr(p, linefeedChr);
            UInt16 titleLen = (cr == 0)? StrLen(p) : cr - p;
            Int16 fntWidthToOffset;
            if (romVersion >= sysMakeROMVersion(3, 1, 0, sysROMStageRelease, 0)) {
               fntWidthToOffset = FntWidthToOffset(p, titleLen, w, 0, 0);
            } else {
               fntWidthToOffset = FntGlueWidthToOffset(p, titleLen, w, 0, 0);
            }
            if (fntWidthToOffset == titleLen) {
               WinDrawChars(p, titleLen, x, y);
            } else {
               Int16 titleWidth;
               titleLen = FntWidthToOffset(p, titleLen, w - FntCharWidth(chrEllipsis), 0, &titleWidth);
               WinDrawChars(p, titleLen, x, y);
               WinDrawChar (chrEllipsis, x + titleWidth, y);
            }
            ++pFindParams->lineNumber;
         }
      }
      MemHandleUnlock(hRecord);
      if (full) { break; }
      ++recordNum;
   }

m_return:
   DmCloseDatabase(dbP);
   return errNone;
}