Jamoma API  0.6.0.a19
PureData/source/j.ui/TTUiInfo.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup pdLibrary
4  *
5  * @brief A base class for j.ui info
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue
10  *
11  * @copyright © 2013, Théo de la Hogue @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #include "TTUiInfo.h"
17 
18 #define thisTTClass TTUiInfo
19 #define thisTTClassName "UiInfo"
20 #define thisTTClassTags "ui info"
21 
22 TT_MODULAR_CONSTRUCTOR,
23 mFreeze(NO),
24 mHighlight(kTTSym_none)
25 {
26  if (arguments.size() == 1)
27  if (arguments[0].type() == kTypePointer)
28  mObject = (t_ui*)(TTPtr(arguments[0]));
29 
33 
34  addMessage(Panel);
35 }
36 
37 
38 TTUiInfo::~TTUiInfo()
39 {
40  ;
41 }
42 
43 TTErr TTUiInfo::setSize(const TTValue& newValue)
44 {
45  t_rect* rect;
46 
47  rect = (t_rect*)malloc(sizeof(t_rect));
48  rect->x = 0;
49  rect->y = 0;
50  rect->width = TTUInt32(newValue[0]);
51  rect->height = TTUInt32(newValue[1]);
52 
53  object_attr_set_rect((t_object*)mObject, _sym_presentation_rect, rect);
54 
55  ui_build(mObject);
56 
57  jbox_redraw(&mObject->box);
58  free(rect);
59 
60  return kTTErrNone;
61 }
62 
64 {
65  value = TTValue(TTUInt32(mObject->box.b_presentation_rect.width));
66  value.append(TTUInt32(mObject->box.b_presentation_rect.height));
67 
68  return kTTErrNone;
69 }
70 
71 TTErr TTUiInfo::setFreeze(const TTValue& newValue)
72 {
73  long argc = 0;
74  t_atom *argv = NULL;
75  TTNodePtr modelNode;
76  TTErr err;
77  TTObject modelObject;
78 
79  mFreeze = newValue;
80 
81  // get the TTContainer object of the view patch
82  err = accessApplicationLocalDirectory->getTTNode(mObject->viewAddress, &modelNode);
83 
84  if (!err) {
85 
86  modelObject = modelNode->getObject();
87 
88  if (modelObject.valid()) {
89 
90  jamoma_ttvalue_to_Atom(mFreeze, &argc, &argv);
91 
92  // set freeze attribute to all j.remote (on 3 levels only as we don't have the // operator)
93  jamoma_container_send(modelObject, gensym("*.*:freeze"), argc, argv);
94  jamoma_container_send(modelObject, gensym("*.*/*.*:freeze"), argc, argv);
95  jamoma_container_send(modelObject, gensym("*.*/*.*/*.*:freeze"), argc, argv);
96 
97  return kTTErrNone;
98  }
99  }
100 
101  return kTTErrGeneric;
102 }
103 
104 TTErr TTUiInfo::setHighlight(const TTValue& inputValue)
105 {
106  TTSymbol newHighlight = inputValue;
107 
108  if (inputValue.size() == 0) {
109  TTLogWarning("j.ui - Missing argument when attempting to set highlight color.");
110  return kTTErrGeneric;
111  }
112 
113  // Filter repetitions
114  if (newHighlight != mHighlight) {
115 
116  if (newHighlight == TTSymbol("none")) {
117  mHighlight = newHighlight;
118  TTLogMessage("none\n");
119  }
120  else if (newHighlight == TTSymbol("red")) {
121  mHighlight = newHighlight;
122  jrgba_set(&mObject->highlightcolor, 1., 0., 0., 1.);
123  TTLogMessage("red\n");
124  }
125  else if (newHighlight == TTSymbol("orange")) {
126  mHighlight = newHighlight;
127  jrgba_set(&mObject->highlightcolor, 1., 0.5, 0., 1.);
128  TTLogMessage("orange\n");
129  }
130  else if (newHighlight == TTSymbol("yellow")) {
131  mHighlight = newHighlight;
132  jrgba_set(&mObject->highlightcolor, 1., 1., 0., 1.);
133  TTLogMessage("yellow\n");
134  }
135  else if (newHighlight == TTSymbol("chartreuseGreen")) {
136  mHighlight = newHighlight;
137  jrgba_set(&mObject->highlightcolor, 0.5, 1., 0., 1.);
138  TTLogMessage("chartreuseGreen\n");
139  }
140  else if (newHighlight == TTSymbol("green")) {
141  mHighlight = newHighlight;
142  jrgba_set(&mObject->highlightcolor, 0., 1., 0., 1.);
143  TTLogMessage("green\n");
144  }
145  else if (newHighlight == TTSymbol("springGreen")) {
146  mHighlight = newHighlight;
147  jrgba_set(&mObject->highlightcolor, 0., 1., 0.5, 1.);
148  TTLogMessage("springGreen\n");
149  }
150  else if (newHighlight == TTSymbol("cyan")) {
151  mHighlight = newHighlight;
152  jrgba_set(&mObject->highlightcolor, 0., 1., 1., 1.);
153  TTLogMessage("cyan\n");
154  }
155  else if (newHighlight == TTSymbol("azure")) {
156  mHighlight = newHighlight;
157  jrgba_set(&mObject->highlightcolor, 0., 0.5, 1., 1.);
158  TTLogMessage("azure\n");
159  }
160  else if (newHighlight == TTSymbol("blue")) {
161  mHighlight = newHighlight;
162  jrgba_set(&mObject->highlightcolor, 0., 0., 1., 1.);
163  TTLogMessage("blue\n");
164  }
165  else if (newHighlight == TTSymbol("violet")) {
166  mHighlight = newHighlight;
167  jrgba_set(&mObject->highlightcolor, 0.5, 0., 1., 1.);
168  TTLogMessage("violet\n");
169  }
170  else if (newHighlight == TTSymbol("magenta")) {
171  mHighlight = newHighlight;
172  jrgba_set(&mObject->highlightcolor, 1., 0., 1., 1.);
173  TTLogMessage("magenta\n");
174  }
175  else if (newHighlight == TTSymbol("rose")) {
176  mHighlight = newHighlight;
177  jrgba_set(&mObject->highlightcolor, 1., 0., 0.5, 1.);
178  TTLogMessage("rose\n");
179  }
180  else if (newHighlight == TTSymbol("black")) {
181  mHighlight = newHighlight;
182  jrgba_set(&mObject->highlightcolor, 0., 0., 0., 1.);
183  TTLogMessage("black\n");
184  }
185  else if (newHighlight == TTSymbol("white")) {
186  mHighlight = newHighlight;
187  jrgba_set(&mObject->highlightcolor, 1., 1., 1., 1.);
188  TTLogMessage("white\n");
189  }
190  else if (newHighlight == TTSymbol("jamoma")) {
191  mHighlight = newHighlight;
192  jrgba_set(&mObject->highlightcolor, 0.62, 0., 0.36, 1.);
193  TTLogMessage("jamoma\n");
194  }
195  else {
196  TTLogWarning("j.ui - unknown color used for highlighting.\n");
197  return kTTErrGeneric;
198  }
199 
200  // Redraw
201  jbox_redraw(&mObject->box);
202  }
203 
204  return kTTErrNone;
205 }
206 
208 {
209  t_atom a;
210 
211  if (mObject->patcher_panel) {
212 
213  // open ui panel and set title
214  atom_setsym(&a, gensym((char*)mObject->viewAddress.c_str()));
215  object_attr_setvalueof(mObject->patcher_panel, _sym_title, 1, &a);
216  object_method(mObject->patcher_panel, _sym_vis);
217  return kTTErrNone;
218  }
219 
220  return kTTErrGeneric;
221 }
A base class for j.ui info.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
Create and use Jamoma object instances.
Definition: TTObject.h:29
TTObject & getObject()
Get the object binded by this node.
Definition: TTNode.cpp:468
size_type size() const noexcept
Return the number of elements.
TTErr JAMOMA_EXPORT jamoma_container_send(TTObject &aContainer, t_symbol *relativeAddressAndAttribute, long argc, const t_atom *argv)
Send Max data to a node (e.g., a j.parameter object) using a TTContainer object.
Symbol type.
Definition: TTBase.h:282
This is a special type used by TTAttribute to indicate that a value is a TTValue and is locally maint...
Definition: TTBase.h:286
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
Definition: TTValue.h:243
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr getSize(TTValue &value)
Attribute accessor.
void JAMOMA_EXPORT jamoma_ttvalue_to_Atom(const TTValue &v, long *argc, t_atom **argv)
Make an Atom array from a TTValue.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
Boolean (1/0) or (true/false) flag.
Definition: TTBase.h:281
TTErr setSize(const TTValue &newValue)
Attribute accessor.
TTErr setHighlight(const TTValue &inputValue)
Set highlight color.
void TTFOUNDATION_EXPORT TTLogWarning(TTImmutableCString message,...)
Platform and host independent method for posting warnings.
Definition: TTBase.cpp:553
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Definition: TTBase.cpp:534
TTErr setFreeze(const TTValue &newValue)
Attribute accessor.
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
Pointer type.
Definition: TTBase.h:284
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
No Error.
Definition: TTBase.h:343
TTErr Panel()
Open the ui panel.
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
Definition: TTObject.cpp:179
#define accessApplicationLocalDirectory
Access to the local application directory.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
#define addAttributeWithGetterAndSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter and sett...
Definition: TTAttribute.h:57