forked from Mirrors/openclonk
Use floating point numbers for C4Facet coordinates
This fixes the lightbulb symbol from floundering around back and forth when zoomed in and scrolling. Since C4Facets can be used to specify a target area to draw into (such as in C4DefGraphics::Draw), and since this area can be zoomed, sub-pixel precision can be achieved this way in such drawing operations.stable-5.3
parent
d0cf12192a
commit
f19caa12f1
|
@ -38,7 +38,7 @@ void C4Facet::Default()
|
|||
Set(NULL,0,0,0,0);
|
||||
}
|
||||
|
||||
void C4Facet::Set(C4Surface * nsfc, int32_t nx, int32_t ny, int32_t nwdt, int32_t nhgt)
|
||||
void C4Facet::Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt)
|
||||
{
|
||||
Surface=nsfc; X=nx; Y=ny; Wdt=nwdt; Hgt=nhgt;
|
||||
}
|
||||
|
@ -553,7 +553,7 @@ C4Facet C4Facet::GetFraction(int32_t percentWdt, int32_t percentHgt, int32_t ali
|
|||
// Simple spec for square fractions
|
||||
if (percentHgt == 0) percentHgt = percentWdt;
|
||||
// Alignment
|
||||
int iX = X, iY = Y, iWdt = Max(Wdt*percentWdt/100, 1), iHgt = Max(Hgt*percentHgt/100, 1);
|
||||
int iX = X, iY = Y, iWdt = Max(Wdt*percentWdt/100, 1.0f), iHgt = Max(Hgt*percentHgt/100, 1.0f);
|
||||
if (alignX & C4FCT_Right) iX += Wdt - iWdt;
|
||||
if (alignX & C4FCT_Center) iX += Wdt/2 - iWdt/2;
|
||||
if (alignY & C4FCT_Bottom) iY += Hgt - iHgt;
|
||||
|
|
|
@ -121,15 +121,15 @@ class C4Facet
|
|||
{
|
||||
public:
|
||||
C4Surface * Surface;
|
||||
int32_t X,Y,Wdt,Hgt;
|
||||
float X,Y,Wdt,Hgt;
|
||||
public:
|
||||
C4Facet();
|
||||
C4Facet(C4Surface * pSfc, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt)
|
||||
C4Facet(C4Surface * pSfc, float iX, float iY, float iWdt, float iHgt)
|
||||
: Surface(pSfc), X(iX), Y(iY), Wdt(iWdt), Hgt(iHgt) { }
|
||||
public:
|
||||
void Default();
|
||||
void Set(C4Surface &rSfc);
|
||||
void Set(C4Surface * nsfc, int32_t nx, int32_t ny, int32_t nwdt, int32_t nhgt);
|
||||
void Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt);
|
||||
void Set(const C4Facet &cpy) { *this=cpy; }
|
||||
void Expand(int32_t iLeft=0, int32_t iRight=0, int32_t iTop=0, int32_t iBottom=0);
|
||||
void DrawTile(C4Surface * sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt);
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <C4Group.h>
|
||||
|
||||
|
||||
void C4TargetFacet::Set(C4Surface * nsfc, int nx, int ny, int nwdt, int nhgt, float ntx, float nty, float Zoom)
|
||||
void C4TargetFacet::Set(C4Surface * nsfc, float nx, float ny, float nwdt, float nhgt, float ntx, float nty, float Zoom)
|
||||
{
|
||||
C4Facet::Set(nsfc, nx, ny, nwdt, nhgt);
|
||||
TargetX = ntx; TargetY = nty; this->Zoom = Zoom;
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
void Set(const C4Facet &cpy) { TargetX=TargetY=0; Zoom=1; C4Facet::Set(cpy); }
|
||||
void Set(const C4TargetFacet &cpy) { *this = cpy; }
|
||||
void Set(class C4Surface *nsfc, int nx, int ny, int nwdt, int nhgt, float ntx=0, float nty=0, float Zoom=1);
|
||||
void Set(class C4Surface *nsfc, float nx, float ny, float nwdt, float nhgt, float ntx=0, float nty=0, float Zoom=1);
|
||||
void Set(class C4Surface *nsfc, const C4Rect & r, float ntx=0, float nty=0, float Zoom=1);
|
||||
|
||||
void DrawLineDw(int iX1, int iY1, int iX2, int iY2, uint32_t col1, uint32_t col2); // uses Target and position
|
||||
|
|
|
@ -123,7 +123,7 @@ int32_t C4MenuItem::GetSymbolWidth(int32_t iForHeight)
|
|||
{
|
||||
// Context or dialog menus
|
||||
if (iStyle==C4MN_Style_Context || (iStyle==C4MN_Style_Dialog && Symbol.Surface))
|
||||
return Max(Symbol.Wdt * iForHeight / Max<int32_t>(Symbol.Hgt, 1), iForHeight);
|
||||
return Max(Symbol.Wdt * iForHeight / Max(Symbol.Hgt, 1.0f), static_cast<float>(iForHeight));
|
||||
// Info menus
|
||||
if (iStyle==C4MN_Style_Info && Symbol.Surface && Symbol.Wdt)
|
||||
return Symbol.Wdt;
|
||||
|
|
|
@ -1169,13 +1169,13 @@ C4StartupPlrColorPickerDlg::Picker::Picker(const C4Rect &bounds)
|
|||
vPickerRect.Hgt = 256 - PlayerColorValueLowBound;
|
||||
|
||||
C4Facet &flagPreviewPic = ::GraphicsResource.fctFlagClr;
|
||||
int preview_width = std::min(flagPreviewPic.Wdt, caMain.GetInnerWidth());
|
||||
int preview_width = std::min<int>(flagPreviewPic.Wdt, caMain.GetInnerWidth());
|
||||
flagPreview = new C4GUI::Picture(caMain.GetFromTop(flagPreviewPic.GetHeightByWidth(preview_width), preview_width), true);
|
||||
flagPreview->SetFacet(flagPreviewPic);
|
||||
AddElement(flagPreview);
|
||||
|
||||
C4Facet &crewPreviewPic = ::GraphicsResource.fctCrewClr;
|
||||
preview_width = std::min(crewPreviewPic.Wdt, caMain.GetInnerWidth());
|
||||
preview_width = std::min<int>(crewPreviewPic.Wdt, caMain.GetInnerWidth());
|
||||
crewPreview = new C4GUI::Picture(caMain.GetFromTop(crewPreviewPic.GetHeightByWidth(preview_width), preview_width), true);
|
||||
crewPreview->SetFacet(crewPreviewPic);
|
||||
AddElement(crewPreview);
|
||||
|
|
Loading…
Reference in New Issue