more code sharing.
This commit is contained in:
@@ -18,6 +18,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* defines
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define AQDG_AXISWIDGET_SCALESIZE 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* forward declarations
|
* forward declarations
|
||||||
* ------------------------------------------------------------------------------------------------
|
* ------------------------------------------------------------------------------------------------
|
||||||
@@ -27,7 +36,8 @@ static GWENHYWFAR_CB void _freeData(void *bp, void *p);
|
|||||||
|
|
||||||
static void _setupObjectTree(AQDG_OBJECT *o);
|
static void _setupObjectTree(AQDG_OBJECT *o);
|
||||||
static void _createTickLabelsForLevel(AQDG_OBJECT *o, AQDG_GRAPH *graph, const AQDG_GRAPH_TICK_LIST *tickList, int level);
|
static void _createTickLabelsForLevel(AQDG_OBJECT *o, AQDG_GRAPH *graph, const AQDG_GRAPH_TICK_LIST *tickList, int level);
|
||||||
static int _doesCollideWithChildren(const AQDG_OBJECT *object, const AQDG_OBJECT *newObject);
|
static int _hasLabelCollisions(const AQDG_OBJECT *o);
|
||||||
|
static int _hideEverySecondLabel(AQDG_OBJECT *o);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -53,6 +63,9 @@ AQDG_OBJECT *AQDG_AxisWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OBJ
|
|||||||
xo->graphObject=graphObject;
|
xo->graphObject=graphObject;
|
||||||
xo->axisIndex=axisIndex;
|
xo->axisIndex=axisIndex;
|
||||||
|
|
||||||
|
/* set defaults */
|
||||||
|
xo->scaleSize=AQDG_AXISWIDGET_SCALESIZE;
|
||||||
|
|
||||||
_setupObjectTree(o);
|
_setupObjectTree(o);
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
@@ -149,6 +162,46 @@ void AQDG_AxisWidget_SetMaxValue(AQDG_OBJECT *o, double v)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQDG_AxisWidget_GetScaleSize(const AQDG_OBJECT *o)
|
||||||
|
{
|
||||||
|
if (o) {
|
||||||
|
AQDG_WIDGET_AXIS *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_AXIS, o);
|
||||||
|
return xo?xo->scaleSize:0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQDG_AxisWidget_SetScaleSize(AQDG_OBJECT *o, int i)
|
||||||
|
{
|
||||||
|
if (o) {
|
||||||
|
AQDG_WIDGET_AXIS *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_AXIS, o);
|
||||||
|
if (xo)
|
||||||
|
xo->scaleSize=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQDG_AxisWidget_HideCollidingChildren(AQDG_OBJECT *o)
|
||||||
|
{
|
||||||
|
int doRun=1;
|
||||||
|
|
||||||
|
while(doRun) {
|
||||||
|
if (_hasLabelCollisions(o))
|
||||||
|
doRun=(_hideEverySecondLabel(o)<0)?0:1;
|
||||||
|
else
|
||||||
|
doRun=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _setupObjectTree(AQDG_OBJECT *o)
|
void _setupObjectTree(AQDG_OBJECT *o)
|
||||||
@@ -228,7 +281,7 @@ void _createTickLabelsForLevel(AQDG_OBJECT *o, AQDG_GRAPH *graph, const AQDG_GRA
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQDG_AxisWidget_DoesCollideWithOtherChildren(const AQDG_OBJECT *object, const AQDG_OBJECT *newObject)
|
int _doesCollideWithOtherChildren(const AQDG_OBJECT *object, const AQDG_OBJECT *newObject)
|
||||||
{
|
{
|
||||||
AQDG_OBJECT *child;
|
AQDG_OBJECT *child;
|
||||||
int xLeft;
|
int xLeft;
|
||||||
@@ -274,6 +327,43 @@ int AQDG_AxisWidget_DoesCollideWithOtherChildren(const AQDG_OBJECT *object, cons
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _hasLabelCollisions(const AQDG_OBJECT *o)
|
||||||
|
{
|
||||||
|
AQDG_OBJECT *child;
|
||||||
|
|
||||||
|
/* align left */
|
||||||
|
child=AQDG_Object_Tree2_GetFirstChild(o);
|
||||||
|
while(child) {
|
||||||
|
if (!(AQDG_Object_GetFlags(child) & AQDG_OBJECT_FLAGS_HIDDEN)) {
|
||||||
|
if (_doesCollideWithOtherChildren(o, child))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
child=AQDG_Object_Tree2_GetNext(child);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _hideEverySecondLabel(AQDG_OBJECT *o)
|
||||||
|
{
|
||||||
|
AQDG_OBJECT *child;
|
||||||
|
int hadVisibleChildren=0;
|
||||||
|
|
||||||
|
child=AQDG_DrawableWidget_GetFirstVisibleChild(o);
|
||||||
|
while(child) {
|
||||||
|
child=AQDG_DrawableWidget_GetNextVisibleWidget(child); /* skip current */
|
||||||
|
if (child) {
|
||||||
|
hadVisibleChildren=1;
|
||||||
|
AQDG_Object_AddFlags(child, AQDG_OBJECT_FLAGS_HIDDEN);
|
||||||
|
}
|
||||||
|
child=AQDG_DrawableWidget_GetNextVisibleWidget(child);
|
||||||
|
}
|
||||||
|
return hadVisibleChildren?0:GWEN_ERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,12 @@ AQDG_API void AQDG_AxisWidget_SetMinValue(AQDG_OBJECT *o, double v);
|
|||||||
AQDG_API double AQDG_AxisWidget_GetMaxValue(const AQDG_OBJECT *o);
|
AQDG_API double AQDG_AxisWidget_GetMaxValue(const AQDG_OBJECT *o);
|
||||||
AQDG_API void AQDG_AxisWidget_SetMaxValue(AQDG_OBJECT *o, double v);
|
AQDG_API void AQDG_AxisWidget_SetMaxValue(AQDG_OBJECT *o, double v);
|
||||||
|
|
||||||
AQDG_API int AQDG_AxisWidget_DoesCollideWithOtherChildren(const AQDG_OBJECT *object, const AQDG_OBJECT *newObject);
|
AQDG_API int AQDG_AxisWidget_GetScaleSize(const AQDG_OBJECT *o);
|
||||||
|
AQDG_API void AQDG_AxisWidget_SetScaleSize(AQDG_OBJECT *o, int i);
|
||||||
|
|
||||||
|
|
||||||
|
AQDG_API void AQDG_AxisWidget_HideCollidingChildren(AQDG_OBJECT *o);
|
||||||
|
AQDG_API void AQDG_AxisWidget_UnhideAllChildren(AQDG_OBJECT *o);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ struct AQDG_WIDGET_AXIS {
|
|||||||
int axisIndex;
|
int axisIndex;
|
||||||
double minValue;
|
double minValue;
|
||||||
double maxValue;
|
double maxValue;
|
||||||
|
|
||||||
|
int scaleSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ void _setChildrenRelY(AQDG_OBJECT *o)
|
|||||||
AQDG_OBJECT *child;
|
AQDG_OBJECT *child;
|
||||||
int borderSize;
|
int borderSize;
|
||||||
|
|
||||||
borderSize=AQDG_Object_GetBorderTop(o);
|
borderSize=AQDG_Object_GetBorderTop(o)+AQDG_AxisWidget_GetScaleSize(o);
|
||||||
/* align left */
|
/* align left */
|
||||||
child=AQDG_Object_Tree2_GetFirstChild(o);
|
child=AQDG_Object_Tree2_GetFirstChild(o);
|
||||||
while(child) {
|
while(child) {
|
||||||
@@ -123,7 +123,7 @@ void _setChildrenRelY(AQDG_OBJECT *o)
|
|||||||
int borderSize;
|
int borderSize;
|
||||||
|
|
||||||
/* align right */
|
/* align right */
|
||||||
borderSize=AQDG_Object_GetBorderBottom(o);
|
borderSize=AQDG_Object_GetBorderBottom(o)+AQDG_AxisWidget_GetScaleSize(o);
|
||||||
child=AQDG_Object_Tree2_GetFirstChild(o);
|
child=AQDG_Object_Tree2_GetFirstChild(o);
|
||||||
while(child) {
|
while(child) {
|
||||||
int pos;
|
int pos;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
static int _calcContentDims(AQDG_OBJECT *object);
|
static int _calcContentDims(AQDG_OBJECT *object);
|
||||||
static int _layout(AQDG_OBJECT *object);
|
static int _layout(AQDG_OBJECT *object);
|
||||||
|
static void _setChildrenRelX(AQDG_OBJECT *o);
|
||||||
|
static void _setChildrenRelYFromValue(AQDG_OBJECT *o);
|
||||||
static int _calcVerticalPos(double value, int contentSize, int borderSize, double minValue, double maxValue);
|
static int _calcVerticalPos(double value, int contentSize, int borderSize, double minValue, double maxValue);
|
||||||
|
|
||||||
|
|
||||||
@@ -49,22 +51,41 @@ AQDG_OBJECT *AQDG_YAxisWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_OB
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _calcContentDims(AQDG_OBJECT *object)
|
int _calcContentDims(AQDG_OBJECT *o)
|
||||||
{
|
{
|
||||||
/* TODO
|
AQDG_OBJECT *child;
|
||||||
* - get axis
|
int w=0;
|
||||||
* - get ticks
|
int h=1;
|
||||||
* - calc max height of tick labels
|
|
||||||
* - add size of axis line + tick lines + spacing
|
/* get max label width */
|
||||||
*/
|
child=AQDG_Object_Tree2_GetFirstChild(o);
|
||||||
|
while(child) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i=AQDG_Object_GetWidth(child);
|
||||||
|
w=(i>w)?i:w;
|
||||||
|
child=AQDG_Object_Tree2_GetNext(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add space for scale, left border and right border */
|
||||||
|
w+=AQDG_AxisWidget_GetScaleSize(o);
|
||||||
|
w+=AQDG_Object_GetBorderLeft(o)+AQDG_Object_GetBorderRight(o);
|
||||||
|
|
||||||
|
AQDG_Object_SetContentWidth(o, w);
|
||||||
|
AQDG_Object_SetContentHeight(o, h);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _layout(AQDG_OBJECT *object)
|
int _layout(AQDG_OBJECT *o)
|
||||||
{
|
{
|
||||||
/* TODO */
|
_setChildrenRelX(o);
|
||||||
|
_setChildrenRelYFromValue(o);
|
||||||
|
AQDG_DrawableWidget_UnhideAllChildren(o);
|
||||||
|
AQDG_AxisWidget_HideCollidingChildren(o);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +101,7 @@ void _setChildrenRelX(AQDG_OBJECT *o)
|
|||||||
AQDG_OBJECT *child;
|
AQDG_OBJECT *child;
|
||||||
int borderSize;
|
int borderSize;
|
||||||
|
|
||||||
borderSize=AQDG_Object_GetBorderLeft(o);
|
borderSize=AQDG_Object_GetBorderLeft(o)+AQDG_AxisWidget_GetScaleSize(o);
|
||||||
/* align left */
|
/* align left */
|
||||||
child=AQDG_Object_Tree2_GetFirstChild(o);
|
child=AQDG_Object_Tree2_GetFirstChild(o);
|
||||||
while(child) {
|
while(child) {
|
||||||
@@ -93,7 +114,7 @@ void _setChildrenRelX(AQDG_OBJECT *o)
|
|||||||
int borderSize;
|
int borderSize;
|
||||||
|
|
||||||
/* align right */
|
/* align right */
|
||||||
borderSize=AQDG_Object_GetBorderRight(o);
|
borderSize=AQDG_Object_GetBorderRight(o)+AQDG_AxisWidget_GetScaleSize(o);
|
||||||
child=AQDG_Object_Tree2_GetFirstChild(o);
|
child=AQDG_Object_Tree2_GetFirstChild(o);
|
||||||
while(child) {
|
while(child) {
|
||||||
int pos;
|
int pos;
|
||||||
|
|||||||
Reference in New Issue
Block a user