libcm is a C development framework with an emphasis on audio signal processing applications.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cmUi.h 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. #ifndef cmUi_h
  2. #define cmUi_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*
  7. cmUI implements a platform independent UI control manager
  8. for multiple simultaneous applications. In this context
  9. an 'application' can be seen as a plug-in style program.
  10. The goal of the manager is to support the easy construction
  11. of panels of graphic user interface controls.
  12. Operation:
  13. 1) A cmUi manager is allocated by the master program. See cmUiAlloc().
  14. 2) The master program then assigns a 'driver' to implmenent
  15. the commands issued by cmUi. All commands can be
  16. described using the cmUiDriverArg_t record.
  17. 3) The master program then registers client applications with
  18. the cmUi manager by calling cmUiCreateApp().
  19. 4) Prior to calling any of the client application functions
  20. the master or client app. must call cmUiSetAppId(). This
  21. function sets the current application id and thereby slightly
  22. simplifies the client app interface by not requiring the
  23. app id be passed with every client app. function call.
  24. 5) Once the current app. id is set with cmUiSetAppId()
  25. the client app can make multiple calls to the cmUi manager
  26. to create or query controls.
  27. 6) Calls to create controls result in callbacks to the
  28. driver function which manages the actual windowing and
  29. initial event handling.
  30. 7) Events generated by the driver based graphic controls
  31. are routed back to the cmUi manager through calls to
  32. cmUiOnDriverEvent().
  33. 8) The cmUiOnDriverEvent() internally caches the
  34. state/value of the control based on the event information
  35. and calls the 'cbFunc' function registered with the
  36. cmUi manager by cmUiAlloc(). This call is intended to
  37. notify the client applications of changes in the state/value
  38. of a user interface control.
  39. Notes:
  40. 1) Application id's must be unique among all applications.
  41. Control id's must be unique among all controls assigned
  42. to the same application. Both application and control id's
  43. are used internally as array indexes they should therefore
  44. be the low, positive, and densely packed integers.
  45. 2) All communication between the cmUi and the driver,
  46. and all callbacks from the cmUi to the master app.
  47. use the cmUiDriverArg_t structure
  48. 3) The panel tabs act like radio buttons. When a tab is
  49. selected the clicked tab generates one event for each
  50. tab (cId=kPanelUiCId usrId=panelId) w/ ival=1 for the
  51. selected tab and ival=0 for all other tabs.
  52. TODO:
  53. 0) [DONE] Remove the 'cbArg' from the cmUiDriverArg_t record and
  54. pass it as a separate paramenter in the cmUiDriverFunc_t calls.
  55. 1) The controls should be based on a multilevel tree model
  56. not the simple two layer panel->controls framework used now.
  57. 2) Given that access to the control values can be non-blocked
  58. and fast many controls won't need to report changes back to
  59. the client - the client can simply read the control value
  60. as necessary directly from the cmUi manager. To decrease
  61. event processing overhead controls should therefore be
  62. flagged as 'callback/no-callback'. Some controls like
  63. buttons should default to turning the flag on, while other
  64. controls, like numbers, should default to turning it off.
  65. 3) Implement support for the creation of arrays of controls.
  66. This can be implemented with a scheme similar to 'next rect'.
  67. cmUiSetupArray(uiH,panelId,baseCtlId,cnt).
  68. 4) Come up with a threading model. For example maybe
  69. control creation should use a blocking scheme since it is
  70. generally to time consuming to do during real-time operation
  71. anyway. If the control flow generated from driver event
  72. callbacks then allows value, but not structural changes,
  73. then non blocking will be necessary.
  74. 5) The cmUiDriverArg_t structure is used for both
  75. commands to the driver and callbacks from the driver.
  76. Many of the fields are not use for event callbacks.
  77. Which fields are used under which circumstances should
  78. be documented. This would allow decreasing the size
  79. of the record during serialization.
  80. 6) [DONE] Write a serialization/deserialization routines for cmUiDriverArg_t.
  81. unsigned cmUiDriverArgSerialBufByteCount(const cmUiDriverArg_t* a);
  82. cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, char* buf, bufByteCnt );
  83. cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, const char* buf, bufByteCnt );
  84. 7) There is no duplex model for validating and then displaying the
  85. value of a control.
  86. */
  87. typedef cmHandle_t cmUiH_t;
  88. extern cmUiH_t cmUiNullHandle;
  89. //=============================================================================================
  90. //
  91. // Master program API
  92. //
  93. // Allocate the cmUi manager. If the driver function is not
  94. // yet available then set drvrFunc to NULL and use
  95. // cmUiSetDriver() to set the driver function at a later
  96. // time. cmUiAlloc() stores but does not call the driver
  97. // and so it is not needed when the cmUI manager is
  98. // constructed - however it must be set prior to making
  99. // any other calls to the manager.
  100. cmUiRC_t cmUiAlloc(
  101. cmCtx_t* ctx,
  102. cmUiH_t* hp,
  103. cmUiDriverFunc_t drvrFunc, // UI driver function
  104. void* drvrArg,
  105. cmUiDriverFunc_t cbFunc, // client event callback function
  106. void* cbArg );
  107. // Release all apps but assume that the driver has already
  108. // been released.
  109. cmUiRC_t cmUiFree( cmUiH_t* hp );
  110. // Validate the cmUiH_t handle.
  111. bool cmUiIsValid( cmUiH_t h );
  112. // Set the driver function. This function allows the driver
  113. // set in cmUiAlloc() to be replaced or set following the
  114. // call to cmUiAlloc().
  115. //
  116. // By setting the driver function to
  117. // NULL the application can prevent callback to the driver.
  118. // This is useful if the driver has been release prior
  119. // to the UI manager begining destroyed.
  120. void cmUiSetDriver( cmUiH_t h, cmUiDriverFunc_t drvrFunc, void* drvrArg );
  121. // Register a client application with the cmUi manager.
  122. // 'appId' must not have been used by any other previously registered.
  123. // application.
  124. // Automatically sets and restores the ambient appId.
  125. // In a plug-in context this function is generally called
  126. // just prior a instantiating a plug-in object.
  127. cmUiRC_t cmUiCreateApp( cmUiH_t uiH, unsigned appId, unsigned asSubIdx );
  128. // Return true if 'appId' is active.
  129. bool cmUiAppIsActive( cmUiH_t uiH, unsigned appId );
  130. // Notify the cmUi manager that the resources associated
  131. // with a client application can be released.
  132. // Automatically sets and restores the ambient appId.
  133. cmUiRC_t cmUiDestroyApp( cmUiH_t uiH, unsigned appId );
  134. // Release all apps.
  135. // Automatically sets and restores the ambient appId.
  136. cmUiRC_t cmUiDestroyAllApps( cmUiH_t h );
  137. // The master program sets the ambient 'appId' prior to passing control
  138. // to a client which will make User API calls. By making the
  139. // 'appId' an ambient parameter the User API calls are slightly
  140. // simplified because they do not have to include it in each of the
  141. // function calls.
  142. //cmUiRC_t cmUiSetAppId( cmUiH_t uiH, unsigned appId );
  143. //unsigned cmUiAppId( cmUiH_t uiH );
  144. unsigned cmUiAppIdToAsSubIndex( cmUiH_t uiH, unsigned appId );
  145. // Return the count of app's.
  146. unsigned cmUiAppCount( cmUiH_t uiH );
  147. // Callbacks from the driver arrive via this function.
  148. cmUiRC_t cmUiOnDriverEvent( cmUiH_t uiH, const cmUiDriverArg_t* p );
  149. //=============================================================================================
  150. //
  151. // Client Application API
  152. //
  153. // See above note on panel tabs acting like radio buttons.
  154. cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned appId, unsigned newPanelId, const cmChar_t* label, unsigned flags );
  155. cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  156. cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt );
  157. cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  158. cmUiRC_t cmUiCreateString( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text );
  159. cmUiRC_t cmUiCreateConsole( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text );
  160. cmUiRC_t cmUiCreateNumber( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt );
  161. cmUiRC_t cmUiCreateHSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt );
  162. cmUiRC_t cmUiCreateVSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt );
  163. cmUiRC_t cmUiCreateProgress( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  164. cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  165. cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  166. cmUiRC_t cmUiCreateFileBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir, const cmChar_t* patStr );
  167. cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir );
  168. cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  169. cmUiRC_t cmUiCreateMenuBtnV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, va_list vl );
  170. cmUiRC_t cmUiCreateMenuBtnA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, ... );
  171. cmUiRC_t cmUiCreateMenuBtnJson( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmJsonNode_t* root, const cmChar_t* memberLabel );
  172. cmUiRC_t cmUiCreateList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt );
  173. cmUiRC_t cmUiCreateListV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, va_list vl );
  174. cmUiRC_t cmUiCreateListA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, ... );
  175. cmUiRC_t cmUiCreateListJson( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmJsonNode_t* root, const cmChar_t* memberLabel );
  176. // If 'id' identifies a 'list' control use tabs as column separators.
  177. cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId );
  178. // Remove all the elements of a list control.
  179. cmUiRC_t cmUiClearList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id );
  180. // Enable/Disable a control
  181. cmUiRC_t cmUiEnableCtl( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, bool enableFl );
  182. // Enable/disable all controls on a panel except those included in the var args list.
  183. // Terminate the var args list with cmInvalidId.
  184. cmUiRC_t cmUiEnableAllExceptV( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, va_list vl );
  185. cmUiRC_t cmUiEnableAllExcept( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, ... );
  186. // If 'id' identifies a panel then all control belonging to the panel
  187. // will also be destroyed.
  188. cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned appId, unsigned id );
  189. // Returns true if the control exists.
  190. // For panels set id=panelId.
  191. //bool cmUiCtlExists( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id );
  192. // Destroy all the controls in a panel.
  193. cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned appId, unsigned panelId );
  194. //------------------------------------------------------------------------------------------
  195. // Location:
  196. // 1) If a 'next rect' is set the control will be placed according to it.
  197. // 2) If cmUiSetBaseCol() was set then the control will be placed at the
  198. // base col and base row.
  199. // 3) If cmUiPlaceRight() or cmUIPlaceBelow() have been called since the
  200. // previous control was created then the new control will be placed
  201. // accordingly.
  202. // 4) The control will be placed according to the 'fill rows' flag.
  203. // If not set (default) the new control will be placed in the
  204. // base column below the previous control.
  205. // If 'fill rows' is set the new control will be placed on the
  206. // same row to the right of the previous control.
  207. // If there is no previous control then it will be placed
  208. // in the base column and base row.
  209. // Get/Set the fill directions. If the 'fill columns' flag is enabled
  210. // then the next control is placed below the previous control otherwise
  211. // the next control is placed to the right of the next control.
  212. bool cmUiFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId );
  213. bool cmUiSetFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl );
  214. // Place the next control to the right/below of the previous ctl.
  215. // These flags override the current fill row/col setting.
  216. // Note that 'place right' and 'place below' are mutually
  217. // exclusive. Enabling one disables the other.
  218. void cmUiPlaceRight( cmUiH_t uiH, unsigned appId, unsigned panelId );
  219. void cmUiPlaceBelow( cmUiH_t uiH, unsigned appId, unsigned panelId );
  220. // Place the next control at the base column below the previous ctl.
  221. void cmUiNewLine( cmUiH_t uiH, unsigned appId, unsigned panelId );
  222. // Set/Get current base col and return previous value. Place the next
  223. // control on the base row.
  224. int cmUiBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId );
  225. int cmUiSetBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId, int x );
  226. // Set/Get current base row and return previous value.
  227. int cmUiBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId );
  228. int cmUiSetBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId, int y );
  229. // Size:
  230. // 1) If a 'next rect' is set the control will be placed according
  231. // to it.
  232. // 2) If a 'next w/h' is set the control will be placed according
  233. // to it. The 'next w/h' setting is only active for the
  234. // next control created.
  235. // 3) The w/h of the new control will be set to the default w/h.
  236. //
  237. // Get/Set the default control width and height.
  238. // Set returns previous value.
  239. int cmUiW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  240. int cmUiH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  241. int cmUiSetW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  242. int cmUiSetH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  243. void cmUiSetWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h );
  244. // Get/Set the control width and height for only the next control.
  245. // Set returns previous value.
  246. int cmUiNextW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  247. int cmUiNextH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  248. void cmUiSetNextW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  249. void cmUiSetNextH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  250. void cmUiSetNextWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h );
  251. // Get/Set the default inter-control borders
  252. // Set returns previous value.
  253. int cmUiHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  254. int cmUiVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  255. int cmUiSetHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  256. int cmUiSetVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  257. // Get/Set the 'next' inter-control borders
  258. // Set returns previous value.
  259. int cmUiNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  260. int cmUiNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  261. int cmUiSetNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  262. int cmUiSetNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  263. // Place the next control at the following coordinates. The
  264. // specified coordinates are only active during the next
  265. // cmUiCreateXXX() call. Setting the 'next rect' overrides all
  266. // other layout directives.
  267. cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int x, int y, int w, int h );
  268. // Get the location/size of the previously created control.
  269. // All ref. args are optional.
  270. cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef );
  271. int cmUiPrevL( cmUiH_t uiH, unsigned appId, unsigned panelId );
  272. int cmUiPrevT( cmUiH_t uiH, unsigned appId, unsigned panelId );
  273. int cmUiPrevR( cmUiH_t uiH, unsigned appId, unsigned panelId );
  274. int cmUiPrevB( cmUiH_t uiH, unsigned appId, unsigned panelId );
  275. int cmUiPrevW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  276. int cmUiPrevH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  277. //------------------------------------------------------------------------------------------
  278. //
  279. // Get/set the value of UI control.
  280. //
  281. // TODO:
  282. // + Need functions for setting auxilliary values like
  283. // min,max,etc..
  284. // Set the value associated with a control.
  285. // Set the local value of the specified control and then
  286. // send the value to the UI driver so that the UI reflects this value.
  287. cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned appId, unsigned id, int v );
  288. cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned appId, unsigned id, unsigned v );
  289. cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned appId, unsigned id, double v );
  290. cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* v );
  291. cmUiRC_t cmUiSetVPrintf(cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, va_list vl );
  292. cmUiRC_t cmUiSetPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, ... );
  293. // Get the value associated with a control. These functions return
  294. // the control value cached in the local control, they do not need
  295. // to call the driver and are therefore very fast.
  296. int cmUiInt( cmUiH_t uiH, unsigned appId, unsigned id );
  297. unsigned cmUiUInt( cmUiH_t uiH, unsigned appId, unsigned id );
  298. double cmUiDouble( cmUiH_t uiH, unsigned appId, unsigned id );
  299. const cmChar_t* cmUiString( cmUiH_t uiH, unsigned appId, unsigned id );
  300. unsigned cmUiListEleCount( cmUiH_t uiH, unsigned appId, unsigned id );
  301. unsigned cmUiListEleId( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index );
  302. const cmChar_t* cmUiListEleLabel( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index );
  303. // Query/set the current error state.
  304. cmUiRC_t cmUiLastRC( cmUiH_t uiH );
  305. cmUiRC_t cmUiSetRC( cmUiH_t uiH, cmUiRC_t rc );
  306. #ifdef __cplusplus
  307. }
  308. #endif
  309. #endif