Commit aa656637 authored by thomas's avatar thomas
Browse files

changed list printing

introduced real boolean attributes


git-svn-id: https://svn.grrrr.org/ext/trunk@687 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 2171c79b
......@@ -29,6 +29,7 @@ Version history:
- better FLEXT_OSAPI resolution
- ListAttributes (or the getattributes message) now lists attributes in the order they were created (first class, then object scope)
- enforcing usage of STL
- explicit boolean attributes (great for attribute editor layout!)
0.4.4:
- fixed deadly bug for Max/MSP method-to-symbol-binding proxies
......
......@@ -91,19 +91,6 @@ int flext::AtomList::Compare(const AtomList &a) const
return Count() < a.Count()?-1:1;
}
std::string flext::AtomList::Print() const
{
char buffer[256];
std::string ret;
for(int i = 0; i < Count(); ++i) {
char *b = buffer;
if(i) *(b++) = ' '; // prepend space
PrintAtom((*this)[i],b,sizeof buffer-1);
ret += buffer;
}
return ret;
}
#if FLEXT_SYS != FLEXT_SYS_JMAX
// not for jmax as long as t_symbol * == char *
......
......@@ -19,7 +19,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <stdio.h>
// \TODO take bufsz into account!
void flext::PrintAtom(const t_atom &a,char *buf,int bufsz)
bool flext::PrintAtom(const t_atom &a,char *buf,int bufsz)
{
if(IsFloat(a)) {
sprintf(buf,"%g",GetFloat(a));
......@@ -35,8 +35,25 @@ void flext::PrintAtom(const t_atom &a,char *buf,int bufsz)
}
else
ERRINTERNAL();
return true;
}
bool flext::AtomList::Print(char *buffer,int buflen) const
{
bool ok = true;
for(int i = 0; ok && i < Count(); ++i) {
if(i) { *(buffer++) = ' '; --buflen; } // prepend space
if(PrintAtom((*this)[i],buffer,buflen)) {
int len = strlen(buffer);
buffer += len,buflen -= len;
}
else
ok = false;
}
return ok;
}
bool flext::ScanAtom(t_atom &a,const char *buf)
{
// skip whitespace
......
......@@ -246,6 +246,13 @@ bool flext_base::SetAttrib(AttrItem *a,int argc,const t_atom *argv)
}
else ok = false;
break;
case a_bool:
if(argc == 1 && CanbeBool(argv[0])) {
any.bt = GetABool(argv[0]);
((methfun_1)a->fun)(this,any);
}
else ok = false;
break;
case a_LIST:
any.vt = &(la(argc,argv));
((methfun_1)a->fun)(this,any);
......@@ -283,6 +290,12 @@ bool flext_base::GetAttrib(AttrItem *a,AtomList &la) const
SetInt(la[0],any.it);
break;
}
case a_bool: {
((methfun_1)a->fun)(const_cast<flext_base *>(this),any);
la(1);
SetBool(la[0],any.bt);
break;
}
case a_symbol: {
((methfun_1)a->fun)(const_cast<flext_base *>(this),any);
la(1);
......
......@@ -120,7 +120,7 @@ void flext_base::SetAttrEditor(t_classid c)
"proc pdtk_flext_dialog {id title attrlist} {\n"
"set vid [string trimleft $id .]\n"
"set alen [expr [llength $attrlist] / 5 ]\n"
"set alen [expr [llength $attrlist] / 6 ]\n"
"toplevel $id\n"
"wm title $id $title\n"
......@@ -152,7 +152,7 @@ void flext_base::SetAttrEditor(t_classid c)
"incr row\n"
"set ix 1\n"
"foreach {an av ai asv afl} $attrlist {\n"
"foreach {an av ai atp asv afl} $attrlist {\n"
// get attribute name
"set var_attr_name [concat [concat var_name_$ix]_$vid ]\n"
"global $var_attr_name\n"
......@@ -187,13 +187,31 @@ void flext_base::SetAttrEditor(t_classid c)
"if { $afl != 0 } {\n"
// attribute is puttable
// entry field for initial value
// entry field for current value
"entry $id.val-$ix -textvariable $var_attr_val\n"
"grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n"
// entry field for initial value
"entry $id.init-$ix -textvariable $var_attr_init\n"
// choose entry field type
"switch $atp {\n"
"0 - 1 {\n" // int or float
"entry $id.init-$ix -textvariable $var_attr_init\n"
"entry $id.val-$ix -textvariable $var_attr_val\n"
"}\n"
"2 {\n" // boolean
"checkbutton $id.init-$ix -variable $var_attr_init\n"
"checkbutton $id.val-$ix -variable $var_attr_val\n"
"}\n"
"3 {\n" // symbol
"entry $id.init-$ix -textvariable $var_attr_init\n"
"entry $id.val-$ix -textvariable $var_attr_val\n"
"}\n"
"4 - 5 {\n" // list or unknown
"entry $id.init-$ix -textvariable $var_attr_init\n"
"entry $id.val-$ix -textvariable $var_attr_val\n"
"}\n"
"}\n"
"grid config $id.init-$ix -column 1 -row $row -padx 5 -sticky {ew}\n"
"grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n"
"button $id.b2i-$ix -text {<-} -height 1 -command \" flext_copyval $var_attr_init $var_attr_val \"\n"
"grid config $id.b2i-$ix -column 2 -row $row -sticky {ew}\n"
......@@ -212,7 +230,24 @@ void flext_base::SetAttrEditor(t_classid c)
// attribute is gettable only
// entry field for current value (read-only)
"entry $id.val-$ix -textvariable $var_attr_val -state disabled\n"
// choose display field type
"switch $atp {\n"
"0 - 1 {\n" // int or float
"entry $id.val-$ix -textvariable $var_attr_val -state disabled\n"
"}\n"
"2 {\n" // boolean
"checkbutton $id.val-$ix -variable $var_attr_val -state disabled\n"
"}\n"
"3 {\n" // symbol
"entry $id.val-$ix -textvariable $var_attr_val -state disabled\n"
"}\n"
"4 - 5 {\n" // list or unknown
"entry $id.val-$ix -textvariable $var_attr_val -state disabled\n"
"}\n"
"}\n"
// "entry $id.val-$ix -textvariable $var_attr_val -state disabled\n"
"grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n"
"label $id.readonly-$ix -text \"read-only\"\n"
......@@ -293,6 +328,12 @@ void flext_base::cb_GfxProperties(t_gobj *c, t_glist *)
for(int i = 0; i < cnt; ++i) {
const t_symbol *sym = GetSymbol(la[i]);
const char *bcur = b;
// get attribute
AttrItem *gattr = th->FindAttrib(sym,true);
// get puttable attribute
AttrItem *pattr = gattr?gattr->Counterpart():th->FindAttrib(sym,false);
// get flags
int sv;
......@@ -308,14 +349,25 @@ void flext_base::cb_GfxProperties(t_gobj *c, t_glist *)
sv = 1;
else
sv = 0;
initdata = a.IsInitValue()?&a.GetInitValue():NULL;
}
STD::sprintf(b,"%s {",GetString(sym)); b += strlen(b);
// get attribute type
int tp;
bool list;
switch((gattr?gattr:pattr)->argtp) {
case a_int: tp = 0; list = false; break;
case a_float: tp = 1; list = false; break;
case a_bool: tp = 2; list = false; break;
case a_symbol: tp = 3; list = true; break;
case a_list:
case a_LIST: tp = 4; list = true; break;
default:
tp = 5; list = true;
FLEXT_ASSERT(false);
}
// get attribute
AttrItem *gattr = th->FindAttrib(sym,true);
STD::sprintf(b,list?"%s {":"%s ",GetString(sym)); b += strlen(b);
AtomList lv;
if(gattr) { // gettable attribute is present
......@@ -325,10 +377,7 @@ void flext_base::cb_GfxProperties(t_gobj *c, t_glist *)
b += PrintList(b,lv.Count(),lv.Atoms());
}
STD::sprintf(b, "} {"); b += strlen(b);
// get puttable attribute
AttrItem *pattr = gattr->Counterpart();
strcpy(b, list?"} {":" "); b += strlen(b);
if(pattr) {
// if there is initialization data take this, otherwise take the current data
......@@ -337,7 +386,7 @@ void flext_base::cb_GfxProperties(t_gobj *c, t_glist *)
b += PrintList(b,lp.Count(),lp.Atoms());
}
STD::sprintf(b, "} %i %i ", sv,pattr?(pattr->BothExist()?2:1):0); b += strlen(b);
STD::sprintf(b, list?"} %i %i %i ":" %i %i %i ",tp,sv,pattr?(pattr->BothExist()?2:1):0); b += strlen(b);
}
strcpy(b, " }\n");
......
......@@ -21,13 +21,6 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "flsupport.h"
// ----- disable attribute editor for PD version < devel_0_36 or 0.37
#ifndef PD_MAJOR_VERSION
#undef FLEXT_NOATTREDIT
#define FLEXT_NOATTREDIT
#endif
class FLEXT_SHARE FLEXT_CLASSDEF(flext_obj);
typedef class FLEXT_CLASSDEF(flext_obj) flext_obj;
......
......@@ -314,7 +314,7 @@ public:
enum metharg {
a_null = 0,
a_float,a_int,
a_float,a_int,a_bool,
a_symbol,a_pointer,
a_list,a_any, // (t_symbol *) / int / t_atom *
a_LIST,a_ANY // AtomList, AtomAnything
......@@ -505,6 +505,7 @@ protected:
void AddAttrib(const char *attr,bool (*get)(flext_base *,float &),bool (*set)(flext_base *,float &)) { AddAttrib(attr,a_float,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,int &),bool (*set)(flext_base *,int &)) { AddAttrib(attr,a_int,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,bool &),bool (*set)(flext_base *,bool &)) { AddAttrib(attr,a_bool,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,const t_symbol *&),bool (*set)(flext_base *,const t_symbol *&)) { AddAttrib(attr,a_symbol,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,t_symptr &),bool (*set)(flext_base *,t_symptr &)) { AddAttrib(attr,a_symbol,(methfun)get,(methfun)set); }
void AddAttrib(const char *attr,bool (*get)(flext_base *,AtomList *&),bool (*set)(flext_base *,AtomList *&)) { AddAttrib(attr,a_LIST,(methfun)get,(methfun)set); }
......@@ -518,6 +519,7 @@ protected:
static void AddAttrib(t_classid c,const char *attr,bool (*get)(flext_base *,float &),bool (*set)(flext_base *,float &)) { AddAttrib(c,attr,a_float,(methfun)get,(methfun)set); }
static void AddAttrib(t_classid c,const char *attr,bool (*get)(flext_base *,int &),bool (*set)(flext_base *,int &)) { AddAttrib(c,attr,a_int,(methfun)get,(methfun)set); }
static void AddAttrib(t_classid c,const char *attr,bool (*get)(flext_base *,bool &),bool (*set)(flext_base *,bool &)) { AddAttrib(c,attr,a_bool,(methfun)get,(methfun)set); }
static void AddAttrib(t_classid c,const char *attr,bool (*get)(flext_base *,const t_symbol *&),bool (*set)(flext_base *,const t_symbol *&)) { AddAttrib(c,attr,a_symbol,(methfun)get,(methfun)set); }
static void AddAttrib(t_classid c,const char *attr,bool (*get)(flext_base *,t_symptr &),bool (*set)(flext_base *,t_symptr &)) { AddAttrib(c,attr,a_symbol,(methfun)get,(methfun)set); }
static void AddAttrib(t_classid c,const char *attr,bool (*get)(flext_base *,AtomList *&),bool (*set)(flext_base *,AtomList *&)) { AddAttrib(c,attr,a_LIST,(methfun)get,(methfun)set); }
......@@ -764,6 +766,7 @@ private:
union t_any {
float ft;
int it;
bool bt;
t_symbol *st;
#if FLEXT_SYS == FLEXT_SYS_PD
t_gpointer *pt;
......
......@@ -49,9 +49,13 @@ FLEXT_CALLSET_(SFUN,float)
FLEXT_CALLSET_(SFUN,int)
//! Declare a set function for a boolean attribute
#define FLEXT_CALLSET_B(FUN) \
#define FLEXT_CALLSET_B(SFUN) \
\
FLEXT_CALLSET_(SFUN,bool)
/*
static bool FLEXT_SET_PRE(FUN)(flext_base *c,int &arg) \
{ bool b = arg != 0; FLEXT_CAST<thisType *>(c)->FUN(b); return true; }
*/
//! Declare a set function for an enum attribute
#define FLEXT_CALLSET_E(SFUN,TP) \
......@@ -85,9 +89,13 @@ FLEXT_CALLGET_(GFUN,float)
FLEXT_CALLGET_(GFUN,int)
//! Declare a get function for a boolean attribute
#define FLEXT_CALLGET_B(FUN) \
#define FLEXT_CALLGET_B(GFUN) \
\
FLEXT_CALLGET_(GFUN,bool)
/*
static bool FLEXT_GET_PRE(FUN)(flext_base *c,int &arg) \
{ bool b; FLEXT_CAST<thisType *>(c)->FUN(b); arg = b?1:0; return true; }
*/
//! Declare a get function for an enum attribute
#define FLEXT_CALLGET_E(GFUN,TP) \
......
......@@ -54,8 +54,12 @@ FLEXT_ATTRSET_(VAR,const t_symbol *)
//! Declare an implicite set function for a boolean attribute
#define FLEXT_ATTRSET_B(VAR) \
\
FLEXT_ATTRSET_(VAR,bool)
/*
static bool FLEXT_SET_PRE(VAR)(flext_base *c,int &arg) \
{ FLEXT_CAST<thisType *>(c)->VAR = arg != 0; return true; }
*/
//! Declare an implicite set function for an enum attribute
#define FLEXT_ATTRSET_E(VAR,TP) \
......@@ -90,8 +94,12 @@ FLEXT_ATTRGET_(VAR,const t_symbol *)
//! Declare an implicite get function for a boolean attribute
#define FLEXT_ATTRGET_B(VAR) \
\
FLEXT_ATTRGET_(VAR,bool)
/*
static bool FLEXT_GET_PRE(VAR)(flext_base *c,int &arg) \
{ arg = FLEXT_CAST<thisType *>(c)->VAR?1:0; return true; }
*/
//! Declare an implicite get function for an enum attribute
#define FLEXT_ATTRGET_E(VAR,TP) \
......
......@@ -229,4 +229,11 @@ typedef t_symbol *t_symptr;
#define FLEXT_EXT
#endif
// ----- disable attribute editor for PD version < devel_0_36 or 0.37
#ifndef PD_MAJOR_VERSION
#undef FLEXT_NOATTREDIT
#define FLEXT_NOATTREDIT
#endif
#endif
......@@ -17,8 +17,6 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "flstdc.h"
#include <string>
class FLEXT_SHARE FLEXT_CLASSDEF(flext);
typedef class FLEXT_CLASSDEF(flext) flext;
......@@ -212,7 +210,7 @@ public:
static void CopyAtom(t_atom *dst,const t_atom *src) { *dst = *src; }
//! Print an atom
static void PrintAtom(const t_atom &a,char *buf,int bufsz = 0);
static bool PrintAtom(const t_atom &a,char *buf,int bufsz);
//! Scan an atom
static bool ScanAtom(t_atom &a,const char *buf);
......@@ -526,7 +524,7 @@ public:
AtomList &Part(int offs,int len) { return (*this = GetPart(offs,len)); }
//! Represent as a string
std::string Print() const;
bool Print(char *buffer,int buflen) const;
protected:
int cnt;
......
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