// Update_Level1 // Handle buttons and update game state for level 1. void GameState::Update_Level1() { // The arrow keys are used to move the current object. // We use CheckKeyHeld() because we want the action to repeat as long // as the player is holding down the button. int dx = 0; int dy = 0; if (CheckKeyHeld(KEY_LEFT)) dx = -1; if (CheckKeyHeld(KEY_RIGHT)) dx = 1; if (CheckKeyHeld(KEY_UP)) dy = -1; if (CheckKeyHeld(KEY_DOWN)) dy = 1; // Handle the player pressing the 'A' button. // We use CheckKeyPress() because we *don't* want the action to repeat // unless the player presses the 'A' button multiple times. if (CheckKeyPress(KEY_A) && !_has_projectile) { // ToDo: Add code to respond to 'A' button press here. _xBall = _xPlayer + 12; _yBall = _yPlayer + 5; MoveObjectTo(kObj_Ball, _xBall, _yBall); _has_projectile = true; ShowObject(kObj_Ball, true); } if (_has_projectile) { _xBall += 0; _yBall += 1; MoveObjectTo(kObj_Ball, _xBall, _yBall); // Get the width/height of the projectile. int width, height; GetObjectSize(kObj_Ball, &width, &height); // Turn off the projectile when it leaves the screen. if (_xBall < -width || _xBall > SCREEN_WIDTH || _yBall < -height || _yBall > SCREEN_HEIGHT) { ShowObject(kObj_Ball, false); _has_projectile = false; } } // If we need to move the player. if (dx != 0 || dy != 0) { // Record the player's new location. _xPlayer += dx; _yPlayer += dy; // Move the player to the new location. MoveObjectTo(kObj_Player, _xPlayer, _yPlayer); } // TODO: Add additional game state updates for level 1 here. }
/* We tell the image to resize themself to our current bounds. Our bounds could have changed because Resize may have been called by some layout-objects between Button.CalcSize and Button.Draw. */ void Button::Layout() { int x,y; size_t width,height; x=this->x; y=this->y; width=this->width; height=this->height; if (ShowImage()) { imageX=x; imageY=y+(height-image->GetHeight())/2; x+=image->GetWidth(); width-=image->GetWidth(); } if (ShowObject()) { if (ShowImage()) { x+=OS::display->GetSpaceHorizontal(OS::Display::spaceIntraObject); width-=OS::display->GetSpaceHorizontal(OS::Display::spaceIntraObject); } object->Resize(width,height); object->Move(x+(width-object->GetOWidth()) / 2, y+(height-object->GetOHeight()) / 2); object->Layout(); } Control::Layout(); }
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; }
// SetupStage_Level1 // Set up the stage (sprites and backgrounds) for level 1. void GameState::SetupStage_Level1() { // Set the default sprite video mode. SetSpriteVideoMode(); // Setup the foreground sprites. // The sprite data is not active until we copy it from our data // tables (in sprites.cpp) into the real Palette and Graphics memory. // So, let's copy the default spriteset there now. ClearSprites(); LoadSpriteset(0); // Setup the background tiles and map. // Just like sprites, the data is not active until we copy it from // our data tables (in background_maps.cpp) into real memory. ClearBackgrounds(); LoadBgTileset(0); LoadBgMap(0); // Initialize the objects for the first level. InitObject(kObj_Player, kSprites_Player); InitObject(kObj_Ball, kSprites_Ball); ShowObject(kObj_Ball, false); // Set the initial location of each object. _xPlayer = 0; _yPlayer = 0; MoveObjectTo(kObj_Player, _xPlayer, _yPlayer); // Initialize the projectile. _xBall = 0; _yBall = 0; MoveObjectTo(kObj_Ball, _xBall, _yBall); _has_projectile = false; // TODO: Add more initialization for level 1 here. }
/*********************************************************************** * * FUNCTION: ThumbnailViewLoadGadgets * * DESCRIPTION: This routine loads sketches into the thumbnail view form * thumbnail gadgets. * * PARAMETERS: recordNum index of the first record to display. * * RETURNED: nothing * ***********************************************************************/ static void ThumbnailViewLoadGadgets(FormType* frm) { UInt16 row; MemHandle recordH; DynamicButtonType* btn; MemPtr ptr; UInt16 attr; UInt16 recordNum = d.top_visible_record; const UInt16 max = Min(recordsPerPage, d.records_in_cat - d.top_row_pos_in_cat); for (row = 0; row < max; row++) { /* Get the next record in the current category. */ recordH = DmQueryNextInCategory (d.dbR, &recordNum, p.category); if(row == 0) { /* store the position of the first row so we can use */ /* d.top_row_pos_in_cat + row when drawing */ d.top_row_pos_in_cat = recordH ? DmPositionInCategory(d.dbR, recordNum, p.category) : 0; } btn = (DynamicButtonType*) FrmGetGadgetData(frm, FrmGetObjectIndex(frm, Thumb1 + row)); /* Store record number */ btn->value = recordNum; /* Clear old internal values */ btn->selected = false; /* Read record attributes */ DmRecordInfo(d.dbR, recordNum, &attr, NULL, NULL); if (attr & dmRecAttrSecret && d.privateRecordStatus == maskPrivateRecords) { DrawMaskedRecord(btn->content.bmpW, maskPattern); } else { /* WinHandle oldH = NULL; */ /* Err err = 0; */ /* BitmapType* bmp = BmpCreate(btn->contentRect.extent.x, */ /* btn->contentRect.extent.y, 1, NULL, &err); */ /* if (err) abort(); */ /* Uncompress thumbnail */ ptr = MemHandleLock(recordH); // MemMove(BmpGetBits(bmp), ptr + sketchDataOffset, sketchThumbnailSize); MemMove(BmpGetBits(WinGetBitmap(btn->content.bmpW)), ptr + sketchDataOffset, sketchThumbnailSize); MemHandleUnlock(recordH); /* Write thumbnail to content bitmap */ /* WinPushDrawState(); */ /* WinSetCoordinateSystem(kCoordinatesNative); */ /* oldH = WinSetDrawWindow(btn->content.bmpW); */ /* WinPaintBitmap(bmp, 0, 0); */ /* WinSetDrawWindow(oldH); */ /* WinPopDrawState(); */ /* Clean up */ /* BmpDelete(bmp); */ } recordNum++; /* Show the right gadgets... */ ShowObject(frm, Thumb1 + row); } /* ...store the index of the last visible thumbnail... */ d.lastVisibleThumbnail = row - 1; /* ... and hide the rest */ for (; row < recordsPerPage; row++) HideObject(frm, Thumb1 + row); /* Update the scroll arrows. */ ThumbnailViewUpdateScrollers (frm); }
/*********************************************************************** * * FUNCTION: RepeatInit * * DESCRIPTION: This routine initializes tthe "Repeat Dialog Box". All * the object in the dialog are initialize, even if they * are not used given the current repeat type. * * PARAMETERS: frm - pointer to the repeat dialog box * * RETURNED: nothing * ***********************************************************************/ void RepeatInit(FormType* frm) { UInt16 id = RepeatDayOfWeek1PushButton; /* ** Set usable the ui object that are appropriate for the given ** repeat type. */ switch (d.tmp_repeat.repeatType) { case repeatNone: ShowObject(frm, RepeatNoRepeatLabel); break; case repeatHourly: ShowObject(frm, RepeatEveryLabel); ShowObject(frm, RepeatFrequenceField); ShowObject(frm, RepeatHoursLabel); ShowObject(frm, RepeatEndOnLabel); ShowObject(frm, RepeatEndOnTrigger); break; case repeatDaily: ShowObject(frm, RepeatEveryLabel); ShowObject(frm, RepeatFrequenceField); ShowObject(frm, RepeatDaysLabel); ShowObject(frm, RepeatEndOnLabel); ShowObject(frm, RepeatEndOnTrigger); break; case repeatWeekly: ShowObject(frm, RepeatEveryLabel); ShowObject(frm, RepeatFrequenceField); ShowObject(frm, RepeatWeeksLabel); ShowObject(frm, RepeatRepeatOnLabel); ShowObject(frm, RepeatEndOnLabel); ShowObject(frm, RepeatEndOnTrigger); for (; id <= RepeatDayOfWeek7PushButton; id++) ShowObject(frm, id); break; case repeatMonthlyByDay: case repeatMonthlyByDate: ShowObject(frm, RepeatEveryLabel); ShowObject(frm, RepeatFrequenceField); ShowObject(frm, RepeatMonthsLabel); ShowObject(frm, RepeatByLabel); ShowObject(frm, RepeatByDayPushButton); ShowObject(frm, RepeatByDatePushButton); ShowObject(frm, RepeatEndOnLabel); ShowObject(frm, RepeatEndOnTrigger); break; case repeatYearly: ShowObject(frm, RepeatEveryLabel); ShowObject(frm, RepeatFrequenceField); ShowObject(frm, RepeatYearsLabel); ShowObject(frm, RepeatEndOnLabel); ShowObject(frm, RepeatEndOnTrigger); break; } FrmSetGadgetHandler(frm, FrmGetObjectIndex(frm, RepeatDescRectGadget), RepeatDescRectHandler); d.repeat_end_date = d.tmp_repeat.repeatEndDate; d.repeat_event_type = d.tmp_repeat.repeatType; RepeatSetUIValues(frm, &d.tmp_repeat); }
/*********************************************************************** * * FUNCTION: RepeatChangeType * * DESCRIPTION: This routine changes the ui gadgets in the repeat dialog * such that they match the newly selected repeat type. The * routine is called when one of the repeat type push buttons * are pushed. * * PARAMETERS: event - pointer to and event * * RETURNED: nothing * ***********************************************************************/ static void RepeatChangeType(EventType* event) { UInt16 id; FormType* frm = FrmGetFormPtr(RepeatForm); const RepeatType oldType = d.repeat_event_type; RepeatType newType; RepeatInfoType repeat; /* If the type if monthly default to monthly-by-date. */ newType = (RepeatType) (event->data.ctlSelect.controlID - RepeatNone); if (newType > repeatWeekly) newType++; if (oldType == newType) return; /* Initialize the UI gadgets. */ if (newType == d.tmp_repeat.repeatType) { RepeatSetUIValues(frm, &d.tmp_repeat); /* ** If reselecting current repeat type, reset d.repeat_end_date global ** to current date so if user attemps to "choose" a new day, the ** default matches date displayed as opposed to last date picked ** last in choose form. */ d.repeat_end_date = d.tmp_repeat.repeatEndDate; } else { repeat.repeatType = newType; /* ** When switching to a repeat type different from the current ** setting, always start user with default end date and frequency ** settings. */ DateToInt(repeat.repeatEndDate) = defaultRepeatEndDate; DateToInt(d.repeat_end_date) = defaultRepeatEndDate; repeat.repeatFrequency = defaultRepeatFrequency; repeat.repeatStartOfWeek = PrefGetPreference(prefWeekStartDay); if (newType == repeatWeekly) { repeat.repeatOn = (1 << DayOfWeek(d.frm_date.month, d.frm_date.day, d.frm_date.year/*+firstYear*/)); } else if (newType == repeatMonthlyByDay) { repeat.repeatOn = DayOfMonth(d.frm_date.month, d.frm_date.day, d.frm_date.year/* + firstYear*/); } else { repeat.repeatOn = 0; } RepeatSetUIValues (frm, &repeat); } /* ** Hide the UI gadgets that are unique to the repeat type we are ** no longer editing. */ switch (oldType) { case repeatNone: HideObject(frm, RepeatNoRepeatLabel); break; case repeatHourly: HideObject(frm, RepeatHoursLabel); break; case repeatDaily: HideObject(frm, RepeatDaysLabel); break; case repeatWeekly: HideObject(frm, RepeatWeeksLabel); for (id = RepeatRepeatOnLabel; id <= RepeatDayOfWeek7PushButton; id++) HideObject (frm, id); break; case repeatMonthlyByDay: case repeatMonthlyByDate: HideObject(frm, RepeatMonthsLabel); for (id = RepeatByLabel; id <= RepeatByDatePushButton; id++) HideObject (frm, id); break; case repeatYearly: HideObject(frm, RepeatYearsLabel); break; } /* Handle switching to or from "no" repeat. */ if (oldType == repeatNone) { ShowObject(frm, RepeatEveryLabel); ShowObject(frm, RepeatFrequenceField); ShowObject(frm, RepeatEndOnLabel); ShowObject(frm, RepeatEndOnTrigger); } else if (newType == repeatNone) { HideObject(frm, RepeatEveryLabel); HideObject(frm, RepeatFrequenceField); HideObject(frm, RepeatEndOnLabel); HideObject(frm, RepeatEndOnTrigger); } /* Show the UI object that are appropriate for the new repeat type. */ switch (newType) { case repeatNone: ShowObject(frm, RepeatNoRepeatLabel); break; case repeatHourly: ShowObject(frm, RepeatHoursLabel); break; case repeatDaily: ShowObject(frm, RepeatDaysLabel); break; case repeatWeekly: ShowObject(frm, RepeatWeeksLabel); ShowObject(frm, RepeatRepeatOnLabel); for (id = RepeatRepeatOnLabel; id <= RepeatDayOfWeek7PushButton; id++) ShowObject(frm, id); break; case repeatMonthlyByDay: case repeatMonthlyByDate: ShowObject(frm, RepeatMonthsLabel); ShowObject(frm, RepeatByLabel); ShowObject(frm, RepeatByDayPushButton); ShowObject(frm, RepeatByDatePushButton); break; case repeatYearly: ShowObject(frm, RepeatYearsLabel); break; } d.repeat_event_type = newType; /* Update the display of the repeat descrition. */ RepeatDrawDescription(frm); }
void dlgRepCluster::OnOK(wxCommandEvent &ev) { #ifdef __WXGTK__ if (!btnOK->IsEnabled()) return; #endif EnableOK(false); bool done = true; done = connection->ExecuteVoid(wxT("BEGIN TRANSACTION;")); if (remoteConn) done = remoteConn->ExecuteVoid(wxT("BEGIN TRANSACTION;")); // initialize cluster on local node done = connection->ExecuteVoid(GetSql()); if (done && chkJoinCluster->GetValue()) { // we're joining an existing cluster wxString schemaPrefix = qtIdent(wxT("_") + cbClusterName->GetValue()) + wxT("."); wxString clusterVersion = remoteConn->ExecuteScalar( wxT("SELECT ") + schemaPrefix + wxT("slonyversion()")); wxString newVersion = connection->ExecuteScalar( wxT("SELECT ") + schemaPrefix + wxT("slonyversion()")); if (clusterVersion != newVersion) { wxMessageDialog msg(this, wxString::Format(_("The newly created cluster version (%s)\n doesn't match the existing cluster's version (%s)"), newVersion.c_str(), clusterVersion.c_str()), _("Error while joining replication cluster"), wxICON_ERROR); msg.ShowModal(); done = false; } if (done) done = CopyTable(remoteConn, connection, schemaPrefix + wxT("sl_node")); if (done) done = CopyTable(remoteConn, connection, schemaPrefix + wxT("sl_path")); if (done) done = CopyTable(remoteConn, connection, schemaPrefix + wxT("sl_listen")); if (done) done = CopyTable(remoteConn, connection, schemaPrefix + wxT("sl_set")); if (done) done = CopyTable(remoteConn, connection, schemaPrefix + wxT("sl_subscribe")); // make sure event seqno starts correctly after node reusage if (done) { pgSet *set = connection->ExecuteSet( wxT("SELECT ev_origin, MAX(ev_seqno) as seqno\n") wxT(" FROM ") + schemaPrefix + wxT("sl_event\n") wxT(" GROUP BY ev_origin")); if (set) { while (done && !set->Eof()) { if (set->GetVal(wxT("ev_origin")) == txtNodeID->GetValue()) { done = connection->ExecuteVoid( wxT("SELECT pg_catalog.setval(") + qtDbString(wxT("_") + cbClusterName->GetValue() + wxT(".sl_event_seq")) + wxT(", ") + set->GetVal(wxT("seqno")) + wxT("::int8 +1)")); } else { done = connection->ExecuteVoid( wxT("INSERT INTO ") + schemaPrefix + wxT("sl_confirm(con_origin, con_received, con_seqno, con_timestamp\n") wxT(" VALUES (") + set->GetVal(wxT("ev_origin")) + wxT(", ") + txtNodeID->GetValue() + wxT(", ") + set->GetVal(wxT("seqno")) + wxT(", current_timestamp")); } set->MoveNext(); } delete set; } } // make sure rowid seq starts correctly if (done) { wxString seqno = connection->ExecuteScalar( wxT("SELECT MAX(seql_last_value)\n") wxT(" FROM ") + schemaPrefix + wxT("sl_seqlog\n") wxT(" WHERE seql_seqid = 0 AND seql_origin = ") + txtNodeID->GetValue()); if (!seqno.IsEmpty()) { done = connection->ExecuteVoid( wxT("SELECT pg_catalog.setval(") + qtDbString(wxT("_") + cbClusterName->GetValue() + wxT(".sl_rowid_seq")) + wxT(", ") + seqno + wxT(")")); } } // create new node on the existing cluster if (done) { wxString sql = wxT("SELECT ") + schemaPrefix + wxT("storenode(") + txtNodeID->GetValue() + wxT(", ") + qtDbString(txtNodeName->GetValue()); if (StrToDouble(remoteVersion) >= 1.1 && StrToDouble(remoteVersion) < 2.0) sql += wxT(", false"); sql += wxT(");\n") wxT("SELECT ") + schemaPrefix + wxT("enablenode(") + txtNodeID->GetValue() + wxT(");\n"); done = remoteConn->ExecuteVoid(sql); } // add admin info to cluster if (done && cbAdminNode->GetCurrentSelection() > 0) { done = remoteConn->ExecuteVoid( wxT("SELECT ") + schemaPrefix + wxT("storepath(") + txtNodeID->GetValue() + wxT(", ") + NumToStr((long)cbAdminNode->wxItemContainer::GetClientData(cbAdminNode->GetCurrentSelection())) + wxT(", ") + qtDbString(wxT("host=") + database->GetServer()->GetName() + wxT(" port=") + NumToStr((long)database->GetServer()->GetPort()) + wxT(" dbname=") + database->GetName()) + wxT(", ") wxT("0);\n")); } } if (!done) { if (remoteConn) done = remoteConn->ExecuteVoid(wxT("ROLLBACK TRANSACTION;")); done = connection->ExecuteVoid(wxT("ROLLBACK TRANSACTION;")); EnableOK(true); return; } if (remoteConn) done = remoteConn->ExecuteVoid(wxT("COMMIT TRANSACTION;")); done = connection->ExecuteVoid(wxT("COMMIT TRANSACTION;")); ShowObject(); Destroy(); }
void Button::Draw(OS::DrawInfo* draw, int x, int y, size_t w, size_t h) { Control::Draw(draw,x,y,w,h); /* We must call Draw of our superclass */ if (!OIntersect(x,y,w,h)) { return; } /* Set the correct draw mode before calling the baseclass, since the baseclass draw the object frame. */ if (model.Valid() && model->IsEnabled()) { if (IsMouseActive() && !model->IsStarted()) { draw->activated=true; } if (triggering && model->IsStarted()) { draw->selected=true; } } else { draw->disabled=true; } draw->focused=HasFocus(); // Draw object if (ShowObject()) { object->Draw(draw,x,y,w,h); } // Draw optional image if (ShowImage()) { image->Draw(draw,imageX,imageY); } draw->activated=false; draw->selected=false; draw->disabled=false; draw->focused=false; if (!scAssigned) { Dialog* window; assert(GetWindow()!=NULL); window=dynamic_cast<Dialog*>(GetWindow()->GetMaster()); if (window!=NULL) { if (shortCut!='\0') { window->RegisterShortcut(this,0,std::wstring(1,shortCut),model); window->RegisterShortcut(this,OS::qualifierAlt,std::wstring(1,shortCut),model); } switch (type) { case typeCommit: window->RegisterCommitShortcut(this,model); break; case typeCancel: window->RegisterCancelShortcut(this,model); break; case typeDefault: window->RegisterDefaultShortcut(this,model); break; default: break; } } scAssigned=true; } }
void Button::CalcSize() { /* Let the frame calculate its size */ switch (type) { case typeNormal: SetBackground(OS::display->GetFill(OS::Display::buttonBackgroundFillIndex)); if (!OS::display->GetTheme()->FocusOnEditableControlsOnly()) { RequestFocus(); } if (OS::display->GetTheme()->RequestFingerFriendlyControls()) { SetMinWidth(OS::display->GetTheme()->GetFingerFriendlyMinWidth()); SetMinHeight(OS::display->GetTheme()->GetFingerFriendlyMinHeight()); } break; case typeDefault: SetBackground(OS::display->GetFill(OS::Display::defaultButtonBackgroundFillIndex)); if (!OS::display->GetTheme()->FocusOnEditableControlsOnly()) { RequestFocus(); } if (OS::display->GetTheme()->RequestFingerFriendlyControls()) { SetMinWidth(OS::display->GetTheme()->GetFingerFriendlyMinWidth()); SetMinHeight(OS::display->GetTheme()->GetFingerFriendlyMinHeight()); } break; case typeCommit: SetBackground(OS::display->GetFill(OS::Display::positiveButtonBackgroundFillIndex)); if (!OS::display->GetTheme()->FocusOnEditableControlsOnly()) { RequestFocus(); } if (OS::display->GetTheme()->RequestFingerFriendlyControls()) { SetMinWidth(OS::display->GetTheme()->GetFingerFriendlyMinWidth()); SetMinHeight(OS::display->GetTheme()->GetFingerFriendlyMinHeight()); } break; case typeCancel: SetBackground(OS::display->GetFill(OS::Display::negativeButtonBackgroundFillIndex)); if (!OS::display->GetTheme()->FocusOnEditableControlsOnly()) { RequestFocus(); } if (OS::display->GetTheme()->RequestFingerFriendlyControls()) { SetMinWidth(OS::display->GetTheme()->GetFingerFriendlyMinWidth()); SetMinHeight(OS::display->GetTheme()->GetFingerFriendlyMinHeight()); } break; case typeIcon: SetBackground(OS::display->GetFill(OS::Display::buttonBackgroundFillIndex)); if (!OS::display->GetTheme()->FocusOnEditableControlsOnly()) { RequestFocus(); } break; case typeAdditional: SetBackground(OS::display->GetFill(OS::Display::buttonBackgroundFillIndex)); if (!OS::display->GetTheme()->FocusOnEditableControlsOnly()) { RequestFocus(); } break; case typeToolBar: SetBackground(OS::display->GetFill(OS::Display::toolbarButtonBackgroundFillIndex)); SetCanFocus(false); break; case typeScroll: SetBackground(OS::display->GetFill(OS::Display::scrollButtonBackgroundFillIndex)); SetCanFocus(false); break; } width=0; height=0; minWidth=0; minHeight=0; if (ShowObject()) { /* Now we let the image calculate its bounds and simply add its size to the size of the button. */ object->CalcSize(); width=object->GetOWidth(); height=object->GetOHeight(); minWidth=object->GetOMinWidth(); minHeight=object->GetOMinHeight(); } if (ShowImage()) { minWidth+=image->GetWidth(); width+=image->GetWidth(); minHeight=std::max(minHeight,image->GetHeight()); height=std::max(height,image->GetHeight()); } if (ShowObject() && ShowImage()) { minWidth+=OS::display->GetSpaceHorizontal(OS::Display::spaceIntraObject); width+=OS::display->GetSpaceHorizontal(OS::Display::spaceIntraObject); } maxWidth=30000; maxHeight=30000; /* We *must* call CalcSize of our superclass! */ Control::CalcSize(); }