more work on objects, fixed some layout glitches.
This commit is contained in:
@@ -431,7 +431,7 @@ int _drawText(AQDG_DRAW_CONTEXT *g, int penId, int fontId, int direction, int x,
|
|||||||
AQDG_DRAW_CONTEXT_CAIRO *xg;
|
AQDG_DRAW_CONTEXT_CAIRO *xg;
|
||||||
AQDG_DRAW_FONT *font;
|
AQDG_DRAW_FONT *font;
|
||||||
AQDG_DRAW_PEN *pen;
|
AQDG_DRAW_PEN *pen;
|
||||||
cairo_font_extents_t extents;
|
cairo_text_extents_t te;
|
||||||
|
|
||||||
xg=_ensureFullCairoContext(g);
|
xg=_ensureFullCairoContext(g);
|
||||||
if (xg==NULL) {
|
if (xg==NULL) {
|
||||||
@@ -456,10 +456,11 @@ int _drawText(AQDG_DRAW_CONTEXT *g, int penId, int fontId, int direction, int x,
|
|||||||
}
|
}
|
||||||
_setFont(xg->cr, font);
|
_setFont(xg->cr, font);
|
||||||
|
|
||||||
cairo_font_extents(xg->cr, &extents);
|
cairo_text_extents(xg->cr, text, &te);
|
||||||
|
|
||||||
/* TODO: translate pos and rotate according to given direction (use cairo_save and cairo_restore) */
|
/* TODO: translate pos and rotate according to given direction (use cairo_save and cairo_restore) */
|
||||||
cairo_move_to(xg->cr, x, y+extents.ascent);
|
/*DBG_ERROR(NULL, "te.x_bearing=%f, te.y_bearing=%f", te.x_bearing, te.y_bearing);*/
|
||||||
|
cairo_move_to(xg->cr, x, y-te.y_bearing);
|
||||||
cairo_show_text(xg->cr, text);
|
cairo_show_text(xg->cr, text);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ int AQDG_DrawableWidget_DrawBackground(AQDG_OBJECT *object)
|
|||||||
|
|
||||||
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_DRAWABLE, object);
|
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_DRAWABLE, object);
|
||||||
if (xo) {
|
if (xo) {
|
||||||
DBG_ERROR(NULL, "Drawing with pen %d to %d/%d %d/%d",
|
DBG_ERROR(NULL, "Drawing background with pen %d to %d/%d %d/%d",
|
||||||
xo->backgroundPenId,
|
xo->backgroundPenId,
|
||||||
AQDG_Object_GetAbsoluteX(object),
|
AQDG_Object_GetAbsoluteX(object),
|
||||||
AQDG_Object_GetAbsoluteY(object),
|
AQDG_Object_GetAbsoluteY(object),
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ static int _calcYPos(AQDG_OBJECT *object, uint32_t opts, int th);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQDG_OBJECT *AQDG_LabelWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext)
|
AQDG_OBJECT *AQDG_LabelWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext, const char *text)
|
||||||
{
|
{
|
||||||
AQDG_OBJECT *object;
|
AQDG_OBJECT *object;
|
||||||
|
|
||||||
@@ -45,6 +45,8 @@ AQDG_OBJECT *AQDG_LabelWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DR
|
|||||||
AQDG_Object_SetOptions(object, options);
|
AQDG_Object_SetOptions(object, options);
|
||||||
AQDG_Object_SetCalcContentDimsFn(object, _calcContentDims);
|
AQDG_Object_SetCalcContentDimsFn(object, _calcContentDims);
|
||||||
AQDG_DrawableWidget_SetDrawFn(object, _draw);
|
AQDG_DrawableWidget_SetDrawFn(object, _draw);
|
||||||
|
if (text)
|
||||||
|
AQDG_DrawableWidget_SetText(object, text);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,29 +125,32 @@ int _calcYPos(AQDG_OBJECT *object, uint32_t opts, int th)
|
|||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
int h;
|
int h;
|
||||||
|
int oh=AQDG_Object_GetHeight(object);
|
||||||
|
int borderBottom=AQDG_Object_GetBorderBottom(object);
|
||||||
|
int borderTop=AQDG_Object_GetBorderTop(object);
|
||||||
|
|
||||||
h=AQDG_Object_GetHeight(object)-AQDG_Object_GetBorderTop(object)-AQDG_Object_GetBorderBottom(object);
|
h=oh-(borderTop+borderBottom);
|
||||||
if (h<0) {
|
if (h<0) {
|
||||||
DBG_ERROR(NULL, "Height smaller than borders (%d)", h);
|
DBG_ERROR(NULL, "Height smaller than borders (%d)", h);
|
||||||
return AQDG_Object_GetBorderTop(object);
|
return borderTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts & AQDG_DRAWABLE_OPTIONS_JUSTIFY_BOTTOM) {
|
if (opts & AQDG_DRAWABLE_OPTIONS_JUSTIFY_BOTTOM) {
|
||||||
/* bottom */
|
/* bottom */
|
||||||
y=(h-th)+AQDG_Object_GetBorderTop(object);
|
y=borderTop+(h-th);
|
||||||
}
|
}
|
||||||
else if (opts & AQDG_DRAWABLE_OPTIONS_JUSTIFY_VCENTER) {
|
else if (opts & AQDG_DRAWABLE_OPTIONS_JUSTIFY_VCENTER) {
|
||||||
/* vcenter */
|
/* vcenter */
|
||||||
y=((h-th)/2)+AQDG_Object_GetBorderTop(object);
|
y=borderTop+((h-th)/2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* top */
|
/* top */
|
||||||
y=AQDG_Object_GetBorderTop(object);
|
y=borderTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y<AQDG_Object_GetBorderTop(object)) {
|
if (y<borderTop) {
|
||||||
DBG_INFO(NULL, "y lower than top border pos");
|
DBG_INFO(NULL, "y lower than top border pos");
|
||||||
y=AQDG_Object_GetBorderTop(object);
|
y=borderTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include <aqdiagram/draw/context.h>
|
#include <aqdiagram/draw/context.h>
|
||||||
|
|
||||||
|
|
||||||
AQDG_API AQDG_OBJECT *AQDG_LabelWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext);
|
AQDG_API AQDG_OBJECT *AQDG_LabelWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext, const char *text);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,16 @@
|
|||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define COLOUR1 0x00000000
|
||||||
|
#define COLOUR2 0xff000000
|
||||||
|
#define COLOUR3 0x0000ff00
|
||||||
|
#define COLOUR4 0x00ff0000
|
||||||
|
#define COLOUR5 0xffec5b00
|
||||||
|
#define COLOUR6 0xc0c0c000
|
||||||
|
#define COLOUR7 0xffffff00
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int test1(int argc, char **argv)
|
int test1(int argc, char **argv)
|
||||||
{
|
{
|
||||||
AQDG_DRAW_CONTEXT *dc;
|
AQDG_DRAW_CONTEXT *dc;
|
||||||
@@ -32,9 +42,15 @@ int test1(int argc, char **argv)
|
|||||||
|
|
||||||
dc=AQDG_Draw_ContextCairo_Png_new("/tmp/test.png", 640, 480);
|
dc=AQDG_Draw_ContextCairo_Png_new("/tmp/test.png", 640, 480);
|
||||||
rootObject=AQDG_HLayoutWidget_new(NULL, AQDG_OBJECT_OPTIONS_STRETCHX | AQDG_OBJECT_OPTIONS_STRETCHY, dc);
|
rootObject=AQDG_HLayoutWidget_new(NULL, AQDG_OBJECT_OPTIONS_STRETCHX | AQDG_OBJECT_OPTIONS_STRETCHY, dc);
|
||||||
|
AQDG_Object_SetBorderLeft(rootObject, 5);
|
||||||
|
AQDG_Object_SetBorderRight(rootObject, 5);
|
||||||
|
AQDG_Object_SetBorderTop(rootObject, 5);
|
||||||
|
AQDG_Object_SetBorderBottom(rootObject, 5);
|
||||||
|
AQDG_Object_SetHSpacing(rootObject, 4);
|
||||||
|
AQDG_Object_SetVSpacing(rootObject, 4);
|
||||||
AQDG_Object_SetWidth(rootObject, 640);
|
AQDG_Object_SetWidth(rootObject, 640);
|
||||||
AQDG_Object_SetHeight(rootObject, 480);
|
AQDG_Object_SetHeight(rootObject, 480);
|
||||||
rv=AQDG_Draw_Context_PenCreate(dc, 0xffec5b00, 1, AQDG_Dash_None);
|
rv=AQDG_Draw_Context_PenCreate(dc, COLOUR2, 1, AQDG_Dash_None);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
||||||
return 2;
|
return 2;
|
||||||
@@ -42,7 +58,7 @@ int test1(int argc, char **argv)
|
|||||||
DBG_ERROR(NULL, "Background pen: %d", rv);
|
DBG_ERROR(NULL, "Background pen: %d", rv);
|
||||||
AQDG_DrawableWidget_SetBackgroundPenId(rootObject, rv);
|
AQDG_DrawableWidget_SetBackgroundPenId(rootObject, rv);
|
||||||
|
|
||||||
rv=AQDG_Draw_Context_PenCreate(dc, 0xff000000, 1, AQDG_Dash_None);
|
rv=AQDG_Draw_Context_PenCreate(dc, COLOUR1, 1, AQDG_Dash_None);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
||||||
return 2;
|
return 2;
|
||||||
@@ -59,9 +75,8 @@ int test1(int argc, char **argv)
|
|||||||
|
|
||||||
o=AQDG_LabelWidget_new(rootObject,
|
o=AQDG_LabelWidget_new(rootObject,
|
||||||
AQDG_OBJECT_OPTIONS_VALIGNCENTER|AQDG_OBJECT_OPTIONS_STRETCHY | AQDG_DRAWABLE_OPTIONS_JUSTIFY_VCENTER,
|
AQDG_OBJECT_OPTIONS_VALIGNCENTER|AQDG_OBJECT_OPTIONS_STRETCHY | AQDG_DRAWABLE_OPTIONS_JUSTIFY_VCENTER,
|
||||||
dc);
|
dc, "First Label");
|
||||||
AQDG_DrawableWidget_SetText(o, "First Label");
|
rv=AQDG_Draw_Context_PenCreate(dc, COLOUR3, 1, AQDG_Dash_None);
|
||||||
rv=AQDG_Draw_Context_PenCreate(dc, 0x80ec5b00, 1, AQDG_Dash_None);
|
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
||||||
return 2;
|
return 2;
|
||||||
@@ -69,8 +84,20 @@ int test1(int argc, char **argv)
|
|||||||
DBG_ERROR(NULL, "Background pen: %d", rv);
|
DBG_ERROR(NULL, "Background pen: %d", rv);
|
||||||
AQDG_DrawableWidget_SetBackgroundPenId(o, rv);
|
AQDG_DrawableWidget_SetBackgroundPenId(o, rv);
|
||||||
|
|
||||||
o=AQDG_LabelWidget_new(rootObject, 0, dc);
|
o=AQDG_LabelWidget_new(rootObject, 0, dc, "Second Label");
|
||||||
AQDG_DrawableWidget_SetText(o, "Second Label");
|
rv=AQDG_Draw_Context_PenCreate(dc, COLOUR4, 1, AQDG_Dash_None);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
DBG_ERROR(NULL, "Background pen: %d", rv);
|
||||||
|
AQDG_DrawableWidget_SetBackgroundPenId(o, rv);
|
||||||
|
rv=AQDG_Draw_Context_FontCreate(dc, "", 24, AQDG_Slant_None, AQDG_Weight_None);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_ERROR(NULL, "Error creating font (%d)", rv);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
AQDG_DrawableWidget_SetFontId(o, rv);
|
||||||
|
|
||||||
DBG_ERROR(NULL, "Layout");
|
DBG_ERROR(NULL, "Layout");
|
||||||
rv=AQDG_Object_Layout(rootObject);
|
rv=AQDG_Object_Layout(rootObject);
|
||||||
@@ -81,6 +108,8 @@ int test1(int argc, char **argv)
|
|||||||
DBG_ERROR(NULL, "CalcAbs");
|
DBG_ERROR(NULL, "CalcAbs");
|
||||||
AQDG_Object_Tree2_CalculateAbsPositions(rootObject);
|
AQDG_Object_Tree2_CalculateAbsPositions(rootObject);
|
||||||
|
|
||||||
|
AQDG_Object_Dump(rootObject, 2);
|
||||||
|
|
||||||
DBG_ERROR(NULL, "Draw");
|
DBG_ERROR(NULL, "Draw");
|
||||||
rv=AQDG_DrawableWidget_Draw(rootObject);
|
rv=AQDG_DrawableWidget_Draw(rootObject);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include "./layout.h"
|
#include "./layout.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
static int _getSumOfElementWidths(const AQDG_PLACEMENT_LAYOUT_ELEMENT *ptrElements, int numElements);
|
static int _getSumOfElementWidths(const AQDG_PLACEMENT_LAYOUT_ELEMENT *ptrElements, int numElements);
|
||||||
static int _getStretchableElements(const AQDG_PLACEMENT_LAYOUT_ELEMENT *ptrElements, int numElements);
|
static int _getStretchableElements(const AQDG_PLACEMENT_LAYOUT_ELEMENT *ptrElements, int numElements);
|
||||||
|
|||||||
@@ -136,8 +136,10 @@
|
|||||||
$(struct_type) *child; \n
|
$(struct_type) *child; \n
|
||||||
\n
|
\n
|
||||||
parent=$(struct_prefix)_Tree2_GetParent(object); \n
|
parent=$(struct_prefix)_Tree2_GetParent(object); \n
|
||||||
if (parent) \n
|
if (parent){ \n
|
||||||
object->absoluteX=parent->absoluteX + object->relativeX; \n
|
object->absoluteX=parent->absoluteX + object->relativeX; \n
|
||||||
|
object->absoluteY=parent->absoluteY + object->relativeY; \n
|
||||||
|
} \n
|
||||||
child=$(struct_prefix)_Tree2_GetFirstChild(object); \n
|
child=$(struct_prefix)_Tree2_GetFirstChild(object); \n
|
||||||
while(child) { \n
|
while(child) { \n
|
||||||
$(struct_prefix)_Tree2_CalculateAbsPositions(child); \n
|
$(struct_prefix)_Tree2_CalculateAbsPositions(child); \n
|
||||||
@@ -149,6 +151,57 @@
|
|||||||
</inline>
|
</inline>
|
||||||
|
|
||||||
|
|
||||||
|
<inline loc="end" access="public">
|
||||||
|
<content>
|
||||||
|
$(api) void $(struct_prefix)_Dump(const $(struct_type) *object, int indent);
|
||||||
|
</content>
|
||||||
|
</inline>
|
||||||
|
|
||||||
|
<inline loc="code">
|
||||||
|
<content>
|
||||||
|
void $(struct_prefix)_Dump(const $(struct_type) *object, int indent) \n
|
||||||
|
{ \n
|
||||||
|
if (object) { \n
|
||||||
|
$(struct_type) *child; \n
|
||||||
|
int i; \n
|
||||||
|
\n
|
||||||
|
for(i=0; i<indent; i++) \n
|
||||||
|
fprintf(stderr, " "); \n
|
||||||
|
fprintf(stderr, "- Object:\\n"); \n
|
||||||
|
for(i=0; i<indent+2; i++) \n
|
||||||
|
fprintf(stderr, " "); \n
|
||||||
|
fprintf(stderr, "absX=%d, absY=%d, relX=%d, relY=%d\\n", \n
|
||||||
|
object->absoluteX, object->absoluteY, \n
|
||||||
|
object->relativeX, object->relativeY); \n
|
||||||
|
for(i=0; i<indent+2; i++) \n
|
||||||
|
fprintf(stderr, " "); \n
|
||||||
|
fprintf(stderr, "width=%d, height=%d\\n", \n
|
||||||
|
object->width, object->height); \n
|
||||||
|
for(i=0; i<indent+2; i++) \n
|
||||||
|
fprintf(stderr, " "); \n
|
||||||
|
fprintf(stderr, "left=%d, right=%d, top=%d, bottom=%d\\n", \n
|
||||||
|
object->borderLeft, \n
|
||||||
|
object->borderRight, \n
|
||||||
|
object->borderTop, \n
|
||||||
|
object->borderBottom); \n
|
||||||
|
for(i=0; i<indent+2; i++) \n
|
||||||
|
fprintf(stderr, " "); \n
|
||||||
|
fprintf(stderr, \n
|
||||||
|
"hSpacing=%d, vSpacing=%d, contWidth=%d, contWidthHeight=%d\\n",\n
|
||||||
|
object->hSpacing, object->vSpacing, \n
|
||||||
|
object->contentWidth, object->contentHeight); \n
|
||||||
|
\n
|
||||||
|
child=$(struct_prefix)_Tree2_GetFirstChild(object); \n
|
||||||
|
while(child) { \n
|
||||||
|
$(struct_prefix)_Dump(child, indent+2); \n
|
||||||
|
child=$(struct_prefix)_Tree2_GetNext(child); \n
|
||||||
|
} \n
|
||||||
|
} \n
|
||||||
|
} \n
|
||||||
|
</content>
|
||||||
|
</inline>
|
||||||
|
|
||||||
|
|
||||||
</inlines>
|
</inlines>
|
||||||
|
|
||||||
</lang>
|
</lang>
|
||||||
|
|||||||
Reference in New Issue
Block a user