static Boolean FormPenDownEvent(EventType * e) { FormPtr frm = FrmGetActiveForm (); UInt16 objIndex; RectangleType r; Boolean res = false; objIndex = FrmGetObjectIndex (frm, ID_EditorMidiKeysGadget); FrmGetObjectBounds (frm, objIndex, &r); if (RctPtInRectangle (e->screenX, e->screenY, &r)) { midikeys_tapped(&midikeys, e->screenX, e->screenY); res = true; } objIndex = FrmGetObjectIndex (frm, ID_EditorNoteListGadget); FrmGetObjectBounds (frm, objIndex, &r); if (RctPtInRectangle (e->screenX, e->screenY, &r)) { notelist_tapped(¬elist, e->screenX, e->screenY); res = true; } UpdateNoteProperties(); return res; }
void GadgetTimeSetRect(RectangleType *rect, TimeType begin, TimeType end, UInt8 day, UInt8 num_times, UInt8 pos) { UInt8 top, height, width, width_base; RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); height = GadgetCalcTimeHeight(begin, end); top = GadgetCalcTimeTop(begin); if ( (top + height) > GADGET_MAX_PIXELHEIGHT) height -= ((top + height) - GADGET_MAX_PIXELHEIGHT); width = gGadgetDaysWidth / num_times; width_base = width; if (pos == (GADGET_MAX_AT_A_TIME-1)) { // It's the last item, add any pixels that get cut off by the division otherwise // (like: width: 20, num_items = 3, item width = 6, 2 got cut off, add them to the last entry) width += (gGadgetDaysWidth - (num_times * width)); } RctSetRectangle(rect, // Left Left Offset Days to left lines between days position offset bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+(gGadgetDaysWidth*day)+day + pos * width_base, // Top Top Offset hours bounds.topLeft.y+GADGET_TOP +top, // Width width, // 2px per 15min height); }
/***************************************************************************** * Function: GadgetDrawHint * * Description: Draw the hintbox with the hint *****************************************************************************/ void GadgetDrawHint(const char *toptext, const char *bottext, UInt16 note) { RectangleType bounds; UInt16 gadgetIndex; RectangleType rect, textbox_top, textbox_bot; FontID oldFont; ControlType *ctl; Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 }; // Not needed any longer, the hint now has its own Gadget // UInt16 top = GADGET_TOP + (GADGET_STRINGS_NUM-1) * GADGET_STRINGS_OFFSET + 5; // 6 - const = VALUE BELOW if (! gForm) return; gadgetIndex = FrmGetObjectIndex(gForm, gHintGadgetID); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); WinEraseRectangle(&bounds, 0); RctSetRectangle(&rect, bounds.topLeft.x+1, // +1 for border bounds.topLeft.y+1, // Put VALUE BELOW here.... +top+1 removed because of own Gadget bounds.extent.x-3, bounds.extent.y - 3); // -4 for bottom border // Erase Gadget area WinSetForeColor(UIColorGetTableEntryIndex(UIObjectFrame)); WinDrawRectangleFrame(popupFrame, &rect); RctSetRectangle(&textbox_top, rect.topLeft.x+2, rect.topLeft.y, rect.extent.x-2,(Int16)((rect.extent.y-2)/2)); RctSetRectangle(&textbox_bot, textbox_top.topLeft.x, textbox_top.topLeft.y+textbox_top.extent.y+1, textbox_top.extent.x, textbox_top.extent.y); oldFont=FntSetFont(boldFont); TNDrawCharsToFitWidth(toptext, &textbox_top); FntSetFont(oldFont); TNDrawCharsToFitWidth(bottext, &textbox_bot); gHintNote = note; if (note) { // This time has a note oldFont = FntSetFont(symbolFont); RctSetRectangle(&rect, rect.topLeft.x+rect.extent.x-8, rect.topLeft.y+rect.extent.y-12, FntLineWidth(noteSymb, 1), FntLineHeight()); TNDrawCharsToFitWidth(noteSymb, &rect); FntSetFont(oldFont); } ctl=GetObjectPtr(BUTTON_edit); CtlShowControl(ctl); ctl=GetObjectPtr(BUTTON_beam); CtlShowControl(ctl); }
void wxControl::DoGetBounds( RectangleType &rect ) const { FormType* form = GetParentForm(); if(form==NULL) return; uint16_t index = FrmGetObjectIndex(form,GetId()); if(index==frmInvalidObjectId) return; FrmGetObjectBounds(form,index,&rect); }
/***************************************************************************** * Function: GadgetDrawTimeline * * Description: Draws a line for the current time *****************************************************************************/ void GadgetDrawTimeline(GadgetTimelineDrawType drawType) { DateTimeType dt; TimeType now; TimSecondsToDateTime(TimGetSeconds(), &dt); if (drawType == gtDraw) { now.hours=dt.hour; now.minutes=dt.minute; gGadgetLastTimeline.hours=now.hours; gGadgetLastTimeline.minutes=now.minutes; GadgetDrawWeekdays(); } else { now.hours=gGadgetLastTimeline.hours; now.minutes=gGadgetLastTimeline.minutes; } if ( ((gGadgetCurScreen == GADGET_SCREEN_DAY) && (now.hours >= 8) && (now.hours < 20)) || ((gGadgetCurScreen == GADGET_SCREEN_NIGHT) && ((now.hours < 8) || (now.hours >= 20))) ) { UInt8 y, gadgetWidth; UInt16 gadgetIndex; FormType *frm; RectangleType bounds; RGBColorType red={0x00, 0xFF, 0x00, 0x00}, old; y = GadgetCalcTimeTop(now); frm = FrmGetActiveForm(); gadgetIndex = FrmGetObjectIndex(frm, gGadgetID); FrmGetObjectBounds(frm, gadgetIndex, &bounds); gadgetWidth=gGadgetDaysNum * gGadgetDaysWidth + gGadgetDaysNum - 1; WinInvertLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y+GADGET_TOP+y, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gadgetWidth-1, bounds.topLeft.y+GADGET_TOP+y); if (drawType == gtDraw) { TNSetForeColorRGB(&red, &old); WinDrawPixel(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gGadgetDaysNum*gGadgetDaysWidth+gGadgetDaysNum+1, bounds.topLeft.y+GADGET_TOP+y); WinDrawLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gGadgetDaysNum*gGadgetDaysWidth+gGadgetDaysNum+2, bounds.topLeft.y+GADGET_TOP+y-1, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gGadgetDaysNum*gGadgetDaysWidth+gGadgetDaysNum+2, bounds.topLeft.y+GADGET_TOP+y+1); WinDrawLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gGadgetDaysNum*gGadgetDaysWidth+gGadgetDaysNum+3, bounds.topLeft.y+GADGET_TOP+y-2, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gGadgetDaysNum*gGadgetDaysWidth+gGadgetDaysNum+3, bounds.topLeft.y+GADGET_TOP+y+2); TNSetForeColorRGB(&old, NULL); } else if (drawType == gtErase) { RectangleType rect; RctSetRectangle(&rect, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gGadgetDaysNum*gGadgetDaysWidth+gGadgetDaysNum+1, bounds.topLeft.y+GADGET_TOP+y-2, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gGadgetDaysNum*gGadgetDaysWidth+gGadgetDaysNum+3, bounds.topLeft.y+GADGET_TOP+y+2); WinEraseRectangle(&rect, 0); } } }
static Boolean IsEventInControl(FormPtr frmP, EventPtr eventP, UInt16 control) { RectangleType rect; FrmGetObjectBounds(frmP, FrmGetObjectIndex(frmP, control), &rect); if ((eventP->screenX >= rect.topLeft.x) && (eventP->screenX <= rect.topLeft.x + rect.extent.x) && (eventP->screenY >= rect.topLeft.y) && (eventP->screenY <= rect.topLeft.y + rect.extent.y)) return true; return false; }
void wxControl::DoGetBounds( WXRECTANGLEPTR rect ) const { if(rect==NULL) return; FormType* form = (FormType*)GetParentForm(); if(form==NULL) return; uint16_t index = FrmGetObjectIndex(form,GetId()); if(index==frmInvalidObjectId) return; FrmGetObjectBounds(form,index,(RectangleType*)rect); }
/* Retrieve the bounds of an object */ void GetControlBounds ( const FormType* form, /* pointer to memory block that contains the form */ const UInt16 objectId, /* ID of an object in the form */ const Int16 controlID /* control ID of the object */ ) { FrmGetObjectBounds( form, FrmGetObjectIndex( form, objectId ), &controls[ controlID ].bounds ); HiResAdjustBounds( &controls[ controlID ].bounds, palmHiRes ); }
void AdjustIconSelTrigger(Int16 id) { FormPtr frmP = FrmGetActiveForm(); RectangleType r; UInt16 idx = FrmGetObjectIndex(frmP, id); FrmGetObjectBounds(frmP, idx, &r); r.extent.x = 12; r.extent.y = 11; FrmSetObjectBounds(frmP, idx, &r); }
/***************************************************************************** * Function: GadgetDrawWeekdays * * Description: Draws the weekdays, extra function since called in * GadgetDrawTimeline *****************************************************************************/ void GadgetDrawWeekdays(void) { UInt8 i; MemHandle mh; Char *text; RGBColorType color, prevColor; DateTimeType now; Int16 dow; RectangleType bounds, rect; UInt16 gadgetIndex; // Get info about Gadget gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); // Initialize time constants TimSecondsToDateTime(TimGetSeconds(), &now); dow = DayOfWeek(now.month, now.day, now.year); RctSetRectangle(&rect, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y, 130, FntLineHeight()+2); // Erase background WinEraseRectangle(&rect, 0); for (i=0; i < gGadgetDaysNum; ++i) { Int16 leftoff; mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+i); text = MemHandleLock(mh); leftoff = (gGadgetDaysWidth+2 - FntLineWidth(text, MemPtrSize(text))) / 2; if (TNisColored() && (dow == i+1)) { color.r = 0xFF; color.g = 0x00; color.b = 0x00; TNSetTextColorRGB(&color, &prevColor); } WinDrawChars(text, StrLen(text), bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+i*gGadgetDaysWidth+i+leftoff+2, bounds.topLeft.y); if (dow == i+1) { if (TNisColored()) { TNSetTextColorRGB(&prevColor, NULL); } else { // Draw some kind of underline to determine current day Int16 lineWidth=FntLineWidth(text, StrLen(text)); WinDrawLine(rect.topLeft.x+i*gGadgetDaysWidth+i+leftoff+1, rect.topLeft.y+FntLineHeight(), rect.topLeft.x+i*gGadgetDaysWidth+i+leftoff+1+lineWidth, rect.topLeft.y+FntLineHeight()); } } MemHandleUnlock(mh); } }
static Int16 LoadIcon(Int16 start) { FormPtr frmP = FrmGetActiveForm(); Int8 i; Int16 num; Int16 iconButtonID = IconSelectIcon1Button; BitmapPtr pbmp; MemHandle h; Int16 x, y; RectangleType r; num = DmNumResources(IconDB); if (start > num) start = 0; for (i = 0; i < 9*8; i++) { UInt16 idx = FrmGetObjectIndex(frmP, iconButtonID + i); FrmGetObjectPosition(frmP, idx, &x, &y); FrmGetObjectBounds(frmP, idx, &r); r.topLeft.x = x; r.topLeft.y = y; WinEraseRectangle(&r, 0); if (i+start <num) { h = (MemPtr)GetIconByIndex(IconDB, i + start); pbmp = (h) ? MemHandleLock(h) : NULL; if (pbmp) { WinDrawBitmap(pbmp, x, y); MemHandleUnlock(h); DmReleaseResource(h); ShowObject(frmP, iconButtonID + i); } else { HideObject(frmP, iconButtonID + i); } } else { HideObject(frmP, iconButtonID + i); } } return num; }
// Graphics icon setting // void DrawFormANIcon(Int16 iconNumber, Int16 id) { FormPtr frmP = FrmGetActiveForm(); Int16 x, y; RectangleType r; UInt16 idx = FrmGetObjectIndex(frmP, id); FrmGetObjectPosition(frmP, idx, &x, &y); FrmGetObjectBounds(frmP, idx, &r); r.topLeft.x = x; r.topLeft.y = y; WinEraseRectangle(&r, 0); if (iconNumber >= 0) DrawANIcon(iconNumber, x+1, y); }
Boolean CGameForm::OnPenUp(EventPtr pEvent, Boolean& bHandled) { FormPtr frmP = FrmGetActiveForm(); RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(frmP, MainPlayerHandGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); // // check and see if this event happened in the gadget // if ( gManager->current == gManager->human && pEvent->screenX >= bounds.topLeft.x && pEvent->screenX <= bounds.topLeft.x + bounds.extent.x && pEvent->screenY >= bounds.topLeft.y && pEvent->screenY <= bounds.topLeft.y + bounds.extent.y ) { // // if this comes back true, then the user picked a card // if ( player_hand.OnPenUp(pEvent, bHandled) ) { // // play the card // gManager->NextPlayedCard( player_hand.CurrentPlayer(), player_hand.CurrentPlayer()->PlayedCard() ); // render anything that needs doing player_hand.Render(true); played_cards.Render(true); // check the game condition CheckGameCondition(); } } else { player_hand.Reset(); player_hand.Render(true); } bHandled = false; return false; }
/***************************************************************************** * Function: GadgetDrawHintErase * * Description: Erase the area where the hintbox goes *****************************************************************************/ void GadgetDrawHintErase(void) { RectangleType bounds; UInt16 gadgetIndex; ControlType *ctl; if (! gForm) return; gadgetIndex = FrmGetObjectIndex(gForm, gHintGadgetID); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); WinEraseRectangle(&bounds, 0); ctl=GetObjectPtr(BUTTON_edit); CtlHideControl(ctl); ctl=GetObjectPtr(BUTTON_beam); CtlHideControl(ctl); }
Boolean CGameForm::OnPenDown(EventPtr pEvent, Boolean& bHandled) { FormPtr frmP = FrmGetActiveForm(); RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(frmP, MainPlayerHandGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); // // check and see if this event happened in the gadget // if ( gManager->current == gManager->human && pEvent->screenX >= bounds.topLeft.x && pEvent->screenX <= bounds.topLeft.x + bounds.extent.x && pEvent->screenY >= bounds.topLeft.y && pEvent->screenY <= bounds.topLeft.y + bounds.extent.y ) { player_hand.OnPenDown(pEvent, bHandled); } bHandled = false; return false; }
/* 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 }
/* ** Popup the transfer details list. */ static void DoXferList(void) { const Int16 num_plugs = PlugIndex(NULL, true); if (!d.xfer.pluglistH || !num_plugs) { FrmAlert(NoPluginInstalled); } else { RectangleType rect; Int16 list_selection = -1; FormType* frm = FrmGetActiveForm(); ListPtr list = GetObjectPointer(frm, XferList); /* Set up plugin list control */ LstSetDrawFunction(list, XferListDrawFunc); LstSetListChoices(list, NULL, num_plugs); LstSetHeight(list, Min(num_plugs, 10)); FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, XferList), &rect); rect.topLeft.x = 16; rect.topLeft.y = 144 - rect.extent.y; rect.extent.x = d.xfer.plug_menu_width; FrmSetObjectBounds(frm, FrmGetObjectIndex(frm, XferList), &rect); /* Pop up the list */ LstSetSelection(list, GetCurrentXferAppListIndex()); list_selection = LstPopupList(list); if (list_selection != -1) { SysDBListItemType* pluglistP = MemHandleLock(d.xfer.pluglistH); /* Store the current plugin */ p.xfer_current_plug = pluglistP[PlugIndex(list_selection, false)].creator; /* Clean up */ MemHandleUnlock(d.xfer.pluglistH); } } }
/***************************************************************************** * Function: GadgetTap * * Description: Handles penDown events (taps) on the gadget *****************************************************************************/ void GadgetTap(FormGadgetType *pGadget, EventType *event) { //you may find it useful to track if they //lift the pen still within the boundaries of the gadget Boolean isPenDown = true; Int16 newPointX, newPointY, startPointX, startPointY; UInt16 index; RectangleType bounds; // This is just needed since we do not want to access internal structure // data directly in FormGadgetType (need rect field below) index = TNGetObjectIndexFromPtr(FrmGetActiveForm(), pGadget); FrmGetObjectBounds(FrmGetActiveForm(), index, &bounds); //track the pen down event EvtGetPen(&newPointX, &newPointY, &isPenDown); startPointX = newPointX; startPointY = newPointY; while (isPenDown){ EvtGetPen(&newPointX, &newPointY, &isPenDown); } if (RctPtInRectangle(newPointX, newPointY, &bounds)) { /* the pen up was also in the gadget This can mean two things: 1) we got a strike command 2) a field was tapped */ RectangleType topRight, bottomRight; Boolean found=false, foundTime=false; MemHandle m; TimeDBRecord *t; UInt16 index=0, wantCourse=0, tmp3_4th=0; GadgetTimeListType *gtl; TNlist *tmpl; /* Check for stroke commands */ tmp3_4th = (3 * bounds.extent.x) / 4; RctSetRectangle(&topRight, bounds.topLeft.x+ tmp3_4th, bounds.topLeft.y, bounds.extent.x - tmp3_4th, bounds.extent.y/2 ); RctSetRectangle(&bottomRight, bounds.topLeft.x + tmp3_4th, bounds.topLeft.y + (bounds.extent.y/2), bounds.extent.x - tmp3_4th, bounds.extent.y / 2 ); if (RctPtInRectangle(startPointX, startPointY, &bottomRight) && RctPtInRectangle(newPointX, newPointY, &topRight) ) { // Stroke Command: BACK GadgetDrawStep(winUp); return; } else if (RctPtInRectangle(startPointX, startPointY, &topRight) && RctPtInRectangle(newPointX, newPointY, &bottomRight) ) { // Stroke Command: NEXT GadgetDrawStep(winDown); return; } tmpl = gGadgetTimeList; while (tmpl != NULL) { gtl = (GadgetTimeListType *)tmpl->data; if (RctPtInRectangle(newPointX, newPointY, &(gtl->rect))) { m = DmQueryRecord(DatabaseGetRef(), gtl->index); if (m) { // mt may be null, for example if next is drawn after delete! t = (TimeDBRecord *)MemHandleLock(m); // we got a match wantCourse = t->course; gTimeIndex = gtl->index; foundTime = true; MemHandleUnlock(m); } } tmpl = tmpl->next; } // Search for the clicked time if (foundTime) { index = 0; while(! found && ((m = DmQueryNextInCategory(DatabaseGetRef(), &index, DatabaseGetCat())) != NULL)) { Char *s = (Char *)MemHandleLock(m); if (s[0] == TYPE_COURSE) { CourseDBRecord c; UnpackCourse(&c, s); if (c.id == wantCourse) { SndPlaySystemSound(sndClick); gCourseIndex = index; found=true; } } MemHandleUnlock(m); index += 1; } } if (found && foundTime) { GadgetDrawHintCurrent(); } else { SndPlaySystemSound(sndError); } } // else outside gadget bounds -> do nothing }
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); }
/* ** TrackXferDone */ static void TrackXferDone(DynamicButtonType* btn) { RectangleType bounds[5], frame, popFrame, popShadowFrame; Boolean penDown, on_button; Int16 x, y, clicked_on = 0; Int16 state = 1; Int16 i = 0; WinHandle offscreenH = NULL; FormType* frm = FrmGetActiveForm(); const UInt16 listIdx = FrmGetObjectIndex(frm, XferDoneList); ListType* list = FrmGetObjectPtr(frm, listIdx); UInt16 width = 0, choices = 0; Err err = errNone; Char str[48]; Int16 n = 0; /* Save the old drawing context */ WinPushDrawState(); /* This should match the XferDoneButton bounds */ FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, btn->id), &bounds[0]); /* Invert the done button */ SelectAndDrawButton(btn, true); SndPlaySystemSound(sndClick); /* Set the status of each menu pick */ for (; i < 4; i++) d.xfer.status[i] = 0x00; if (xferGotoIsAlways) d.xfer.status[0] = TRACKXFERDONE_ALWAYS; else if (xferGotoIsNever) d.xfer.status[0] = TRACKXFERDONE_NEVER; else if (p.flags&PFLAGS_XFER_GOTO) d.xfer.status[0] = TRACKXFERDONE_CHECKED; if (xferCompleteIsAlways) d.xfer.status[1] = TRACKXFERDONE_ALWAYS; else if (xferCompleteIsNever) d.xfer.status[1] = TRACKXFERDONE_NEVER; else if (d.xfer.complete) d.xfer.status[1] = TRACKXFERDONE_CHECKED; if (!d.linker_available) d.xfer.status[2] = TRACKXFERDONE_NEVER; else if (p.flags&PFLAGS_XFER_BACKLINK) d.xfer.status[2] = TRACKXFERDONE_CHECKED; if (p.flags&PFLAGS_XFER_DELETE) d.xfer.status[3] = TRACKXFERDONE_CHECKED; for (i = 0; i < 4; ++i) { if (!(d.xfer.status[i] & TRACKXFERDONE_NEVER)) { d.xfer.choice_map[choices] = i; ++choices; /* calculate list width */ SysCopyStringResource(str, XferMenuOptionsStrings + i); n = FntCharsWidth(str, StrLen(str)); width = Max(width, n); } } LstSetDrawFunction(list, XferDoneListDrawFunc); LstSetListChoices(list, 0, choices); LstSetHeight(list, Min(choices, 10)); FrmGetObjectBounds(frm, listIdx, &frame); frame.topLeft.y = 144 - frame.extent.y - 1; /* -1 to compensate for white border */ frame.extent.x = width + 15 + 6; FrmSetObjectBounds(frm, listIdx, &frame); WinGetFramesRectangle(popupFrame, &frame, &popFrame); WinGetFramesRectangle(rectangleFrame, &popFrame, &popShadowFrame); for (i = 0; i < choices; ++i) RctSetRectangle(&bounds[i+1], frame.topLeft.x, frame.topLeft.y + 10 * i, frame.extent.x, 10); /* Save the bits of the whole menu */ offscreenH = WinSaveBits(&popShadowFrame, &err); if (err) abort(); /* None selected */ LstSetSelection(list, -1); FrmShowObject(frm, listIdx); WinEraseRectangle(&popShadowFrame, 0); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); do { EvtGetPen(&x, &y, &penDown); if (!state || !RctPtInRectangle(x, y, &bounds[state-1])) { on_button = false; for (i = 1; i <= choices + 1; i++) { if ((state != i) && RctPtInRectangle(x, y, &bounds[i-1])) { /* Invert the new state */ LstSetSelection(list, i - 2); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); SelectAndDrawButton(btn, i == 1); state = i; on_button = true; } } if (state && !on_button) { /* Moved off the current button */ LstSetSelection(list, -1); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); if (state == 1) SelectAndDrawButton(btn, false); state = 0; } } } while (penDown); FrmHideObject(frm, listIdx); LstEraseList(list); /* Restore the framed rect */ WinRestoreBits(offscreenH, popShadowFrame.topLeft.x, popShadowFrame.topLeft.y); /* Unselect the button */ SelectAndDrawButton(btn, false); /* Finish up if we just tapped the button */ if (RctPtInRectangle(x, y, &bounds[0])) { FinishXferMode(); /* Restore the old draw state */ WinPopDrawState(); return; } /* Change the setting for goto or delete */ for (i = 1; i <= choices; i++) { if (RctPtInRectangle(x, y, &bounds[i])) { clicked_on = i; break; } } if (clicked_on) clicked_on = d.xfer.choice_map[clicked_on-1] + 1; switch (clicked_on) { case 1: /* Goto */ if (d.xfer.status[0] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_GOTO; else if (!d.xfer.status[0]) p.flags |= PFLAGS_XFER_GOTO; break; case 2: /* Complete */ if (d.xfer.status[1] & TRACKXFERDONE_CHECKED) d.xfer.complete = false; else if (!d.xfer.status[1]) d.xfer.complete = true; break; case 3: /* BackLink */ if (d.xfer.status[2] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_BACKLINK; else if (!d.xfer.status[2]) { p.flags |= PFLAGS_XFER_BACKLINK; p.flags &= ~PFLAGS_XFER_DELETE; /* No delete if backlink */ } break; case 4: /* Delete */ if (d.xfer.status[3] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_DELETE; else if (!d.xfer.status[3]) { p.flags |= PFLAGS_XFER_DELETE; p.flags &= ~PFLAGS_XFER_BACKLINK; /* No backlink if delete */ } break; } /* Click and redraw the button */ if (clicked_on) { DrawXferDoneButton(btn); DynBtnDraw(btn); if (d.xfer.status[clicked_on-1] & TRACKXFERDONE_ALWAYS) SndPlaySystemSound(sndWarning); else SndPlaySystemSound(sndClick); } /* Restore the old draw state */ WinPopDrawState(); }
/***************************************************************************** * Function: GadgetHintTap * * Description: Handles penDown events (taps) on the hint gadget *****************************************************************************/ void GadgetHintTap(FormGadgetType *pGadget, EventType *event) { //you may find it useful to track if they //lift the pen still within the boundaries of the gadget Boolean isPenDown = true; Int16 newPointX, newPointY, startPointX, startPointY; UInt16 index; RectangleType bounds, rect; Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 }; FontID oldFont; Boolean drawn=false; IndexedColorType curForeColor, curBackColor, curTextColor; // This is just needed since we do not want to access internal structure // data directly in FormGadgetType (need rect field below) index = TNGetObjectIndexFromPtr(FrmGetActiveForm(), pGadget); FrmGetObjectBounds(FrmGetActiveForm(), index, &bounds); oldFont = FntSetFont(symbolFont); RctSetRectangle(&rect, bounds.topLeft.x+1, // +1 for border bounds.topLeft.y+1, // Put VALUE BELOW here.... +top+1 removed because of own Gadget bounds.extent.x-3, bounds.extent.y - 3); // -4 for bottom border RctSetRectangle(&rect, rect.topLeft.x+rect.extent.x-8, rect.topLeft.y+rect.extent.y-12, FntLineWidth(noteSymb, 1), FntLineHeight()); //track the pen down event EvtGetPen(&newPointX, &newPointY, &isPenDown); startPointX = newPointX; startPointY = newPointY; while (isPenDown){ EvtGetPen(&newPointX, &newPointY, &isPenDown); if (gHintNote) { if (! drawn && RctPtInRectangle(newPointX, newPointY, &rect)) { curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground)); curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectSelectedFill)); curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground)); TNDrawCharsToFitWidth(noteSymb, &rect); WinSetForeColor(curForeColor); WinSetForeColor(curBackColor); WinSetForeColor(curTextColor); drawn = true; } else if (drawn && ! RctPtInRectangle(newPointX, newPointY, &rect)) { curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectForeground)); curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectFill)); curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectForeground)); TNDrawCharsToFitWidth(noteSymb, &rect); WinSetForeColor(curForeColor); WinSetForeColor(curBackColor); WinSetForeColor(curTextColor); drawn = false; } } } FntSetFont(oldFont); if (gHintNote && RctPtInRectangle(newPointX, newPointY, &rect)) { NoteSet(GadgetGetHintTimeIndex(), FORM_main); FrmPopupForm(NewNoteView); } // else outside gadget bounds -> do nothing }
Boolean CBiddingForm::OnNilEvent(EventPtr pEvent, Boolean& bHandled) { if ( gManager->Status() == GetHandBids ) { HighlightActiveBidder(); FormPtr frmP = FrmGetActiveForm(); Int16 player_index = (*gManager->tbl->current_bidder)->playerIndex; // // if this is a human player, we need to render the screen widgets for their bid // if ( player_index == gManager->humanIndex && player_has_bid == false ) { player_hand.Render(true); Int16 current_bid = 0; if ( (*gManager->tbl->dealer)->playerIndex != gManager->humanIndex || ! gManager->dealer_take_bid ) { current_bid = gManager->tbl->high_bid; } else { current_bid = gManager->tbl->high_bid - 1; } if ( (*gManager->tbl->dealer)->playerIndex == gManager->humanIndex && gManager->tbl->high_bid < 2 ) { CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), "-Pass-"); } else { switch (current_bid) { case 5: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), "-S-"); case 4: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); case 3: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); case 2: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), "-2-"); } } } // if if ( player_index == 3 && player_has_bid == false ) // // handle processing actual bids here - get one automatically if this player isn't // a human, or if the human has already bid // if ( player_index != gManager->humanIndex || player_has_bid == true ) { Boolean player_did_bid = gManager->GetNextBid(gManager->trk, false ); Int16 tmp_bid = (*gManager->tbl->current_bidder)->Bid(); if ( player_did_bid && gManager->tbl->current_bidder == gManager->tbl->winning_bidder && (tmp_bid >= 2) ) { char x[10]; StrPrintF(x, "bids %d", tmp_bid ); bidstr = x; } else { bidstr = "passes"; } bids[(*gManager->tbl->current_bidder)->playerIndex].Replace(bidstr); // // if we just got the dealer's bid, then we are all done // if ( gManager->tbl->current_bidder == gManager->tbl->dealer ) { // // at this point we need to set trump... // gManager->Status(SetHandTrump); if ( (*gManager->tbl->winning_bidder)->playerIndex == gManager->humanIndex ) { CPlayerTrumpForm frmPlayerTrump; frmPlayerTrump.DoModal(); } FrmDrawForm(frmP); // // ... and display the final results // Card::suit_t foo = (*gManager->tbl->winning_bidder)->Trump(); gManager->tbl->trump = foo; gManager->trk->no_trump_first_trick = (*gManager->tbl->winning_bidder)->NoTrumpFirstTrickP(); 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; } if ( gManager->trk->no_trump_first_trick ) { FrmCustomAlert(NoTrumpFirstTrickAlert, (*gManager->tbl->winning_bidder)->name, "", ""); } RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(frmP, BiddingTrumpGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); WinPaintChars("Trump Is: ", StrLen("Trump Is: "), bounds.topLeft.x, bounds.topLeft.y ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); bitmapP = (BitmapType*) MemHandleLock(hRsc); WinDrawBitmap (bitmapP, bounds.topLeft.x + 40, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); UInt32 hsStatusVersion; if (FtrGet (hsFtrCreator, hsFtrIDNavigationSupported, &hsStatusVersion) == 0) { FrmGlueNavObjectTakeFocus(FrmGetActiveForm(), BiddingOKButton ); } } // if ( dealer bid ) else { // move along to the next player gManager->tbl->current_bidder = gManager->getNextPlayerIter(gManager->tbl->current_bidder); EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); // pause here // SysTaskDelay(SysTicksPerSecond()); gManager->ShortDelay(); } } // if ( player_index != 3 || player_has_bid == true ) } // if GetHandBids bHandled = false; return true; }
/***************************************************************************** * Function: GadgetDrawHintCurrent * * Description: Draw hint for current gTimeIndex if needed (may be forced NOT * to draw with GadgetSetNeedsRedraw(false)); *****************************************************************************/ void GadgetDrawHintCurrent(void) { Char *tmp, *bot, begin[timeStringLength], end[timeStringLength], *day; MemHandle mc, mt, mh, type; CourseDBRecord c; TimeDBRecord *tc; RectangleType rect, bounds; UInt16 gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID); RGBColorType color, prevColor; UInt16 attr; // Need to check that due to damn f*** DmRecordInfo which will show a // fatal alert when called on non-existing record (this happens for example // right after creating the new database... if ((gTimeIndex >= DmNumRecords(DatabaseGetRef())) || (gCourseIndex >= DmNumRecords(DatabaseGetRef())) ) return; if (gHintDrawn) { // Delete border around previous entry if ( (gTimeDrawnIndex < DmNumRecords(DatabaseGetRef())) && (DmRecordInfo(DatabaseGetRef(), gTimeDrawnIndex, &attr, NULL, NULL) == errNone) ) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { mt = DmQueryRecord(DatabaseGetRef(), gTimeDrawnIndex); if (mt) { // mt may be null, for example if next is drawn after delete! tc = (TimeDBRecord *)MemHandleLock(mt); if ((tc->type == TYPE_TIME) && GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } color.r=tc->color[0]; color.g=tc->color[1]; color.b=tc->color[2]; if (gPrefs.showTimeline) GadgetDrawTimeline(gtErase); if (gtl != NULL) { GadgetDrawTime(tc->begin, tc->end, tc->day, &color, tc->course, gtl->num, gtl->pos); } if (gPrefs.showTimeline) GadgetDrawTimeline(gtDraw); } MemHandleUnlock(mt); } } } } gTimeDrawnIndex=gTimeIndex; gHintDrawn=true; if (DmRecordInfo(DatabaseGetRef(), gCourseIndex, &attr, NULL, NULL) == errNone) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { // Record is in currently displayed category mc = DmQueryRecord(DatabaseGetRef(), gCourseIndex); if (! mc) return; mt = DmQueryRecord(DatabaseGetRef(), gTimeIndex); if (! mt) return; UnpackCourse(&c, MemHandleLock(mc)); tc = (TimeDBRecord *)MemHandleLock(mt); if ( GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); day = (Char *)MemHandleLock(mh); // Lecture Name (Teacher) [Typ] tmp=(Char *)MemPtrNew(StrLen(c.name)+StrLen(c.teacherName)+4+3+CTYPE_SHORT_MAXLENGTH); MemSet(tmp, MemPtrSize(tmp), 0); type = MemHandleNew(1); CourseTypeGetShort(&type, c.ctype); StrPrintF(tmp, "%s (%s) [%s]", c.name, c.teacherName, (Char *)MemHandleLock(type)); MemHandleUnlock(type); MemHandleFree(type); // Fr 08:00 - 09:30 (Room) <-- Example // 3 5 3 5 3+StrLen(room) <-- Num Chars for MemPtrNew bot=(Char *)MemPtrNew(20+sizeof(tc->room)+MemPtrSize(day)); MemSet(bot, MemPtrSize(bot), 0); TimeToAscii(tc->begin.hours, tc->begin.minutes, GadgetGetTimeFormat(), begin); TimeToAscii(tc->end.hours, tc->end.minutes, GadgetGetTimeFormat(), end); mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); StrPrintF(bot, "%s %s - %s (%s)", day, begin, end, tc->room); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); if (gtl != NULL) { GadgetTimeSetRect(&rect, tc->begin, tc->end, tc->day, gtl->num, gtl->pos); RctSetRectangle(&rect, // + inset (two boxes, one black, one white) rect.topLeft.x + 2, rect.topLeft.y + 2, // width - 2 * inset rect.extent.x - 4, // height - 2 * inset rect.extent.y - 4 ); /* Invert color, looks not so nice aka bad color.r=255- tc->color[0]; color.g=255- tc->color[1]; color.b=255- tc->color[2]; */ color.r=255; color.g=255; color.b=255; TNSetForeColorRGB(&color, &prevColor); WinDrawRectangleFrame(simpleFrame, &rect); color.r=0; color.g=0; color.b=0; RctSetRectangle(&rect, rect.topLeft.x-1, rect.topLeft.y-1, rect.extent.x+2, rect.extent.y+2); TNSetForeColorRGB(&color, NULL); WinDrawRectangleFrame(simpleFrame, &rect); TNSetForeColorRGB(&prevColor, NULL); } // WinInvertRectangleFrame(simpleFrame, &rect); GadgetDrawHint(tmp, bot, tc->note); MemPtrFree((MemPtr) tmp); MemPtrFree((MemPtr) bot); MemHandleUnlock(mh); } else { MemHandleUnlock(mc); MemHandleUnlock(mt); GadgetDrawHintNext(); return; } MemHandleUnlock(mc); MemHandleUnlock(mt); } // End attr == current category } }
/***************************************************************************** * Function: GadgetDraw * * Description: Draws the basic gadget (grid, days, times) *****************************************************************************/ void GadgetDraw(Boolean eraseFirst) { RectangleType bounds; UInt8 i, gadgetWidth; RGBColorType color, prevColor; UInt16 gadgetIndex; RectangleType rect; FormType *frm=gForm; // Check if GadgetSet has already been called. If not => die if (! frm) return; gadgetIndex = FrmGetObjectIndex(frm, gGadgetID); FrmGetObjectBounds(frm, gadgetIndex, &bounds); // Erase background if (eraseFirst) WinEraseRectangle(&bounds, 0); // Write Times if (gGadgetCurScreen == GADGET_SCREEN_DAY) { for (i=0; i < 7; i++) { // 7 because we have to write 7 times 08:00, 10:00,..., 20:00 Char time[timeStringLength]; if (i < 1) StrPrintF(time, "0%u:00", 8+i*2); else StrPrintF(time, "%u:00", 8+i*2); WinDrawChars(time, StrLen(time), bounds.topLeft.x+GADGET_BASELEFT, (i != 7 - 1) ? bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET /* ^last^ */ : bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET-2); } } else { for (i=0; i < 2; i++) { Char time[timeStringLength]; StrPrintF(time, "%u:00", 20+i*2); WinDrawChars(time, StrLen(time), bounds.topLeft.x+GADGET_BASELEFT, bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET); } for (i=2; i < 7; i++) { Char time[timeStringLength]; StrPrintF(time, "0%u:00", (i-2)*2); WinDrawChars(time, StrLen(time), bounds.topLeft.x+GADGET_BASELEFT, (i != 7 - 1) ? bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET /* ^last^ */ : bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET-2); } } // Write Weekdays GadgetDrawWeekdays(); // Draw Grid: Color is light gray on colored palms, dark gray on gray palms if (TNisColored()) { color.r = 0x77; color.g = 0x77; color.b = 0x77; } else { color.r = 0x44; color.g = 0x44; color.b = 0x44; } TNSetForeColorRGB(&color, &prevColor); gadgetWidth=gGadgetDaysNum * gGadgetDaysWidth + gGadgetDaysNum - 1; RctSetRectangle(&rect, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y+GADGET_TOP, gadgetWidth, GADGET_HEIGHT); WinDrawRectangleFrame(simpleFrame, &rect); for(i=1; i <= 5; ++i) { // Draw the 5 gray dashed lines if ( (gGadgetCurScreen == GADGET_SCREEN_NIGHT) && (i == 2)) { WinDrawLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gadgetWidth-1, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET); } else { WinDrawGrayLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gadgetWidth-1, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET); } } for(i=1; i <= gGadgetDaysNum -1; ++i) { WinDrawLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+i*gGadgetDaysWidth+(i-1), bounds.topLeft.y+GADGET_TOP, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+i*gGadgetDaysWidth+(i-1), bounds.topLeft.y+GADGET_TOP+GADGET_HEIGHT-1); } TNSetForeColorRGB(&prevColor, NULL); }
void CScoringForm::OnDraw() { HostTraceOutputTL(sysErrorClass, "OnDraw"); Boolean won_bid = false; Int16 high_p = -1, low_p = -1, jack_p = -1, game_p = -1; Card::face_t high_c, low_c; Int16 points[3]; Int16 old_points[3]; points[0] = gManager->scores[0]; points[1] = gManager->scores[1]; points[2] = gManager->scores[2]; old_points[0] = gManager->scores[0]; old_points[1] = gManager->scores[1]; old_points[2] = gManager->scores[2]; Boolean smudge = false; won_bid = gManager->trk->CalculateGamePoints(&high_p, &low_p, &jack_p, &game_p, &high_c, &low_c, &smudge ); if ( gManager->CutThroat() == false ) { if ( smudge ) { switch ( (*gManager->tbl->winning_bidder)->playerIndex ) { case 0: case 2: points[0]++; break; case 1: case 3: points[1]++; break; } } switch( high_p ) { case 0: case 2: points[0]++; break; case 1: case 3: points[1]++; break; } switch( low_p ) { case 0: case 2: points[0]++; break; case 1: case 3: points[1]++; break; } switch( game_p ) { case 0: case 2: points[0]++; break; case 1: case 3: points[1]++; break; } switch( jack_p ) { case 0: case 2: points[0]++; break; case 1: case 3: points[1]++; break; } } else { points[high_p]++; points[low_p]++; if ( game_p != -1 ) { points[game_p]++; } if ( jack_p != -1 ) { points[jack_p]++; } } if ( high_p != -1 ) { high_field.Replace( (const char *)gManager->getPlayer(high_p)->getName() ); } if ( low_p != -1 ) { low_field.Replace( (const char *)gManager->getPlayer(low_p)->getName() ); } if ( jack_p != -1 ) { jack_field.Replace( (const char *)gManager->getPlayer(jack_p)->getName() ); } else { jack_field.Replace("none"); } Card foo(gManager->trk->getTrump(), high_c); Card foo2(gManager->trk->getTrump(), low_c); FormPtr frmP = FrmGetActiveForm(); RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(frmP, HighCardGadget ); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); foo.Draw(bounds.topLeft.x, bounds.topLeft.y, CPlayerHandGadget::card_width, CPlayerHandGadget::card_height); gadgetIndex = FrmGetObjectIndex(frmP, LowCardGadget ); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); foo2.Draw(bounds.topLeft.x, bounds.topLeft.y, CPlayerHandGadget::card_width, CPlayerHandGadget::card_height); char gamestr[80]; if ( gManager->CutThroat() == false ) { if ( game_p == 1 ) { StrPrintF(gamestr, "E/W team wins, %d - %d", gManager->GetTeamPoints('b'), gManager->GetTeamPoints('a') ); } else if ( game_p == 0 ) { StrPrintF(gamestr, "N/S team wins, %d - %d", gManager->GetTeamPoints('a'), gManager->GetTeamPoints('b') ); } else { StrPrintF(gamestr, "teams tied on points at %d", gManager->GetTeamPoints('a') ); } } else { if ( game_p == 2 ) { StrPrintF(gamestr, "%s wins, %d - %d - %d", (const char *)gManager->players[2]->getName(), gManager->GetTeamPoints('c'), gManager->GetTeamPoints('a'), gManager->GetTeamPoints('b') ); } else if ( game_p == 1 ) { StrPrintF(gamestr, "%s wins, %d - %d - %d", (const char *)gManager->players[1]->getName(), gManager->GetTeamPoints('b'), gManager->GetTeamPoints('a'), gManager->GetTeamPoints('c') ); } else if ( game_p == 0 ) { StrPrintF(gamestr, "%s wins, %d - %d - %d", (const char *)gManager->players[0]->getName(), gManager->GetTeamPoints('a'), gManager->GetTeamPoints('b'), gManager->GetTeamPoints('c') ); } else { StrPrintF(gamestr, "tied on points at %d", gManager->GetTeamPoints('a') ); } } game_field.Replace( gamestr ); char bid_results_str[255]; char bidval[10]; if ( gManager->tbl->bid != 5 ) { StrPrintF(bidval, "%d", gManager->tbl->bid); } else { StrCopy(bidval, "smudge"); } Int16 score_diff; Int16 bidder_score = 0; char other_results[80]; other_results[0] = 0; if ( gManager->CutThroat() == false ) { if ( (*gManager->tbl->winning_bidder)->playerIndex == 1 || (*gManager->tbl->winning_bidder)->playerIndex == 3 ) { score_diff = points[0] - old_points[0]; bidder_score = points[1] - old_points[1]; } else { score_diff = points[1] - old_points[1]; bidder_score = points[0] - old_points[0]; } } else { bidder_score = points[(*gManager->tbl->winning_bidder)->playerIndex] - old_points[(*gManager->tbl->winning_bidder)->playerIndex]; } if ( won_bid ) { StrPrintF(bid_results_str, "%s bid %s and won %d\n", (const char *)(*gManager->tbl->winning_bidder)->getName(), bidval, bidder_score ); } else { StrPrintF(bid_results_str, "%s bid %s and lost\n", (const char *)(*gManager->tbl->winning_bidder)->getName(), bidval ); if ( gManager->CutThroat() == false ) { switch ( (*gManager->tbl->winning_bidder)->playerIndex ) { case 0: case 2: // points[0] += (-1 * gManager->tbl->bid); points[0] = old_points[0] + (-1 * gManager->tbl->bid); break; case 1: case 3: // points[1] += (-1 * gManager->tbl->bid); points[1] = old_points[1] + (-1 * gManager->tbl->bid); break; } } else { // points[(*gManager->tbl->winning_bidder)->playerIndex] = -1 * gManager->tbl->bid; points[(*gManager->tbl->winning_bidder)->playerIndex] = old_points[(*gManager->tbl->winning_bidder)->playerIndex] + (-1 * gManager->tbl->bid); } } if ( gManager->CutThroat() == false ) { char other_team[4]; if ( (*gManager->tbl->winning_bidder)->playerIndex == 1 || (*gManager->tbl->winning_bidder)->playerIndex == 3 ) { StrCopy(other_team, "N/S"); } else { StrCopy(other_team, "E/W"); } if ( score_diff == 0 ) { StrPrintF(other_results, "%s team scored no points", other_team); } else if ( score_diff == 1 ) { StrPrintF(other_results, "%s team scored 1 point", other_team); } else { StrPrintF(other_results, "%s team scored %d points", other_team, score_diff); } StrCat(bid_results_str, other_results); } else { bidder_score = points[(*gManager->tbl->winning_bidder)->playerIndex] - old_points[(*gManager->tbl->winning_bidder)->playerIndex]; if ((*gManager->tbl->winning_bidder)->playerIndex != 0 ) { score_diff = points[0] - old_points[0]; if ( score_diff == 0 ) { StrPrintF(other_results, "%s scored no points\n", (const char *)gManager->players[0]->getName() ); } else if ( score_diff == 1 ) { StrPrintF(other_results, "%s scored 1 point\n", (const char *)gManager->players[0]->getName() ); } else { StrPrintF(other_results, "%s scored %d points\n", (const char *)gManager->players[0]->getName(), score_diff ); } StrCat(bid_results_str, other_results); } if ((*gManager->tbl->winning_bidder)->playerIndex != 1 ) { score_diff = points[1] - old_points[1]; char tmpstr[40]; if ( score_diff == 0 ) { StrPrintF(tmpstr, "%s scored no points\n", (const char *)gManager->players[1]->getName() ); } else if ( score_diff == 1 ) { StrPrintF(tmpstr, "%s scored 1 point\n", (const char *)gManager->players[1]->getName() ); } else { StrPrintF(tmpstr, "%s scored %d points\n", (const char *)gManager->players[1]->getName(), score_diff ); } StrCat(bid_results_str, tmpstr); } if ((*gManager->tbl->winning_bidder)->playerIndex != 2 ) { score_diff = points[2] - old_points[2]; char tmpstr[60]; if ( score_diff == 0 ) { StrPrintF(tmpstr, "%s scored no points", (const char *)gManager->players[2]->getName() ); } else if ( score_diff == 1 ) { StrPrintF(tmpstr, "%s scored 1 point", (const char *)gManager->players[2]->getName() ); } else { StrPrintF(tmpstr, "%s scored %d points", (const char *)gManager->players[2]->getName(), score_diff ); } StrCat(bid_results_str, tmpstr); } } bid_results.Replace( bid_results_str ); RectangleType score_bounds; gadgetIndex = FrmGetObjectIndex(frmP, ScoreDisplayGadget ); FrmGetObjectBounds(frmP, gadgetIndex, &score_bounds); Int16 y = score_bounds.topLeft.y; if ( gManager->CutThroat() ) { CString scores[3]; CString tmp; for ( int i = 0; i < 3; i++ ) { // tmp.Format("%d", gManager->scores[i] + points[i] - old_points[i]); tmp.Format("%d", points[i]); scores[i] = gManager->players[i]->getName() + ": " + tmp + " points"; WinPaintChars(scores[i], StrLen(scores[i]), score_bounds.topLeft.x + 2, y); y += FntLineHeight() + 2; } } else { CString ew_score_str; CString ns_score_str; // ew_score_str.Format("E/W: %d points", gManager->scores[1] + points[1] - old_points[1]); // ns_score_str.Format("N/S: %d points", gManager->scores[0] + points[0] - old_points[0]); ns_score_str.Format("N/S: %d points", points[0]); ew_score_str.Format("E/W: %d points", points[1]); WinPaintChars(ns_score_str, StrLen(ns_score_str), score_bounds.topLeft.x + 2, y ); y += FntLineHeight() + 2; WinPaintChars(ew_score_str, StrLen(ew_score_str), score_bounds.topLeft.x + 2, y); } HostTraceOutputTL(sysErrorClass, "OnDraw done"); }
static void UpdateDisplay(void) { UInt16 j; const char timer[] = "\024"; PFScreenLock(false); GUIFormDraw(); /* * make sure that the selected waypoint is kept high-lighted i.e. * move the list selector if the waypoint moves position in the list * */ if (selectedWaypointID != UNSELECTED && proxList.waypoints[currentSelection].id != selectedWaypointID) { /* * look for the waypoint ID in the list * */ for (j=0;j<proxList.numWaypoints;j++) { if (proxList.waypoints[j].id == selectedWaypointID) { currentSelection = j; break; } } /* * didn't find it? Clear the list selection * */ if (j == proxList.numWaypoints) { currentSelection = noListSelection; selectedWaypointID = UNSELECTED; } } if (GUIMenuIsDisplayed()) return; SetupScrollbar(); for (j=0;j<numProxWaypointsToDisplay;j++) { DrawWaypoint(j); } if (newProxList == &proxList) { FntSetFont(symbolFont); PFDrawChars(timer,1, StandardPageWidth-20,0); } else { FntSetFont(stdFont); PFDrawChars(" ",4, StandardPageWidth-20,0); } if (HSIMiniPanel) HSIMiniPanelDraw(HSIMiniPanel); PFScreenUnlock(); #ifdef ALTERNATE if (newProxList == &proxList) { PFScreenRectType r; FormPtr f = FrmGetActiveForm(); FrmGetObjectBounds(f, FrmGetObjectIndex(f, displayFilter + DvAirfieldPushbutton), &r); DrawAlignedChars(timer, ALIGNCENTRE, r.x1+r.extent.x/2, r.y1+r.extent.y/2 - FntLineHeight()/2); } else { CtlDrawControl(GetObjectPtr(FrmGetActiveForm(), displayFilter+DvAirfieldPushbutton)); } #endif PFSendSimpleEvent(evtScreenRedrawn); }