/** * Return true if this linearizer can linearize a specified 2D point. * * @param const int x * @param const int y * * @return bool */ bool Linearizer2D::contains(const int x, const int y) const { return x >= getOffsetX() && y >= getOffsetY() && x < getWidth() + getOffsetX() && y < getHeight() + getOffsetY(); }
/* * This is the plane's constructor */ Plane::Plane() : collisionBoxes_(7) { //Randomly select color of the plane from the start srand(time(0)); color_ = (Color)(rand() % 4); //Initialize the motion of the plane motion_ = MOTION_Falling; //Initialize the frame counter frameCounter_ = 0; //Initialize the offset x and offset y of the plane //The offset x of the plane is constant setOffsetX(INITIAL_OFFSET_X); setOffsetY(INITIAL_OFFSET_Y); //Set the width and height of the plane //Width and height are constant setSourceWidth(SPRITE_WIDTH); setSourceHeight(SPRITE_HEIGHT); //Velocity of plane on the x axis is constant and does not change setVelocityX(0.0f); setVelocityY(0.0f); elapseTime_ = 0; puffCloud_.setOffsetY(getOffsetY() + 10.0f); //Initialize the collision boxes width and height for (int i = 0; i < collisionBoxes_.size(); i++) { collisionBoxes_[i].w = COLLISION_BOX_W[i]; collisionBoxes_[i].h = COLLISION_BOX_H[i]; } }
void TextBox::drawText() { font->setColor(textColor); float innerWidth = width - paddingLeft - paddingRight; float innerHeight = height - paddingTop - paddingBottom; float limitTop = y + paddingTop + font->getAscent(); float limitBottom = limitTop + innerHeight; float yy = limitTop + getOffsetY(); font->beginSequence(); for (int i = 0; i < wrapper.size && yy < limitBottom; i++) { if (yy + lineHeight > limitTop) { int start = wrapper.offsets[i]; int end = start + wrapper.lengths[i]; float limitLeft = x + paddingLeft; float limitRight = limitLeft + innerWidth; float xx = limitLeft + getOffsetX(start, end); drawTextSpan(xx, yy, start, end, limitLeft, limitRight); } yy += lineHeight; } font->endSequence(); }
/* * Shift the collision boxes as the ground's location change */ void Ground::shiftCollisionBoxes() { for (int i = 0; i < collisionBoxes_.size(); i++) { collisionBoxes_[i].x = getOffsetX() + COLLISION_BOX_X[i]; collisionBoxes_[i].y = getOffsetY() + COLLISION_BOX_Y[i]; } for (int i = 0; i < collisionBoxes_Loop_.size(); i++) { collisionBoxes_Loop_[i].x = getOffsetX() + COLLISION_BOX_X[i] + 808.0f; collisionBoxes_Loop_[i].y = getOffsetY() + COLLISION_BOX_Y[i]; } }
void OffsetCameraDecorator::getProjection( Matrix &result, UInt32 width, UInt32 height) { if(width == 0 || height == 0) { result.setIdentity(); return; } CameraPtr camera = getDecoratee(); if(camera == NullFC) { FWARNING(("OffsetCameraDecorator::getProjection: no decoratee!\n")); result.setIdentity(); return; } if(getFullWidth() != 0) width = getFullWidth(); if(getFullHeight() != 0) height = getFullHeight(); camera->getProjection(result, width, height); Real32 x = getOffsetX() / Real32(width); Real32 y = getOffsetY() / Real32(height); Matrix sm( 1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, 0, 0, 0, 0, 1); result.multLeft(sm); }
/* * Shift the collision boxes as the plane's location changes */ void Plane::shiftCollisionBoxes() { for (int i = 0; i < collisionBoxes_.size(); i++) { collisionBoxes_[i].x = getOffsetX() + COLLISION_BOX_X[i]; collisionBoxes_[i].y = getOffsetY() + COLLISION_BOX_Y[i]; } }
void ofxTextAlign::draw(string str, float x, float y, unsigned int flags) { const char *ptr = str.c_str(); float cursor_y = y+getOffsetY(ptr, flags, false); int line_count = getLineCount(ptr); float y_interval = line_count>1?(getDrawHeight(ptr, false)-getLineHeight())/(float)(line_count-1):0; while(*ptr != '\0') { float cursor_x = x+getOffsetX(ptr, flags, true); ptr = drawLine(ptr, cursor_x, cursor_y); cursor_y += y_interval; } }
void GuiImage::render() { if(mTextureID && getOpacity() > 0) { GLfloat points[12], texs[12]; GLubyte colors[6*4]; if(mTiled) { float xCount = ((float)mResizeWidth/mWidth); float yCount = ((float)mResizeHeight/mHeight); Renderer::buildGLColorArray(colors, 0xFFFFFF00 | (getOpacity()), 6); buildImageArray(getOffsetX(), getOffsetY(), points, texs, xCount, yCount); }else{ Renderer::buildGLColorArray(colors, 0xFFFFFF00 | (getOpacity()), 6); buildImageArray(getOffsetX(), getOffsetY(), points, texs); } drawImageArray(points, texs, colors, 6); } }
void GuiList<listType>::render() { const int cutoff = getOffsetY(); const int entrySize = mFont->getHeight() + 5; int startEntry = 0; //number of entries that can fit on the screen simultaniously int screenCount = (Renderer::getScreenHeight() - cutoff) / entrySize; //screenCount -= 1; if((int)mRowVector.size() >= screenCount) { startEntry = mSelection - (int)(screenCount * 0.5); if(startEntry < 0) startEntry = 0; if(startEntry >= (int)mRowVector.size() - screenCount) startEntry = mRowVector.size() - screenCount; } int y = cutoff; if(mRowVector.size() == 0) { Renderer::drawCenteredText("The list is empty.", 0, y, 0xFF0000FF, mFont); return; } int listCutoff = startEntry + screenCount; if(listCutoff > (int)mRowVector.size()) listCutoff = mRowVector.size(); for(int i = startEntry; i < listCutoff; i++) { //draw selector bar if(mSelection == i) { Renderer::drawRect(getOffsetX(), y, Renderer::getScreenWidth(), mFont->getHeight(), mSelectorColor); } ListRow row = mRowVector.at((unsigned int)i); if(mDrawCentered) Renderer::drawCenteredText(row.name, getOffsetX(), y, (mSelection == i && mSelectedTextColorOverride != 0) ? mSelectedTextColorOverride : row.color, mFont); else Renderer::drawText(row.name, getOffsetX() + mTextOffsetX, y, (mSelection == i && mSelectedTextColorOverride != 0) ? mSelectedTextColorOverride : row.color, mFont); y += entrySize; } }
void Plane::update(int deltaTime, bool gameOver) { //If the game is over continue to make the plane fall if (gameOver) { setVelocityY(getVelocityY() + GRAVITY * (deltaTime/1000.0f)); setOffsetY(getOffsetY() + getVelocityY()); //Check if the plane has reach the bottom maximum bounds if (getOffsetY() >= SPRITE_MAX_BOTTOM) { setOffsetY(getOffsetY() - getVelocityY()); } } elapseTime_ += deltaTime; if (elapseTime_ > FPS) { frameCounter_++; if (frameCounter_ == 3) { frameCounter_ = 0; } elapseTime_ = 0; } //Update the puff cloud puffCloud_.setOffsetY(getOffsetY() + 10.0f); puffCloud_.update(deltaTime); //Shift the collision boxes shiftCollisionBoxes(); }
string PrecisionModel::toString() const { ostringstream s; if (modelType == FLOATING) { s<<"Floating"; } else if (modelType == FLOATING_SINGLE) { s<<"Floating-Single"; } else if (modelType == FIXED) { s <<"Fixed (Scale=" << getScale() << " OffsetX=" << getOffsetX() << " OffsetY=" << getOffsetY() << ")"; } else { s<<"UNKNOWN"; } return s.str(); }
/* * AN index EQUAL TO numeric_limits<int>::min() MEANS: FIRST CHARACTER ON THE LINE * AN index EQUAL TO numeric_limits<int>::max() MEANS: LAST CHARACTER ON THE LINE */ Vec2f TextBox::getLocationAt(int line, int index) { int start = wrapper.offsets[line]; int end = start + wrapper.lengths[line]; if (index == numeric_limits<int>::min()) { index = start; } else if (index == numeric_limits<int>::max()) { index = end; } float xx = x + paddingLeft + getOffsetX(start, end) + font->getSubStringAdvance(text, start, index); float yy = y + paddingTop + getOffsetY() + line * lineHeight; return Vec2f(xx, yy); }
bool GlyphLayerShadowInset::render( cairo_t* c, cairo_glyph_t* glyph, unsigned int width, unsigned int height ) { if(cairo_status(c) || !glyph) return false; cairo_push_group(c); cairo_glyph_path(c, glyph, 1); cairo_clip(c); cairo_translate(c, getOffsetX(), getOffsetY()); // cairo_set_line_join(c, CAIRO_LINE_JOIN_ROUND); cairo_set_line_width(c, static_cast<double>(_radius) - 0.5f); cairo_glyph_path(c, glyph, 1); cairo_stroke(c); cairo_pattern_t* pattern = cairo_pop_group(c); cairo_surface_t* tmp = createBlurredSurface(CAIRO_FORMAT_A8, pattern, width, height); cairo_set_source_surface( c, tmp, -static_cast<double>(_getBlurSize()) * 2, -static_cast<double>(_getBlurSize()) * 2 ); cairo_glyph_path(c, glyph, 1); cairo_clip(c); cairo_paint(c); cairo_surface_destroy(tmp); cairo_pattern_destroy(pattern); return true; }
/* * This updates the planes offsets and frame * * @param input is used to check for player input * @param deltaTime is used to update the frame of the plane */ void Plane::update(Input* input, int deltaTime) { //std::cout << "Delta is: " << deltaTime << std::endl; //If player press the space key then make the plane jump if (input->isKeyHit(SDLK_SPACE)) { startJump(); } //If plane is falling if (motion_ == MOTION_Falling) { setVelocityY(getVelocityY() + GRAVITY * (deltaTime/1000.0f)); setOffsetY(getOffsetY() + getVelocityY()); //Check if the plane has reach the bottom maximum bounds if (getOffsetY() >= SPRITE_MAX_BOTTOM) { setOffsetY(getOffsetY() - getVelocityY()); } } //Else if plane is jumping else if (motion_ == MOTION_Jumping) { jump_.update(deltaTime); if (jump_.getJumpTimeRemaining() > 0) { //Set the velocity setVelocityY( getVelocityY() + JUMP_VELOCITY); setOffsetY(getOffsetY() - getVelocityY()); //Check if the plane has reach the top maximum bounds if (getOffsetY() <= SPRITE_MAX_TOP) { setOffsetY(getOffsetY() + getVelocityY()); //Stop jumping stopJump(); } } //Max jump is reach else { stopJump(); } } elapseTime_ += deltaTime; if (elapseTime_ > FPS) { frameCounter_++; if (frameCounter_ == 3) { frameCounter_ = 0; } elapseTime_ = 0; } //Update the puff cloud puffCloud_.setOffsetY(getOffsetY() + 10.0f); puffCloud_.update(deltaTime); //Shift the collision boxes shiftCollisionBoxes(); }
void Ground::draw(Graphics* graphics, Image* image) { image->draw(getOffsetX(), getOffsetY(), SOURCE_SPRITE_OFFSET_X[type_], SOURCE_SPRITE_OFFSET_Y[type_], getSourceWidth(), getSourceHeight(), graphics); image->draw((getOffsetX() + GROUND_WIDTH), getOffsetY(), SOURCE_SPRITE_OFFSET_X[type_], SOURCE_SPRITE_OFFSET_Y[type_], getSourceWidth(), getSourceHeight(), graphics); }
/** * Called whenever the graphic view has changed. * Adjusts the scrollbar ranges / steps. */ void QG_GraphicView::adjustOffsetControls() { if (scrollbars) { static bool running = false; if (running) { return; } running = true; if (container==NULL || hScrollBar==NULL || vScrollBar==NULL) { return; } int ox = getOffsetX(); int oy = getOffsetY(); RS_Vector min = container->getMin(); RS_Vector max = container->getMax(); // no drawing yet - still allow to scroll if (max.x < min.x+1.0e-6 || max.y < min.y+1.0e-6 || max.x > RS_MAXDOUBLE || max.x < RS_MINDOUBLE || min.x > RS_MAXDOUBLE || min.x < RS_MINDOUBLE || max.y > RS_MAXDOUBLE || max.y < RS_MINDOUBLE || min.y > RS_MAXDOUBLE || min.y < RS_MINDOUBLE ) { min = RS_Vector(-10,-10); max = RS_Vector(100,100); } auto factor = getFactor(); int minVal = (int)(-getWidth()*0.75 + std::min(min.x, 0.)*factor.x); int maxVal = (int)(-getWidth()*0.25 + std::max(max.x, 0.)*factor.x); if (minVal<=maxVal) { hScrollBar->setRange(minVal, maxVal); } minVal = (int)(+getHeight()*0.25 - std::max(max.y, 0.)*factor.y); maxVal = (int)(+getHeight()*0.75 - std::min(min.y, 0.)*factor.y); if (minVal<=maxVal) { vScrollBar->setRange(minVal, maxVal); } hScrollBar->setPageStep(getWidth()); vScrollBar->setPageStep(getHeight()); hScrollBar->setValue(-ox); vScrollBar->setValue(oy); slotHScrolled(-ox); slotVScrolled(oy); // RS_DEBUG->print("H min: %d / max: %d / step: %d / value: %d\n", // hScrollBar->minimum(), hScrollBar->maximum(), // hScrollBar->pageStep(), ox); // RS_DEBUG->print(/*RS_Debug::D_WARNING, */"V min: %d / max: %d / step: %d / value: %d\n", // vScrollBar->minimum(), vScrollBar->maximum(), // vScrollBar->pageStep(), oy); running = false; } }
float CameraSystem::getEndY() const { return _lookAtY + getOffsetY(); }
float CameraSystem::getStartY() const { return _lookAtY - getOffsetY(); }
float wyScrollableLayer::getContainerPositionYPercent() { return getOffsetY() / m_yExtent; }
void Background::draw(Graphics* graphics, Image* image) { image->draw(getOffsetX(), getOffsetY(), SOURCE_SPRITE_OFFSET_X, SOURCE_SPRITE_OFFSET_Y, getSourceWidth(), getSourceHeight(), graphics); }
/* * This method takes in a graphics and image objects to be used into * drawing the plane sprite onto the screen * * @param graphics is used for drawing the plane sprite * @param image is the sprite sheet where the plane sprite is retrieve from */ void Plane::draw(Graphics* graphics, Image* image) { image->draw(getOffsetX(), getOffsetY(), SOURCE_SPRITE_OFFSET_X[color_][frameCounter_], SOURCE_SPRITE_OFFSET_Y[color_][frameCounter_], getSourceWidth(), getSourceHeight(), graphics); puffCloud_.draw(graphics, image); }
/** * Called whenever the graphic view has changed. * Adjusts the scrollbar ranges / steps. */ void QG_GraphicView::adjustOffsetControls() { static bool running = false; if (running) { return; } running = true; RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() begin"); if (container==NULL || hScrollBar==NULL || vScrollBar==NULL) { return; } int ox = getOffsetX(); int oy = getOffsetY(); RS_Vector min = container->getMin(); RS_Vector max = container->getMax(); // no drawing yet - still allow to scroll if (max.x < min.x+1.0e-6 || max.y < min.y+1.0e-6 || max.x > RS_MAXDOUBLE || max.x < RS_MINDOUBLE || min.x > RS_MAXDOUBLE || min.x < RS_MINDOUBLE || max.y > RS_MAXDOUBLE || max.y < RS_MINDOUBLE || min.y > RS_MAXDOUBLE || min.y < RS_MINDOUBLE ) { min = RS_Vector(-10,-10); max = RS_Vector(100,100); } int minVal = (int)(-ox-toGuiDX(getWidth())*0.5 - QG_SCROLLMARGIN - getBorderLeft()); int maxVal = (int)(-ox+toGuiDX(getWidth())*0.5 + QG_SCROLLMARGIN + getBorderRight()); hScrollBar->setValue(0); if (minVal<=maxVal) { hScrollBar->setRange(minVal, maxVal); } //hScrollBar->setMinValue(minVal); //hScrollBar->setMaxValue(maxVal); minVal = (int)(oy-toGuiDY(getHeight())*0.5 - QG_SCROLLMARGIN - getBorderTop()); maxVal = (int)(oy+toGuiDY(getHeight())*0.5 +QG_SCROLLMARGIN + getBorderBottom()); if (minVal<=maxVal) { vScrollBar->setRange(minVal, maxVal); } //vScrollBar->setMaxValue((int)(QG_SCROLLMARGIN + getBorderBottom() // - (min.y * getFactor().y))); //vScrollBar->setMinValue((int)(getHeight() - // max.y * getFactor().y // - QG_SCROLLMARGIN - getBorderTop())); hScrollBar->setPageStep((int)(getWidth())); vScrollBar->setPageStep((int)(getHeight())); hScrollBar->setValue(-ox); vScrollBar->setValue(oy); slotHScrolled(-ox); slotVScrolled(oy); RS_DEBUG->print("H min: %d / max: %d / step: %d / value: %d\n", hScrollBar->minimum(), hScrollBar->maximum(), hScrollBar->pageStep(), ox); // DEBUG_HEADER(); RS_DEBUG->print(/*RS_Debug::D_WARNING, */"V min: %d / max: %d / step: %d / value: %d\n", vScrollBar->minimum(), vScrollBar->maximum(), vScrollBar->pageStep(), oy); RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() end"); running = false; }
/** * Slot for vertical scroll events. */ void QG_GraphicView::slotVScrolled(int value) { // Scrollbar behaviour tends to change with every Qt version.. // so let's keep old code in here for now //static int running = false; //if (!running) { //running = true; // DEBUG_HEADER(); RS_DEBUG->print(/*RS_Debug::D_WARNING,*/ "%s %s(): set vertical offset from %d to %d\n", __FILE__, __FUNCTION__, getOffsetY(), value); if (vScrollBar->maximum()==vScrollBar->minimum()) { centerOffsetY(); } else { setOffsetY(value); } //if (isUpdateEnabled()) { // updateGrid(); redraw(); }
int32_t LuaDrawable::getOffsetY(lua_State *L) { auto drawable = Lua::getObject<Drawable>(L, 1, LuaType::Drawable); Lua::pushNumber(L, drawable->getOffsetY()); return 1; }