void read_rect_node(grect& rect, hlxml::Node* node, bool allowNoSize) { rect.set(0.0f, 0.0f, 0.0f, 0.0f); if (allowNoSize) { rect.setSize(-1.0f, -1.0f); } if (node->pexists("rect")) { rect = hstr_to_grect(node->pstr("rect")); } else { if (node->pexists("position")) { rect.setPosition(hstr_to_gvec2(node->pstr("position"))); } else { rect.setPosition(node->pfloat("x"), node->pfloat("y")); } if (node->pexists("size")) { rect.setSize(hstr_to_gvec2(node->pstr("size"))); } else if (!allowNoSize) { rect.setSize(node->pfloat("w"), node->pfloat("h")); } else { rect.setSize(node->pfloat("w", -1.0f), node->pfloat("h", -1.0f)); } } }
void RenderSystem::setOrthoProjection(grect rect) { // TODOaa - change and improve this implementation // also: this variable needs to be updated in ::setProjectionMatrix() as well in order to prevent a stale value when using getOrthoProjection() this->orthoProjection = rect; rect -= rect.getSize() * this->getPixelOffset() / april::window->getSize(); this->projectionMatrix.ortho(rect); this->_setProjectionMatrix(this->projectionMatrix); }
bool onUpdate(float timeSinceLastFrame) { this->angle += timeSinceLastFrame * 90.0f; april::rendersys->clear(); april::rendersys->setPerspective(60.0f, 1.0f / drawRect.getAspect(), 1.0f, 1000.0f); april::rendersys->lookAt(gvec3(2.0f, 2.0f, -5.0f), gvec3(0.0f, 0.0f, 0.0f), gvec3(0.0f, 1.0f, 0.0f)); april::rendersys->rotate(this->angle, 0.0f, 1.0f, 0.0f); april::rendersys->setTexture(texture); april::rendersys->render(april::RO_TRIANGLE_STRIP, v, 4); return true; }
void april_init(const harray<hstr>& args) { srand((unsigned int)htime()); april::init(new CustomRenderSystem(), new CustomWindow()); april::createRenderSystem(); april::createWindow((int)drawRect.w, (int)drawRect.h, false, "APRIL: Simple Interface"); april::window->setUpdateDelegate(&updateDelegate); april::window->setSystemDelegate(&systemDelegate); april::window->setMouseDelegate(&mouseDelegate); texture = april::rendersys->createTextureFromResource(RESOURCE_PATH "jpt_final", april::Texture::TYPE_MANAGED); textureRect.setSize(texture->getWidth() * 0.5f, texture->getHeight() * 0.5f); textureRect.x = -textureRect.w / 2; textureRect.y = -textureRect.h / 2; }
RenderRectangle Font::makeRenderRectangle(const grect& rect, grect area, unsigned int code) { static RenderRectangle result; result.src.set(0.0f, 0.0f, 0.0f, 0.0f); result.dest = area; // if destination rectangle not entirely inside drawing area if (rect.intersects(result.dest)) { static gvec2 fullSize(1.0f, 1.0f); static gvec2 leftTop; static gvec2 rightBottom; static gvec2 textureInvertedSize; static CharacterDefinition* chr = NULL; static grect charRect; static april::Texture* texture = NULL; texture = this->getTexture(code); textureInvertedSize.set(1.0f / texture->getWidth(), 1.0f / texture->getHeight()); chr = &this->characters[code]; charRect.set(chr->x, chr->y, chr->w, chr->h); // vertical/horizontal cutoff of destination rectangle (using left/right/top/bottom semantics for consistency) leftTop.x = (area.left() < rect.left() ? (area.right() - rect.left()) / area.w : fullSize.x); leftTop.y = (area.top() < rect.top() ? (area.bottom() - rect.top()) / area.h : fullSize.y); rightBottom.x = (rect.right() < area.right() ? (rect.right() - area.left()) / area.w : fullSize.x); rightBottom.y = (rect.bottom() < area.bottom() ? (rect.bottom() - area.top()) / area.h : fullSize.y); // apply cutoff on destination result.dest.setPosition(area.getPosition() + area.getSize() * (fullSize - leftTop)); result.dest.setSize(area.getSize() * (leftTop + rightBottom - fullSize)); // apply cutoff on source result.src.setPosition((charRect.getPosition() + charRect.getSize() * (fullSize - leftTop)) * textureInvertedSize); result.src.setSize((charRect.getSize() * (leftTop + rightBottom - fullSize)) * textureInvertedSize); } return result; }
#include <april/Platform.h> #include <april/RenderSystem.h> #include <april/SystemDelegate.h> #include <april/UpdateDelegate.h> #include <april/Window.h> #include <gtypes/Rectangle.h> #include <gtypes/Vector2.h> #include <hltypes/hlog.h> #include <hltypes/hltypesUtil.h> #include <hltypes/hstring.h> #include "CustomRenderSystem.h" #include "CustomWindow.h" static april::Texture* texture = NULL; static grect drawRect(0.0f, 0.0f, 800.0f, 600.0f); static gvec2 offset = drawRect.getSize() * 0.5f; static grect textureRect; static bool mousePressed = false; class UpdateDelegate : public april::UpdateDelegate { bool onUpdate(float timeDelta) { april::rendersys->clear(); april::rendersys->setOrthoProjection(drawRect); april::rendersys->drawFilledRect(drawRect, april::Color(64, 64, 64)); april::rendersys->setTexture(texture); april::rendersys->drawTexturedRect(textureRect + offset, grect(0.0f, 0.0f, 1.0f, 1.0f)); april::rendersys->drawFilledRect(grect(0.0f, 0.0f, 100.0f, 75.0f), april::Color::Orange); april::rendersys->drawFilledRect(grect(10.0f, 10.0f, 80.0f, 55.0f), april::Color::Yellow);
void april_init(const harray<hstr>& args) { #ifdef __APPLE__ // On MacOSX, the current working directory is not set by // the Finder, since you are expected to use Core Foundation // or ObjC APIs to find files. // So, when porting you probably want to set the current working // directory to something sane (e.g. .../Resources/ in the app // bundle). // In this case, we set it to parent of the .app bundle. { CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); // let's hope chdir() will be happy with utf8 encoding const char* cpath = CFStringGetCStringPtr(path, kCFStringEncodingUTF8); char* cpath_alloc = NULL; if (cpath == NULL) { // CFStringGetCStringPtr is allowed to return NULL. bummer. // we need to use CFStringGetCString instead. cpath_alloc = (char*)malloc(CFStringGetLength(path) + 1); CFStringGetCString(path, cpath_alloc, CFStringGetLength(path) + 1, kCFStringEncodingUTF8); } else { // even though it didn't return NULL, we still want to slice off bundle name. cpath_alloc = (char*)malloc(CFStringGetLength(path) + 1); strcpy(cpath_alloc, cpath); } // just in case / is appended to .app path for some reason if (cpath_alloc[CFStringGetLength(path) - 1] == '/') { cpath_alloc[CFStringGetLength(path) - 1] = 0; } // replace pre-.app / with a null character, thus // cutting off .app's name and getting parent of .app. strrchr(cpath_alloc, '/')[0] = 0; // change current dir using posix api chdir(cpath_alloc); free(cpath_alloc); // even if null, still ok CFRelease(path); CFRelease(url); } #endif updateDelegate = new UpdateDelegate(); keyboardDelegate = new KeyboardDelegate(); mouseDelegate = new MouseDelegate(); try { #if defined(_ANDROID) || defined(_IOS) drawRect.setSize(april::getSystemInfo().displayResolution); #endif april::init(april::RS_DEFAULT, april::WS_DEFAULT); april::createRenderSystem(); april::createWindow((int)drawRect.w, (int)drawRect.h, false, "AprilParticle Demo AprilUI"); atres::init(); aprilui::init(); aprilparticle::init(); aprilparticle::setUseCache(false); apriluiparticle::init(); april::window->setUpdateDelegate(updateDelegate); april::window->setKeyboardDelegate(keyboardDelegate); april::window->setMouseDelegate(mouseDelegate); apriluiparticle::setDefaultPath(""); dataset = new aprilui::Dataset(RESOURCE_PATH "demo_aprilui.dts"); dataset->load(); #ifdef _DEBUG //aprilui::setDebugEnabled(true); #endif } catch (hltypes::exception& e) { hlog::error(LOG_TAG, e.getMessage()); } }
void april_init(const harray<hstr>& args) { #ifdef __APPLE__ // On MacOSX, the current working directory is not set by // the Finder, since you are expected to use Core Foundation // or ObjC APIs to find files. // So, when porting you probably want to set the current working // directory to something sane (e.g. .../Resources/ in the app // bundle). // In this case, we set it to parent of the .app bundle. { // curly braces in order to localize variables CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); // let's hope chdir() will be happy with utf8 encoding const char* cpath = CFStringGetCStringPtr(path, kCFStringEncodingUTF8); char* cpath_alloc = NULL; if (cpath == NULL) { // CFStringGetCStringPtr is allowed to return NULL. bummer. // we need to use CFStringGetCString instead. cpath_alloc = (char*)malloc(CFStringGetLength(path) + 1); CFStringGetCString(path, cpath_alloc, CFStringGetLength(path) + 1, kCFStringEncodingUTF8); } else { // even though it didn't return NULL, we still want to slice off bundle name. cpath_alloc = (char*)malloc(CFStringGetLength(path) + 1); strcpy(cpath_alloc, cpath); } // just in case / is appended to .app path for some reason if (cpath_alloc[CFStringGetLength(path) - 1] == '/') { cpath_alloc[CFStringGetLength(path) - 1] = 0; } // replace pre-.app / with a null character, thus // cutting off .app's name and getting parent of .app. strrchr(cpath_alloc, '/')[0] = 0; // change current dir using posix api chdir(cpath_alloc); free(cpath_alloc); // even if null, still ok CFRelease(path); CFRelease(url); } #endif updateDelegate = new UpdateDelegate(); #if defined(_ANDROID) || defined(_IOS) || defined(_WINRT) drawRect.setSize(april::getSystemInfo().displayResolution); #endif april::init(april::RS_DEFAULT, april::WS_DEFAULT); april::createRenderSystem(); april::createWindow((int)drawRect.w, (int)drawRect.h, false, "APRIL: Simple 3D"); #ifdef _WINRT april::window->setParam("cursor_mappings", "101 " RESOURCE_PATH "cursor\n102 " RESOURCE_PATH "simple"); #endif april::window->setUpdateDelegate(updateDelegate); april::window->setCursorFilename(RESOURCE_PATH "cursor"); texture = april::rendersys->createTextureFromResource(RESOURCE_PATH "texture"); v[0].x = -1.0f; v[0].y = 1.0f; v[0].z = 0.0f; v[0].u = 0.0f; v[0].v = 0.0f; v[1].x = 1.0f; v[1].y = 1.0f; v[1].z = 0.0f; v[1].u = 1.0f; v[1].v = 0.0f; v[2].x = -1.0f; v[2].y = -1.0f; v[2].z = 0.0f; v[2].u = 0.0f; v[2].v = 1.0f; v[3].x = 1.0f; v[3].y = -1.0f; v[3].z = 0.0f; v[3].u = 1.0f; v[3].v = 1.0f; }
april::Cursor* cursor = NULL; april::Texture* background = NULL; april::Texture* x_symbol = NULL; april::Texture* o_symbol = NULL; april::Texture* line_horz = NULL; april::Texture* line_vert = NULL; april::Texture* line45 = NULL; april::Texture* line315 = NULL; int positions[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; int victory = 0; bool player = 0; april::TexturedVertex v[4]; #if !defined(_ANDROID) && !defined(_IOS) && !defined(_WINP8) grect drawRect(0.0f, 0.0f, 800.0f, 600.0f); #else grect drawRect(0.0f, 0.0f, 480.0f, 320.0f); #endif gvec2 size = drawRect.getSize() * 5 / 16; void draw_symbol(int x, int y, chstr symbol) { float x1, x2, x3, x4, y1, y2, y3, y4; x1 = x * size.x - size.x + (x - 1) * 10; x2 = x * size.x + (x - 1) * 10; x3 = x * size.x - size.x + (x - 1) * 10; x4 = x * size.x + (x - 1) * 10; y1 = y * size.y - size.y + (y - 1) * 10; y2 = y * size.y - size.y + (y - 1) * 10;