VisualTheme.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // zlib open source license
  2. //
  3. // Copyright (c) 2018 to 2023 David Forsgren Piuva
  4. //
  5. // This software is provided 'as-is', without any express or implied
  6. // warranty. In no event will the authors be held liable for any damages
  7. // arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it
  11. // freely, subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented; you must not
  14. // claim that you wrote the original software. If you use this software
  15. // in a product, an acknowledgment in the product documentation would be
  16. // appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such, and must not be
  19. // misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source
  22. // distribution.
  23. #ifndef DFPSR_GUI_VISUALTHEME
  24. #define DFPSR_GUI_VISUALTHEME
  25. #include "../../api/mediaMachineAPI.h"
  26. #include "componentStates.h"
  27. namespace dsr {
  28. // ---------------------------------------- WARNING! ----------------------------------------
  29. //
  30. // This API is not yet finished and may break backwards compatibility before completed.
  31. // It is not yet decided if the media machine will expose virtual assembly code,
  32. // which syntax to define themes using or if themes should be bundled together into archives.
  33. //
  34. // ------------------------------------------------------------------------------------------
  35. // TODO: Move to the API folder once complete.
  36. // A handle to a GUI theme.
  37. // Themes describes the visual appearance of an interface.
  38. // By having more than one theme for your interface, you can let the user select one.
  39. class VisualThemeImpl;
  40. using VisualTheme = Handle<VisualThemeImpl>;
  41. // Create a theme using a virtual machine with functions to call, style settings telling which functions to call with what arguments, and a path to load any non-embedded images from.
  42. VisualTheme theme_createFromText(const MediaMachine &machine, const ReadableString &styleSettings, const ReadableString &fromPath);
  43. // Create a theme using a virtual machine with functions to call, and a path to the style settings to load.
  44. // Any non-embedded images will be loaded relative to styleFilename's folder;
  45. VisualTheme theme_createFromFile(const MediaMachine &machine, const ReadableString &styleFilename);
  46. // Get a handle to the default theme.
  47. VisualTheme theme_getDefault();
  48. // Returns true iff theme exists, otherwise false.
  49. bool theme_exists(const VisualTheme &theme);
  50. // Returns the index of className in theme, 0 if it did not exist in theme or -1 if theme does not exist.
  51. int theme_getClassIndex(const VisualTheme &theme, const ReadableString &className);
  52. // Returns true iff className exists in theme.
  53. bool theme_class_exists(const VisualTheme &theme, const ReadableString &className);
  54. // Returns suggestedClassName if it exists in theme, fallbackClassName otherwise.
  55. String theme_selectClass(const VisualTheme &theme, const ReadableString &suggestedClassName, const ReadableString &fallbackClassName);
  56. // Getters for resources in the theme's *.ini configuration file.
  57. // If className is not found in the theme, the settings declared before the first class are used.
  58. // This allow unhandled components to have a generic look, get a pattern that signals unfinished work or leave it blank to terminate with an error when a class is not handled.
  59. // Settings after the class name within [] until the end of the file or next class belong to that class.
  60. // Get the scalable image created using the media machine method name stored in the string setting "method" within className in theme.
  61. // If there is no method name assigned to "method" after [className], the "method" before the first [] block is used instead.
  62. // If no method is found at all, it means that the theme wants to throw an exception to alert the developer about a class that needs to be handled.
  63. // The matches for className and "method" are both case insensitive.
  64. MediaMethod theme_getScalableImage(const VisualTheme &theme, const ReadableString &className);
  65. // TODO: Create syntax for naming sub-image regions within the atlas to be used as icons without needing to load separate files.
  66. // Get a fixed size image from className in theme using settingName, an empty handle if not found in theme or theme does not exist.
  67. // Looks for image assignments to settingName after [className] first, then before the first [] block, and then returns an empty handle if not found at all.
  68. // The matches for className and settingName are both case insensitive.
  69. // Use theme_getClassIndex if you are unsure of why an empty handle was returned, because it will not throw exceptions.
  70. OrderedImageRgbaU8 theme_getImage(const VisualTheme &theme, const ReadableString &className, const ReadableString &settingName);
  71. // Get a fixed-point value from className in theme using settingName, the default value if not found, or throw an exception if theme does not exist.
  72. // Looks for scalar assignments to settingName after [className] first, then before the first [] block, and then returns defaultValue if not found at all.
  73. // The matches for className and settingName are both case insensitive.
  74. // Use theme_getClassIndex if you are unsure of why defaultValue was returned, because it will not throw exceptions.
  75. FixedPoint theme_getFixedPoint(const VisualTheme &theme, const ReadableString &className, const ReadableString &settingName, const FixedPoint &defaultValue);
  76. // Get FixedPoint and truncate to an integer, which should leave 16 bits of useful range.
  77. int theme_getInteger(const VisualTheme &theme, const ReadableString &className, const ReadableString &settingName, const int &defaultValue);
  78. // Get a string from className in theme using settingName, the default value if not found, or throw an exception if theme does not exist.
  79. // Looks for string assignments to settingName after [className] first, then before the first [] block, and then returns defaultValue if not found at all.
  80. // The matches for className and settingName are both case insensitive.
  81. // Use theme_getClassIndex if you are unsure of why defaultValue was returned, because it will not throw exceptions.
  82. ReadableString theme_getString(const VisualTheme &theme, const ReadableString &className, const ReadableString &settingName, const FixedPoint &defaultValue);
  83. // Called by VisualComponent to assign input arguments to functions in the media machine that were not given by the component itself.
  84. // Post-condition: Returns true if argumentName was identified and assigned as input to inputIndex of methodIndex in machine.
  85. bool theme_assignMediaMachineArguments(const VisualTheme &theme, int contextIndex, MediaMachine &machine, int methodIndex, int inputIndex, const ReadableString &argumentName);
  86. // Post-condition:
  87. // Returns a bit-mask for the direct states that have corresponding input arguments in the method.
  88. // Includes the componentState_focusDirect bit if the method has an input argument named "focused".
  89. // Includes the componentState_hoverDirect bit if the method has an input argument named "hover".
  90. ComponentState theme_getStateListenerMask(const MediaMethod &scalableImage);
  91. }
  92. #endif