mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-24 20:22:10 +00:00
Abstract out quad calculation from Sensor
The calculation of the bounding quad is now in CairoArea, as it is quite useful
This commit is contained in:
parent
5654ab6f0b
commit
9e48830dc8
2 changed files with 33 additions and 22 deletions
|
@ -229,6 +229,28 @@ void CairoArea::Create()
|
||||||
ApplyPropertiesToWidget();
|
ApplyPropertiesToWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Quad CairoArea::GetQuad()
|
||||||
|
{
|
||||||
|
GtkAllocation dim;
|
||||||
|
gtk_widget_get_allocation(m_Widget, &dim);
|
||||||
|
Quad q;
|
||||||
|
if (dim.height >= dim.width)
|
||||||
|
{
|
||||||
|
// Height greater than width; Fill in x and add margin at the top and bottom
|
||||||
|
q.size = dim.width;
|
||||||
|
q.x = 0;
|
||||||
|
q.y = ((double)dim.height - (double)dim.width) / 2;
|
||||||
|
}
|
||||||
|
else if (dim.width < dim.height)
|
||||||
|
{
|
||||||
|
// Height greater than width; Fill in y and add margin at the sides
|
||||||
|
q.size = dim.height;
|
||||||
|
q.y = 0;
|
||||||
|
q.x = ((double)dim.width - (double)dim.height) / 2;
|
||||||
|
}
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
void Sensor::SetValue(double val)
|
void Sensor::SetValue(double val)
|
||||||
{
|
{
|
||||||
m_Val = val;
|
m_Val = val;
|
||||||
|
@ -245,29 +267,11 @@ void Sensor::SetStyle(SensorStyle style)
|
||||||
|
|
||||||
void Sensor::Draw(cairo_t* cr)
|
void Sensor::Draw(cairo_t* cr)
|
||||||
{
|
{
|
||||||
GtkAllocation dim;
|
Quad q = GetQuad();
|
||||||
gtk_widget_get_allocation(m_Widget, &dim);
|
|
||||||
double xStart = 0;
|
|
||||||
double yStart = 0;
|
|
||||||
double size = dim.width;
|
|
||||||
if (dim.height >= dim.width)
|
|
||||||
{
|
|
||||||
// Height greater than width; Fill in x and add margin at the top and bottom
|
|
||||||
size = dim.width;
|
|
||||||
xStart = 0;
|
|
||||||
yStart = ((double)dim.height - (double)dim.width) / 2;
|
|
||||||
}
|
|
||||||
else if (dim.width < dim.height)
|
|
||||||
{
|
|
||||||
// Height greater than width; Fill in y and add margin at the sides
|
|
||||||
size = dim.height;
|
|
||||||
yStart = 0;
|
|
||||||
xStart = ((double)dim.width - (double)dim.height) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
double xCenter = xStart + size / 2;
|
double xCenter = q.x + q.size / 2;
|
||||||
double yCenter = yStart + size / 2;
|
double yCenter = q.y + q.size / 2;
|
||||||
double radius = (size / 2) - (m_Style.strokeWidth / 2);
|
double radius = (q.size / 2) - (m_Style.strokeWidth / 2);
|
||||||
|
|
||||||
double beg = m_Style.start * (M_PI / 180);
|
double beg = m_Style.start * (M_PI / 180);
|
||||||
double angle = m_Val * 2 * M_PI;
|
double angle = m_Val * 2 * M_PI;
|
||||||
|
|
|
@ -47,6 +47,11 @@ struct Transition
|
||||||
uint32_t durationMS;
|
uint32_t durationMS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Quad
|
||||||
|
{
|
||||||
|
double x, y, size;
|
||||||
|
};
|
||||||
|
|
||||||
struct SensorStyle
|
struct SensorStyle
|
||||||
{
|
{
|
||||||
double start = -90; // 0 = leftmost; -90 = topmost
|
double start = -90; // 0 = leftmost; -90 = topmost
|
||||||
|
@ -203,6 +208,8 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Draw(cairo_t* cr) = 0;
|
virtual void Draw(cairo_t* cr) = 0;
|
||||||
|
|
||||||
|
Quad GetQuad();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Sensor : public CairoArea
|
class Sensor : public CairoArea
|
||||||
|
|
Loading…
Reference in a new issue