Commit 1e632ead authored by claes's avatar claes

Scale type in move dynamics

parent 4744ddf2
......@@ -853,6 +853,9 @@ static attrnav_sEnumElement elem_anim_sequence[] = {
static attrnav_sEnumElement elem_limit_type[] = {
{ (int) ge_eLimitType_Gt, "GreaterThan"},
{ (int) ge_eLimitType_Lt, "LessThan"},
{ (int) ge_eLimitType_Ge, "GreaterEqual"},
{ (int) ge_eLimitType_Le, "LessEqual"},
{ (int) ge_eLimitType_Eq, "Equal"},
{ 0, ""}};
static attrnav_sEnumElement elem_relief[] = {
......@@ -869,6 +872,14 @@ static attrnav_sEnumElement elem_text_size[] = {
{ (int) glow_eTextSize_24, "24"},
{ 0, ""}};
static attrnav_sEnumElement elem_scale_type[] = {
{ (int) glow_eScaleType_LowerLeft, "UpperLeft"},
{ (int) glow_eScaleType_LowerRight, "UpperRight"},
{ (int) glow_eScaleType_UpperLeft, "LowerLeft"},
{ (int) glow_eScaleType_UpperRight, "LowerRight"},
{ (int) glow_eScaleType_Center, "Center"},
{ 0, ""}};
static attrnav_sEnum enum_types[] = {
{ (int) glow_eType_Direction, (attrnav_sEnumElement *) &elem_direction},
{ (int) glow_eType_Color, (attrnav_sEnumElement *) &elem_color},
......@@ -881,6 +892,7 @@ static attrnav_sEnum enum_types[] = {
{ (int) glow_eType_Relief, (attrnav_sEnumElement *) &elem_relief},
{ (int) glow_eType_TextSize, (attrnav_sEnumElement *) &elem_text_size},
{ (int) glow_eType_InputFocusMark, (attrnav_sEnumElement *) &elem_input_focus_mark},
{ (int) ge_eAttrType_ScaleType, (attrnav_sEnumElement *) &elem_scale_type},
{ 0, NULL}};
static attrnav_sEnum mask_types[] = {
......@@ -950,6 +962,7 @@ int attrnav_attr_string_to_value( int type_id, char *value_str,
case ge_eAttrType_LimitType:
case ge_eAttrType_InstanceMask:
case ge_eAttrType_InputFocus:
case ge_eAttrType_ScaleType:
{
if ( sscanf( value_str, "%u", (int *)buffer_ptr) != 1)
return ATTRNAV__INPUT_SYNTAX;
......@@ -1023,6 +1036,7 @@ void attrnav_attrvalue_to_string( int type_id, void *value_ptr,
case glow_eType_TextSize:
case ge_eAttrType_AnimSequence:
case ge_eAttrType_LimitType:
case ge_eAttrType_ScaleType:
{
attrnav_sEnumElement *elem_p;
attrnav_sEnum *enum_p;
......@@ -2084,6 +2098,7 @@ ItemLocal::ItemLocal( AttrNav *attrnav, char *item_name, char *attr,
case ge_eAttrType_LimitType:
case ge_eAttrType_InstanceMask:
case ge_eAttrType_InputFocus:
case ge_eAttrType_ScaleType:
if ( !noedit)
{
brow_SetAnnotPixmap( node, 0, attrnav->brow->pixmap_attrarray);
......
......@@ -843,7 +843,7 @@ GeDynElem *GeDyn::create_dyn_element( int mask, int instance)
e = (GeDynElem *) new GeDigText(this);
break;
case ge_mDynType_Value:
e = (GeDynElem *) new GeValue(this);
e = (GeDynElem *) new GeValue(this, (ge_mInstance)instance);
break;
case ge_mDynType_AnalogColor:
e = (GeDynElem *) new GeAnalogColor(this, (ge_mInstance)instance);
......@@ -2437,6 +2437,7 @@ void GeValue::get_attributes( attr_sItem *attrinfo, int *item_count)
{
int i = *item_count;
if ( instance == ge_mInstance_1) {
strcpy( attrinfo[i].name, "Value.Attribute");
attrinfo[i].value = attribute;
attrinfo[i].type = glow_eType_String;
......@@ -2447,6 +2448,30 @@ void GeValue::get_attributes( attr_sItem *attrinfo, int *item_count)
attrinfo[i].type = glow_eType_String;
attrinfo[i++].size = sizeof( format);
strcpy( attrinfo[i].name, "Value.Instances");
attrinfo[i].value = &instance_mask;
attrinfo[i].type = ge_eAttrType_InstanceMask;
attrinfo[i++].size = sizeof( instance_mask);
}
else {
// Get instance number
int inst = 1;
int m = instance;
while( m > 1) {
m = m >> 1;
inst++;
}
sprintf( attrinfo[i].name, "Value[%d].Attribute", inst);
attrinfo[i].value = attribute;
attrinfo[i].type = glow_eType_String;
attrinfo[i++].size = sizeof( attribute);
sprintf( attrinfo[i].name, "Value[%d].Format", inst);
attrinfo[i].value = format;
attrinfo[i].type = glow_eType_String;
attrinfo[i++].size = sizeof( format);
}
*item_count = i;
}
......@@ -2467,10 +2492,12 @@ void GeValue::set_attribute( grow_tObject object, char *attr_name, int *cnt)
if ( *cnt == 0) {
char msg[200];
if ( instance == ge_mInstance_1) {
strncpy( attribute, attr_name, sizeof( attribute));
sprintf( msg, "Value.Attribute = %s", attr_name);
dyn->graph->message( 'I', msg);
}
}
}
void GeValue::replace_attribute( char *from, char *to, int *cnt, int strict)
......@@ -2483,6 +2510,8 @@ void GeValue::save( ofstream& fp)
fp << int(ge_eSave_Value) << endl;
fp << int(ge_eSave_Value_attribute) << FSPACE << attribute << endl;
fp << int(ge_eSave_Value_format) << FSPACE << format << endl;
fp << int(ge_eSave_Value_instance) << FSPACE << int(instance) << endl;
fp << int(ge_eSave_Value_instance_mask) << FSPACE << int(instance_mask) << endl;
fp << int(ge_eSave_End) << endl;
}
......@@ -2491,6 +2520,7 @@ void GeValue::open( ifstream& fp)
int type;
int end_found = 0;
char dummy[40];
int tmp;
for (;;)
{
......@@ -2505,6 +2535,8 @@ void GeValue::open( ifstream& fp)
fp.get();
fp.getline( format, sizeof(format));
break;
case ge_eSave_Value_instance: fp >> tmp; instance = (ge_mInstance)tmp; break;
case ge_eSave_Value_instance_mask: fp >> tmp; instance_mask = (ge_mInstance)tmp; break;
case ge_eSave_End: end_found = 1; break;
default:
cout << "GeValue:open syntax error" << endl;
......@@ -2620,7 +2652,11 @@ int GeValue::scan( grow_tObject object)
len = strlen(buf);
}
}
grow_SetAnnotationBrief( object, 1, buf, len);
int annot_num = GeDyn::instance_to_number( instance);
if ( annot_num == 1)
grow_SetAnnotationBrief( object, annot_num, buf, len);
else
grow_SetAnnotation( object, annot_num, buf, len);
memcpy( &old_value, p, MIN(size, (int) sizeof(old_value)));
return 1;
}
......@@ -3207,23 +3243,67 @@ int GeAnalogColor::scan( grow_tObject object)
bool set_color = false;
bool reset_color = false;
if ( limit_type == ge_eLimitType_Gt) {
switch ( limit_type) {
case ge_eLimitType_Gt: {
switch ( type) {
case pwr_eType_Float32:
state = *p > limit;
break;
case pwr_eType_Int32:
state = *(pwr_tInt32 *)p > limit;
break;
default: ;
}
break;
}
else {
case ge_eLimitType_Ge: {
switch ( type) {
case pwr_eType_Float32:
state = *p >= (limit - FLT_EPSILON);
break;
case pwr_eType_Int32:
state = *(pwr_tInt32 *)p >= limit;
break;
default: ;
}
break;
}
case ge_eLimitType_Lt: {
switch ( type) {
case pwr_eType_Float32:
state = *p < limit;
break;
case pwr_eType_Int32:
state = *(pwr_tInt32 *)p < limit;
break;
default: ;
}
break;
}
case ge_eLimitType_Le: {
switch ( type) {
case pwr_eType_Float32:
state = *p <= (limit + FLT_EPSILON);
break;
case pwr_eType_Int32:
state = *(pwr_tInt32 *)p <= limit;
break;
default: ;
}
break;
}
case ge_eLimitType_Eq: {
switch ( type) {
case pwr_eType_Float32:
state = fabs(*p - limit) < FLT_EPSILON;
break;
case pwr_eType_Int32:
state = *(pwr_tInt32 *)p == limit;
break;
default: ;
}
break;
}
}
if ( state != old_state || dyn->reset_color || first_scan) {
......@@ -3508,6 +3588,11 @@ void GeMove::get_attributes( attr_sItem *attrinfo, int *item_count)
attrinfo[i].type = glow_eType_Double;
attrinfo[i++].size = sizeof( scale_factor);
strcpy( attrinfo[i].name, "Move.ScaleType");
attrinfo[i].value = &scale_type;
attrinfo[i].type = ge_eAttrType_ScaleType;
attrinfo[i++].size = sizeof( scale_type);
*item_count = i;
}
......@@ -3550,6 +3635,7 @@ void GeMove::save( ofstream& fp)
fp << int(ge_eSave_Move_y_offset) << FSPACE << y_offset << endl;
fp << int(ge_eSave_Move_factor) << FSPACE << factor << endl;
fp << int(ge_eSave_Move_scale_factor) << FSPACE << scale_factor << endl;
fp << int(ge_eSave_Move_scale_type) << FSPACE << scale_type << endl;
fp << int(ge_eSave_End) << endl;
}
......@@ -3558,6 +3644,7 @@ void GeMove::open( ifstream& fp)
int type;
int end_found = 0;
char dummy[40];
int tmp;
for (;;)
{
......@@ -3584,6 +3671,7 @@ void GeMove::open( ifstream& fp)
case ge_eSave_Move_y_offset: fp >> y_offset; break;
case ge_eSave_Move_factor: fp >> factor; break;
case ge_eSave_Move_scale_factor: fp >> scale_factor; break;
case ge_eSave_Move_scale_type: fp >> tmp; scale_type = (glow_eScaleType)tmp; break;
case ge_eSave_End: end_found = 1; break;
default:
cout << "GeMove:open syntax error" << endl;
......@@ -3653,6 +3741,8 @@ int GeMove::connect( grow_tObject object, glow_sTraceData *trace_data)
first_scan = true;
grow_StoreTransform( object);
grow_MeasureNode( object, &x_orig, &y_orig, &ur_x, &ur_y);
width_orig = ur_x - x_orig;
height_orig = ur_y - y_orig;
return 1;
}
......@@ -3720,7 +3810,7 @@ int GeMove::scan( grow_tObject object)
if ( !(move_x_p || move_y_p))
grow_SetObjectScale( object, scale_x, scale_y, 0, 0,
glow_eScaleType_LowerLeft);
scale_type);
if ( scale_x_p)
memcpy( &scale_x_old_value, scale_x_p, scale_x_size);
if ( scale_y_p)
......@@ -3729,24 +3819,49 @@ int GeMove::scan( grow_tObject object)
if ( move_x_p || move_y_p) {
if ( move_x_p) {
double scale_offs = 0;
// Adjust position for different scaletypes
switch ( scale_type) {
case glow_eScaleType_LowerRight:
case glow_eScaleType_UpperRight:
scale_offs = width_orig * ( 1 - scale_x);
break;
case glow_eScaleType_Center:
scale_offs = width_orig * ( 1 - scale_x) / 2;
break;
default: ;
}
switch ( move_x_type) {
case pwr_eType_Float32: move_x = x_orig + (*move_x_p - x_offset) * factor; break;
case pwr_eType_Float64: move_x = x_orig + (*(pwr_tFloat64 *) move_x_p - x_offset) * factor; break;
case pwr_eType_Int32: move_x = x_orig + (*(pwr_tInt32 *) move_x_p - x_offset) * factor; break;
case pwr_eType_UInt32: move_x = x_orig + (*(pwr_tUInt32 *) move_x_p - x_offset) * factor; break;
default: move_x = x_orig;
case pwr_eType_Float32: move_x = x_orig + scale_offs + (*move_x_p - x_offset) * factor; break;
case pwr_eType_Float64: move_x = x_orig + scale_offs + (*(pwr_tFloat64 *) move_x_p - x_offset) * factor; break;
case pwr_eType_Int32: move_x = x_orig + scale_offs + (*(pwr_tInt32 *) move_x_p - x_offset) * factor; break;
case pwr_eType_UInt32: move_x = x_orig + scale_offs + (*(pwr_tUInt32 *) move_x_p - x_offset) * factor; break;
default: move_x = x_orig + scale_offs;
}
}
else
move_x = x_orig;
if ( move_y_p) {
double scale_offs = 0;
// Adjust position for different scaletypes
switch ( scale_type) {
case glow_eScaleType_LowerRight:
case glow_eScaleType_UpperRight:
scale_offs = height_orig * ( 1 - scale_y);
break;
case glow_eScaleType_Center:
scale_offs = height_orig * ( 1 - scale_y) / 2;
break;
default: ;
}
switch ( move_y_type) {
case pwr_eType_Float32: move_y = y_orig + (*move_y_p - y_offset) * factor; break;
case pwr_eType_Float64: move_y = y_orig + (*(pwr_tFloat64 *) move_y_p - y_offset) * factor; break;
case pwr_eType_Int32: move_y = y_orig + (*(pwr_tInt32 *) move_y_p - y_offset) * factor; break;
case pwr_eType_UInt32: move_y = y_orig + (*(pwr_tUInt32 *) move_y_p - y_offset) * factor; break;
default: move_y = y_orig;
case pwr_eType_Float32: move_y = y_orig + scale_offs + (*move_y_p - y_offset) * factor; break;
case pwr_eType_Float64: move_y = y_orig + scale_offs + (*(pwr_tFloat64 *) move_y_p - y_offset) * factor; break;
case pwr_eType_Int32: move_y = y_orig + scale_offs + (*(pwr_tInt32 *) move_y_p - y_offset) * factor; break;
case pwr_eType_UInt32: move_y = y_orig + scale_offs + (*(pwr_tUInt32 *) move_y_p - y_offset) * factor; break;
default: move_y = y_orig + scale_offs;
}
}
else
......@@ -3754,7 +3869,7 @@ int GeMove::scan( grow_tObject object)
grow_SetObjectScalePos( object, move_x, move_y,
scale_x, scale_y, 0, 0,
glow_eScaleType_LowerLeft);
scale_type);
if ( move_x_p)
memcpy( &move_x_old_value, move_x_p, move_x_size);
if ( move_y_p)
......
......@@ -45,7 +45,10 @@ extern "C" {
//! Values for a limit type.
typedef enum {
ge_eLimitType_Gt, //!< Greater then.
ge_eLimitType_Lt //!< Less then.
ge_eLimitType_Lt, //!< Less then.
ge_eLimitType_Ge, //!< Greater then or equal.
ge_eLimitType_Le, //!< Less then or equal.
ge_eLimitType_Eq //!< Equal.
} ge_eLimitType;
//! Mask for initial and first input focus.
......@@ -275,6 +278,8 @@ extern "C" {
ge_eSave_DigText_low_text = 1101,
ge_eSave_Value_attribute = 1200,
ge_eSave_Value_format = 1201,
ge_eSave_Value_instance = 1202,
ge_eSave_Value_instance_mask = 1203,
ge_eSave_ValueInput_attribute = 1300,
ge_eSave_ValueInput_format = 1301,
ge_eSave_ValueInput_min_value = 1302,
......@@ -293,6 +298,7 @@ extern "C" {
ge_eSave_Move_scale_x_attribute = 1505,
ge_eSave_Move_scale_y_attribute = 1506,
ge_eSave_Move_scale_factor = 1507,
ge_eSave_Move_scale_type = 1508,
ge_eSave_AnalogShift_attribute = 1700,
ge_eSave_DigShift_attribute = 1800,
ge_eSave_Animation_attribute = 1900,
......@@ -1020,13 +1026,14 @@ class GeValue : public GeDynElem {
int annot_typeid;
int annot_size;
GeValue( GeDyn *e_dyn) :
GeValue( GeDyn *e_dyn, ge_mInstance e_instance = ge_mInstance_1) :
GeDynElem(e_dyn, ge_mDynType_Value, (ge_mActionType) 0, ge_eDynPrio_Value),
annot_typeid(0), annot_size(0)
{ strcpy( attribute, ""); strcpy( format, "");}
{ strcpy( attribute, ""); strcpy( format, ""); instance = e_instance;}
GeValue( const GeValue& x) :
GeDynElem(x.dyn,x.dyn_type,x.action_type,x.prio)
{ strcpy( attribute, x.attribute); strcpy( format, x.format);}
{ strcpy( attribute, x.attribute); strcpy( format, x.format);
instance = x.instance; instance_mask = x.instance_mask;}
void get_attributes( attr_sItem *attrinfo, int *item_count);
int get_transtab( char **tt);
void save( ofstream& fp);
......@@ -1156,6 +1163,7 @@ class GeMove : public GeDynElem {
double y_offset;
double factor;
double scale_factor;
glow_eScaleType scale_type;
pwr_tFloat32 *move_x_p;
pwr_tSubid move_x_subid;
......@@ -1184,10 +1192,13 @@ class GeMove : public GeDynElem {
bool first_scan;
double x_orig;
double y_orig;
double width_orig;
double height_orig;
GeMove( GeDyn *e_dyn) :
GeDynElem(e_dyn, ge_mDynType_Move, (ge_mActionType) 0, ge_eDynPrio_Move),
x_offset(0), y_offset(0), factor(1), scale_factor(1)
x_offset(0), y_offset(0), factor(1), scale_factor(1),
scale_type(glow_eScaleType_LowerLeft)
{
strcpy( move_x_attribute, "");
strcpy( move_y_attribute, "");
......@@ -1196,7 +1207,8 @@ class GeMove : public GeDynElem {
}
GeMove( const GeMove& x) :
GeDynElem(x.dyn,x.dyn_type,x.action_type,x.prio), x_offset(x.x_offset),
y_offset(x.y_offset), factor(x.factor), scale_factor(x.scale_factor)
y_offset(x.y_offset), factor(x.factor), scale_factor(x.scale_factor),
scale_type(x.scale_type)
{
strcpy( move_x_attribute, x.move_x_attribute);
strcpy( move_y_attribute, x.move_y_attribute);
......
......@@ -64,7 +64,8 @@ typedef enum {
ge_eAttrType_LimitType = 1004, //!< Limit type (Gt or Lt).
ge_eAttrType_InstanceMask = 1005, //!< Instance mask.
ge_eAttrType_InputFocus = 1006, //!< Initial input focus mask.
ge_eAttrType_Dyn = 1007 //!< Dynamic data.
ge_eAttrType_Dyn = 1007, //!< Dynamic data.
ge_eAttrType_ScaleType = 1008 //!< Scale type.
} ge_eAttrType;
//! Graph mode.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment