void BTPrint::draw(BTBackgroundAndScreen &d, int x, int y, ObjectSerializer *pc) { int xMult, yMult; SDL_Rect dst; d.getDisplay()->getMultiplier(xMult, yMult); dst.x = (x + position.x) * xMult; dst.y = (y + position.y) * yMult; dst.w = position.w * xMult; dst.h = position.h * yMult; d.drawFont(text, dst, d.getColor(color), (BTAlignment::alignment)align); }
void BTFacingIcon::draw(BTBackgroundAndScreen &d, unsigned long ticks) { bool oldActive = active; BTIcon::draw(d, ticks); if (active) { int xMult, yMult; SDL_Rect dst; BTGame *g = BTGame::getGame(); int newFacing = g->getFacing(); if (newFacing != facing) { d.getDisplay()->getMultiplier(xMult, yMult); dst.x = position.x * xMult; dst.y = position.y * yMult; dst.w = position.w * xMult; dst.h = position.h * yMult; if (dirAni[facing].animation) d.removeAnimation(&dirAni[facing]); d.clear(dst); if (animation.animation) d.drawImage(animation.animation->frame[animation.frame], animation.dst); else { d.drawImage(img, dst); } facing = newFacing; if ((NULL == dirImg[facing]) && (NULL == dirAni[facing].animation)) { const char *period = strrchr(image, '.'); std::string filename(image, period - image); filename.append(1, '0' + facing); filename += period; d.getDisplay()->loadImageOrAnimation(filename.c_str(), &dirImg[facing], &dirAni[facing].animation, false); } if (dirImg[facing]) d.drawImage(dirImg[facing], dst); else { IMG_SetAnimationState(&dirAni[facing], -1, 0); dirAni[facing].dst = dst; d.addAnimation(&dirAni[facing]); } } } else { if (oldActive) { d.removeAnimation(&dirAni[facing]); } facing = -1; } }
void BTIcon::draw(BTBackgroundAndScreen &d, unsigned long ticks) { int xMult, yMult; SDL_Rect dst; d.getDisplay()->getMultiplier(xMult, yMult); if ((NULL == img) && (NULL == animation.animation)) { d.getDisplay()->loadImageOrAnimation(image, &img, &animation.animation, false); } dst.x = position.x * xMult; dst.y = position.y * yMult; dst.w = position.w * xMult; dst.h = position.h * yMult; if ((isActive()) && (active == false)) { if (img) { d.drawImage(img, dst); } else { IMG_SetAnimationState(&animation, -1, 0); animation.dst = dst; d.addAnimation(&animation, true); } active = true; } else if ((!isActive()) && (active)) { d.clear(dst); if (animation.animation) d.removeAnimation(&animation); active = false; } }
void BTStatBlock::draw(BTBackgroundAndScreen &d, int x, int y, ObjectSerializer *pc) { int xMult, yMult; SDL_Rect dst; std::string color("black"); d.getDisplay()->getMultiplier(xMult, yMult); dst.x = (x + position.x) * xMult; dst.y = (y + position.y) * yMult; dst.w = position.w * xMult; dst.h = position.h * yMult; XMLAction *state = pc->find(attribute, NULL); if (state) { switch(state->getType()) { case XMLTYPE_BOOL: if (*(reinterpret_cast<bool*>(state->object))) d.drawFont("true", dst, d.getColor(color), (BTAlignment::alignment)align); else d.drawFont("false", dst, d.getColor(color), (BTAlignment::alignment)align); break; case XMLTYPE_INT: if (compare.attribute != "") { XMLAction *cmpState = pc->find(compare.attribute.c_str(), NULL); if ((cmpState) && (cmpState->getType() == XMLTYPE_INT)) { int curVal = *(reinterpret_cast<int*>(state->object)); int maxVal = *(reinterpret_cast<int*>(cmpState->object)); if (maxVal == curVal) color = compare.full; else if (curVal < (maxVal / 2)) color = compare.half; } } if (state->data) { d.drawFont(reinterpret_cast<ValueLookup*>(state->data)->getName(*(reinterpret_cast<int*>(state->object))).c_str(), dst, d.getColor(color), (BTAlignment::alignment)align); } else { int val = *(reinterpret_cast<int*>(state->object)) + modifier; if (negate) val *= -1; if ((maxValue != -1) && (maxValue < val)) { d.drawFont(overflow, dst, d.getColor(color), (BTAlignment::alignment)align); } else { char tmp[40]; snprintf(tmp, 40, "%d", val); d.drawFont(tmp, dst, d.getColor(color), (BTAlignment::alignment)align); } } break; case XMLTYPE_UINT: { /* char tmp[40]; snprintf(tmp, 40, "%u", *(reinterpret_cast<unsigned int*>(state->object))); line.back() += tmp;*/ break; } case XMLTYPE_STRING: d.drawFont(*(reinterpret_cast<char**>(state->object)), dst, d.getColor(color), (BTAlignment::alignment)align); break; case XMLTYPE_BITFIELD: default: break; } } }