void CHTMLSection::LoadFromResource( UINT uID ) { CResourceLoader rsrc( m_hDefaultInstance ); VERIFY( rsrc.Load( uID, RT_RCDATA ) ); CHTMLDocument *pDoc = NULL; #ifdef _UNICODE LPTSTR pszHTML = reinterpret_cast<LPTSTR>( malloc( rsrc.GetSize() * sizeof( TCHAR ) + 1 ) ); { MultiByteToWideChar(CP_ACP, 0, (LPCSTR)rsrc.GetData(), rsrc.GetSize(), pszHTML, rsrc.GetSize() * sizeof( TCHAR ) ); CHTMLParse html( pszHTML, rsrc.GetSize(), m_hDefaultInstance, NULL, m_pDefaults ); #else // _UNICODE CHTMLParse html( (LPCTSTR)rsrc.GetData(), rsrc.GetSize(), m_hDefaultInstance, NULL, m_pDefaults ); #endif // _UNICODE pDoc = html.Parse(); #ifdef _UNICODE free( pszHTML ); } #endif // _UNICODE if( pDoc ) { DestroyDocument(); m_pDocument = pDoc; } }
// --------------------------------------------------------------------------- // // ----------- OSStatus bPrintMgr::set_page_format(PMPageFormat pf, const char* name){ OSStatus status; char path[PATH_MAX]; map_doc->location(path); bStdDirectory root(path); if(root.status()){ return(root.status()); } bStdDirectory rsrc("Contents/Resources/"); if(rsrc.status()){ return(rsrc.status()); } char nm[256]; int sgn=kPrintSignature; sprintf(nm,"%.4s/",(char*)&sgn); bStdDirectory prn(nm); if(prn.status()){ return(prn.status()); } bStdFile f(name,"w"); if(f.status()){ return(f.status()); } CFDataRef dt; status=PMPageFormatCreateDataRepresentation(pf,&dt,kPMDataFormatXMLDefault); if(status){ return(status); } f.write((void*)CFDataGetBytePtr(dt),CFDataGetLength(dt)); CFRelease(dt); return(noErr); }
void OpenAlSoundDriver::open_sound(PrintItem path, scoped_ptr<Sound>& sound) { scoped_ptr<OpenAlSound> result(new OpenAlSound(*this)); Resource rsrc(path); AudioFile audio_file(rsrc.data()); result->buffer(audio_file); sound.reset(result.release()); }
String DebriefingScreen::build_score_text( game_ticks your_time, game_ticks par_time, int your_loss, int par_loss, int your_kill, int par_kill) { Resource rsrc("text", "txt", 6000); String text(utf8::decode(rsrc.data())); StringList strings(6000); const int your_mins = duration_cast<secs>(your_time.time_since_epoch()).count() / 60; const int your_secs = duration_cast<secs>(your_time.time_since_epoch()).count() % 60; const int par_mins = duration_cast<secs>(par_time.time_since_epoch()).count() / 60; const int par_secs = duration_cast<secs>(par_time.time_since_epoch()).count() % 60; const int your_score = score(your_time, par_time, your_loss, par_loss, your_kill, par_kill); const int par_score = 100; string_replace(&text, strings.at(0), your_mins); string_replace(&text, strings.at(1), dec(your_secs, 2)); if (par_time > game_ticks()) { string_replace(&text, strings.at(2), par_mins); String secs_string; print(secs_string, format(":{0}", dec(par_secs, 2))); string_replace(&text, strings.at(3), secs_string); } else { StringList data_strings(6002); string_replace(&text, strings.at(2), data_strings.at(8)); // = "N/A" string_replace(&text, strings.at(3), ""); } string_replace(&text, strings.at(4), your_loss); string_replace(&text, strings.at(5), par_loss); string_replace(&text, strings.at(6), your_kill); string_replace(&text, strings.at(7), par_kill); string_replace(&text, strings.at(8), your_score); string_replace(&text, strings.at(9), par_score); return text; }
NatePixTable::NatePixTable(int id, uint8_t color) { Resource rsrc("sprites", "json", id); String data(utf8::decode(rsrc.data())); Json json; if (!string_to_json(data, json)) { throw Exception("invalid sprite json"); } PixTableVisitor::State state; json.accept(PixTableVisitor(state, id, color, _frames)); }
void CreateObjectDataText(String* text, short id) { Resource rsrc("text", "txt", kShipDataTextID); String data(macroman::decode(rsrc.data())); const baseObjectType& baseObject = gBaseObjectData.get()[id]; StringList keys(kShipDataKeyStringID); StringList values(kShipDataNameID); // *** Replace place-holders in text with real data, using the fabulous find_replace routine // an object or a ship? if ( baseObject.attributes & kCanThink) { const StringSlice& name = values.at(0); find_replace(data, 0, keys.at(kShipOrObjectStringNum), name); } else { const StringSlice& name = values.at(1); find_replace(data, 0, keys.at(kShipOrObjectStringNum), name); } // ship name { StringList names(5000); const StringSlice& name = names.at(id); find_replace(data, 0, keys.at(kShipTypeStringNum), name); } // ship mass find_replace(data, 0, keys.at(kMassStringNum), fixed(baseObject.mass)); // ship shields find_replace(data, 0, keys.at(kShieldStringNum), baseObject.health); // light speed find_replace(data, 0, keys.at(kHasLightStringNum), baseObject.warpSpeed); // max velocity find_replace(data, 0, keys.at(kMaxSpeedStringNum), fixed(baseObject.maxVelocity)); // thrust find_replace(data, 0, keys.at(kThrustStringNum), fixed(baseObject.maxThrust)); // par turn find_replace(data, 0, keys.at(kTurnStringNum), fixed(baseObject.frame.rotation.turnAcceleration)); // now, check for weapons! CreateWeaponDataText(&data, baseObject.pulse, values.at(kShipDataPulseStringNum)); CreateWeaponDataText(&data, baseObject.beam, values.at(kShipDataBeamStringNum)); CreateWeaponDataText(&data, baseObject.special, values.at(kShipDataSpecialStringNum)); print(*text, data); }
LabeledRect DebriefingScreen::initialize(int text_id, bool do_score) { Resource rsrc("text", "txt", text_id); _message.assign(utf8::decode(rsrc.data())); int text_height = GetInterfaceTextHeightFromWidth(_message, kLarge, kTextWidth); Rect text_bounds(0, 0, kTextWidth, text_height); if (do_score) { text_bounds.bottom += kScoreTableHeight; } text_bounds.center_in(viewport()); LabeledRect data_item = interface_item(text_bounds); _pix_bounds = pix_bounds(data_item); _message_bounds = text_bounds; _message_bounds.offset(-_pix_bounds.left, -_pix_bounds.top); return data_item; }
// --------------------------------------------------------------------------- // // ----------- OSStatus bPrintMgr::get_page_format(PMPageFormat* pf, const char* name){ *pf=kPMNoPageFormat; OSStatus status; char path[PATH_MAX]; map_doc->location(path); bStdDirectory root(path); if(root.status()){ return(root.status()); } bStdDirectory rsrc("Contents/Resources/"); if(rsrc.status()){ return(rsrc.status()); } char nm[256]; int sgn=kPrintSignature; sprintf(nm,"%.4s/",(char*)&sgn); bStdDirectory prn(nm); if(prn.status()){ return(prn.status()); } bStdFile f(name,"r"); if(f.status()){ return(f.status()); } void* buf; int sz; f.mount((char**)&buf,&sz); if(f.status()){ return(f.status()); } CFDataRef dt=CFDataCreate(kCFAllocatorDefault,(UInt8*)buf,sz); free(buf); if(!dt){ return(-1); } status=PMPageFormatCreateWithDataRepresentation(dt,pf); CFRelease(dt); if(status){ *pf=kPMNoPageFormat; return(status); } return(noErr); }
void Image::copyRect( int x, int y, const Image& img, const Recti & rect ) { checkFormat( img, __PRETTY_FUNCTION__, __LINE__, _mem->_format ); int tx, ty; tx = -x + rect.x; ty = -y + rect.y; Recti rdst( 0, 0, ( int ) _mem->_width, ( int ) _mem->_height ); rdst.translate( tx, ty ); Recti rsrc( 0, 0, ( int ) img._mem->_width, ( int ) img._mem->_height ); rsrc.intersect( rect ); rsrc.intersect( rdst ); if( rsrc.isEmpty() ) return; rdst.copy( rsrc ); rdst.translate( -tx, -ty ); SIMD* simd = SIMD::instance(); size_t dstride; uint8_t* dst = map( &dstride ); uint8_t* dbase = dst; dst += rdst.y * dstride + bpp() * rdst.x; size_t sstride; const uint8_t* src = img.map( &sstride ); const uint8_t* sbase = src; src += rsrc.y * sstride + rsrc.x * img.bpp(); size_t n = rsrc.width * img.bpp(); size_t i = rsrc.height; while( i-- ) { simd->Memcpy( dst, src, n ); src += sstride; dst += dstride; } img.unmap( sbase ); unmap( dbase ); }
bool CHTMLSection::SetHTML( HINSTANCE hInst, LPCTSTR pcszName ) { CResourceLoader rsrc( hInst ); if( rsrc.Load( pcszName, RT_RCDATA ) || rsrc.Load( pcszName, RT_HTML ) ) { CHTMLDocument *pDoc = NULL; #ifdef _UNICODE LPTSTR pszHTML = reinterpret_cast<LPTSTR>( malloc( rsrc.GetSize() * sizeof( TCHAR ) + 1 ) ); { MultiByteToWideChar(CP_ACP, 0, (LPCSTR)rsrc.GetData(), rsrc.GetSize(), pszHTML, rsrc.GetSize() * sizeof( TCHAR ) ); CHTMLParse html( pszHTML, rsrc.GetSize(), hInst, NULL, m_pDefaults ); m_strHTML.Set( pszHTML, rsrc.GetSize() ); #else // _UNICODE CHTMLParse html( (LPCTSTR)rsrc.GetData(), rsrc.GetSize(), hInst, NULL, m_pDefaults ); m_strHTML.Set( (LPCTSTR)rsrc.GetData(), rsrc.GetSize() ); #endif // _UNICODE pDoc = html.Parse(); #ifdef _UNICODE free( pszHTML ); } #endif // _UNICODE if( pDoc ) { DestroyDocument(); m_pDocument = pDoc; OnLoadedDocument(); return true; } } return false; }
virtual void become_front() { switch (_state) { case NEW: _state = REPLAY; init(); Randomize(4); // For the decision to replay intro. _game_result = NO_GAME; g.random.seed = _random_seed; stack()->push(new MainPlay( Handle<Level>(_replay_data.chapter_id - 1), true, &_input_source, false, &_game_result)); break; case REPLAY: if (_output_path.has()) { String path(format("{0}/debriefing.txt", *_output_path)); makedirs(path::dirname(path), 0755); ScopedFd outcome(open(path, O_WRONLY | O_CREAT, 0644)); if ((g.victory_text >= 0)) { Resource rsrc("text", "txt", g.victory_text); sfz::write(outcome, rsrc.data()); if (_game_result == WIN_GAME) { sfz::write(outcome, "\n\n"); Handle<Admiral> player(0); String text = DebriefingScreen::build_score_text( g.time, g.level->parTime, GetAdmiralLoss(player), g.level->parLosses, GetAdmiralKill(player), g.level->parKills); sfz::write(outcome, utf8::encode(text)); } sfz::write(outcome, "\n"); } } stack()->pop(this); break; } }
http::doc urlhandle(const std::string &url, const std::string &querystr, const uint32_t remoteip) { //std::cout << url << "\n"; const uint32_t localip = util::str2ip("127.0.0.1"); // TODO Make this configurable std::vector<std::string> path = util::strsplit(url, '/'); if (path.size() && path[0] == "") path.erase(path.begin()); for (std::string &elem : path) elem = util::urldecode(elem); std::unordered_map<std::string, std::string> query{}; if (querystr.size() > 0) for (const std::string &qu : util::strsplit(querystr, '&')) { std::string::size_type idx = qu.find("="); if (idx == qu.npos) query[util::urldecode(qu)] = ""; else query[util::urldecode(qu.substr(0, idx), true)] = util::urldecode(qu.substr(idx + 1), true); } try { if (path.size() == 0 || path[0] == "") return home(remoteip == localip); if (path[0] == "search" || path[0] == "view" || path[0] == "content" || path[0] == "complete" || path[0] == "titles" || path[0] == "shuffle") { if (path.size() < 2) return error("Bad Request", "Missing volume ID"); if (! volumes.check(path[1])) return error("Not Found", "No volume with ID “" + path[1] + "” exists"); std::string input{}; std::string::const_iterator start = util::find_nth(url.begin(), url.end(), '/', 3) + 1; if (start > url.end()) input = ""; else input = util::urldecode(std::string{start, url.end()}); std::string input_qstr = input + (querystr.size() ? "?" + querystr : ""); if (path[0] == "search") return search(volumes.get(path[1]), input_qstr); else if (path[0] == "view") return content(volumes.get(path[1]), input, true); else if (path[0] == "complete") return complete(volumes.get(path[1]), input_qstr); else if (path[0] == "titles") return titles(volumes.get(path[1]), input_qstr); else if (path[0] == "shuffle") return shuffle(volumes.get(path[1])); else return content(volumes.get(path[1]), input); } else if (path[0] == "load" || path[0] == "unload") { if (path.size() < 2) return error("Bad Request", "Missing category name"); if (path[0] == "load") return loadcat(path[1]); else return unloadcat(path[1]); } else if (path[0] == "external") { if (path.size() < 2) return error("Bad Request", "Missing external path"); if (remoteip != localip) return error("Denied", "You do not have permission to access this functionality"); return http::doc{"text/plain", volumes.load_external(path[1])}; } else if (path[0] == "pref") return pref(); else if (path[0] == "rsrc") return rsrc(util::strjoin(path, '/', 1)); else if (path[0] == "add") return http::doc{resource("html/add.html")}; else if (path[0] == "action") { if (path.size() < 2) return error("Bad Request", "No action selected"); if (remoteip != localip) return error("Denied", "You do not have permission to access this functionality"); return action(path[1], query); } else throw handle_error{"Unknown action “" + path[0] + "”"}; } catch (std::exception &e) { return error("Error", e.what()); } }
void CreateWeaponDataText(String* text, long whichWeapon, const StringSlice& weaponName) { baseObjectType *weaponObject, *missileObject; long mostDamage, actionNum; objectActionType *action; bool isGuided = false; if (whichWeapon == kNoShip) { return; } weaponObject = gBaseObjectData.get() + whichWeapon; // TODO(sfiera): catch exception. Resource rsrc("text", "txt", kWeaponDataTextID); String data(macroman::decode(rsrc.data())); // damage; this is tricky--we have to guess by walking through activate actions, // and for all the createObject actions, see which creates the most damaging // object. We calc this first so we can use isGuided mostDamage = 0; isGuided = false; if ( weaponObject->activateActionNum > 0) { action = gObjectActionData.get() + weaponObject->activateAction; for ( actionNum = 0; actionNum < weaponObject->activateActionNum; actionNum++) { if (( action->verb == kCreateObject) || ( action->verb == kCreateObjectSetDest)) { missileObject = gBaseObjectData.get() + action->argument.createObject.whichBaseType; if ( missileObject->attributes & kIsGuided) isGuided = true; if ( missileObject->damage > mostDamage) mostDamage = missileObject->damage; } action++; } } StringList keys(kShipDataKeyStringID); StringList values(kShipDataNameID); // weapon name # find_replace(data, 0, keys.at(kWeaponNumberStringNum), weaponName); // weapon name { StringList names(5000); const StringSlice& name = names.at(whichWeapon); find_replace(data, 0, keys.at(kWeaponNameStringNum), name); } const StringSlice& yes = values.at(kShipDataYesStringNum); const StringSlice& no = values.at(kShipDataNoStringNum); const StringSlice& dash = values.at(kShipDataDashStringNum); // is guided if (isGuided) { find_replace(data, 0, keys.at(kWeaponGuidedStringNum), yes); } else { find_replace(data, 0, keys.at(kWeaponGuidedStringNum), no); } // is autotarget if (weaponObject->attributes & kAutoTarget) { find_replace(data, 0, keys.at(kWeaponAutoTargetStringNum), yes); } else { find_replace(data, 0, keys.at(kWeaponAutoTargetStringNum), no); } // range find_replace(data, 0, keys.at(kWeaponRangeStringNum), lsqrt(weaponObject->frame.weapon.range)); if (mostDamage > 0) { find_replace(data, 0, keys.at(kWeaponDamageStringNum), mostDamage); } else { find_replace(data, 0, keys.at(kWeaponDamageStringNum), dash); } print(*text, data); }
void update_mission_brief_point( interfaceItemType *dataItem, long whichBriefPoint, const Scenario* scenario, coordPointType *corner, long scale, Rect *bounds, vector<inlinePictType>& inlinePict, Rect& highlight_rect, vector<pair<Point, Point> >& lines, String& text) { if (whichBriefPoint < kMissionBriefPointOffset) { // No longer handled here. return; } whichBriefPoint -= kMissionBriefPointOffset; Rect hiliteBounds; long headerID, headerNumber, contentID; BriefPoint_Data_Get(whichBriefPoint, scenario, &headerID, &headerNumber, &contentID, &hiliteBounds, corner, scale, 16, 32, bounds); hiliteBounds.offset(bounds->left, bounds->top); // TODO(sfiera): catch exception. Resource rsrc("text", "txt", contentID); text.assign(macroman::decode(rsrc.data())); short textHeight = GetInterfaceTextHeightFromWidth(text, dataItem->style, kMissionDataWidth); if (hiliteBounds.left == hiliteBounds.right) { dataItem->bounds.left = (bounds->right - bounds->left) / 2 - (kMissionDataWidth / 2) + bounds->left; dataItem->bounds.right = dataItem->bounds.left + kMissionDataWidth; dataItem->bounds.top = (bounds->bottom - bounds->top) / 2 - (textHeight / 2) + bounds->top; dataItem->bounds.bottom = dataItem->bounds.top + textHeight; } else { if ((hiliteBounds.left + (hiliteBounds.right - hiliteBounds.left) / 2) > (bounds->left + (bounds->right - bounds->left) / 2)) { dataItem->bounds.right = hiliteBounds.left - kMissionDataHBuffer; dataItem->bounds.left = dataItem->bounds.right - kMissionDataWidth; } else { dataItem->bounds.left = hiliteBounds.right + kMissionDataHBuffer; dataItem->bounds.right = dataItem->bounds.left + kMissionDataWidth; } dataItem->bounds.top = hiliteBounds.top + (hiliteBounds.bottom - hiliteBounds.top) / 2 - textHeight / 2; dataItem->bounds.bottom = dataItem->bounds.top + textHeight; if (dataItem->bounds.top < (bounds->top + kMissionDataTopBuffer)) { dataItem->bounds.top = bounds->top + kMissionDataTopBuffer; dataItem->bounds.bottom = dataItem->bounds.top + textHeight; } if (dataItem->bounds.bottom > (bounds->bottom - kMissionDataBottomBuffer)) { dataItem->bounds.bottom = bounds->bottom - kMissionDataBottomBuffer; dataItem->bounds.top = dataItem->bounds.bottom - textHeight; } if (dataItem->bounds.left < (bounds->left + kMissionDataVBuffer)) { dataItem->bounds.left = bounds->left + kMissionDataVBuffer; dataItem->bounds.right = dataItem->bounds.left + kMissionDataWidth; } if (dataItem->bounds.right > (bounds->right - kMissionDataVBuffer)) { dataItem->bounds.right = bounds->right - kMissionDataVBuffer; dataItem->bounds.left = dataItem->bounds.right - kMissionDataWidth; } hiliteBounds.right++; hiliteBounds.bottom++; highlight_rect = hiliteBounds; Rect newRect; GetAnyInterfaceItemGraphicBounds(*dataItem, &newRect); lines.clear(); if (dataItem->bounds.right < hiliteBounds.left) { Point p1(hiliteBounds.left, hiliteBounds.top); Point p2(newRect.right + kMissionLineHJog, hiliteBounds.top); Point p3(newRect.right + kMissionLineHJog, newRect.top); Point p4(newRect.right + 2, newRect.top); lines.push_back(make_pair(p1, p2)); lines.push_back(make_pair(p2, p3)); lines.push_back(make_pair(p3, p4)); Point p5(hiliteBounds.left, hiliteBounds.bottom - 1); Point p6(newRect.right + kMissionLineHJog, hiliteBounds.bottom - 1); Point p7(newRect.right + kMissionLineHJog, newRect.bottom - 1); Point p8(newRect.right + 2, newRect.bottom - 1); lines.push_back(make_pair(p5, p6)); lines.push_back(make_pair(p6, p7)); lines.push_back(make_pair(p7, p8)); } else { Point p1(hiliteBounds.right, hiliteBounds.top); Point p2(newRect.left - kMissionLineHJog, hiliteBounds.top); Point p3(newRect.left - kMissionLineHJog, newRect.top); Point p4(newRect.left - 3, newRect.top); lines.push_back(make_pair(p1, p2)); lines.push_back(make_pair(p2, p3)); lines.push_back(make_pair(p3, p4)); Point p5(hiliteBounds.right, hiliteBounds.bottom - 1); Point p6(newRect.left - kMissionLineHJog, hiliteBounds.bottom - 1); Point p7(newRect.left - kMissionLineHJog, newRect.bottom - 1); Point p8(newRect.left - 3, newRect.bottom - 1); lines.push_back(make_pair(p5, p6)); lines.push_back(make_pair(p6, p7)); lines.push_back(make_pair(p7, p8)); } } dataItem->item.labeledRect.label.stringID = headerID; dataItem->item.labeledRect.label.stringNumber = headerNumber; Rect newRect; GetAnyInterfaceItemGraphicBounds(*dataItem, &newRect); populate_inline_picts(dataItem->bounds, text, dataItem->style, inlinePict); }