subbrute_attack_view.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include "../subbrute_custom_event.h"
  3. #include <gui/view.h>
  4. #include <input/input.h>
  5. #include <gui/elements.h>
  6. typedef void (*SubBruteAttackViewCallback)(SubBruteCustomEvent event, void* context);
  7. typedef struct SubBruteAttackView SubBruteAttackView;
  8. /**
  9. * @brief Sets the callback function and context for the SubBruteAttackView.
  10. *
  11. * This function sets the callback function and context that will be used by the SubBruteAttackView
  12. * instance. The callback function will be called when a particular event occurs in the SubBruteAttackView.
  13. * The context parameter will be passed to the callback function as an argument.
  14. *
  15. * @param[in] instance The SubBruteAttackView instance to set the callback for.
  16. * @param[in] callback The callback function to be called when an event occurs.
  17. * @param[in] context The context to be passed to the callback function when it is called.
  18. *
  19. * @note The callback function should have the following signature:
  20. * `void callback(SubBruteCustomEvent event, void* context)`
  21. *
  22. * @note The callback function should not take ownership of the instance, it should only perform
  23. * the necessary logic based on the event.
  24. *
  25. * @warning The instance parameter must not be NULL.
  26. * @warning The callback parameter must not be NULL.
  27. */
  28. void subbrute_attack_view_set_callback(
  29. SubBruteAttackView* instance,
  30. SubBruteAttackViewCallback callback,
  31. void* context);
  32. /**
  33. * @brief Allocates memory for a new SubBruteAttackView object.
  34. *
  35. * This function allocates memory for a new @c SubBruteAttackView structure on the heap, assigns necessary properties
  36. * and returns a pointer to it. The SubBruteAttackView struct is consisted of attributes attack_type, max_value,
  37. * current_step, is_attacking and icon. The initial values are assigned in this function. It also sets up
  38. * the necessary callbacks for view drawing, input handling, and entrance/exit events.
  39. *
  40. * @note As there are no input parameters, @c tag is not required for this function. Instead, the structure
  41. * SubBruteAttackView and its members are initialized within the function.
  42. *
  43. * @return A pointer to a newly allocated @c SubBruteAttackView object.
  44. *
  45. */
  46. SubBruteAttackView* subbrute_attack_view_alloc();
  47. /**
  48. * @brief Frees the memory allocated for a SubBruteAttackView instance.
  49. *
  50. * The function verifies the provided instance, frees the icon animation in the
  51. * associated view model (if any), frees the view, and finally, frees the instance itself.
  52. * This effectively destroys the SubBruteAttackView instance and cleans up the associated resources.
  53. * After a call to this function, the provided pointer should not be used.
  54. *
  55. * @param[in] instance Pointer to the SubBruteAttackView instance to free.
  56. *
  57. */
  58. void subbrute_attack_view_free(SubBruteAttackView* instance);
  59. /**
  60. * @brief Retrieves the view associated with the SubBruteAttackView instance.
  61. *
  62. * @param[in] instance The SubBruteAttackView instance to retrieve the view from.
  63. *
  64. * @return A pointer to the associated view.
  65. *
  66. */
  67. View* subbrute_attack_view_get_view(SubBruteAttackView* instance);
  68. /**
  69. * @brief Sets the current step for the SubBruteAttackView instance.
  70. *
  71. * This function sets the current step of the SubBruteAttackView instance
  72. * to the specified value.
  73. *
  74. * @param [in] instance A pointer to the SubBruteAttackView instance.
  75. * @param [in] current_step The value to set as the current step.
  76. *
  77. * @note The current step represents the current progress of the attack view.
  78. * It should be an unsigned 64-bit integer.
  79. */
  80. void subbrute_attack_view_set_current_step(SubBruteAttackView* instance, uint64_t current_step);
  81. /**
  82. * @class SubBruteAttackView
  83. * @brief Class for initializing the values of a SubBruteAttackView instance.
  84. *
  85. * The SubBruteAttackView class is used to store and initialize the values
  86. * of a SubBruteAttackView instance. These values include the index, maximum value,
  87. * current step, attack status, and extra repeats.
  88. *
  89. * @note We need to call init every time, because not every time we call "enter"
  90. * normally, so call "enter" only once
  91. *
  92. * @param[in] instance A pointer to the instance of SubBruteAttackView to be initialized.
  93. * @param[in] index The starting index for attack.
  94. * @param[in] max_value The maximum value that could be used for the attack.
  95. * @param[in] current_step The current step of the attack.
  96. * @param[in] is_attacking A boolean flag to identify if the current instance is attacking.
  97. * @param[in] extra_repeats The number of extra repeats in the attack.
  98. *
  99. */
  100. void subbrute_attack_view_init_values(
  101. SubBruteAttackView* instance,
  102. uint8_t index,
  103. uint64_t max_value,
  104. uint64_t current_step,
  105. bool is_attacking,
  106. uint8_t extra_repeats);