MHEG5  18.9.0
MHEG5 Documentation
mh5slider.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  * Copyright © 2000 Koninklijke Philips Electronics N.V
5  *
6  * This file is part of a DTVKit Software Component
7  * You are permitted to copy, modify or distribute this file subject to the terms
8  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
9  *
10  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * If you or your organisation is not a member of DTVKit then you have access
15  * to this source code outside of the terms of the licence agreement
16  * and you are expected to delete this and any associated files immediately.
17  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
18  *******************************************************************************/
32 /*---includes for this file--------------------------------------------------*/
33 #include "mh5slider.h"
34 #include "mh5scene.h"
35 #include "mh5object.h" /* for actions */
36 #include "mh5variable.h" /* for actions */
37 #include "mh5display.h" /* for actions */
38 #include "mh5application.h" /* Default Colour */
39 #include "mh5queue.h" /* Events */
40 #include "mh5memory.h" /* Constructor */
41 #include "mh5debug.h"
42 
43 #ifdef MH5PRINTOUT
44 #include <string.h>
45 #endif /* #ifdef MH5PRINTOUT */
46 
47 /*---constant definitions for this file--------------------------------------*/
48 
49 
50 /*---local typedef structs for this file-------------------------------------*/
51 
52 /*---local (static) variable declarations for this file----------------------*/
53 
54 /*---local function definitions----------------------------------------------*/
55 
56 /*---global function definitions---------------------------------------------*/
57 
63 /*
64  Debug
65  */
66 #ifdef MH5PRINTOUT
67 
74 void MHEG5sliderPrint(MHEG5Slider *slider, char *out)
75 {
76  MHEG5visiblePrint(&slider->visible, out);
77  MHEG5interactiblePrint(&slider->interactible, out);
78 
79  /* exchanged attributes */
80  MHEG5indent(out);
81  MHEG_PRINT(out, ":Orientation: ");
82  switch (slider->orientation)
83  {
84  case MHEG5LEFT:
85  MHEG_PRINT(out, "LEFT");
86  break;
87  case MHEG5RIGHT:
88  MHEG_PRINT(out, "RIGHT");
89  break;
90  case MHEG5UP:
91  MHEG_PRINT(out, "UP");
92  break;
93  case MHEG5DOWN:
94  MHEG_PRINT(out, "DOWN");
95  break;
96  default:
97  MHEG_PRINT(out, "<Internal Error>");
98  break;
99  }
100  MHEG5newLine(out);
101 
102  MHEG5indent(out);
103  MHEG_PRINT(out, ":InitialValue ");
104  MHEG5intPrint(slider->initialValue, out);
105  MHEG5newLine(out);
106 
107  MHEG5indent(out);
108  MHEG_PRINT(out, ":OriginalMinValue: ");
109  MHEG5intPrint(slider->originalMinValue, out);
110  MHEG5newLine(out);
111 
112  MHEG5indent(out);
113  MHEG_PRINT(out, ":OriginalMaxValue: ");
114  MHEG5intPrint(slider->originalMaxValue, out);
115  MHEG5newLine(out);
116 
117  MHEG5indent(out);
118  MHEG_PRINT(out, ":InitialPortion: ");
119  MHEG5intPrint(slider->initialPortion, out);
120  MHEG5newLine(out);
121 
122  MHEG5indent(out);
123  MHEG_PRINT(out, ":OriginalStepSize: ");
124  MHEG5intPrint(slider->originalStepSize, out);
125  MHEG5newLine(out);
126 
127  MHEG5indent(out);
128  MHEG_PRINT(out, ":SliderStyle: ");
129  switch (slider->sliderStyle)
130  {
131  case MHEG5NORMAL:
132  MHEG_PRINT(out, "NORMAL");
133  break;
134  case MHEG5THERMOMETER:
135  MHEG_PRINT(out, "THERMOMETER");
136  break;
137  case MHEG5PROPORTIONAL:
138  MHEG_PRINT(out, "PROPORTIONAL");
139  break;
140  default:
141  MHEG_PRINT(out, "<Internal Error>");
142  break;
143  }
144  MHEG5newLine(out);
145 
146  MHEG5indent(out);
147  MHEG_PRINT(out, "SliderRefColour: ");
148  MHEG5colourPrint(slider->sliderRefColour, out);
149  MHEG5newLine(out);
150 
151  /* local attributes */
152  MHEG5indent(out);
153  MHEG_PRINT(out, "// Value:\t");
154  MHEG5intPrint(slider->sliderValue, out);
155  MHEG5newLine(out);
156 
157  MHEG5indent(out);
158  MHEG_PRINT(out, "// Portion:\t");
159  MHEG5intPrint(slider->portion, out);
160  MHEG5newLine(out);
161 
162  MHEG5indent(out);
163  MHEG_PRINT(out, "// MinValue:\t");
164  MHEG5intPrint(slider->minValue, out);
165  MHEG5newLine(out);
166 
167  MHEG5indent(out);
168  MHEG_PRINT(out, "// MaxValue:\t");
169  MHEG5intPrint(slider->maxValue, out);
170  MHEG5newLine(out);
171 
172  MHEG5indent(out);
173  MHEG_PRINT(out, "// StepSize:\t");
174  MHEG5intPrint(slider->stepSize, out);
175  MHEG5newLine(out);
176 }
177 
178 #endif
179 
180 
181 /*
182  Constructor
183  */
184 
191 {
192  assert(slider);
193 
194  MHEG5visibleInit(&slider->visible);
196 
197  /* Default value of InitialValue is specified to be MinValue. We cannot know
198  * MinValue yet, so set it to the default value of MinValue.
199  */
200  slider->initialValue = 1;
201  slider->originalMinValue = 1;
202  slider->originalStepSize = 1;
203 }
204 
213 {
214  assert(slider);
215 
216  MHEG5visibleFree(&slider->visible);
218 
220 }
221 
222 /*
223  Internal behaviours
224  */
225 
236 {
237  assert(slider);
238 
239  slider->sliderValue = slider->initialValue;
240  slider->portion = slider->initialPortion;
241  slider->minValue = slider->originalMinValue;
242  slider->maxValue = slider->originalMaxValue;
243  slider->stepSize = slider->originalStepSize;
244 
246  MHEG5visiblePrepare(&slider->visible);
247 }
248 
258 {
259  assert(slider);
260 
262  {
263  MHEG5sliderPrepare( slider );
264  }
265  MHEG5visibleActivate(&slider->visible);
266 }
267 
277 {
278  assert(slider);
279 
281 
282  /* Apply deactivation behaviour inherrited from Interactible class */
284 }
285 
293 {
294  assert(slider);
295 
296  MHEG5visibleDestruct(&slider->visible);
298 }
299 
300 /*
301  Actions
302  */
303 
314 {
315  MHEG5Int nSteps, newValue;
316  MHEG5Slider *slider;
317 
318  assert(target);
319 
320  if (target->clazz != MHEG5SLIDER)
321  return MHEG5ERR_WRONGTARGET;
322  slider = (MHEG5Slider *) target;
323 
324  if (!params)
326  MHEG5resolveGenericInteger(params, &nSteps);
327 
328  newValue = slider->stepSize * nSteps + slider->sliderValue;
329  if (newValue < slider->minValue)
330  newValue = slider->minValue;
331  if ((newValue + slider->portion) > slider->maxValue)
332  return MHEG5ERR_NOERROR;
333  slider->sliderValue = newValue;
334 
335  MHEG5displayRedraw((MHEG5Visible *) target);
336 
337  /* Send the slider value changed event with new slider value as parameter */
339 
340  return MHEG5ERR_NOERROR;
341 }
342 
354 {
355  MHEG5Int newValue;
356  MHEG5Slider *slider;
357 
358  assert(target);
359 
360  if (target->clazz != MHEG5SLIDER)
361  return MHEG5ERR_WRONGTARGET;
362  slider = (MHEG5Slider *) target;
363 
364  if (!params)
366  MHEG5resolveGenericInteger(params, &newValue);
367  if (newValue < slider->minValue)
368  return MHEG5ERR_NOERROR;
369  if ((newValue + slider->portion) > slider->maxValue)
370  return MHEG5ERR_NOERROR;
371 
372  slider->sliderValue = newValue;
373 
374  MHEG5displayRedraw((MHEG5Visible *) target);
375 
376  /* Send the slider value changed event with new slider value as parameter */
378 
379  return MHEG5ERR_NOERROR;
380 }
381 
394 {
395  MHEG5Root *intVar = 0;
396  MHEG5IntegerVariable *rc = 0;
397  MHEG5Slider *slider;
398 
399  if (target->clazz != MHEG5SLIDER)
400  return MHEG5ERR_WRONGTARGET;
401  slider = (MHEG5Slider *) target;
402 
403  if (!params)
405  MHEG5resolveORef(params, &intVar);
406  if (!intVar)
408  if (intVar->clazz != MHEG5INTEGERVARIABLE)
409  return MHEG5ERR_WRONGPARAM;
410  if (!intVar->runningStatus)
412 
413  rc = (MHEG5IntegerVariable *)intVar;
414  rc->value = slider->sliderValue;
415 
416  return MHEG5ERR_NOERROR;
417 }
418 
429 {
430  MHEG5Int newPortion;
431  MHEG5Slider *slider;
432 
433  if (target->clazz != MHEG5SLIDER)
434  return MHEG5ERR_WRONGTARGET;
435  slider = (MHEG5Slider *) target;
436 
437  if (!params)
439  MHEG5resolveGenericInteger(params, &newPortion);
440 
441  if (newPortion > (slider->maxValue - slider->sliderValue))
442  return MHEG5ERR_NOERROR;
443 
444  slider->portion = newPortion;
445 
446  MHEG5displayRedraw((MHEG5Visible *) target);
447 
448  /* Send the slider value changed event with new slider value as parameter */
450 
451  return MHEG5ERR_NOERROR;
452 }
453 
465 {
466  MHEG5Root *intVar = 0;
467  MHEG5IntegerVariable *rc = 0;
468  MHEG5Slider *slider;
469 
470  assert(target);
471 
472  if (target->clazz != MHEG5SLIDER)
473  return MHEG5ERR_WRONGTARGET;
474  slider = (MHEG5Slider *) target;
475 
476  if (!params)
478  MHEG5resolveORef(params, &intVar);
479  if (!intVar)
480  return MHEG5ERR_WRONGPARAM;
481  if (intVar->clazz != MHEG5INTEGERVARIABLE)
482  return MHEG5ERR_WRONGPARAM;
483  if (!intVar->runningStatus)
485 
486  rc = (MHEG5IntegerVariable *)intVar;
487  rc->value = slider->portion;
488 
489  return MHEG5ERR_NOERROR;
490 }
491 
503 {
504  MHEG5GList *thirdParam, *fourthParam;
505  MHEG5Int newMinValue;
506  MHEG5Int newMaxValue;
507  MHEG5Int newStepSize;
508  MHEG5Slider *slider;
509 
510  assert(target);
511 
512  if (target->clazz != MHEG5SLIDER)
513  return MHEG5ERR_WRONGTARGET;
514  slider = (MHEG5Slider *) target;
515 
516  if (!params)
518  thirdParam = MHEG5resolveGenericInteger(params, &newMinValue);
519 
520  if (!thirdParam)
522  fourthParam = MHEG5resolveGenericInteger(thirdParam, &newMaxValue);
523 
524  if (!fourthParam)
526  MHEG5resolveGenericInteger(fourthParam, &newStepSize);
527 
528  if (newMinValue >= newMaxValue)
529  return MHEG5ERR_NOERROR;
530  if (((newMaxValue - newMinValue) % newStepSize) != 0)
531  return MHEG5ERR_NOERROR;
532  if ((newMaxValue - newMinValue) < slider->portion)
533  return MHEG5ERR_NOERROR;
534 
535  slider->sliderValue = newMinValue;
536  slider->minValue = newMinValue;
537  slider->maxValue = newMaxValue;
538  slider->stepSize = newStepSize;
539 
540  MHEG5displayRedraw((MHEG5Visible *) target);
541 
542  /* Send the slider value changed event with new slider value as parameter */
544 
545  return MHEG5ERR_NOERROR;
546 }
547 
554 {
555  MHEG5Int newValue;
556  switch (slider->orientation)
557  {
558  case MHEG5LEFT:
559  newValue = slider->sliderValue + slider->stepSize;
560  break;
561  case MHEG5RIGHT:
562  newValue = slider->sliderValue - slider->stepSize;
563  break;
564  default:
565  return;
566  }
567 
568  if (newValue < slider->minValue)
569  {
570  newValue = slider->minValue;
571  }
572  if ((newValue + slider->portion) > slider->maxValue)
573  {
574  return;
575  }
576  slider->sliderValue = newValue;
577 
578  MHEG5displayRedraw((MHEG5Visible *) slider);
579 
580  /* Send the slider value changed event with new slider value as parameter */
582 }
583 
590 {
591  MHEG5Int newValue;
592  switch (slider->orientation)
593  {
594  case MHEG5UP:
595  newValue = slider->sliderValue + slider->stepSize;
596  break;
597  case MHEG5DOWN:
598  newValue = slider->sliderValue - slider->stepSize;
599  break;
600  default:
601  return;
602  }
603 
604  if (newValue < slider->minValue)
605  {
606  newValue = slider->minValue;
607  }
608  if ((newValue + slider->portion) > slider->maxValue)
609  {
610  return;
611  }
612  slider->sliderValue = newValue;
613 
614  MHEG5displayRedraw((MHEG5Visible *) slider);
615 
616  /* Send the slider value changed event with new slider value as parameter */
618 }
619 
626 {
627  MHEG5Int newValue;
628  switch (slider->orientation)
629  {
630  case MHEG5RIGHT:
631  newValue = slider->sliderValue + slider->stepSize;
632  break;
633  case MHEG5LEFT:
634  newValue = slider->sliderValue - slider->stepSize;
635  break;
636  default:
637  return;
638  }
639 
640  if (newValue < slider->minValue)
641  {
642  newValue = slider->minValue;
643  }
644  if ((newValue + slider->portion) > slider->maxValue)
645  {
646  return;
647  }
648  slider->sliderValue = newValue;
649 
650  MHEG5displayRedraw((MHEG5Visible *) slider);
651 
652  /* Send the slider value changed event with new slider value as parameter */
654 }
655 
662 {
663  MHEG5Int newValue;
664  switch (slider->orientation)
665  {
666  case MHEG5DOWN:
667  newValue = slider->sliderValue + slider->stepSize;
668  break;
669  case MHEG5UP:
670  newValue = slider->sliderValue - slider->stepSize;
671  break;
672  default:
673  return;
674  }
675 
676  if (newValue < slider->minValue)
677  {
678  newValue = slider->minValue;
679  }
680  if ((newValue + slider->portion) > slider->maxValue)
681  {
682  return;
683  }
684  slider->sliderValue = newValue;
685 
686  MHEG5displayRedraw((MHEG5Visible *) slider);
687 
688  /* Send the slider value changed event with new slider value as parameter */
690 }
691 
698 {
699  MHEG5Scene *scene;
700 
701  scene = MHEG5getCurrentScene();
702 
704  scene->currentInteractible = 0;
705 
707 }
708 
715 {
716  MHEG5Scene *scene;
717 
718  scene = MHEG5getCurrentScene();
719 
721  scene->currentInteractible = 0;
722 
724 }
725 
MHEG5Bool availabilityStatus
Definition: mh5root.h:52
MHEG5Int initialValue
Definition: mh5slider.h:51
MHEG5Visible visible
Definition: mh5slider.h:46
void MHEG5visibleActivate(MHEG5Visible *visible)
Apply the activation behaviour of the visible class. Apply the activation behaviour off the visible c...
Definition: mh5visible.c:306
MHEG5ErrorCode MHEG5getSliderValue(MHEG5Root *target, MHEG5GList *params)
This action retrieves the SliderValue from the target and stores it in the variable, passed as the second parameter of this action. Implementation of the GetSliderValue (Target, SliderValueVar) action of the slider class.
Definition: mh5slider.c:393
MHEG5Int sliderValue
Definition: mh5slider.h:60
void MHEG5sliderInit(MHEG5Slider *slider)
<Function description>="">
Definition: mh5slider.c:190
void MHEG5sliderLEFT(MHEG5Slider *slider)
Perform action of left arrow key on interacting Slider.
Definition: mh5slider.c:553
MHEG5Int originalStepSize
Definition: mh5slider.h:55
MHEG5GList * MHEG5resolveGenericInteger(MHEG5GList *params, MHEG5Int *value)
Definition: mh5object.c:510
MHEG5Final clazz
Definition: mh5root.h:55
void MHEG5interactibleDestruct(MHEG5Interactible *interactible)
MHEG5Int maxValue
Definition: mh5slider.h:63
MHEG5Colour sliderRefColour
Definition: mh5slider.h:57
void MHEG5visibleFree(MHEG5Visible *visible)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
Definition: mh5visible.c:186
void MHEG5sliderEXIT(MHEG5Slider *slider)
Perform action of exit key on interacting Slider.
Definition: mh5slider.c:714
void MHEG5sliderUP(MHEG5Slider *slider)
Perform action of up arrow key on interacting Slider.
Definition: mh5slider.c:589
void MHEG5visiblePrepare(MHEG5Visible *visible)
Apply the preparation behaviour off the visible class Apply the preparation behaviour of the visible ...
Definition: mh5visible.c:239
Implement the MHEG5 Slider Class. Slider Class. Defines the behaviour of sliders. Base class: Visible...
void MHEG5sliderActivate(MHEG5Slider *slider)
Apply the activation behaviour of the slider class. As this class has no own activation behaviour thi...
Definition: mh5slider.c:257
void MHEG5sliderDOWN(MHEG5Slider *slider)
Perform action of down arrow key on interacting Slider.
Definition: mh5slider.c:661
Implement the MHEG5 Variable Class 21 Variable Class Defines a variable within the context of a Group...
void MHEG5visibleDestruct(MHEG5Visible *visible)
Destruct a visible object.
Definition: mh5visible.c:282
long MHEG5Int
Definition: mh5base.h:73
void MHEG5interactibleDeactivate(MHEG5Interactible *interactible)
Implementation of the deactivation behaviour of the interactible class. This behaviour was introduced...
void MHEG5sliderPrepare(MHEG5Slider *slider)
Apply the preparation behaviour of the slider class Apply the preparation behaviour of the slider cla...
Definition: mh5slider.c:235
#define MHEG5displayRedraw(v)
Definition: mh5display.h:47
MHEG5ErrorCode MHEG5setSliderParameters(MHEG5Root *target, MHEG5GList *params)
The effect of this action is to set the MinValue, MaxValue and StepSize to the given values...
Definition: mh5slider.c:502
MHEG5ErrorCode MHEG5setSliderValue(MHEG5Root *target, MHEG5GList *params)
The effect of this action is to set the SliderValue to the given value. Implementation of the SetSlid...
Definition: mh5slider.c:353
MHEG5ErrorCode
Definition: mh5base.h:222
#define MHEG5colourDestruct
Definition: mh5base.h:62
MHEG5Int portion
Definition: mh5slider.h:61
MHEG5Int minValue
Definition: mh5slider.h:62
MHEG5ErrorCode MHEG5step(MHEG5Root *target, MHEG5GList *params)
The effect of this action is to modify the SliderValue of the target by the number given...
Definition: mh5slider.c:313
Event handling. Implementation of a combined queue for events and actions. This is the eventsystem wh...
void MHEG5sliderDestruct(MHEG5Slider *slider)
Destruct a slider object.
Definition: mh5slider.c:292
MHEG5Bool interactionStatus
void MHEG5sliderRIGHT(MHEG5Slider *slider)
Perform action of right arrow key on interacting Slider.
Definition: mh5slider.c:625
MHEG5Int originalMinValue
Definition: mh5slider.h:52
Implement functions to retrieve MHEG5objects by GroupID and ID.
Implementation of the MHEG5 Application Class Defines a set of Ingredient objects, which are shared within an application scope. Base class: Group Subclasses: None Status: Concrete class.
Implementation of the MHEG5 Scene Class Scene Class Defines a set of Ingredient objects to be activat...
Mheg5 logging and debug printing.
void MHEG5interactibleInteractionCompleted(MHEG5Interactible *interactible, MHEG5Root *item)
MHEG5Bool runningStatus
Definition: mh5root.h:51
MHEG5Ingredient ingredient
Definition: mh5visible.h:49
void MHEG5interactibleInit(MHEG5Interactible *interactible)
<Function description>="">
MHEG5Int originalMaxValue
Definition: mh5slider.h:53
MHEG5Orientation orientation
Definition: mh5slider.h:50
MHEG5Int stepSize
Definition: mh5slider.h:64
redirection include
MHEG5Interactible interactible
Definition: mh5slider.h:47
MHEG5Scene * MHEG5getCurrentScene(void)
<Function description>="">
Definition: mh5scene.c:207
void MHEG5sendEvent(MHEG5Root *source, MHEG5EventType event, MHEG5Int data)
Store an event in the asynchronous event queue.
Definition: mh5queue.c:1540
MHEG5ErrorCode MHEG5getPortion(MHEG5Root *target, MHEG5GList *params)
This action retrieves the size of the slider portion and stores it in the PortionVar, which is passed to this action as the second parameter. Implementation of the GetPortion (Target, PortionVar) action of the slider class.
Definition: mh5slider.c:464
MHEG5Root * currentInteractible
Definition: mh5scene.h:56
void MHEG5sliderFree(MHEG5Slider *slider)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
Definition: mh5slider.c:212
void MHEG5interactibleFree(MHEG5Interactible *interactible)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
MHEG5ErrorCode MHEG5setPortion(MHEG5Root *target, MHEG5GList *params)
This action sets the portion of the slider to a new value, given as the second parameter to this acti...
Definition: mh5slider.c:428
MHEG5GList * MHEG5resolveORef(MHEG5GList *params, MHEG5Root **object)
Definition: mh5object.c:126
MHEG5Int initialPortion
Definition: mh5slider.h:54
void MHEG5sliderDeactivate(MHEG5Slider *slider)
Apply the deactivation behaviour of the slider class. As this class has no own deactivation behaviour...
Definition: mh5slider.c:276
Implement generic MHEG5-display functions - independent from the OSD These are generic functions used...
void MHEG5visibleDeactivate(MHEG5Visible *visible)
Apply the deactivation behaviour of the visible class. As this class has no own deactivation behaviou...
Definition: mh5visible.c:338
void MHEG5interactiblePrepare(MHEG5Interactible *interactible)
Sets all internal attributes for the specified object to their default values.
void MHEG5sliderSELECT(MHEG5Slider *slider)
Perform action of select key on interacting Slider.
Definition: mh5slider.c:697
MHEG5SliderStyle sliderStyle
Definition: mh5slider.h:56
#define MHEG5FALSE
Definition: mh5base.h:48
void MHEG5visibleInit(MHEG5Visible *visible)
Initialise a visible object with default values.
Definition: mh5visible.c:172