1 /************************************************************************
2
3 IMPORTANT NOTE : this file contains two clearly delimited sections :
4 the ARCHITECTURE section (in two parts) and the USER section. Each section
5 is governed by its own copyright and license. Please check individually
6 each section for license and copyright information.
7 *************************************************************************/
8
9 /*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
10
11 /************************************************************************
12 FAUST Architecture File
13 Copyright (C) 2004-2012 GRAME, Centre National de Creation Musicale
14 ---------------------------------------------------------------------
15 This Architecture section is free software; you can redistribute it
16 and/or modify it under the terms of the GNU Lesser General Public
17 License as published by the Free Software Foundation; either version 3
18 of the License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License for more details.
24
25 You should have received a copy of the GNU Lesser General Public License
26 along with this program; If not, see <http://www.gnu.org/licenses/>.
27
28 EXCEPTION : As a special exception, you may create a larger work
29 that contains this FAUST architecture section and distribute
30 that work under terms of your choice, so long as this FAUST
31 architecture section is not modified.
32
33
34 ************************************************************************
35 ************************************************************************/
36
37 #import <UIKit/UIKit.h>
38 #import "FIMainViewController.h"
39
40 #include <list>
41 #include <map>
42
43 #import "FIKnob.h"
44 #import "FISlider.h"
45 #import "FIButton.h"
46 #import "FITextField.h"
47 #import "FIBargraph.h"
48 #import "FIBox.h"
49 #import "FITabView.h"
50
51 using namespace std;
52 class CocoaUI;
53 class uiCocoaItem;
54 class uiBox;
55
56 /******************************************************************************
57 *******************************************************************************
58
59 GRAPHIC USER INTERFACE (v2)
60 abstract interfaces
61
62 *******************************************************************************
63 *******************************************************************************/
64
65
66 //=================
67 // COCOA part
68 //=================
69
70 // Widget assignation type
71 #define kAssignationNone 0
72 #define kAssignationAccelX 1
73 #define kAssignationAccelY 2
74 #define kAssignationAccelZ 3
75 #define kAssignationGyroX 4
76 #define kAssignationGyroY 5
77 #define kAssignationGyroZ 6
78
79 #define kCurve1 0
80 #define kCurve2 1
81 #define kCurve3 2
82 #define kCurve4 3
83
84 // Current layout mode
85 #define kHorizontalLayout 0
86 #define kVerticalLayout 1
87 #define kTabLayout 2
88 #define kColorLayout 3
89
90 // Global dimensions
91 #define kWidgetSlice 50.f
92 #define kOffsetY 20.f
93 #define kSpaceSize 5.f
94
95 // Responders dimensions
96 // Boxes
97 #define kStdTabHeight 40.f
98 #define kMinBoxWidth 100.f
99 #define kMinBoxHeight 100.f
100 #define kStdBoxLabelHeight 20.0
101 #define kStdBoxLabelXOffset 5.0
102
103 // Buttons
104 #define kStdButtonWidth 100.0
105 #define kStdButtonHeight 40.0
106
107 // Num entry
108 #define kStdNumEntryWidth 100.0
109 #define kStdNumEntryHeight 40.0
110 #define kStdNumEntryLabelWidth 100.0
111 #define kStdNumEntryLabelHeight 20.0
112
113 // Knob
114 #define kStdKnobWidth 100.0
115 #define kStdKnobHeight 100.0
116 #define kStdKnobArcWidth 20.0
117 #define kStdKnobLabelWidth 100.0
118 #define kStdKnobLabelHeight 20.0
119
120 // Slider
121 #define kMinHorizontalSliderWidth 170.0
122 #define kStdHorizontalSliderHeight 40.0
123 #define kStdVerticalSliderWidth 40.0
124 #define kMinVerticalSliderHeight 170.0
125 #define kStdSliderLabelWidth 60.0
126 #define kStdSliderLabelHeight 20.0
127
128 // Bargraph
129 #define kMinHorizontalBargraphWidth 170.0
130 #define kStdHorizontalBargraphHeight 30.0
131 #define kStdVerticalBargraphWidth 30.0
132 #define kMinVerticalBargraphHeight 170.0
133 #define kStdLedWidth 270.0
134 #define kStdLedHeight 270.0
135 #define kStdBargraphLabelWidth 60.0
136 #define kStdBargraphLabelHeight 20.0
137
138 // Routines
139 CGPoint inBoxPosition2absolutePosition(float x, float y, uiCocoaItem* box);
140 CGPoint absolutePosition(uiCocoaItem* widget);
141
142 // All Cocoa widget classes inheritate from uiCocoaItem, which inheritate from Faust uiItem
143 class uiCocoaItem : public uiItem
144 {
145
146 protected:
147
148 static int gItemCount;
149 int fItemCount;
150
151 NSString* fName;
152 BOOL fHidden;
153 uiCocoaItem* fParent;
154
155 float fx;
156 float fy;
157 float fw;
158 float fh;
159 float fAbstractX;
160 float fAbstractY;
161 float fAbstractW;
162 float fAbstractH;
163 BOOL fSelected;
164
165 int fInitAssignationType;
166 int fInitAssignationCurve;
167
168 float fInitR;
169 float fInitG;
170 float fInitB;
171
172 float fInitMinCurve;
173 float fInitMidCurve;
174 float fInitMaxCurve;
175
176 int fAssignationType;
177 int fAssignationCurve;
178
179 float fMinCurve;
180 float fMidCurve;
181 float fMaxCurve;
182
183 float fR;
184 float fG;
185 float fB;
186 BOOL fHideOnGUI;
187
188 public:
189
190 UILabel* fLabel;
191 float fInit;
192
193 // Default widget parameter
resetParameters()194 void resetParameters()
195 {
196 fAssignationType = fInitAssignationType;
197 fAssignationCurve = fInitAssignationCurve;
198
199 fR = fInitR;
200 fG = fInitG;
201 fB = fInitB;
202
203 fMinCurve = fInitMinCurve;
204 fMidCurve = fInitMidCurve;
205 fMaxCurve = fInitMaxCurve;
206 }
207
208 // Constructor / Destuctor
209 uiCocoaItem(GUI* ui, float* zone, FIMainViewController* controller, const char* name);
210
~uiCocoaItem()211 ~uiCocoaItem()
212 {
213 [fName release];
214 }
215
216 // Getters, setters
getItemCount()217 int getItemCount() {return fItemCount;}
218
getName()219 NSString* getName() {return fName;}
220
221 virtual void resetInitialValue() = 0;
222
223 virtual void setHidden(BOOL hidden) = 0;
isHidden()224 BOOL isHidden() {return fHidden;}
225 virtual BOOL isHExpandable() = 0;
226 virtual BOOL isVExpandable() = 0;
227
228 virtual void enableLongPressGestureRecognizer(BOOL enable) = 0;
229
getX()230 float getX() {return fx;}
getY()231 float getY() {return fy;}
getW()232 float getW() {return fw;}
getH()233 float getH() {return fh;}
setFrame(float x,float y,float w,float h)234 virtual void setFrame(float x, float y, float w, float h) {fx = x; fy = y; fw = w; fh = h;}
235
getAbstractX()236 float getAbstractX() {return fAbstractX;}
getAbstractY()237 float getAbstractY() {return fAbstractY;}
getAbstractW()238 float getAbstractW() {if (fHideOnGUI) return 0; else return fAbstractW;}
getAbstractH()239 float getAbstractH() {if (fHideOnGUI) return 0; else return fAbstractH;}
setAbstractFrame(float x,float y,float w,float h)240 void setAbstractFrame(float x, float y, float w, float h) {fAbstractX = x; fAbstractY = y; fAbstractW = w; fAbstractH = h;}
241
setParent(uiCocoaItem * parent)242 void setParent(uiCocoaItem* parent) {fParent = parent;}
243
getParent()244 uiCocoaItem* getParent() {return fParent;}
245
isSelected()246 BOOL isSelected() {return fSelected;}
setSelected(BOOL selected)247 virtual void setSelected(BOOL selected) {fSelected = selected;}
248
getInitAssignationType()249 int getInitAssignationType() {return fInitAssignationType;}
setInitAssignationType(int assignationType)250 void setInitAssignationType(int assignationType) {fInitAssignationType = assignationType; setAssignationType(assignationType);}
251
getAssignationType()252 int getAssignationType() {return fAssignationType;}
setAssignationType(int assignationType)253 virtual void setAssignationType(int assignationType) {fAssignationType = assignationType;}
254
getInitAssignationCurve()255 int getInitAssignationCurve() {return fInitAssignationCurve;}
setInitAssignationCurve(int assignationCurve)256 void setInitAssignationCurve(int assignationCurve) {fInitAssignationCurve = assignationCurve; setAssignationCurve(assignationCurve);}
257
getAssignationCurve()258 int getAssignationCurve() {return fAssignationCurve;}
setAssignationCurve(int assignationCurve)259 virtual void setAssignationCurve(int assignationCurve) {fAssignationCurve = assignationCurve;}
260
getCurveMin()261 float getCurveMin() {return fMinCurve;}
setCurveMin(float minCurve)262 virtual void setCurveMin(float minCurve) {fMinCurve = minCurve;}
263
getCurveMid()264 float getCurveMid() {return fMidCurve;}
setCurveMid(float midCurve)265 virtual void setCurveMid(float midCurve) {fMidCurve = midCurve;}
266
getCurveMax()267 float getCurveMax() {return fMaxCurve;}
setCurveMax(float maxCurve)268 virtual void setCurveMax(float maxCurve) {fMaxCurve = maxCurve;}
269
getInitCurveMin()270 float getInitCurveMin() {return fInitMinCurve;}
getInitCurveMid()271 float getInitCurveMid() {return fInitMidCurve;}
getInitCurveMax()272 float getInitCurveMax() {return fInitMaxCurve;}
273
setCurve(float min,float mid,float max)274 virtual void setCurve(float min, float mid, float max)
275 {
276 fMinCurve = min; fMidCurve = mid; fMaxCurve = max;
277 }
278
setInitCurve(float min,float mid,float max)279 virtual void setInitCurve(float min, float mid, float max)
280 {
281 fInitMinCurve = min; fInitMidCurve = mid; fInitMaxCurve = max;
282 }
283
getInitR()284 float getInitR() {return fInitR;}
getInitG()285 float getInitG() {return fInitG;}
getInitB()286 float getInitB() {return fInitB;}
setInitColor(float r,float g,float b)287 virtual void setInitColor(float r, float g, float b) {fInitR = r; fInitG = g; fInitB = b; setColor(r, g, b);}
288
getR()289 float getR() {return fR;}
getG()290 float getG() {return fG;}
getB()291 float getB() {return fB;}
setColor(float r,float g,float b)292 virtual void setColor(float r, float g, float b) {fR = r; fG = g; fB = b;}
293
setHideOnGUI(BOOL hideOnGUI)294 void setHideOnGUI(BOOL hideOnGUI) {fHideOnGUI = hideOnGUI; if (fLabel) fLabel.hidden = hideOnGUI;}
getHideOnGUI()295 BOOL getHideOnGUI() {return fHideOnGUI;}
296 };
297
298
299 // --------------------------- Box ---------------------------
300
301 class uiBox : public uiCocoaItem
302 {
303
304 public:
305
306 FIBox* fBox;
307 FITabView* fTabView;
308 list <uiCocoaItem*> fWidgetList; // if kTabLayout : boxes containing each tab elements ; else : elements within box
309 BOOL fClosed;
310 int fBoxType;
311 float fLastX;
312 float fLastY;
313 static float gDummy;
314
uiBox(GUI * ui,FIMainViewController * controller,const char * name,int boxType)315 uiBox(GUI* ui, FIMainViewController* controller, const char* name, int boxType)
316 : uiCocoaItem(ui, &gDummy, controller, name)
317 {
318 float tabOffset = 0;
319 fBoxType = boxType;
320 fLastX = 0.f;
321 fLastY = 0.f;
322 fTabView = nil;
323 fLabel = nil;
324
325 if (boxType == kTabLayout)
326 {
327 fTabView = [[[FITabView alloc] initWithDelegate:controller] autorelease];
328 fTabView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
329 fTabView.labelColor = [UIColor blueColor];
330 fTabView.backgroundColorAlpha = 0.4;
331 fTabView.value = 0.f;
332 fTabView.autoresizingMask = UIViewAutoresizingNone;
333 [controller.dspView addSubview:fTabView];
334 tabOffset = kStdTabHeight;
335 }
336
337 fClosed = FALSE;
338 fBox = [[[FIBox alloc] init] autorelease];
339 fBox.color = [UIColor darkGrayColor];
340 fBox.autoresizingMask = UIViewAutoresizingNone;
341
342 [controller.dspView addSubview:fBox];
343
344 if (boxType == kColorLayout) {
345 fBox.backgroundColor = [UIColor whiteColor];
346 }
347
348 if (boxType != kTabLayout)
349 {
350 fLabel = [[[UILabel alloc] init] autorelease];
351 fLabel.font = [UIFont boldSystemFontOfSize:18];
352 fLabel.textAlignment = NSTextAlignmentLeft;
353 fLabel.autoresizingMask = UIViewAutoresizingNone;
354 fLabel.text = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
355 fLabel.textColor = [UIColor colorWithWhite:1. alpha:1.];
356 fLabel.backgroundColor = [UIColor clearColor];
357 [controller.dspView addSubview:fLabel];
358
359 fLastY = kStdBoxLabelHeight;
360 }
361 }
362
~uiBox()363 ~uiBox()
364 {
365 if (fLabel) [fLabel release];
366 if (fTabView) [fTabView release];
367 [fBox release];
368 }
369
resetInitialValue()370 void resetInitialValue()
371 {
372 }
373
isHExpandable()374 BOOL isHExpandable()
375 {
376 return TRUE;
377 }
378
isVExpandable()379 BOOL isVExpandable()
380 {
381 return FALSE;
382 }
383
enableLongPressGestureRecognizer(BOOL enable)384 void enableLongPressGestureRecognizer(BOOL enable)
385 {
386 // Do nothing
387 }
388
getNumberOfDirectChildren()389 int getNumberOfDirectChildren()
390 {
391 list<uiCocoaItem*>::iterator i;
392 int cpt = 0;
393
394 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
395 {
396 if ((*i)->getParent() == this)
397 {
398 cpt++;
399 }
400 }
401
402 return cpt;
403 }
404
setColor(int color)405 void setColor(int color)
406 {
407 CGFloat red = CGFloat(255 & (color >> 16))/255.;
408 CGFloat green = CGFloat(255 & (color >> 8))/255.;
409 CGFloat blue = CGFloat(255 & (color >> 0))/255.;
410 fBox.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.f];
411 }
412
setFrame(float x,float y,float w,float h)413 void setFrame(float x, float y, float w, float h)
414 {
415 CGPoint pt = inBoxPosition2absolutePosition(x, y, fParent);
416 list<uiCocoaItem*>::iterator i;
417 float labelYOffset = 0.f;
418
419 if (fBoxType == kColorLayout) {
420 // Hack to force full screen layout even in 'portrait' only mode
421 w = h = std::max(w, h);
422 } else {
423 uiCocoaItem::setFrame(x, y, w, h);
424 }
425
426 // For tab views : simply resize the tab corresponding box
427 if (fTabView)
428 {
429 fTabView.frame = CGRectMake(pt.x, pt.y, w, kStdTabHeight);
430 fBox.frame = CGRectMake(pt.x, pt.y + kStdTabHeight, w, h - kStdTabHeight);
431
432 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
433 {
434 if ((*i)->getW() != w || (*i)->getW() != h - kStdTabHeight)
435 {
436 (*i)->setFrame((*i)->getX(), (*i)->getY(), w, h - kStdTabHeight);
437 }
438 }
439 }
440
441 // For vertical and horizontal boxes
442 else
443 {
444 fBox.frame = CGRectMake(pt.x, pt.y, w, h);
445 if (fLabel)
446 {
447 labelYOffset = kStdBoxLabelHeight;
448 fLabel.frame = CGRectMake(pt.x + kStdBoxLabelXOffset, pt.y, w - kStdBoxLabelXOffset, labelYOffset);
449 }
450
451 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
452 {
453 if (fBoxType == kVerticalLayout
454 && (*i)->getW() < w - 2 * kSpaceSize
455 && (*i)->getParent() == this)
456 {
457 (*i)->setFrame((*i)->getX(), (*i)->getY(), w - 2 * kSpaceSize, (*i)->getH());
458 }
459 else if (fBoxType == kHorizontalLayout
460 && (*i)->getH() < h - 2 * kSpaceSize - labelYOffset
461 && (*i)->getParent() == this)
462 {
463 (*i)->setFrame((*i)->getX(), (*i)->getY(), (*i)->getW(), h - 2 * kSpaceSize - labelYOffset);
464 }
465 }
466 }
467 }
468
469 // Returns minimum size used by widgets within the box
getContentSize()470 CGSize getContentSize()
471 {
472 list<uiCocoaItem*>::iterator i;
473 float maxW = 0.f;
474 float maxH = 0.f;
475
476 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
477 {
478 if ((*i)->getParent() == this)
479 {
480 maxW = max((*i)->getX() + (*i)->getW(), maxW);
481 maxH = max((*i)->getY() + (*i)->getH(), maxH);
482 }
483 }
484
485 return CGSizeMake(maxW, maxH);
486 }
487
setHidden(BOOL hidden)488 void setHidden(BOOL hidden)
489 {
490 fHidden = hidden;
491 fBox.hidden = hidden || getHideOnGUI();
492 if (fLabel) fLabel.hidden = hidden || getHideOnGUI();
493
494 list<uiCocoaItem*>::iterator i;
495 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
496 {
497 (*i)->setHidden(hidden);
498 }
499
500 [fBox setNeedsDisplay];
501 if (fTabView)
502 {
503 fTabView.hidden = hidden || getHideOnGUI();
504 [fTabView setNeedsDisplay];
505 }
506 }
507
close(int index)508 void close(int index)
509 {
510 fClosed = TRUE;
511 }
512
reflectZone()513 void reflectZone()
514 {
515 [fBox setNeedsDisplay];
516
517 if (fTabView)
518 {
519 list<uiCocoaItem*>::iterator i;
520 int index = 0;
521
522 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
523 {
524 if (fTabView.value != index)
525 {
526 (*i)->setHidden(true);
527 }
528 else
529 {
530 (*i)->setHidden(false);
531 }
532 ++index;
533 }
534 [fTabView setNeedsDisplay];
535 }
536 }
537 };
538
539 // Constructor / Destuctor
uiCocoaItem(GUI * ui,float * zone,FIMainViewController * controller,const char * name)540 uiCocoaItem::uiCocoaItem(GUI* ui, float* zone, FIMainViewController* controller, const char* name)
541 : uiItem(ui, zone)
542 {
543 fName = [[NSString alloc] initWithString:[NSString stringWithCString:name encoding:NSASCIIStringEncoding]];
544 fLabel = nil;
545 fHidden = false;
546 fParent = NULL;
547
548 fx = 0.f;
549 fy = 0.f;
550 fw = 0.f;
551 fh = 0.f;
552
553 fAbstractX = 0.f;
554 fAbstractY = 0.f;
555 fAbstractW = 0.f;
556 fAbstractH = 0.f;
557
558 fSelected = false;
559
560 fInitAssignationType = kAssignationNone;
561 fInitAssignationCurve = kAssignationNone;
562
563 fInitR = 0.f;
564 fInitG = 0.f;
565 fInitB = 1.f;
566
567 fInitMinCurve = -100.f;
568 fInitMidCurve = 0.f;
569 fInitMaxCurve = 100.f;
570
571 fHideOnGUI = false;
572 fInit = 0.f;
573 if (zone != &uiBox::gDummy) {
574 fItemCount = gItemCount++;
575 } else {
576 fItemCount = -1;
577 }
578
579 resetParameters();
580 }
581
582 // -------------------------- Knob -----------------------------------
583
584 class uiKnob : public uiCocoaItem
585 {
586
587 public :
588
589 FIKnob* fKnob;
590 UILongPressGestureRecognizer* fLongPressGesture;
591
uiKnob(GUI * ui,FIMainViewController * controller,const char * name,float * zone,float init,float min,float max,float step,BOOL horizontal)592 uiKnob(GUI* ui, FIMainViewController* controller, const char* name, float* zone, float init, float min, float max, float step, BOOL horizontal)
593 : uiCocoaItem(ui, zone, controller, name)
594 {
595 fLabel = [[[UILabel alloc] init] autorelease];
596 fLabel.font = [UIFont boldSystemFontOfSize:12];
597 fLabel.textAlignment = NSTextAlignmentCenter;
598 fLabel.text = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
599 fLabel.textColor = [UIColor whiteColor];
600 fLabel.backgroundColor = [UIColor clearColor];
601 [controller.dspView addSubview:fLabel];
602
603 fKnob = [[[FIKnob alloc] initWithDelegate:controller] autorelease];
604 fKnob.autoresizingMask = UIViewAutoresizingNone;
605 fKnob.labelFont = [UIFont boldSystemFontOfSize:14.0];
606 fKnob.labelColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
607 fKnob.color = [UIColor colorWithRed:fR green:fG blue:fB alpha:1.f];
608 fKnob.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
609 fKnob.min = min;
610 fKnob.max = max;
611 fKnob.step = step;
612 fInit = init;
613 fKnob.value = init;
614 fKnob.valueArcWidth = kStdKnobArcWidth;
615 fKnob.backgroundColorAlpha = 0.4;
616 [controller.dspView addSubview:fKnob];
617
618 fLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:controller action:@selector(showWidgetPreferencesView:)];
619 fLongPressGesture.delegate = controller;
620 [fKnob addGestureRecognizer:fLongPressGesture];
621 }
622
~uiKnob()623 ~uiKnob()
624 {
625 [fLabel release];
626 [fKnob release];
627 [fLongPressGesture release];
628 }
629
resetInitialValue()630 void resetInitialValue()
631 {
632 fKnob.value = fInit;
633 }
634
isHExpandable()635 BOOL isHExpandable()
636 {
637 return FALSE;
638 }
639
isVExpandable()640 BOOL isVExpandable()
641 {
642 return FALSE;
643 }
644
enableLongPressGestureRecognizer(BOOL enable)645 void enableLongPressGestureRecognizer(BOOL enable)
646 {
647 if (enable)
648 {
649 [fKnob addGestureRecognizer:fLongPressGesture];
650 }
651 else
652 {
653 [fKnob removeGestureRecognizer:fLongPressGesture];
654 }
655 }
656
setFrame(float x,float y,float w,float h)657 void setFrame(float x, float y, float w, float h)
658 {
659 CGPoint pt = inBoxPosition2absolutePosition(x, y, fParent);
660
661 uiCocoaItem::setFrame(x, y, w, h);
662
663 fKnob.frame = CGRectMake(pt.x + (w - kStdKnobWidth) / 2.f,
664 pt.y + (h - kStdKnobHeight - kSpaceSize - kStdKnobLabelHeight) / 2.f,
665 kStdKnobWidth,
666 kStdKnobHeight);
667
668 fLabel.frame = CGRectMake(pt.x + (w - kStdKnobLabelWidth) / 2.f,
669 pt.y + (h + kStdKnobHeight - kSpaceSize - kStdKnobLabelHeight) / 2.f + kSpaceSize,
670 kStdKnobLabelWidth,
671 kStdKnobLabelHeight);
672 }
673
setHidden(BOOL hidden)674 void setHidden(BOOL hidden)
675 {
676 fHidden = hidden;
677 fLabel.hidden = hidden || getHideOnGUI();
678 fKnob.hidden = hidden || getHideOnGUI();
679 }
680
setSelected(BOOL selected)681 void setSelected(BOOL selected)
682 {
683 uiCocoaItem::setSelected(selected);
684 fKnob.responderSelected = selected;
685 [fKnob setNeedsDisplay];
686 }
687
setColor(float r,float g,float b)688 void setColor(float r, float g, float b)
689 {
690 uiCocoaItem::setColor(r, g, b);
691
692 fKnob.color = [UIColor colorWithRed:fR green:fG blue:fB alpha:1.f];
693 [fKnob setNeedsDisplay];
694 }
695
setAssignationType(int assignationType)696 void setAssignationType(int assignationType)
697 {
698 uiCocoaItem::setAssignationType(assignationType);
699 if (assignationType != kAssignationNone)
700 {
701 fKnob.assignated = true;
702 }
703 else
704 {
705 fKnob.assignated = false;
706 }
707 [fKnob setNeedsDisplay];
708 }
709
reflectZone()710 void reflectZone()
711 {
712 float v = *fZone;
713 fCache = v;
714 fKnob.value = v;
715 }
716 };
717
718 // -------------------------- Slider -----------------------------------
719
720 class uiSlider : public uiCocoaItem
721 {
722
723 public :
724
725 FISlider* fSlider;
726 BOOL fHorizontal;
727 UILongPressGestureRecognizer* fLongPressGesture;
728
729 uiSlider(GUI* ui, FIMainViewController* controller, const char* name, float* zone, float init, float min, float max, float step, BOOL horizontal, const char* menu = NULL)
uiCocoaItem(ui,zone,controller,name)730 : uiCocoaItem(ui, zone, controller, name)
731 {
732 fLabel = [[[UILabel alloc] init] autorelease];
733 fLabel.font = [UIFont boldSystemFontOfSize:12];
734 if (horizontal) fLabel.textAlignment = NSTextAlignmentRight;
735 else fLabel.textAlignment = NSTextAlignmentCenter;
736 fLabel.text = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
737 fLabel.textColor = [UIColor whiteColor];
738 fLabel.backgroundColor = [UIColor clearColor];
739 [controller.dspView addSubview:fLabel];
740
741 fSlider = [[[FISlider alloc] initWithDelegate:controller] autorelease];
742 fSlider.isHorizontalSlider = horizontal;
743 fHorizontal = horizontal;
744 fSlider.autoresizingMask = UIViewAutoresizingNone;
745 fSlider.labelFont = [UIFont boldSystemFontOfSize:14.0];
746 fSlider.labelColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
747 fSlider.color = [UIColor colorWithRed:fR green:fG blue:fB alpha:1.f];
748 fSlider.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
749 fSlider.min = min;
750 fSlider.max = max;
751 fInit = init;
752 fSlider.value = init;
753 fSlider.backgroundColorAlpha = 0.4;
754 fSlider.handleSize = 50;
755 fSlider.step = step;
756 [controller.dspView addSubview:fSlider];
757 fLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:controller action:@selector(showWidgetPreferencesView:)];
758 fLongPressGesture.delegate = controller;
759 [fSlider addGestureRecognizer:fLongPressGesture];
760
761 // Menu
762 if (menu) {
763 const char* p = menu;
764 vector<string> names;
765 vector<double> values;
766 parseMenuList(p, names, values);
767 fSlider.fMenuItemNames = names;
768 fSlider.fMenuItemValues = values;
769 }
770 }
771
~uiSlider()772 ~uiSlider()
773 {
774 [fLabel release];
775 [fSlider release];
776 [fLongPressGesture release];
777 }
778
resetInitialValue()779 void resetInitialValue()
780 {
781 fSlider.value = fInit;
782 }
783
isHExpandable()784 BOOL isHExpandable()
785 {
786 if (fHorizontal)
787 {
788 return TRUE;
789 }
790 return FALSE;
791 }
792
isVExpandable()793 BOOL isVExpandable()
794 {
795 if (fHorizontal)
796 {
797 return FALSE;
798 }
799 return TRUE;
800 }
801
enableLongPressGestureRecognizer(BOOL enable)802 void enableLongPressGestureRecognizer(BOOL enable)
803 {
804 if (enable)
805 {
806 [fSlider addGestureRecognizer:fLongPressGesture];
807 }
808 else
809 {
810 [fSlider removeGestureRecognizer:fLongPressGesture];
811 }
812 }
813
setFrame(float x,float y,float w,float h)814 void setFrame(float x, float y, float w, float h)
815 {
816 CGPoint pt = inBoxPosition2absolutePosition(x, y, fParent);
817
818 uiCocoaItem::setFrame(x, y, w, h);
819
820 if (fHorizontal)
821 {
822 fLabel.frame = CGRectMake( pt.x,
823 pt.y + (h - kStdSliderLabelHeight) / 2.f,
824 kStdSliderLabelWidth,
825 kStdSliderLabelHeight);
826
827 fSlider.frame = CGRectMake( pt.x + kStdSliderLabelWidth + kSpaceSize,
828 pt.y + (h - kStdHorizontalSliderHeight) / 2.f,
829 w - kStdSliderLabelWidth - kSpaceSize,
830 kStdHorizontalSliderHeight);
831 }
832 else
833 {
834 fSlider.frame = CGRectMake( pt.x + (w - kStdVerticalSliderWidth) / 2.f,
835 pt.y,
836 kStdVerticalSliderWidth,
837 h - kSpaceSize - kStdSliderLabelHeight);
838
839 fLabel.frame = CGRectMake( pt.x + (w - kStdSliderLabelWidth) / 2.f,
840 pt.y + h - kSpaceSize - kStdSliderLabelHeight,
841 kStdSliderLabelWidth,
842 kStdSliderLabelHeight);
843 }
844 }
845
setHidden(BOOL hidden)846 void setHidden(BOOL hidden)
847 {
848 fHidden = hidden;
849 fLabel.hidden = hidden || getHideOnGUI();
850 fSlider.hidden = hidden || getHideOnGUI();
851 }
852
setColor(float r,float g,float b)853 void setColor(float r, float g, float b)
854 {
855 uiCocoaItem::setColor(r, g, b);
856
857 fSlider.color = [UIColor colorWithRed:fR green:fG blue:fB alpha:1.f];
858 [fSlider setNeedsDisplay];
859 }
860
setAssignationType(int assignationType)861 void setAssignationType(int assignationType)
862 {
863 uiCocoaItem::setAssignationType(assignationType);
864 if (assignationType != kAssignationNone)
865 {
866 fSlider.assignated = true;
867 }
868 else
869 {
870 fSlider.assignated = false;
871 }
872 [fSlider setNeedsDisplay];
873 }
874
setSelected(BOOL selected)875 void setSelected(BOOL selected)
876 {
877 uiCocoaItem::setSelected(selected);
878 fSlider.responderSelected = selected;
879 [fSlider setNeedsDisplay];
880 }
881
reflectZone()882 void reflectZone()
883 {
884 float v = *fZone;
885 fCache = v;
886 fSlider.value = v;
887 }
888 };
889
890 // --------------------------- Press button ---------------------------
891
892 class uiButton : public uiCocoaItem
893 {
894
895 public:
896
897 FIButton* fButton;
898 float fValue; // Specific value to be triggered by the button
899 //UILongPressGestureRecognizer* fLongPressGesture;
900
901 uiButton(GUI* ui, FIMainViewController* controller, const char* name, float* zone, int type, float value = FLT_MAX)
uiCocoaItem(ui,zone,controller,name)902 : uiCocoaItem(ui, zone, controller, name)
903 {
904 fButton = [[[FIButton alloc] initWithDelegate:controller] autorelease];
905 fButton.autoresizingMask = UIViewAutoresizingNone;
906 fButton.title = [[NSString alloc] initWithCString:name encoding:NSASCIIStringEncoding];
907 fButton.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
908 fButton.labelColor = [UIColor whiteColor];
909 fButton.backgroundColorAlpha = 0.4;
910 fButton.type = type;
911 fButton.color = [UIColor colorWithRed:fR green:fG blue:fB alpha:1.f];
912 [controller.dspView addSubview:fButton];
913
914 fValue = value;
915
916 //fLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:controller action:@selector(showWidgetPreferencesView:)];
917 //fLongPressGesture.delegate = controller;
918 //[fButton addGestureRecognizer:fLongPressGesture];
919 }
920
~uiButton()921 ~uiButton()
922 {
923 [fButton release];
924 //[fLongPressGesture release];
925 }
926
resetInitialValue()927 void resetInitialValue()
928 {}
929
setOn()930 void setOn()
931 {
932 [fButton setOn];
933 }
934
isHExpandable()935 BOOL isHExpandable()
936 {
937 return TRUE;
938 }
939
isVExpandable()940 BOOL isVExpandable()
941 {
942 return FALSE;
943 }
944
enableLongPressGestureRecognizer(BOOL enable)945 void enableLongPressGestureRecognizer(BOOL enable)
946 {
947 /*if (enable)
948 {
949 [fButton addGestureRecognizer:fLongPressGesture];
950 }
951 else
952 {
953 [fButton removeGestureRecognizer:fLongPressGesture];
954 }*/
955 }
956
setFrame(float x,float y,float w,float h)957 void setFrame(float x, float y, float w, float h)
958 {
959 CGPoint pt = inBoxPosition2absolutePosition(x, y, fParent);
960
961 uiCocoaItem::setFrame(x, y, w, h);
962
963 fButton.frame = CGRectMake(pt.x + (w - kStdButtonWidth) / 2.f,
964 pt.y + (h - kStdButtonHeight) / 2.f,
965 kStdButtonWidth,
966 kStdButtonHeight);
967 }
968
setHidden(BOOL hidden)969 void setHidden(BOOL hidden)
970 {
971 fHidden = hidden;
972 fButton.hidden = hidden || getHideOnGUI();
973 }
974
setSelected(BOOL selected)975 void setSelected(BOOL selected)
976 {
977 uiCocoaItem::setSelected(selected);
978 fButton.responderSelected = selected;
979 [fButton setNeedsDisplay];
980 }
981
setColor(float r,float g,float b)982 void setColor(float r, float g, float b)
983 {
984 uiCocoaItem::setColor(r, g, b);
985
986 fButton.color = [UIColor colorWithRed:fR green:fG blue:fB alpha:1.f];
987 [fButton setNeedsDisplay];
988 }
989
setAssignationType(int assignationType)990 void setAssignationType(int assignationType)
991 {
992 uiCocoaItem::setAssignationType(assignationType);
993 if (assignationType != kAssignationNone)
994 {
995 fButton.assignated = true;
996 }
997 else
998 {
999 fButton.assignated = false;
1000 }
1001 [fButton setNeedsDisplay];
1002 }
1003
modifyZone(float value)1004 void modifyZone(float value)
1005 {
1006 // Radio button mode
1007 if (fButton.type == kCheckButtonType && fValue != FLT_MAX) {
1008 if (value == 1.0f) {
1009 fCache = fValue;
1010 if (*fZone != fValue) {
1011 *fZone = fValue;
1012 }
1013 }
1014 } else {
1015 fCache = value;
1016 if (*fZone != value) {
1017 *fZone = value;
1018 fGUI->updateZone(fZone);
1019 }
1020 }
1021 }
1022
reflectZone()1023 void reflectZone()
1024 {
1025 float v = *fZone;
1026
1027 // Radio button mode
1028 if ((fButton.type == kCheckButtonType) && (fValue != FLT_MAX)) {
1029 fButton.value = (v == fValue) ? 1.f : 0.f;
1030 } else {
1031 fCache = v;
1032 if (fButton.type == kToggleButtonType) fButton.value = v;
1033 }
1034 }
1035
1036 };
1037
1038 // ------------------------------ Num Entry -----------------------------------
1039
1040 class uiNumEntry : public uiCocoaItem
1041 {
1042
1043 public:
1044
1045 FITextField* fTextField;
1046
1047 uiNumEntry(GUI* ui, FIMainViewController* controller, const char* label, float* zone, float init, float min, float max, float step,const char* menu = NULL)
uiCocoaItem(ui,zone,controller,label)1048 : uiCocoaItem(ui, zone, controller, label)
1049 {
1050 fLabel = [[[UILabel alloc] init] autorelease];
1051 fLabel.font = [UIFont boldSystemFontOfSize:12];
1052 fLabel.textAlignment = NSTextAlignmentCenter;
1053 fLabel.text = [NSString stringWithCString:label encoding:NSASCIIStringEncoding];
1054 fLabel.textColor = [UIColor whiteColor];
1055 fLabel.backgroundColor = [UIColor clearColor];
1056 [controller.dspView addSubview:fLabel];
1057
1058 fTextField = [[[FITextField alloc] initWithDelegate:controller] autorelease];
1059 fTextField.autoresizingMask = UIViewAutoresizingNone;
1060 fTextField.backgroundColor = [UIColor lightGrayColor];
1061 fTextField.textColor = [UIColor whiteColor];
1062 fTextField.labelColor = [UIColor whiteColor];
1063 fTextField.backgroundColorAlpha = 0.4;
1064 fTextField.min = min;
1065 fTextField.max = max;
1066 fInit = init;
1067 fTextField.value = init;
1068 fTextField.step = step;
1069 [controller.dspView addSubview:fTextField];
1070
1071 // Menu
1072 if (menu) {
1073 const char* p = menu;
1074 vector<string> names;
1075 vector<double> values;
1076 parseMenuList(p, names, values);
1077 fTextField.fMenuItemNames = names;
1078 fTextField.fMenuItemValues = values;
1079 }
1080 }
1081
~uiNumEntry()1082 ~uiNumEntry()
1083 {
1084 [fTextField release];
1085 }
1086
resetInitialValue()1087 void resetInitialValue()
1088 {
1089 fTextField.value = fInit;
1090 }
1091
isHExpandable()1092 BOOL isHExpandable()
1093 {
1094 return FALSE;
1095 }
1096
isVExpandable()1097 BOOL isVExpandable()
1098 {
1099 return FALSE;
1100 }
1101
enableLongPressGestureRecognizer(BOOL enable)1102 void enableLongPressGestureRecognizer(BOOL enable)
1103 {
1104 // Do nothing
1105 }
1106
setFrame(float x,float y,float w,float h)1107 void setFrame(float x, float y, float w, float h)
1108 {
1109 CGPoint pt = inBoxPosition2absolutePosition(x, y, fParent);
1110
1111 uiCocoaItem::setFrame(x, y, w, h);
1112
1113 fTextField.frame = CGRectMake(pt.x + (w - kStdNumEntryWidth) / 2.f,
1114 pt.y + (h - kStdNumEntryHeight - kSpaceSize - kStdNumEntryLabelHeight) / 2.f,
1115 kStdNumEntryWidth,
1116 kStdNumEntryHeight);
1117
1118 fLabel.frame = CGRectMake(pt.x + (w - kStdNumEntryLabelWidth) / 2.f,
1119 pt.y + (h + kStdNumEntryHeight - kSpaceSize - kStdNumEntryLabelHeight) / 2.f + kSpaceSize,
1120 kStdNumEntryLabelWidth,
1121 kStdNumEntryLabelHeight);
1122 }
1123
setHidden(BOOL hidden)1124 void setHidden(BOOL hidden)
1125 {
1126 fHidden = hidden;
1127 fLabel.hidden = hidden || getHideOnGUI();
1128 fTextField.hidden = hidden || getHideOnGUI();
1129 }
1130
reflectZone()1131 void reflectZone()
1132 {
1133 float v = *fZone;
1134 fCache = v;
1135 fTextField.value = v;
1136 }
1137 };
1138
1139 // ------------------------------ Bargraph -----------------------------------
1140
1141 class uiBargraph : public uiCocoaItem
1142 {
1143
1144 public:
1145
1146 FIBargraph* fBargraph;
1147 BOOL fHorizontal;
1148 BOOL fLed;
1149
uiBargraph(GUI * ui,FIMainViewController * controller,const char * name,float * zone,float min,float max,BOOL horizontal)1150 uiBargraph(GUI* ui, FIMainViewController* controller, const char* name, float* zone, float min, float max, BOOL horizontal)
1151 : uiCocoaItem(ui, zone, controller, name)
1152 {
1153 fLed = false;
1154 fLabel = [[[UILabel alloc] init] autorelease];
1155 fLabel.font = [UIFont boldSystemFontOfSize:12];
1156 if (horizontal) fLabel.textAlignment = NSTextAlignmentRight;
1157 else fLabel.textAlignment = NSTextAlignmentCenter;
1158 fLabel.text = [NSString stringWithCString:name encoding:NSASCIIStringEncoding];
1159 fLabel.textColor = [UIColor whiteColor];
1160 fLabel.backgroundColor = [UIColor blackColor];
1161 [controller.dspView addSubview:fLabel];
1162
1163 fBargraph = [[[FIBargraph alloc] initWithFrame:CGRectMake(0.f, 0.f, 0.f, 0.f)] autorelease];
1164 fBargraph.autoresizingMask = UIViewAutoresizingNone;
1165 fHorizontal = horizontal;
1166 fBargraph.value = 0.f;
1167 fBargraph.minLimit = min;
1168 fBargraph.maxLimit = max;
1169 fBargraph.numBars = 8;
1170 fBargraph.holdPeak = false;
1171 [controller.dspView addSubview:fBargraph];
1172 }
1173
~uiBargraph()1174 ~uiBargraph()
1175 {
1176 [fLabel release];
1177 [fBargraph release];
1178 }
1179
resetInitialValue()1180 void resetInitialValue()
1181 {
1182 }
1183
isHExpandable()1184 BOOL isHExpandable()
1185 {
1186 /*if (fLed) return YES;
1187 else*/ if (fHorizontal) return TRUE;
1188
1189 return FALSE;
1190 }
1191
isVExpandable()1192 BOOL isVExpandable()
1193 {
1194 /*if (fLed) return YES;
1195 else*/ if (!fHorizontal) return TRUE;
1196
1197 return FALSE;
1198 }
1199
enableLongPressGestureRecognizer(BOOL enable)1200 void enableLongPressGestureRecognizer(BOOL enable)
1201 {
1202 // Do nothing
1203 }
1204
setFrame(float x,float y,float w,float h)1205 void setFrame(float x, float y, float w, float h)
1206 {
1207 CGPoint pt = inBoxPosition2absolutePosition(x, y, fParent);
1208
1209 uiCocoaItem::setFrame(x, y, w, h);
1210
1211 if (fLed)
1212 {
1213 /*fBargraph.frame = CGRectMake( pt.x + (w - kStdLedWidth) / 2.f,
1214 pt.y + (h - kStdLedHeight - kSpaceSize - kStdBargraphLabelHeight) / 2.f,
1215 kStdLedWidth,
1216 kStdLedHeight);
1217
1218 fLabel.frame = CGRectMake( pt.x + (w - kStdBargraphLabelWidth) / 2.f,
1219 pt.y + (h + kStdBargraphLabelHeight - kSpaceSize - kStdBargraphLabelHeight) / 2.f + kSpaceSize,
1220 kStdBargraphLabelWidth,
1221 kStdBargraphLabelHeight);*/
1222
1223 if (fHorizontal)
1224 {
1225 fBargraph.frame = CGRectMake(pt.x + kStdLedWidth + kSpaceSize,
1226 pt.y + (h - kStdLedHeight) / 2.f,
1227 w - kStdBargraphLabelWidth - kSpaceSize,
1228 kStdLedHeight);
1229
1230 fLabel.frame = CGRectMake(pt.x,
1231 pt.y + (h - kStdBargraphLabelHeight) / 2.f,
1232 kStdBargraphLabelWidth,
1233 kStdBargraphLabelHeight);
1234 }
1235 else
1236 {
1237 fBargraph.frame = CGRectMake(pt.x + (w - kStdLedWidth) / 2.f,
1238 pt.y,
1239 kStdLedWidth,
1240 h - kSpaceSize - kStdBargraphLabelHeight);
1241
1242 fLabel.frame = CGRectMake(pt.x + (w - kStdBargraphLabelWidth) / 2.f,
1243 pt.y + h - kSpaceSize - kStdBargraphLabelHeight,
1244 kStdBargraphLabelWidth,
1245 kStdBargraphLabelHeight);
1246 }
1247 }
1248 else if (fHorizontal)
1249 {
1250 fBargraph.frame = CGRectMake(pt.x + kStdBargraphLabelWidth + kSpaceSize,
1251 pt.y + (h - kStdHorizontalBargraphHeight) / 2.f,
1252 w - kStdBargraphLabelWidth - kSpaceSize,
1253 kStdHorizontalBargraphHeight);
1254
1255 fLabel.frame = CGRectMake(pt.x,
1256 pt.y + (h - kStdBargraphLabelHeight) / 2.f,
1257 kStdBargraphLabelWidth,
1258 kStdBargraphLabelHeight);
1259 }
1260 else
1261 {
1262 fBargraph.frame = CGRectMake(pt.x + (w - kStdVerticalBargraphWidth) / 2.f,
1263 pt.y,
1264 kStdVerticalBargraphWidth,
1265 h - kSpaceSize - kStdBargraphLabelHeight);
1266
1267 fLabel.frame = CGRectMake(pt.x + (w - kStdBargraphLabelWidth) / 2.f,
1268 pt.y + h - kSpaceSize - kStdBargraphLabelHeight,
1269 kStdBargraphLabelWidth,
1270 kStdBargraphLabelHeight);
1271 }
1272 }
1273
setHidden(BOOL hidden)1274 void setHidden(BOOL hidden)
1275 {
1276 fHidden = hidden;
1277 fLabel.hidden = hidden || getHideOnGUI();
1278 fBargraph.hidden = hidden || getHideOnGUI();
1279 }
1280
setLed(BOOL led)1281 void setLed(BOOL led)
1282 {
1283 fLed = led;
1284 fBargraph.led = led;
1285
1286 if (led)
1287 {
1288 fLabel.textAlignment = NSTextAlignmentCenter;
1289 }
1290 else
1291 {
1292 if (fHorizontal) fLabel.textAlignment = NSTextAlignmentRight;
1293 else fLabel.textAlignment = NSTextAlignmentCenter;
1294 }
1295 }
1296
reflectZone()1297 void reflectZone()
1298 {
1299 float v = *fZone;
1300 fCache = v;
1301 fBargraph.value = v;
1302 }
1303 };
1304
1305 // ------------------------------ CocoaUI -----------------------------------
1306
1307 class CocoaUI : public GUI
1308 {
1309
1310 public:
1311
1312 list <uiCocoaItem*> fWidgetList;
1313
setHidden(bool state)1314 void setHidden(bool state)
1315 {
1316 map<float*, bool>::iterator it;
1317 for (it = fHideOnGUI.begin(); it != fHideOnGUI.end(); it++) {
1318 (*it).second = state;
1319 }
1320 }
1321
1322 private:
1323
1324 UIWindow* fWindow;
1325 FIMainViewController* fViewController;
1326 MY_Meta* fMetadata;
1327 map<float*, string> fUnit;
1328 map<float*, float> fR;
1329 map<float*, float> fG;
1330 map<float*, float> fB;
1331 map<float*, int> fAssignationType;
1332 map<float*, bool> fHideOnGUI;
1333 map<float*, bool> fLed;
1334 map<float*, float> fLedR;
1335 map<float*, float> fLedG;
1336 map<float*, float> fLedB;
1337 map<float*, string> fRadioDescription;
1338 map<float*, string> fMenuDescription;
1339 set<float*> fKnobSet;
1340 int fCurrentLayoutType;
1341 bool fNextBoxIsHideOnGUI;
1342 APIUI fAPIUI;
1343 bool fBuildUI;
1344 uiBox* fMonoView;
1345
1346 // Layout management
getActiveBox()1347 uiBox* getActiveBox()
1348 {
1349 list<uiCocoaItem*>::reverse_iterator i;
1350
1351 // Loop on each widgets, from the last
1352 for (i = fWidgetList.rbegin(); i != fWidgetList.rend(); i++)
1353 {
1354 uiBox* box = dynamic_cast<uiBox*>(*i);
1355 if (box && !box->fClosed) {
1356 return box;
1357 }
1358 }
1359 return NULL;
1360 }
1361
1362 // General rules to place objet
computeWidgetFrame(uiCocoaItem * widget)1363 void computeWidgetFrame(uiCocoaItem* widget)
1364 {
1365 uiBox* parent = dynamic_cast<uiBox*>(widget->getParent());
1366 float x = 0.f;
1367 float y = 0.f;
1368 float w = 0.f;
1369 float h = 0.f;
1370
1371 // If no parent : the widget is the main container and is placed at the origin of the view
1372 if (!parent)
1373 {
1374 x = 0.f;
1375 y = 0.f;
1376
1377 // If main box : no label
1378 uiBox* box = dynamic_cast<uiBox*>(widget);
1379 if (box && box->fLabel) {
1380 [box->fLabel removeFromSuperview];
1381 box->fLabel = nil;
1382 box->fLastY = box->fLastY - kStdBoxLabelHeight;
1383 }
1384 }
1385
1386 // Otherwise, computing (x, y) of the widget within its parent box
1387 else
1388 {
1389 // If the box is a tab content box : no label
1390 if (parent->fBoxType == kTabLayout)
1391 {
1392 uiBox* box = dynamic_cast<uiBox*>(widget);
1393 if (box && box->fLabel) {
1394 [box->fLabel removeFromSuperview];
1395 box->fLabel = nil;
1396 box->fLastY = box->fLastY - kStdBoxLabelHeight;
1397 }
1398 }
1399
1400 // Check the current layout mode (eg : the layout mode of widget's parent)
1401 switch (fCurrentLayoutType)
1402 {
1403 // Tab layout mode : widget is the box containing the content of a tab
1404 case kTabLayout:
1405 x = 0.f;
1406 y = kStdTabHeight;
1407 break;
1408
1409 // Vertical layout mode
1410 case kVerticalLayout:
1411 x = kSpaceSize;
1412 y = parent->fLastY + kSpaceSize;
1413 break;
1414
1415 // Horizontal layout mode
1416 case kHorizontalLayout:
1417 x = parent->fLastX + kSpaceSize;
1418 if (parent->fLabel) y = kSpaceSize + kStdBoxLabelHeight;
1419 else y = kSpaceSize;
1420 break;
1421
1422 // Shouldn't happen, but if there is a bug, behaves like in vertical default mode
1423 default:
1424 x = kSpaceSize;
1425 y = parent->fLastY + kSpaceSize;
1426 break;
1427 }
1428 }
1429
1430 // Set minimum size to widget, regarding its type
1431 if (dynamic_cast<uiBox*>(widget))
1432 {
1433 if (dynamic_cast<uiBox*>(widget)->fBoxType == kTabLayout)
1434 {
1435 w = kMinBoxWidth;
1436 h = kMinBoxHeight + kStdTabHeight;
1437 }
1438 else
1439 {
1440 w = kMinBoxWidth;
1441 if (parent && parent->fLabel)
1442 {
1443 h = kMinBoxHeight + kStdBoxLabelHeight;
1444 }
1445 else h = kMinBoxHeight;
1446 }
1447 }
1448 else if (dynamic_cast<uiButton*>(widget))
1449 {
1450 w = kStdButtonWidth;
1451 h = kStdButtonHeight;
1452 }
1453 else if (dynamic_cast<uiNumEntry*>(widget))
1454 {
1455 w = max(kStdNumEntryWidth, kStdNumEntryLabelWidth);
1456 h = kStdNumEntryHeight + kSpaceSize + kStdNumEntryLabelHeight;
1457 }
1458 else if (dynamic_cast<uiKnob*>(widget))
1459 {
1460 w = max(kStdKnobWidth, kStdKnobLabelWidth);
1461 h = kStdKnobHeight + kSpaceSize + kStdKnobLabelHeight;
1462 }
1463 else if (dynamic_cast<uiSlider*>(widget))
1464 {
1465 if (dynamic_cast<uiSlider*>(widget)->fHorizontal)
1466 {
1467 w = kMinHorizontalSliderWidth + kSpaceSize + kStdSliderLabelWidth;
1468 h = max(kStdHorizontalSliderHeight, kStdSliderLabelHeight);
1469 }
1470 else
1471 {
1472 w = max(kStdVerticalSliderWidth, kStdSliderLabelWidth);
1473 h = kMinVerticalSliderHeight + kSpaceSize + kStdSliderLabelHeight;
1474 }
1475 }
1476 else if (dynamic_cast<uiBargraph*>(widget))
1477 {
1478 if (dynamic_cast<uiBargraph*>(widget)->fLed)
1479 {
1480 if (dynamic_cast<uiBargraph*>(widget)->fHorizontal)
1481 {
1482 //w = max(kStdLedWidth, kStdBargraphLabelWidth);
1483 //h = kStdLedHeight + kSpaceSize + kStdBargraphLabelHeight;
1484 w = kMinHorizontalBargraphWidth + kSpaceSize + kStdBargraphLabelWidth;
1485 h = max(kStdLedHeight, kStdBargraphLabelHeight);
1486 }
1487 else
1488 {
1489 //w = max(kStdLedWidth, kStdBargraphLabelWidth);
1490 //h = kStdLedHeight + kSpaceSize + kStdBargraphLabelHeight;
1491 //w = max(kStdLedWidth, kStdBargraphLabelWidth);
1492 //h = kMinVerticalBargraphHeight + kSpaceSize + kStdBargraphLabelHeight;
1493 w = max(kStdLedWidth, kStdBargraphLabelWidth);
1494 h = kMinVerticalBargraphHeight + kSpaceSize + kStdBargraphLabelHeight;
1495 }
1496 }
1497 else if (dynamic_cast<uiBargraph*>(widget)->fHorizontal)
1498 {
1499 w = kMinHorizontalBargraphWidth + kSpaceSize + kStdBargraphLabelWidth;
1500 h = max(kStdHorizontalBargraphHeight, kStdBargraphLabelHeight);
1501 }
1502 else
1503 {
1504 w = max(kStdVerticalBargraphWidth, kStdBargraphLabelWidth);
1505 h = kMinVerticalBargraphHeight + kSpaceSize + kStdBargraphLabelHeight;
1506 }
1507 }
1508
1509 if (widget->getHideOnGUI())
1510 {
1511 w = 0;
1512 h = 0;
1513 }
1514
1515 // Place widget in the box
1516 widget->setFrame(x, y, w, h);
1517
1518 // Refresh last x and last y of the parent box
1519 if (parent)
1520 {
1521 parent->fLastX = x + w;
1522 parent->fLastY = y + h;
1523 }
1524 }
1525
refreshLayout(uiCocoaItem * widget)1526 void refreshLayout(uiCocoaItem* widget)
1527 {
1528 uiBox* parent = dynamic_cast<uiBox*>(widget->getParent());
1529 CGSize contentSize;
1530
1531 if (parent)
1532 {
1533 contentSize = parent->getContentSize();
1534
1535 parent->setFrame(parent->getX(),
1536 parent->getY(),
1537 contentSize.width + kSpaceSize,
1538 contentSize.height + kSpaceSize);
1539
1540 parent->fLastX = widget->getX() + widget->getW();
1541 parent->fLastY = widget->getY() + widget->getH();
1542
1543 refreshLayout(parent);
1544 }
1545 }
1546
updateBoxChildren(const char * label,uiCocoaItem * widget)1547 void updateBoxChildren(const char* label, uiCocoaItem* widget)
1548 {
1549 list<uiCocoaItem*>::reverse_iterator i;
1550 uiBox* box = NULL;
1551
1552 if (fCurrentLayoutType == kTabLayout)
1553 {
1554 for (i = fWidgetList.rbegin(); i != fWidgetList.rend(); i++)
1555 {
1556 if ((box = dynamic_cast<uiBox*>(*i)))
1557 {
1558 if (box->fBoxType == kTabLayout
1559 && box != widget
1560 && !box->fClosed)
1561 {
1562 // Add FIButton in the fTabView
1563 [box->fTabView addButtonWithLabel:[NSString stringWithCString:label encoding:NSASCIIStringEncoding]];
1564
1565 // Add uiCocoaItem in the uiBox (*i)
1566 box->fWidgetList.push_back(widget);
1567 }
1568 }
1569 }
1570
1571 /* SL : 01/09/16 : seems unecessary...
1572 list<uiCocoaItem*>::iterator i1 = fWidgetList.begin();
1573 box = dynamic_cast<uiBox*>(*i1);
1574
1575 if (box->fBoxType == kTabLayout
1576 && box != widget)
1577 {
1578 [box->fTabView addButtonWithLabel:[NSString stringWithCString:label encoding:NSASCIIStringEncoding]];
1579 box->fWidgetList.push_back(widget);
1580 }
1581 */
1582 }
1583 else
1584 {
1585 for (i = fWidgetList.rbegin(); i != fWidgetList.rend(); i++)
1586 {
1587 if ((box = dynamic_cast<uiBox*>(*i)))
1588 {
1589 if ((box->fBoxType == kHorizontalLayout
1590 || box->fBoxType == kVerticalLayout)
1591 && box != widget)
1592 {
1593 // Add uiCocoaItem in the uiBox (*i)
1594 box->fWidgetList.push_back(widget);
1595 }
1596 }
1597 }
1598
1599 list<uiCocoaItem*>::iterator i1 = fWidgetList.begin();
1600 box = dynamic_cast<uiBox*>(*i1);
1601
1602 if (((box)->fBoxType == kHorizontalLayout
1603 || box->fBoxType == kVerticalLayout)
1604 && box != widget)
1605 {
1606 box->fWidgetList.push_back(widget);
1607 }
1608 }
1609 }
1610
insert(const char * label,uiCocoaItem * widget)1611 void insert(const char* label, uiCocoaItem* widget)
1612 {
1613 // Link widget to its parent
1614 widget->setParent(getActiveBox());
1615
1616 // Add widget in the widgts list
1617 fWidgetList.push_back(widget);
1618
1619 // Set position of the widget
1620 computeWidgetFrame(widget);
1621
1622 // Manage boxes and current layout type
1623 updateBoxChildren(label, widget);
1624
1625 // Refresh whole layout
1626 refreshLayout(widget);
1627 }
1628
1629 public:
1630
1631 // -- Labels and metadata
1632
1633 // virtual void declare (float* zone, const char* key, const char* value);
1634 // virtual int checkLabelOptions (GtkWidget* widget, const string& fullLabel, string& simplifiedLabel);
1635 // virtual void checkForTooltip (float* zone, GtkWidget* widget);
1636
1637 // -- layout groups
1638
CocoaUI(UIWindow * window,FIMainViewController * viewController,MY_Meta * metadata,dsp * DSP)1639 CocoaUI(UIWindow* window, FIMainViewController* viewController, MY_Meta* metadata, dsp* DSP)
1640 {
1641 fCurrentLayoutType = kVerticalLayout;
1642 fViewController = viewController;
1643 fWindow = window;
1644 fMetadata = metadata;
1645 fNextBoxIsHideOnGUI = false;
1646
1647 fViewController.dspView.backgroundColor = [UIColor blackColor];
1648 fViewController.dspScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
1649
1650 DSP->buildUserInterface(&fAPIUI);
1651
1652 [window addSubview:viewController.view];
1653 [window makeKeyAndVisible];
1654
1655 fBuildUI = (fAPIUI.getScreenColor() < 0);
1656
1657 if (!fBuildUI) {
1658 fMonoView = new uiBox(this, fViewController, "ColorBox", kColorLayout);
1659 insert("ColorBox", fMonoView);
1660 } else {
1661 fMonoView = NULL;
1662 }
1663 }
1664
~CocoaUI()1665 ~CocoaUI()
1666 {
1667 [fViewController release];
1668 [fWindow release];
1669 delete fMonoView;
1670 }
1671
isScreenUI()1672 bool isScreenUI() { return !fBuildUI; }
1673
getParamType(int index)1674 APIUI::Type getParamType(int index)
1675 {
1676 return fAPIUI.getParamType(index);
1677 }
1678
getParamType(APIUI::Type type)1679 bool getParamType(APIUI::Type type)
1680 {
1681 /*
1682 29/11/18: used by startMotion to activate the accelerometer and/or gyroscope
1683 correction to make it work even if screen mode is activated
1684 */
1685
1686 /*
1687 list<uiCocoaItem*>::iterator i;
1688 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++) {
1689 if (getParamType((*i)->getItemCount()) == type) {
1690 return true;
1691 }
1692 }
1693 return false;
1694 */
1695
1696 for (int i = 0; i < fAPIUI.getParamsCount(); i++) {
1697 if (fAPIUI.getParamType(i) == type) {
1698 return true;
1699 }
1700 }
1701 return false;
1702 }
1703
setAccValues(float x,float y,float z)1704 void setAccValues(float x, float y, float z)
1705 {
1706 fAPIUI.propagateAcc(0, x);
1707 fAPIUI.propagateAcc(1, y);
1708 fAPIUI.propagateAcc(2, z);
1709 }
1710
setGyrValues(float x,float y,float z)1711 void setGyrValues(float x, float y, float z)
1712 {
1713 fAPIUI.propagateGyr(0, x);
1714 fAPIUI.propagateGyr(1, y);
1715 fAPIUI.propagateGyr(2, z);
1716 }
1717
setAccConverter(int index,int type,int curve,float min,float mid,float max)1718 void setAccConverter(int index, int type, int curve, float min, float mid, float max)
1719 {
1720 printf("setAccConverter %d %d %d %f %f %f\n", index, type, curve, min, mid, max);
1721 fAPIUI.setAccConverter(index, type, curve, min, mid, max);
1722 }
1723
getAccConverter(int index,int & type,int & curve,float & min,float & mid,float & max)1724 void getAccConverter(int index, int& type, int& curve, float& min, float& mid, float& max)
1725 {
1726 double dmin, dmid, dmax;
1727 fAPIUI.getAccConverter(index, type, curve, dmin, dmid, dmax);
1728 min = dmin;
1729 mid = dmid;
1730 max = dmax;
1731 printf("getAccConverter %d %d %d %f %f %f\n", index, type, curve, min, mid, max);
1732 }
1733
setGyrConverter(int index,int type,int curve,float min,float mid,float max)1734 void setGyrConverter(int index, int type, int curve, float min, float mid, float max)
1735 {
1736 printf("setGyrConverter %d %d %d %f %f %f\n", index, type, curve, min, mid, max);
1737 fAPIUI.setGyrConverter(index, type, curve, min, mid, max);
1738 }
1739
getGyrConverter(int index,int & type,int & curve,float & min,float & mid,float & max)1740 void getGyrConverter(int index, int& type, int& curve, float& min, float& mid, float& max)
1741 {
1742 double dmin, dmid, dmax;
1743 fAPIUI.getGyrConverter(index, type, curve, dmin, dmid, dmax);
1744 min = dmin;
1745 mid = dmid;
1746 max = dmax;
1747 printf("getGyrConverter %d %d %d %f %f %f\n", index, type, curve, min, mid, max);
1748 }
1749
1750 // Abstract layout : layout computed regardless screen dimensions
saveAbstractLayout()1751 void saveAbstractLayout()
1752 {
1753 list<uiCocoaItem*>::iterator i = fWidgetList.begin();
1754
1755 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
1756 {
1757 (*i)->setAbstractFrame((*i)->getX(), (*i)->getY(), (*i)->getW(), (*i)->getH());
1758 }
1759 }
1760
loadAbstractLayout()1761 void loadAbstractLayout()
1762 {
1763 list<uiCocoaItem*>::iterator i = fWidgetList.begin();
1764
1765 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
1766 {
1767 (*i)->setFrame((*i)->getAbstractX(), (*i)->getAbstractY(), (*i)->getAbstractW(), (*i)->getAbstractH());
1768 }
1769 }
1770
setHideOnGUI(BOOL state)1771 void setHideOnGUI(BOOL state)
1772 {
1773 list<uiCocoaItem*>::iterator i = fWidgetList.begin();
1774
1775 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
1776 {
1777 (*i)->setHideOnGUI(state);
1778 }
1779 }
1780
updateScreenCorlor()1781 void updateScreenCorlor()
1782 {
1783 if (fMonoView) {
1784 fMonoView->setColor(fAPIUI.getScreenColor());
1785 }
1786 }
1787
1788 // Function used to place widgets within a box when the horizontal box is too large or vertical box is too high
expandBoxesContent()1789 void expandBoxesContent()
1790 {
1791 list<uiCocoaItem*>::iterator i = fWidgetList.begin();
1792 list<uiCocoaItem*>::iterator j = fWidgetList.begin();
1793 uiBox* box = NULL;
1794 CGSize contentSize;
1795 float labelHeight = 0.f;
1796 float extensibleElementsTotalSize = 0.f;
1797 float fixedElementsTotalSize = 0.f;
1798 float rx = 1.f;
1799 float cpt = 0.f;
1800 float newVal = 0.f;
1801
1802 // Loop on every boxes of the layout
1803 for (i = fWidgetList.begin(); i != fWidgetList.end(); i++)
1804 {
1805 if ((box = dynamic_cast<uiBox*>(*i)))
1806 {
1807 // Compute content size, ie minimum size used by widgets within the box
1808 contentSize = box->getContentSize();
1809
1810 // Expand objects if content height is < than box height (vertical box)
1811 if (box->fBoxType == kVerticalLayout
1812 && contentSize.height + kSpaceSize < box->getH())
1813 {
1814 // Init values
1815 extensibleElementsTotalSize = 0.f;
1816 fixedElementsTotalSize = 0.f;
1817 rx = 1.f;
1818 cpt = 0.f;
1819 newVal = 0.f;
1820
1821 // Compute extensible and fixed heights
1822 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
1823 {
1824 if ((*j)->getParent() == box)
1825 {
1826 if ((*j)->isVExpandable())
1827 {
1828 extensibleElementsTotalSize += (*j)->getH();
1829 }
1830 else
1831 {
1832 fixedElementsTotalSize += (*j)->getH();
1833 }
1834 }
1835 }
1836
1837 // If there is at least 1 extensible element, elements will take the whole box height
1838 if (extensibleElementsTotalSize > 0.)
1839 {
1840 // Compute extension ratio
1841 rx = (box->getH() - fixedElementsTotalSize - (box->getNumberOfDirectChildren() + 1) * kSpaceSize - labelHeight) / extensibleElementsTotalSize;
1842
1843 // Replace elements
1844 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
1845 {
1846 if ((*j)->getParent() == box)
1847 {
1848 if ((*j)->isVExpandable())
1849 {
1850 newVal = (*j)->getH() * rx;
1851 }
1852 else
1853 {
1854 newVal = (*j)->getH();
1855 }
1856
1857 (*j)->setFrame((*j)->getX(),
1858 cpt + kSpaceSize + labelHeight,
1859 (*j)->getW(),
1860 newVal);
1861
1862 cpt += newVal + kSpaceSize + labelHeight;
1863 }
1864 }
1865 }
1866
1867 // There is no extensible element
1868 else
1869 {
1870 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
1871 {
1872 if ((*j)->getParent() == box)
1873 {
1874 if (box->fLabel) labelHeight = kStdBoxLabelHeight;
1875 else labelHeight = 0.f;
1876
1877 // Place objects on all the height of the box
1878 float y;
1879 float h;
1880
1881 if (contentSize.height == kSpaceSize)
1882 {
1883 y = 0.f;
1884 h = 0.f;
1885 }
1886 else
1887 {
1888 float divider = (contentSize.height - kSpaceSize - labelHeight);
1889
1890 if(divider != 0.0)
1891 {
1892 y = ((*j)->getY() - kSpaceSize - labelHeight) * ((box->getH() - 2.f * kSpaceSize - labelHeight) / divider) + kSpaceSize + labelHeight;
1893 h = (*j)->getH() * ((box->getH() - 2.f * kSpaceSize - labelHeight) / divider);
1894 }
1895 else
1896 {
1897 y = 0.f;
1898 h = 0.f;
1899 }
1900
1901 }
1902
1903 (*j)->setFrame((*j)->getX(),
1904 y,
1905 (*j)->getW(),
1906 h);
1907 }
1908 }
1909 }
1910 }
1911
1912 // Expand objects if content width is < than box width (horizontal box)
1913 else if (box->fBoxType == kHorizontalLayout
1914 && contentSize.width + kSpaceSize < box->getW())
1915 {
1916 // Init values
1917 extensibleElementsTotalSize = 0.f;
1918 fixedElementsTotalSize = 0.f;
1919 rx = 1.f;
1920 cpt = 0.f;
1921 newVal = 0.f;
1922
1923 // Compute extensible and fixed widths
1924 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
1925 {
1926 if ((*j)->getParent() == box)
1927 {
1928 if ((*j)->isHExpandable())
1929 {
1930 extensibleElementsTotalSize += (*j)->getW();
1931 }
1932 else
1933 {
1934 fixedElementsTotalSize += (*j)->getW();
1935 }
1936 }
1937 }
1938
1939 // There is at least 1 extensible element, elements will take the whole box width
1940 if (extensibleElementsTotalSize > 0.)
1941 {
1942 // Compute extension ratio
1943 rx = (box->getW() - fixedElementsTotalSize - (box->getNumberOfDirectChildren() + 1) * kSpaceSize) / extensibleElementsTotalSize;
1944
1945 // Replace elements
1946 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
1947 {
1948 if ((*j)->getParent() == box)
1949 {
1950 if ((*j)->isHExpandable())
1951 {
1952 newVal = (*j)->getW() * rx;
1953 }
1954 else
1955 {
1956 newVal = (*j)->getW();
1957 }
1958
1959 (*j)->setFrame(cpt + kSpaceSize,
1960 (*j)->getY(),
1961 newVal,
1962 (*j)->getH());
1963
1964 cpt += newVal + kSpaceSize;
1965 }
1966 }
1967 }
1968
1969 // There is no extensible element
1970 else
1971 {
1972 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
1973 {
1974 if ((*j)->getParent() == box)
1975 {
1976 // Place objects on all the width of the box
1977 float x;
1978 float w;
1979
1980 if (contentSize.width == kSpaceSize)
1981 {
1982 x = 0.f;
1983 w = 0.f;
1984 }
1985 else
1986 {
1987 x = ((*j)->getX() - kSpaceSize) * ((box->getW() - 2.f * kSpaceSize) / (contentSize.width - kSpaceSize)) + kSpaceSize;
1988 w = (*j)->getW() * ((box->getW() - 2.f * kSpaceSize) / (contentSize.width - kSpaceSize));
1989 }
1990
1991 (*j)->setFrame(x,
1992 (*j)->getY(),
1993 w,
1994 (*j)->getH());
1995 }
1996 }
1997 }
1998 }
1999 }
2000 }
2001 }
2002
2003 // This function takes abstract layout and adapt it to current screen dimensions
adaptLayoutToWindow(float width,float height)2004 void adaptLayoutToWindow(float width, float height)
2005 {
2006 list<uiCocoaItem*>::iterator i = fWidgetList.begin();
2007 list<uiCocoaItem*>::iterator j = fWidgetList.begin();
2008 BOOL hExpandable = NO;
2009 BOOL vExpandable = NO;
2010 float newWidth = 0.f;
2011 float newHeight = 0.f;
2012 int cpt = 0;
2013 uiBox* box = NULL;
2014
2015 if ((box = dynamic_cast<uiBox*>(*i)))
2016 {
2017 // Make main box transparent if it is not a tab box
2018 if (box->fBoxType != kTabLayout)
2019 {
2020 box->fBox.color = [UIColor clearColor];
2021 }
2022
2023 // Load abstract layout
2024 loadAbstractLayout();
2025
2026 // Algo : window is h exp if (a) there is at least 1 h exp element in the patch
2027 // or (b) there is more than 1 column
2028 // AND window is v exp if (a) there is at least 1 v exp element in the patch
2029 // or (b) there is more than 1 line
2030 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
2031 {
2032 if (!dynamic_cast<uiBox*>(*j))
2033 {
2034 if ((*j)->isHExpandable()) hExpandable = TRUE;
2035 if ((*j)->isVExpandable()) vExpandable = TRUE;
2036 }
2037 }
2038
2039 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
2040 {
2041 if ((box = dynamic_cast<uiBox*>(*j)))
2042 {
2043 if (!hExpandable
2044 && box->fBoxType == kHorizontalLayout
2045 && box->getNumberOfDirectChildren() > 1)
2046 {
2047 hExpandable = TRUE;
2048 }
2049
2050 if (!vExpandable
2051 && box->fBoxType == kVerticalLayout
2052 && box->getNumberOfDirectChildren() > 1)
2053 {
2054 vExpandable = TRUE;
2055 }
2056 }
2057 }
2058
2059 if (hExpandable) newWidth = max((*i)->getAbstractW(), width);
2060 else newWidth = (*i)->getAbstractW();
2061
2062 if (vExpandable) newHeight = max((*i)->getAbstractH(), height);
2063 else newHeight = (*i)->getAbstractH();
2064
2065 // Adapt abstract layout to device and orientation
2066 (*i)->setFrame((*i)->getX(),
2067 (*i)->getY(),
2068 newWidth,
2069 newHeight);
2070
2071 // Finally, if there's only 1 widget in the whole patch, center it
2072 for (j = fWidgetList.begin(); j != fWidgetList.end(); j++)
2073 {
2074 if (!dynamic_cast<uiBox*>(*j))
2075 {
2076 cpt++;
2077 }
2078 }
2079
2080 if (cpt == 1)
2081 {
2082 (*i)->setFrame((*i)->getX(),
2083 (*i)->getY(),
2084 width,
2085 height);
2086 }
2087 }
2088
2089 expandBoxesContent();
2090
2091 if (!fBuildUI) {
2092 fMonoView->setFrame(0, 0, width, height);
2093 }
2094 }
2095
getBoxAbsoluteFrameForWidget(uiCocoaItem * widget)2096 CGRect getBoxAbsoluteFrameForWidget(uiCocoaItem* widget)
2097 {
2098 CGPoint pt = absolutePosition(widget);
2099 return CGRectMake(pt.x, pt.y, widget->getW(), widget->getH());
2100 }
2101
2102 // Returns the box containing the point
getBoxForPoint(CGPoint pt)2103 uiBox* getBoxForPoint(CGPoint pt)
2104 {
2105 list<uiCocoaItem*>::reverse_iterator i;
2106 uiBox* box = NULL;
2107
2108 // Loop on each widgets, from the last
2109 for (i = fWidgetList.rbegin(); i != fWidgetList.rend(); i++)
2110 {
2111 if ((box = dynamic_cast<uiBox*>(*i)))
2112 {
2113 if (!(*i)->isHidden()
2114 && pt.x >= absolutePosition(*i).x
2115 && pt.x <= absolutePosition(*i).x + (*i)->getW()
2116 && pt.y >= absolutePosition(*i).y
2117 && pt.y <= absolutePosition(*i).y + (*i)->getH())
2118 {
2119 if (box->getParent())
2120 {
2121 if (dynamic_cast<uiBox*>(box->getParent())->fBoxType == kTabLayout)
2122 {
2123 return dynamic_cast<uiBox*>(box->getParent());
2124 }
2125 }
2126
2127 return box;
2128 }
2129 }
2130 }
2131
2132 return NULL;
2133 }
2134
getMainBox()2135 uiBox* getMainBox()
2136 {
2137 return (fWidgetList.size() > 0) ? dynamic_cast<uiBox*>(*fWidgetList.begin()): NULL;
2138 }
2139
isKnob(float * zone)2140 bool isKnob(float* zone)
2141 {
2142 return fKnobSet.count(zone) > 0;
2143 }
2144
isRadio(float * zone)2145 bool isRadio(float* zone)
2146 {
2147 return fRadioDescription.count(zone) > 0;
2148 }
2149
isMenu(float * zone)2150 bool isMenu(float* zone)
2151 {
2152 return fMenuDescription.count(zone) > 0;
2153 }
2154
openFrameBox(const char * label)2155 virtual void openFrameBox(const char* label)
2156 {}
2157
2158 virtual void openTabBox(const char* label = "")
2159 {
2160 if (!fBuildUI) {
2161 return;
2162 }
2163
2164 uiCocoaItem* item = new uiBox(this, fViewController, label, kTabLayout);
2165 insert(label, item);
2166 fCurrentLayoutType = kTabLayout;
2167 }
2168
2169 virtual void openHorizontalBox(const char* label = "")
2170 {
2171 if (!fBuildUI) {
2172 return;
2173 }
2174
2175 uiCocoaItem* item = new uiBox(this, fViewController, label, kHorizontalLayout);
2176
2177 if (getCurrentOpenedBox()) item->setHideOnGUI(fNextBoxIsHideOnGUI || getCurrentOpenedBox()->getHideOnGUI());
2178 else item->setHideOnGUI(fNextBoxIsHideOnGUI);
2179 if (fNextBoxIsHideOnGUI) fNextBoxIsHideOnGUI = false;
2180
2181 insert(label, item);
2182 fCurrentLayoutType = kHorizontalLayout;
2183 }
2184
2185 virtual void openVerticalBox(const char* label = "")
2186 {
2187 if (!fBuildUI) {
2188 return;
2189 }
2190
2191 uiCocoaItem* item = new uiBox(this, fViewController, label, kVerticalLayout);
2192
2193 if (getCurrentOpenedBox()) item->setHideOnGUI(fNextBoxIsHideOnGUI || getCurrentOpenedBox()->getHideOnGUI());
2194 else item->setHideOnGUI(fNextBoxIsHideOnGUI);
2195 if (fNextBoxIsHideOnGUI) fNextBoxIsHideOnGUI = false;
2196
2197 insert(label, item);
2198 fCurrentLayoutType = kVerticalLayout;
2199 }
2200
2201 // -- extra widget's layouts
2202
openDialogBox(const char * label,float * zone)2203 virtual void openDialogBox(const char* label, float* zone)
2204 {}
2205 virtual void openEventBox(const char* label = "")
2206 {}
2207 virtual void openHandleBox(const char* label = "")
2208 {}
openExpanderBox(const char * label,float * zone)2209 virtual void openExpanderBox(const char* label, float* zone)
2210 {}
2211
getCurrentOpenedBox()2212 virtual uiBox* getCurrentOpenedBox()
2213 {
2214 list<uiCocoaItem*>::reverse_iterator i;
2215
2216 // Find the last box to close
2217 for (i = fWidgetList.rbegin(); i != fWidgetList.rend(); i++)
2218 {
2219 uiBox* box = dynamic_cast<uiBox*>(*i);
2220 if (box && !box->fClosed) {
2221 return box;
2222 }
2223 }
2224
2225 return NULL;
2226 }
2227
closeBox()2228 virtual void closeBox()
2229 {
2230 list<uiCocoaItem*>::reverse_iterator i;
2231
2232 for (i = fWidgetList.rbegin(); i != fWidgetList.rend(); i++) {
2233 uiBox* box = dynamic_cast<uiBox*>(*i);
2234 if (box && !box->fClosed) {
2235 box->close(fWidgetList.size());
2236 break;
2237 }
2238 }
2239
2240 for (i = fWidgetList.rbegin(); i != fWidgetList.rend(); i++) {
2241 uiBox* box = dynamic_cast<uiBox*>(*i);
2242 if (box && !box->fClosed) {
2243 fCurrentLayoutType = box->fBoxType;
2244 break;
2245 }
2246 }
2247 }
2248
2249 //virtual void adjustStack(int n);
2250
2251 // -- active widgets
2252
addButton(const char * label,float * zone)2253 virtual void addButton(const char* label, float* zone)
2254 {
2255 if (!fBuildUI) {
2256 return;
2257 }
2258
2259 uiCocoaItem* item = new uiButton(this, fViewController, label, zone, kPushButtonType);
2260
2261 // Default parameters
2262 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2263 if (getCurrentOpenedBox())
2264 {
2265 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2266 }
2267 else
2268 {
2269 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2270 }
2271 dynamic_cast<uiButton*>(item)->fButton.hideOnGUI = item->getHideOnGUI();
2272
2273 insert(label, item);
2274 }
2275
addToggleButton(const char * label,float * zone)2276 virtual void addToggleButton(const char* label, float* zone)
2277 {
2278 if (!fBuildUI) {
2279 return;
2280 }
2281
2282 uiCocoaItem* item = new uiButton(this, fViewController, label, zone, kToggleButtonType);
2283
2284 // Default parameters
2285 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2286 if (getCurrentOpenedBox())
2287 {
2288 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2289 }
2290 else
2291 {
2292 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2293 }
2294 dynamic_cast<uiButton*>(item)->fButton.hideOnGUI = item->getHideOnGUI();
2295
2296 insert(label, item);
2297 }
2298
addCheckButton(const char * label,float * zone)2299 virtual void addCheckButton(const char* label, float* zone)
2300 {
2301 if (!fBuildUI) {
2302 return;
2303 }
2304
2305 uiCocoaItem* item = new uiButton(this, fViewController, label, zone, kToggleButtonType);
2306
2307 // Default parameters
2308 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2309 if (getCurrentOpenedBox())
2310 {
2311 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2312 }
2313 else
2314 {
2315 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2316 }
2317 dynamic_cast<uiButton*>(item)->fButton.hideOnGUI = item->getHideOnGUI();
2318
2319 insert(label, item);
2320 }
2321
2322 virtual void addRadioButton(const char* label, float init, float* zone, float value = FLT_MAX)
2323 {
2324 if (!fBuildUI) {
2325 return;
2326 }
2327
2328 uiButton* item = new uiButton(this, fViewController, label, zone, kCheckButtonType, value);
2329
2330 // Default parameters
2331 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2332 if (getCurrentOpenedBox())
2333 {
2334 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2335 }
2336 else
2337 {
2338 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2339 }
2340 dynamic_cast<uiButton*>(item)->fButton.hideOnGUI = item->getHideOnGUI();
2341
2342 insert(label, item);
2343
2344 if (init == value) {
2345 item->setOn();
2346 }
2347 }
2348
addVerticalKnob(const char * label,float * zone,float init,float min,float max,float step)2349 virtual void addVerticalKnob(const char* label , float* zone, float init, float min, float max, float step)
2350 {
2351 uiCocoaItem* item = new uiKnob(this, fViewController, label, zone, init, min, max, step, false);
2352 if (dynamic_cast<uiKnob*>(item)->fKnob.suffixe) [dynamic_cast<uiKnob*>(item)->fKnob.suffixe release];
2353 dynamic_cast<uiKnob*>(item)->fKnob.suffixe = [[NSString alloc] initWithCString:fUnit[zone].c_str() encoding:NSUTF8StringEncoding];
2354
2355 // Default parameters
2356 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2357 if (fAssignationType[zone]) item->setInitAssignationType(fAssignationType[zone]);
2358 if (getCurrentOpenedBox())
2359 {
2360 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2361 }
2362 else
2363 {
2364 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2365 }
2366 dynamic_cast<uiKnob*>(item)->fKnob.hideOnGUI = item->getHideOnGUI();
2367
2368 insert(label, item);
2369 }
2370
addHorizontalKnob(const char * label,float * zone,float init,float min,float max,float step)2371 virtual void addHorizontalKnob(const char* label , float* zone, float init, float min, float max, float step)
2372 {
2373 uiCocoaItem* item = new uiKnob(this, fViewController, label, zone, init, min, max, step, true);
2374 if (dynamic_cast<uiKnob*>(item)->fKnob.suffixe) [dynamic_cast<uiKnob*>(item)->fKnob.suffixe release];
2375 dynamic_cast<uiKnob*>(item)->fKnob.suffixe = [[NSString alloc] initWithCString:fUnit[zone].c_str() encoding:NSUTF8StringEncoding];
2376
2377 // Default parameters
2378 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2379 if (fAssignationType[zone]) item->setInitAssignationType(fAssignationType[zone]);
2380 if (getCurrentOpenedBox())
2381 {
2382 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2383 }
2384 else
2385 {
2386 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2387 }
2388 dynamic_cast<uiKnob*>(item)->fKnob.hideOnGUI = item->getHideOnGUI();
2389
2390 insert(label, item);
2391 }
2392
addVerticalSlider(const char * label,float * zone,float init,float min,float max,float step)2393 virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step)
2394 {
2395 if (!fBuildUI) {
2396 return;
2397 }
2398
2399 if (isKnob(zone)) {
2400 addVerticalKnob(label, zone, init, min, max, step);
2401 } else if (isRadio(zone)) {
2402 addVerticalRadioButtons(label, zone, init, min, max, step, fRadioDescription[zone].c_str());
2403 } else {
2404 uiCocoaItem* item = new uiSlider(this, fViewController, label, zone, init, min, max, step, false,
2405 ((fMenuDescription.count(zone) ? fMenuDescription[zone].c_str() : NULL)));
2406 if (dynamic_cast<uiSlider*>(item)->fSlider.suffixe) [dynamic_cast<uiSlider*>(item)->fSlider.suffixe release];
2407 dynamic_cast<uiSlider*>(item)->fSlider.suffixe = [[NSString alloc] initWithCString:fUnit[zone].c_str() encoding:NSUTF8StringEncoding];
2408
2409 // Default parameters
2410 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2411 if (fAssignationType[zone]) item->setInitAssignationType(fAssignationType[zone]);
2412 if (getCurrentOpenedBox())
2413 {
2414 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2415 }
2416 else
2417 {
2418 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2419 }
2420 dynamic_cast<uiSlider*>(item)->fSlider.hideOnGUI = item->getHideOnGUI();
2421
2422 insert(label, item);
2423 }
2424 }
2425
addHorizontalSlider(const char * label,float * zone,float init,float min,float max,float step)2426 virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step)
2427 {
2428 if (!fBuildUI) {
2429 return;
2430 }
2431
2432 if (isKnob(zone)){
2433 addHorizontalKnob(label, zone, init, min, max, step);
2434 } else if (isRadio(zone)) {
2435 addHorizontalRadioButtons(label, zone, init, min, max, step, fRadioDescription[zone].c_str());
2436 } else {
2437 uiCocoaItem* item = new uiSlider(this, fViewController, label, zone, init, min, max, step, true,
2438 ((fMenuDescription.count(zone) ? fMenuDescription[zone].c_str() : NULL)));
2439 if (dynamic_cast<uiSlider*>(item)->fSlider.suffixe) [dynamic_cast<uiSlider*>(item)->fSlider.suffixe release];
2440 dynamic_cast<uiSlider*>(item)->fSlider.suffixe = [[NSString alloc] initWithCString:fUnit[zone].c_str() encoding:NSUTF8StringEncoding];
2441
2442 // Default parameters
2443 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2444 if (fAssignationType[zone]) item->setInitAssignationType(fAssignationType[zone]);
2445 if (getCurrentOpenedBox())
2446 {
2447 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2448 }
2449 else
2450 {
2451 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2452 }
2453 dynamic_cast<uiSlider*>(item)->fSlider.hideOnGUI = item->getHideOnGUI();
2454
2455 insert(label, item);
2456 }
2457 }
2458
addVerticalRadioButtons(const char * label,float * zone,float init,float min,float max,float step,const char * mdescr)2459 virtual void addVerticalRadioButtons(const char* label, float* zone, float init, float min, float max, float step, const char* mdescr)
2460 {
2461 if (!fBuildUI) {
2462 return;
2463 }
2464 const char* p = mdescr;
2465 vector<string> names;
2466 vector<double> values;
2467 parseMenuList(p, names, values);
2468
2469 openVerticalBox(label);
2470 for (int i = 0; i < names.size(); i++) {
2471 addRadioButton(names[i].c_str(), init, zone, values[i]);
2472 }
2473 closeBox();
2474 }
2475
addHorizontalRadioButtons(const char * label,float * zone,float init,float min,float max,float step,const char * mdescr)2476 virtual void addHorizontalRadioButtons(const char* label, float* zone, float init, float min, float max, float step, const char* mdescr)
2477 {
2478 if (!fBuildUI) {
2479 return;
2480 }
2481 const char* p = mdescr;
2482 vector<string> names;
2483 vector<double> values;
2484 parseMenuList(p, names, values);
2485
2486 openHorizontalBox(label);
2487 for (int i = 0; i < names.size(); i++) {
2488 addRadioButton(names[i].c_str(), init, zone, values[i]);
2489 }
2490 closeBox();
2491 }
2492
addNumEntry(const char * label,float * zone,float init,float min,float max,float step)2493 virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step)
2494 {
2495 if (!fBuildUI) {
2496 return;
2497 }
2498
2499 if (isKnob(zone))
2500 {
2501 addVerticalKnob(label, zone, init, min, max, step);
2502 }
2503 else
2504 {
2505 uiCocoaItem* item = new uiNumEntry(this, fViewController, label, zone, init, min, max, step, ((fMenuDescription.count(zone) ? fMenuDescription[zone].c_str() : NULL)));
2506 if (dynamic_cast<uiNumEntry*>(item)->fTextField.suffixe) [dynamic_cast<uiNumEntry*>(item)->fTextField.suffixe release];
2507 dynamic_cast<uiNumEntry*>(item)->fTextField.suffixe = [[NSString alloc] initWithCString:fUnit[zone].c_str() encoding:NSUTF8StringEncoding];
2508
2509 // Default parameters
2510 if (fR[zone] && fG[zone] && fB[zone]) item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2511 if (getCurrentOpenedBox())
2512 {
2513 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2514 }
2515 else
2516 {
2517 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2518 }
2519 dynamic_cast<uiNumEntry*>(item)->fTextField.hideOnGUI = item->getHideOnGUI();
2520
2521 insert(label, item);
2522 }
2523 }
2524
2525 // -- passive display widgets
2526
addNumDisplay(const char * label,float * zone,int precision)2527 virtual void addNumDisplay(const char* label, float* zone, int precision)
2528 {}
2529
addTextDisplay(const char * label,float * zone,const char * names[],float min,float max)2530 virtual void addTextDisplay(const char* label, float* zone, const char* names[], float min, float max)
2531 {}
2532
addHorizontalBargraph(const char * label,float * zone,float min,float max)2533 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max)
2534 {
2535 if (!fBuildUI) {
2536 return;
2537 }
2538
2539 uiCocoaItem* item = new uiBargraph(this, fViewController, label, zone, min, max, true);
2540
2541 if (fR[zone] && fG[zone] && fB[zone])
2542 {
2543 item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2544 dynamic_cast<uiBargraph*>(item)->fBargraph.ledMaxColor = [[UIColor colorWithRed:fR[zone] - 1000.
2545 green:fG[zone] - 1000.
2546 blue:fB[zone] - 1000.
2547 alpha:1.] retain];
2548 }
2549 if (getCurrentOpenedBox())
2550 {
2551 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2552 }
2553 else
2554 {
2555 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2556 }
2557 dynamic_cast<uiBargraph*>(item)->setLed(fLed[zone]);
2558
2559 if (fLedR[zone] || fLedG[zone] || fLedB[zone])
2560 {
2561 dynamic_cast<uiBargraph*>(item)->fBargraph.ledMinColor = [[UIColor colorWithRed:fLedR[zone]
2562 green:fLedG[zone]
2563 blue:fLedB[zone]
2564 alpha:1.] retain];
2565 }
2566
2567 insert(label, item);
2568 }
2569
addVerticalBargraph(const char * label,float * zone,float min,float max)2570 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max)
2571 {
2572 if (!fBuildUI) {
2573 return;
2574 }
2575
2576 uiCocoaItem* item = new uiBargraph(this, fViewController, label, zone, min, max, false);
2577
2578 if (fR[zone] && fG[zone] && fB[zone])
2579 {
2580 item->setInitColor(fR[zone] - 1000., fG[zone] - 1000., fB[zone] - 1000.);
2581 dynamic_cast<uiBargraph*>(item)->fBargraph.ledMaxColor = [[UIColor colorWithRed:fR[zone] - 1000.
2582 green:fG[zone] - 1000.
2583 blue:fB[zone] - 1000.
2584 alpha:1.] retain];
2585 }
2586 if (getCurrentOpenedBox())
2587 {
2588 if (fHideOnGUI[zone] || getCurrentOpenedBox()->getHideOnGUI()) item->setHideOnGUI(TRUE);
2589 }
2590 else
2591 {
2592 if (fHideOnGUI[zone]) item->setHideOnGUI(TRUE);
2593 }
2594 dynamic_cast<uiBargraph*>(item)->setLed(fLed[zone]);
2595
2596 if (fLedR[zone] || fLedG[zone] || fLedB[zone])
2597 {
2598 dynamic_cast<uiBargraph*>(item)->fBargraph.ledMinColor = [[UIColor colorWithRed:fLedR[zone]
2599 green:fLedG[zone]
2600 blue:fLedB[zone]
2601 alpha:1.] retain];
2602 }
2603
2604 insert(label, item);
2605 }
2606
run()2607 virtual bool run()
2608 {
2609 return true;
2610 }
2611
declare(float * zone,const char * key,const char * value)2612 virtual void declare(float* zone, const char* key, const char* value)
2613 {
2614 if (zone == 0)
2615 {
2616 // special zone 0 means group metadata
2617 /*if (strcmp(key,"tooltip")==0)
2618 {
2619 // only group tooltip are currently implemented
2620 gGroupTooltip = formatTooltip(30, value);
2621 }*/
2622
2623 if (strcmp(key, "hidden") == 0)
2624 {
2625 NSString* str = [NSString stringWithCString:value encoding:NSUTF8StringEncoding];
2626 NSArray* arr = [str componentsSeparatedByString:@" "];
2627
2628 if ([((NSString*)[arr objectAtIndex:0]) integerValue] == 1)
2629 {
2630 fNextBoxIsHideOnGUI = true;
2631 }
2632 }
2633 }
2634 else
2635 {
2636 if (strcmp(key, "size") == 0)
2637 {
2638 //fGuiSize[zone]=atof(value);
2639 }
2640 else if (strcmp(key, "tooltip") == 0)
2641 {
2642 //fTooltip[zone] = formatTooltip(30, value) ;
2643 }
2644 else if (strcmp(key, "unit") == 0)
2645 {
2646 fUnit[zone] = value;
2647 }
2648 else if (strcmp(key, "hidden") == 0)
2649 {
2650 NSString* str = [NSString stringWithCString:value encoding:NSUTF8StringEncoding];
2651 NSArray* arr = [str componentsSeparatedByString:@" "];
2652
2653 if ([((NSString*)[arr objectAtIndex:0]) integerValue] == 1)
2654 {
2655 fHideOnGUI[zone] = true;
2656 }
2657 }
2658 else if (strcmp(key, "style") == 0)
2659 {
2660 NSString* str = [NSString stringWithCString:value encoding:NSUTF8StringEncoding];
2661 NSArray* arr = [str componentsSeparatedByString:@" "];
2662 const char* p = value;
2663
2664 if ([arr count] == 0) return;
2665
2666 if ([((NSString*)[arr objectAtIndex:0]) compare:@"knob"] == NSOrderedSame)
2667 {
2668 fKnobSet.insert(zone);
2669 }
2670 else if ([((NSString*)[arr objectAtIndex:0]) compare:@"led"] == NSOrderedSame)
2671 {
2672 fLed[zone] = true;
2673
2674 fLedR[zone] = 0.f;
2675 fLedG[zone] = 0.f;
2676 fLedB[zone] = 0.f;
2677
2678 if ([arr count] == 2)
2679 {
2680 fLedR[zone] = (float)[((NSString*)[arr objectAtIndex:1]) integerValue] / 255.f;
2681 }
2682 else if ([arr count] == 3)
2683 {
2684 fLedR[zone] = (float)[((NSString*)[arr objectAtIndex:1]) integerValue] / 255.f;
2685 fLedG[zone] = (float)[((NSString*)[arr objectAtIndex:2]) integerValue] / 255.f;
2686 }
2687 else if ([arr count] == 4)
2688 {
2689 fLedR[zone] = (float)[((NSString*)[arr objectAtIndex:1]) integerValue] / 255.f;
2690 fLedG[zone] = (float)[((NSString*)[arr objectAtIndex:2]) integerValue] / 255.f;
2691 fLedB[zone] = (float)[((NSString*)[arr objectAtIndex:3]) integerValue] / 255.f;
2692 }
2693 } else if (parseWord(p, "radio")) {
2694 fRadioDescription[zone] = string(p);
2695 } else if (parseWord(p, "menu")) {
2696 fMenuDescription[zone] = string(p);
2697 }
2698 }
2699 else if (strcmp(key, "color") == 0)
2700 {
2701 NSString* str = [NSString stringWithCString:value encoding:NSUTF8StringEncoding];
2702 NSArray* arr = [str componentsSeparatedByString:@" "];
2703
2704 fR[zone] = (float)[((NSString*)[arr objectAtIndex:0]) integerValue] / 255.f + 1000.;
2705 fG[zone] = (float)[((NSString*)[arr objectAtIndex:1]) integerValue] / 255.f + 1000.;
2706 fB[zone] = (float)[((NSString*)[arr objectAtIndex:2]) integerValue] / 255.f + 1000.;
2707 }
2708 else if (strcmp(key,"accx") == 0
2709 || strcmp(key,"accy") == 0
2710 || strcmp(key,"accz") == 0
2711 || strcmp(key,"gyrox") == 0
2712 || strcmp(key,"gyroy") == 0
2713 || strcmp(key,"gyroz") == 0)
2714 {
2715 if (strcmp(key,"accx") == 0) fAssignationType[zone] = kAssignationAccelX;
2716 else if (strcmp(key,"accy") == 0) fAssignationType[zone] = kAssignationAccelY;
2717 else if (strcmp(key,"accz") == 0) fAssignationType[zone] = kAssignationAccelZ;
2718 else if (strcmp(key,"gyrox") == 0) fAssignationType[zone] = kAssignationGyroX;
2719 else if (strcmp(key,"gyroy") == 0) fAssignationType[zone] = kAssignationGyroY;
2720 else if (strcmp(key,"gyroz") == 0) fAssignationType[zone] = kAssignationGyroZ;
2721 }
2722 }
2723 }
2724 };
2725
inBoxPosition2absolutePosition(float x,float y,uiCocoaItem * box)2726 CGPoint inBoxPosition2absolutePosition(float x, float y, uiCocoaItem* box)
2727 {
2728 CGPoint parentBoxOrigin = CGPointMake(0.f, 0.f);
2729 CGPoint absolutePosition = CGPointMake(0.f, 0.f);
2730 uiBox* parent = NULL;
2731
2732 if (box)
2733 {
2734 parent = dynamic_cast<uiBox*>(box->getParent());
2735
2736 if (parent)
2737 {
2738 parentBoxOrigin = inBoxPosition2absolutePosition(box->getX(), box->getY(), parent);
2739 }
2740 }
2741
2742 absolutePosition = CGPointMake(x + parentBoxOrigin.x, y + parentBoxOrigin.y);
2743 return absolutePosition;
2744 }
2745
absolutePosition(uiCocoaItem * widget)2746 CGPoint absolutePosition(uiCocoaItem* widget)
2747 {
2748 return inBoxPosition2absolutePosition(widget->getX(), widget->getY(), widget->getParent());
2749 }
2750