some fixes, more work on widgets and objects, added test.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
@@ -18,9 +18,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
AQDG_API AQDG_DRAW_CONTEXT *AQDG_ContextCairo_Pdf_new(const char *fileName, int w, int h);
|
||||
AQDG_API AQDG_DRAW_CONTEXT *AQDG_ContextCairo_Ps_new(const char *fileName, int w, int h);
|
||||
AQDG_API AQDG_DRAW_CONTEXT *AQDG_ContextCairo_Png_new(const char *fileName, int w, int h);
|
||||
AQDG_API AQDG_DRAW_CONTEXT *AQDG_Draw_ContextCairo_Pdf_new(const char *fileName, int w, int h);
|
||||
AQDG_API AQDG_DRAW_CONTEXT *AQDG_Draw_ContextCairo_Ps_new(const char *fileName, int w, int h);
|
||||
AQDG_API AQDG_DRAW_CONTEXT *AQDG_Draw_ContextCairo_Png_new(const char *fileName, int w, int h);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -47,6 +47,13 @@ AQDG_OBJECT *AQDG_DrawableWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG
|
||||
AQDG_DrawableWidget_Extend(object, drawContext);
|
||||
AQDG_Object_SetOptions(object, options);
|
||||
|
||||
AQDG_Object_SetBorderLeft(object, AQDG_DRAWABLE_DEFAULT_BORDER);
|
||||
AQDG_Object_SetBorderRight(object, AQDG_DRAWABLE_DEFAULT_BORDER);
|
||||
AQDG_Object_SetBorderTop(object, AQDG_DRAWABLE_DEFAULT_BORDER);
|
||||
AQDG_Object_SetBorderBottom(object, AQDG_DRAWABLE_DEFAULT_BORDER);
|
||||
AQDG_Object_SetHSpacing(object, AQDG_DRAWABLE_DEFAULT_HSPACING);
|
||||
AQDG_Object_SetVSpacing(object, AQDG_DRAWABLE_DEFAULT_VSPACING);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -241,6 +248,7 @@ AQDG_WIDGET_DRAWABLE_DRAW_FN AQDG_DrawableWidget_SetDrawFn(AQDG_OBJECT *object,
|
||||
|
||||
int AQDG_DrawableWidget_Draw(AQDG_OBJECT *object)
|
||||
{
|
||||
DBG_ERROR(NULL, "Draw %p", object);
|
||||
if (object) {
|
||||
AQDG_OBJECT_DRAWABLE *xo;
|
||||
|
||||
@@ -261,6 +269,12 @@ int AQDG_DrawableWidget_DrawBackground(AQDG_OBJECT *object)
|
||||
|
||||
xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_OBJECT_DRAWABLE, object);
|
||||
if (xo) {
|
||||
DBG_ERROR(NULL, "Drawing with pen %d to %d/%d %d/%d",
|
||||
xo->backgroundPenId,
|
||||
AQDG_Object_GetAbsoluteX(object),
|
||||
AQDG_Object_GetAbsoluteY(object),
|
||||
AQDG_Object_GetWidth(object),
|
||||
AQDG_Object_GetHeight(object));
|
||||
AQDG_Draw_Context_DrawFilledRect(xo->drawContext,
|
||||
xo->backgroundPenId,
|
||||
AQDG_Object_GetAbsoluteX(object),
|
||||
|
||||
@@ -22,6 +22,10 @@ typedef int (*AQDG_WIDGET_DRAWABLE_DRAW_FN)(AQDG_OBJECT *object);
|
||||
#define AQDG_DRAWABLE_OPTIONS_JUSTIFY_BOTTOM 0x00000004
|
||||
#define AQDG_DRAWABLE_OPTIONS_JUSTIFY_VCENTER 0x00000008
|
||||
|
||||
#define AQDG_DRAWABLE_DEFAULT_BORDER 5
|
||||
#define AQDG_DRAWABLE_DEFAULT_HSPACING 4
|
||||
#define AQDG_DRAWABLE_DEFAULT_VSPACING 4
|
||||
|
||||
|
||||
/**
|
||||
* Sets virtual functions:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "./w_vlayout.h"
|
||||
#include "./w_hlayout.h"
|
||||
|
||||
#include "./w_drawable.h"
|
||||
#include "aqdiagram/placement/o_hlayout.h"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
static int _draw(AQDG_OBJECT *object);
|
||||
static int _calcContentDims(AQDG_OBJECT *object);
|
||||
static int _calcXPos(AQDG_OBJECT *object, uint32_t opts, int tw);
|
||||
static int _calcYPos(AQDG_OBJECT *object, uint32_t opts, int th);
|
||||
|
||||
@@ -42,14 +43,23 @@ AQDG_OBJECT *AQDG_LabelWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DR
|
||||
|
||||
object=AQDG_DrawableWidget_new(parent, options, drawContext);
|
||||
AQDG_Object_SetOptions(object, options);
|
||||
AQDG_Object_SetCalcContentDimsFn(object, _calcContentDims);
|
||||
AQDG_DrawableWidget_SetDrawFn(object, _draw);
|
||||
if (parent)
|
||||
AQDG_Object_Tree2_AddChild(parent, object);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _calcContentDims(AQDG_OBJECT *object)
|
||||
{
|
||||
AQDG_DrawableWidget_UpdateTextContentDims(object);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int _draw(AQDG_OBJECT *object)
|
||||
{
|
||||
if (object) {
|
||||
|
||||
@@ -13,19 +13,122 @@
|
||||
|
||||
#include <aqdiagram/aqdiagram.h>
|
||||
#include <aqdiagram/placement/o_hlayout-t.h>
|
||||
#include <aqdiagram/draw/w_drawable.h>
|
||||
#include <aqdiagram/draw/w_hlayout.h>
|
||||
#include <aqdiagram/draw/w_label.h>
|
||||
#include <aqdiagram/draw/context_cairo.h>
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/cgui.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
int test1(int argc, char **argv)
|
||||
{
|
||||
AQDG_DRAW_CONTEXT *dc;
|
||||
AQDG_OBJECT *rootObject;
|
||||
AQDG_OBJECT *o;
|
||||
int rv;
|
||||
|
||||
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);
|
||||
AQDG_Object_SetWidth(rootObject, 640);
|
||||
AQDG_Object_SetHeight(rootObject, 480);
|
||||
rv=AQDG_Draw_Context_PenCreate(dc, 0xffec5b00, 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(rootObject, rv);
|
||||
|
||||
rv=AQDG_Draw_Context_PenCreate(dc, 0xff000000, 1, AQDG_Dash_None);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error creating pen (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
DBG_ERROR(NULL, "Foreground pen: %d", rv);
|
||||
AQDG_DrawableWidget_SetForegroundPenId(rootObject, rv);
|
||||
|
||||
rv=AQDG_Draw_Context_FontCreate(dc, "", 16, AQDG_Slant_None, AQDG_Weight_None);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error creating font (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
AQDG_DrawableWidget_SetFontId(rootObject, rv);
|
||||
|
||||
o=AQDG_LabelWidget_new(rootObject,
|
||||
AQDG_OBJECT_OPTIONS_VALIGNCENTER|AQDG_OBJECT_OPTIONS_STRETCHY | AQDG_DRAWABLE_OPTIONS_JUSTIFY_VCENTER,
|
||||
dc);
|
||||
AQDG_DrawableWidget_SetText(o, "First Label");
|
||||
rv=AQDG_Draw_Context_PenCreate(dc, 0x80ec5b00, 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);
|
||||
|
||||
o=AQDG_LabelWidget_new(rootObject, 0, dc);
|
||||
AQDG_DrawableWidget_SetText(o, "Second Label");
|
||||
|
||||
DBG_ERROR(NULL, "Layout");
|
||||
rv=AQDG_Object_Layout(rootObject);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error on layout (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
DBG_ERROR(NULL, "CalcAbs");
|
||||
AQDG_Object_Tree2_CalculateAbsPositions(rootObject);
|
||||
|
||||
DBG_ERROR(NULL, "Draw");
|
||||
rv=AQDG_DrawableWidget_Draw(rootObject);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error drawing (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
rv=AQDG_Draw_Context_Finish(dc);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error finishing drawing (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int modTest(int argc, char **argv)
|
||||
{
|
||||
int rv;
|
||||
GWEN_TEST_FRAMEWORK *tf;
|
||||
|
||||
tf=TestFramework_new();
|
||||
|
||||
rv=AQDG_HLayoutObject_AddTests(TestFramework_GetModulesRoot(tf));
|
||||
if (rv) {
|
||||
fprintf(stderr, "FAILED: test_hlayout()\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
rv=TestFramework_Run(tf, argc, argv);
|
||||
if (rv) {
|
||||
fprintf(stderr, "Some tests failed.\n");
|
||||
return 2;
|
||||
}
|
||||
TestFramework_free(tf);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rv;
|
||||
GWEN_GUI *gui;
|
||||
GWEN_TEST_FRAMEWORK *tf;
|
||||
|
||||
rv=GWEN_Init();
|
||||
if (rv) {
|
||||
@@ -37,23 +140,17 @@ int main(int argc, char **argv)
|
||||
//GWEN_Gui_SetCharSet(gui, "ISO-8859-15");
|
||||
GWEN_Gui_SetGui(gui);
|
||||
GWEN_Logger_SetLevel(AQDG_LOGDOMAIN, GWEN_LoggerLevel_Info);
|
||||
GWEN_Logger_SetLevel(NULL, GWEN_LoggerLevel_Info);
|
||||
|
||||
tf=TestFramework_new();
|
||||
rv=test1(argc, argv);
|
||||
|
||||
rv=AQDG_HLayoutObject_AddTests(TestFramework_GetModulesRoot(tf));
|
||||
if (rv) {
|
||||
fprintf(stderr, "FAILED: test_db_factory()\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
rv=TestFramework_Run(tf, argc, argv);
|
||||
if (rv) {
|
||||
fprintf(stderr, "SomeError in tests failed.\n");
|
||||
if (rv!=0){
|
||||
DBG_ERROR(NULL, "here (%d)", rv);
|
||||
GWEN_Gui_SetGui(NULL);
|
||||
GWEN_Gui_free(gui);
|
||||
GWEN_Fini();
|
||||
return 2;
|
||||
}
|
||||
TestFramework_free(tf);
|
||||
|
||||
|
||||
rv=GWEN_Fini();
|
||||
|
||||
@@ -72,12 +72,16 @@
|
||||
|
||||
|
||||
<inline loc="end" access="public">
|
||||
<typeFlagsMask> with_tree2 </typeFlagsMask>
|
||||
<typeFlagsValue> with_tree2 </typeFlagsValue>
|
||||
<content>
|
||||
$(api) int $(struct_prefix)_GetDefaultWidth($(struct_type) *object);
|
||||
</content>
|
||||
</inline>
|
||||
|
||||
<inline loc="code">
|
||||
<typeFlagsMask> with_tree2 </typeFlagsMask>
|
||||
<typeFlagsValue> with_tree2 </typeFlagsValue>
|
||||
<content>
|
||||
int $(struct_prefix)_GetDefaultWidth($(struct_type) *object) \n
|
||||
{ \n
|
||||
@@ -117,6 +121,34 @@
|
||||
</inline>
|
||||
|
||||
|
||||
<inline loc="end" access="public">
|
||||
<content>
|
||||
$(api) void $(struct_prefix)_Tree2_CalculateAbsPositions($(struct_type) *object);
|
||||
</content>
|
||||
</inline>
|
||||
|
||||
<inline loc="code">
|
||||
<content>
|
||||
void $(struct_prefix)_Tree2_CalculateAbsPositions($(struct_type) *object) \n
|
||||
{ \n
|
||||
if (object) { \n
|
||||
$(struct_type) *parent; \n
|
||||
$(struct_type) *child; \n
|
||||
\n
|
||||
parent=$(struct_prefix)_Tree2_GetParent(object); \n
|
||||
if (parent) \n
|
||||
object->absoluteX=parent->absoluteX + object->relativeX; \n
|
||||
child=$(struct_prefix)_Tree2_GetFirstChild(object); \n
|
||||
while(child) { \n
|
||||
$(struct_prefix)_Tree2_CalculateAbsPositions(child); \n
|
||||
child=$(struct_prefix)_Tree2_GetNext(child); \n
|
||||
} \n
|
||||
} \n
|
||||
} \n
|
||||
</content>
|
||||
</inline>
|
||||
|
||||
|
||||
</inlines>
|
||||
|
||||
</lang>
|
||||
|
||||
Reference in New Issue
Block a user