bool DragAndDropSprite::OnMouseOver(int x, int y, bool button, StringId& eventId, void*& userData) { if (!IsEnabled()) { dragging_=false; return false; } if (dragging_) { SetPosition((float)x-dragOffsetX_,(float)y-dragOffsetY_); } const BitmapStrip& bitmapStrip=GetBitmap(); if (bitmapStrip.GetCelCount()!=0) { int currentCel=(int)GetCel(); const Bitmap& bitmap=bitmapStrip.GetCel(currentCel); if (bitmap.GetPixelAlpha(x-(int)(GetX()+GetOriginX()),y-(int)(GetY()+GetOriginY()))>128) { if (IsEnabled()) { // highlighted_=true; if (button) { SetState(State_Pressed); if (!dragging_) { dragOffsetX_=x-GetX()+GetOriginX(); dragOffsetY_=y-GetY()+GetOriginY(); } dragging_=true; } else { SetState(State_Highlighted); dragging_=false; } } eventId=GetEventId(); userData=GetEventUserData(); return true; } } return false; }
void Sprite::Render(Bitmap& bitmap) { if (!visible_) { return; } GetBitmap().Blit((int)GetCel(),bitmap,Round(GetX()-GetOriginX()),Round(GetY()-GetOriginY()),GetColor(),GetAlpha()); }
bool Player::IntersectsWith(Player &p) { if(sqrt(pow(GetOriginX() - p.GetOriginX(), 2) + pow(GetOriginY() - p.GetOriginY(), 2)) >= radius + p.GetRadius()) { SDL_SetTextureColorMod(texture, 255, 255, 255); return false; } SDL_SetTextureColorMod(texture, 255, 0, 0); return true; }
bool Sprite::PickPixel(int x, int y) const { if (GetBitmap().GetCelCount()!=0) { const Bitmap& bitmap=GetBitmap().GetCel((int)GetCel()); if (bitmap.GetPixelAlpha(x-(int)(GetX()-GetOriginX()),y-(int)(GetY()-GetOriginY()))>64) { return true; } } return false; }
void QuadPane::Draw(const BannerResources& resources, u8 render_alpha, const float ws_scale, Mtx &modelview, u16 material_index, u8 texture_flip) const { if(!header) return; if (material_index < resources.materials.size()) { bool modulate_color = IsModulateColor(header->vertex_colors, render_alpha); resources.materials[material_index]->Apply(resources, render_alpha, modulate_color); } Mtx m, mv; guMtxIdentity (m); guMtxTransApply(m,m, -0.5f * GetOriginX(), -0.5f * GetOriginY(), 0.f); guMtxScaleApply(m,m, GetWidth(), GetHeight(), 1.f); guMtxConcat (modelview, m, mv); GX_LoadPosMtxImm (mv, GX_PNMTX0); GX_ClearVtxDesc(); GX_InvVtxCache(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); for(u32 i = 0; i < header->tex_coord_count; i++) GX_SetVtxDesc(GX_VA_TEX0+i, GX_DIRECT); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); if(texture_flip) { SetVertex(0, 0.f, 0.f, render_alpha); SetVertex(1, 1.f, 0.f, render_alpha); SetVertex(3, 1.f, 1.f, render_alpha); SetVertex(2, 0.f, 1.f, render_alpha); } else { SetVertex(2, 0.f, 0.f, render_alpha); SetVertex(3, 1.f, 0.f, render_alpha); SetVertex(1, 1.f, 1.f, render_alpha); SetVertex(0, 0.f, 1.f, render_alpha); } GX_End(); }
void Rectangle::Render(Bitmap& bitmap) { if (IsVisible() && width_>0 && height_>0) { int x1=(int)(GetX()-GetOriginX()); int y1=(int)(GetY()-GetOriginY()); int x2=x1+(int)GetWidth()-1; int y2=y1+(int)GetHeight()-1; if (x1==0 && y1==0 && x2==bitmap.GetWidth()-1 && y2==bitmap.GetHeight()-1 && GetColor()==0 && GetAlpha()==255) { bitmap.Clear(); } else { bitmap.Fill(x1,y1,x2,y2,GetColor(),GetAlpha()); } } }
void Textbox::Draw(const BannerResources& resources, u8 parent_alpha, const float ws_scale, Mtx &modelview) const { if(!text) return; if(header->font_index >= resources.fonts.size()) return; WiiFont *font = resources.fonts[header->font_index]; if(!font->IsLoaded()) return; // Ugly...but doing it by going through all panes is more ugly // TODO: move it to somewhere else if(lineWidths.empty()) ((Textbox *) this)->SetTextWidth(font); if(lineWidths.empty()) return; SetupGX(resources); GX_LoadPosMtxImm(modelview, GX_PNMTX0); // Setup text color GXColor color0 = { header->color[0].r, header->color[0].g, header->color[0].b, MultiplyAlpha(header->color[0].a, parent_alpha) }; GXColor color1 = { header->color[1].r, header->color[1].g, header->color[1].b, MultiplyAlpha(header->color[1].a, parent_alpha) }; u32 lastSheetIdx = 0xffff; float scale = header->font_size /(float)font->CharacterHeight(); // use complete text width if not aligned to middle float textWidth = (GetAlignHor() == 1) ? lineWidths[0] : frameWidth; // position offset calculation for first line...why the hell is it that complex? float xPos = -0.5f * ( GetOriginX() * GetWidth() * ws_scale + GetAlignHor() * (-GetWidth() * ws_scale + textWidth) ); float yPos = -0.5f * ( GetAlignVer() * -frameHeight + GetHeight() * (GetAlignVer() - (2 - GetOriginY())) ) - header->font_size; // store the character width here for later use, it's constant over the text float charWidth = scale * (float)font->CharacterWidth(); int lineNumber = 0; for(const u16 *txtString = text; *txtString != 0; txtString++) { if(*txtString == '\n') { lineNumber++; // use complete text width if not aligned to middle textWidth = (GetAlignHor() == 1) ? lineWidths[lineNumber] : frameWidth; // calculate text position depending on line width xPos = -0.5f * (GetOriginX() * GetWidth() * ws_scale + GetAlignHor() * (-GetWidth() * ws_scale + textWidth)); // go one line down yPos -= (header->font_size + header->space_line); continue; } const WiiFont::CharInfo *charInfo = font->GetCharInfo(*txtString); if(!charInfo) continue; if(charInfo->sheetIdx != lastSheetIdx) { lastSheetIdx = charInfo->sheetIdx; if(!font->Apply(charInfo->sheetIdx)) continue; } if(charInfo->unk) xPos += scale * (float)charInfo->advanceKerning; GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position3f32(xPos, yPos, 0.f); GX_Color4u8(color1.r, color1.g, color1.b, color1.a); GX_TexCoord2f32(charInfo->s1, charInfo->t2); GX_Position3f32(xPos + charWidth, yPos, 0.f); GX_Color4u8(color1.r, color1.g, color1.b, color1.a); GX_TexCoord2f32(charInfo->s2, charInfo->t2); GX_Position3f32(xPos + charWidth, yPos + header->font_size, 0.f); GX_Color4u8(color0.r, color0.g, color0.b, color0.a); GX_TexCoord2f32(charInfo->s2, charInfo->t1); GX_Position3f32(xPos, yPos + header->font_size, 0.f); GX_Color4u8(color0.r, color0.g, color0.b, color0.a); GX_TexCoord2f32(charInfo->s1, charInfo->t1); GX_End(); xPos += scale * (float)charInfo->advanceGlyphX; } }
void Pane::Render(const Resources& resources, u8 parent_alpha, Mtx &modelview, bool widescreen, bool modify_alpha) const { if (!GetVisible() || GetHide()) return; u8 render_alpha = header->alpha; if(RootPane && parent_alpha != 0xFF) { render_alpha = MultiplyAlpha(header->alpha, parent_alpha); modify_alpha = true; } else if(!RootPane && modify_alpha) { render_alpha = MultiplyAlpha(header->alpha, parent_alpha); } else if(GetInfluencedAlpha() && header->alpha != 0xff) { modify_alpha = true; parent_alpha = MultiplyAlpha(header->alpha, parent_alpha); } float ws_scale = 1.0f; if( widescreen && GetWidescren() ) { ws_scale *= 0.82f; // should actually be 0.75? widescreen = false; } Mtx m1,m2,m3,m4; guMtxIdentity (m1); // Scale guMtxScaleApply(m1,m1, header->scale.x * ws_scale, header->scale.y, 1.f); // Rotate guMtxRotDeg ( m2, 'x', header->rotate.x ); guMtxRotDeg ( m3, 'y', header->rotate.y ); guMtxRotDeg ( m4, 'z', header->rotate.z ); guMtxConcat(m2, m3, m2); guMtxConcat(m2, m4, m2); guMtxConcat(m1, m2, m1); // Translate guMtxTransApply(m1,m1, header->translate.x, header->translate.y, header->translate.z); guMtxConcat (modelview, m1, pane_view); bool scissor = gxScissorForBindedLayouts; u32 scissorX = 0; u32 scissorY = 0; u32 scissorW = 0; u32 scissorH = 0; // calculate scissors if they will be used if( scissor ) { Mtx mv2, mv3; guMtxIdentity (mv2); guMtxIdentity (mv3); guMtxTransApply(mv2,mv2, -0.5f * GetOriginX() * GetWidth(), -0.5f * GetOriginY() * GetHeight(), 0.f); guMtxTransApply(mv3,mv3, 0.5f * GetOriginX() * GetWidth(), 0.5f * GetOriginY() * GetHeight(), 0.f); guMtxScaleApply(mv2, mv2, 1.0f, -1.0f, 1.0f); guMtxScaleApply(mv3, mv3, 1.0f, -1.0f, 1.0f); guMtxConcat (pane_view, mv2, mv2); guMtxConcat (pane_view, mv3, mv3); f32 viewport[6]; f32 projection[7]; GX_GetViewportv(viewport); GX_GetProjectionv(MainProjection, projection, GX_ORTHOGRAPHIC); guVector vecTL; guVector vecBR; GX_Project(0.0f, 0.0f, 0.0f, mv2, projection, viewport, &vecTL.x, &vecTL.y, &vecTL.z); GX_Project(0.0f, 0.0f, 0.0f, mv3, projection, viewport, &vecBR.x, &vecBR.y, &vecBR.z); // round up scissor box offset and round down the size scissorX = (u32)(0.5f + std::max(vecTL.x, 0.0f)); scissorY = (u32)(0.5f + std::max(vecTL.y, 0.0f)); scissorW = (u32)std::max(vecBR.x - vecTL.x, 0.0f); scissorH = (u32)std::max(vecBR.y - vecTL.y, 0.0f); GX_SetScissor( scissorX, scissorY, scissorW, scissorH ); } // binded layouts dont inheiret the modified widescreen setting bool realWS = ( _CONF_GetAspectRatio() == CONF_ASPECT_16_9 ); // draw binded layouts that appear under this one foreach( Layout *l, bindedLayoutsUnder ) { l->RenderWithCurrentMtx( pane_view, realWS ); }
int Entity::CheckWorldBBox(BBox2D::Rect box) { return BBox2D::CheckWorldBBox(GetOriginX(), GetOriginY(), box); }
BBox2D::Rect Entity::GetWorldBBox() { return BBox2D::GetWorldBBox(GetOriginX(), GetOriginY()); }
void Entity::Update(int iDelta) { Origin2D::Update(iDelta); SetImageX( (int)GetOriginX() ); SetImageY( (int)GetOriginY() ); }