TEST(NumLib, SpatialFunctionInterpolationSurface) { // create geometry GeoLib::Point pt1(0.0, 0.0, 0.0); GeoLib::Point pt2(10.0, 0.0, 0.0); GeoLib::Point pt3(10.0, 10.0, 0.0); GeoLib::Point pt4(0.0, 10.0, 0.0); std::vector<GeoLib::Point*> pnts = {&pt1, &pt2, &pt3, &pt4}; GeoLib::Polyline ply0(pnts); ply0.addPoint(0); ply0.addPoint(1); ply0.addPoint(2); ply0.addPoint(3); ply0.addPoint(0); std::unique_ptr<GeoLib::Surface> sfc1(GeoLib::Surface::createSurface(ply0)); // define a function const std::vector<std::size_t> vec_point_ids = {{0, 1, 2, 3}}; const std::vector<double> vec_point_values = {{0., 100., 100., 0.}}; NumLib::LinearInterpolationOnSurface interpolate(*sfc1, vec_point_ids, vec_point_values, std::numeric_limits<double>::max()); // normal for (unsigned k=0; k<10; k++) { ASSERT_DOUBLE_EQ(k*10., interpolate(GeoLib::Point(k,0,0))); ASSERT_DOUBLE_EQ(k*10., interpolate(GeoLib::Point(k,5,0))); ASSERT_DOUBLE_EQ(k*10., interpolate(GeoLib::Point(k,10,0))); } // failure // x, y ASSERT_DOUBLE_EQ(std::numeric_limits<double>::max(), interpolate(GeoLib::Point(-1,-1,0))); ASSERT_DOUBLE_EQ(std::numeric_limits<double>::max(), interpolate(GeoLib::Point(11,-1,0))); ASSERT_DOUBLE_EQ(std::numeric_limits<double>::max(), interpolate(GeoLib::Point(11,11,0))); ASSERT_DOUBLE_EQ(std::numeric_limits<double>::max(), interpolate(GeoLib::Point(-1,11,0))); // z ASSERT_DOUBLE_EQ(std::numeric_limits<double>::max(), interpolate(GeoLib::Point(0,0,1))); ASSERT_DOUBLE_EQ(std::numeric_limits<double>::max(), interpolate(GeoLib::Point(0,0,-1))); }
Dialog::answer_t PocketPC::HeroesOpenDialog(Heroes & hero, bool readonly) { Cursor & cursor = Cursor::Get(); Display & display = Display::Get(); LocalEvent & le = LocalEvent::Get(); cursor.Hide(); cursor.SetThemes(cursor.POINTER); const u16 window_w = 320; const u16 window_h = 224; Dialog::FrameBorder frameborder; frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); frameborder.Redraw(); const Rect & dst_rt = frameborder.GetArea(); const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); const Sprite & backSprite = AGG::GetICN(ICN::SWAPWIN, 0); background.Blit(Rect(0, 0, window_w, window_h), dst_rt); // portrait AGG::GetICN(ICN::BRCREST, 6).Blit(dst_rt.x + 8, dst_rt.y, display); hero.GetPortrait50x46().Blit(dst_rt.x + 12, dst_rt.y + 4, display); // name std::string message = _("%{name} the %{race} ( Level %{level} )"); String::Replace(message, "%{name}", hero.GetName()); String::Replace(message, "%{race}", Race::String(hero.GetRace())); String::Replace(message, "%{level}", hero.GetLevel()); Text text(message, Font::SMALL); text.Blit(dst_rt.x + 73, dst_rt.y + 1); // experience ExperienceIndicator experienceInfo(hero); experienceInfo.SetPos(Point(dst_rt.x + 205, dst_rt.y + 14)); experienceInfo.Redraw(); // spell points SpellPointsIndicator spellPointsInfo(hero); spellPointsInfo.SetPos(Point(dst_rt.x + 238, dst_rt.y + 16)); spellPointsInfo.Redraw(); // morale MoraleIndicator moraleIndicator(hero); moraleIndicator.SetPos(Point(dst_rt.x + 280, dst_rt.y + 20)); moraleIndicator.Redraw(); // luck LuckIndicator luckIndicator(hero); luckIndicator.SetPos(Point(dst_rt.x + 280, dst_rt.y + 60)); luckIndicator.Redraw(); // prim skill const Rect ras(dst_rt.x + 74, dst_rt.y + 14, 34, 34); backSprite.Blit(Rect(216, 51, ras.w, ras.h), ras); text.Set(GetString(hero.GetAttack())); text.Blit(dst_rt.x + 74 + (34 - text.w()) / 2, dst_rt.y + 47); const Rect rds(dst_rt.x + 107, dst_rt.y + 14, 34, 34); backSprite.Blit(Rect(216, 84, rds.w, rds.h), rds); text.Set(GetString(hero.GetDefense())); text.Blit(dst_rt.x + 107 + (34 - text.w()) / 2, dst_rt.y + 47); const Rect rps(dst_rt.x + 140, dst_rt.y + 14, 34, 34); backSprite.Blit(Rect(216, 117, rps.w, rps.h), rps); text.Set(GetString(hero.GetPower())); text.Blit(dst_rt.x + 140 + (34 - text.w()) / 2, dst_rt.y + 47); const Rect rks(dst_rt.x + 173, dst_rt.y + 14, 34, 34); backSprite.Blit(Rect(216, 150, rks.w, rks.h), rks); text.Set(GetString(hero.GetKnowledge())); text.Blit(dst_rt.x + 173 + (34 - text.w()) / 2, dst_rt.y + 47); // sec skill backSprite.Blit(Rect(21, 198, 267, 36), dst_rt.x + 7, dst_rt.y + 57); // secondary skill SecondarySkillBar secskill_bar; secskill_bar.SetPos(dst_rt.x + 9, dst_rt.y + 59); secskill_bar.SetUseMiniSprite(); secskill_bar.SetInterval(1); secskill_bar.SetSkills(hero.GetSecondarySkills()); secskill_bar.Redraw(); // army bar const Rect rt1(36, 267, 43, 53); Surface sfb1(rt1.w, rt1.h); backSprite.Blit(rt1, 0, 0, sfb1); Surface sfc1(rt1.w, rt1.h - 10); Cursor::DrawCursor(sfc1, 0xd6, true); SelectArmyBar selectArmy; selectArmy.SetArmy(hero.GetArmy()); selectArmy.SetPos(dst_rt.x + 50, dst_rt.y + 170); selectArmy.SetInterval(2); selectArmy.SetBackgroundSprite(sfb1); selectArmy.SetCursorSprite(sfc1); selectArmy.SetUseMons32Sprite(); selectArmy.SetSaveLastTroop(); if(readonly) selectArmy.SetReadOnly(); const Castle* castle = hero.inCastle(); if(castle) selectArmy.SetCastle(*castle); selectArmy.Redraw(); // art bar const Rect rt2(23, 347, 34, 34); Surface sfb2(rt2.w, rt2.h); backSprite.Blit(rt2, 0, 0, sfb2); Surface sfc2(rt2.w, rt2.h); Cursor::DrawCursor(sfc2, 0xd6, true); SelectArtifactsBar selectArtifacts(hero); selectArtifacts.SetPos(dst_rt.x + 37, dst_rt.y + 95); selectArtifacts.SetInterval(2); selectArtifacts.SetBackgroundSprite(sfb2); selectArtifacts.SetCursorSprite(sfc2); selectArtifacts.SetUseArts32Sprite(); if(readonly) selectArtifacts.SetReadOnly(); selectArtifacts.Redraw(); Button buttonDismiss(dst_rt.x + dst_rt.w / 2 - 160, dst_rt.y + dst_rt.h - 125, ICN::HSBTNS, 0, 1); Button buttonExit(dst_rt.x + dst_rt.w / 2 + 130, dst_rt.y + dst_rt.h - 125, ICN::HSBTNS, 2, 3); Button buttonPrev(dst_rt.x + 34, dst_rt.y + 200, ICN::TRADPOST, 3, 4); Button buttonNext(dst_rt.x + 275, dst_rt.y + 200, ICN::TRADPOST, 5, 6); if(castle || readonly) { buttonDismiss.Press(); buttonDismiss.SetDisable(true); } if(readonly || 2 > world.GetKingdom(hero.GetColor()).GetHeroes().size()) { buttonNext.Press(); buttonPrev.Press(); buttonNext.SetDisable(true); buttonPrev.SetDisable(true); } buttonDismiss.Draw(); buttonExit.Draw(); buttonNext.Draw(); buttonPrev.Draw(); cursor.Show(); display.Flip(); while(le.HandleEvents()) { le.MousePressLeft(buttonNext) ? buttonNext.PressDraw() : buttonNext.ReleaseDraw(); le.MousePressLeft(buttonPrev) ? buttonPrev.PressDraw() : buttonPrev.ReleaseDraw(); le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); if(buttonDismiss.isEnable()) le.MousePressLeft(buttonDismiss) ? buttonDismiss.PressDraw() : buttonDismiss.ReleaseDraw(); if(buttonNext.isEnable() && le.MouseClickLeft(buttonNext)) return Dialog::NEXT; else if(buttonPrev.isEnable() && le.MouseClickLeft(buttonPrev)) return Dialog::PREV; else // exit if(le.MouseClickLeft(buttonExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) return Dialog::CANCEL; else // dismiss if(buttonDismiss.isEnable() && le.MouseClickLeft(buttonDismiss) && Dialog::YES == Dialog::Message(hero.GetName(), _("Are you sure you want to dismiss this Hero?"), Font::BIG, Dialog::YES | Dialog::NO)) { return Dialog::DISMISS; } // primary click info if(le.MouseClickLeft(ras)) Dialog::Message(_("Attack Skill"), _("Your attack skill is a bonus added to each creature's attack skill."), Font::BIG, Dialog::OK); else if(le.MouseClickLeft(rds)) Dialog::Message(_("Defense Skill"), _("Your defense skill is a bonus added to each creature's defense skill."), Font::BIG, Dialog::OK); else if(le.MouseClickLeft(rps)) Dialog::Message(_("Spell Power"), _("Your spell power determines the length or power of a spell."), Font::BIG, Dialog::OK); else if(le.MouseClickLeft(rks)) Dialog::Message(_("Knowledge"), _("Your knowledge determines how many spell points your hero may have. Under normal cirumstances, a hero is limited to 10 spell points per level of knowledge."), Font::BIG, Dialog::OK); if(le.MouseCursor(secskill_bar.GetArea())) secskill_bar.QueueEventProcessing(); // selector troops event if(le.MouseCursor(selectArmy.GetArea())) { if(selectArtifacts.isSelected()) selectArtifacts.Reset(); if(SelectArmyBar::QueueEventProcessing(selectArmy)) { cursor.Hide(); moraleIndicator.Redraw(); luckIndicator.Redraw(); cursor.Show(); display.Flip(); } } // selector artifacts event if(le.MouseCursor(selectArtifacts.GetArea())) { if(selectArmy.isSelected()) selectArmy.Reset(); SelectArtifactsBar::QueueEventProcessing(selectArtifacts); } if(le.MouseCursor(moraleIndicator.GetArea())) MoraleIndicator::QueueEventProcessing(moraleIndicator); else if(le.MouseCursor(luckIndicator.GetArea())) LuckIndicator::QueueEventProcessing(luckIndicator); else if(le.MouseCursor(experienceInfo.GetArea())) experienceInfo.QueueEventProcessing(); else if(le.MouseCursor(spellPointsInfo.GetArea())) spellPointsInfo.QueueEventProcessing(); } return Dialog::ZERO; }