How to return this data to C?

This is a problem of thought, and I struggled for about a day.

I am writing an engine for playing C (open source, for fun), and all the elements of the (read GUI) interface deal with mouse input in the interface of the Mouse () function. Basically, I regularly call interfaceMouse () to find out if the user acted with the interface.

I would like this function to take the last click of the mouse, looking to see if it interacts with any GUI element, and then returns how this mouse click interacts with the gui element.

Given two different gui elements:

  • (button pressed by user A)
  • select menu (user-selected option 1 of menu A)

I am trying to figure out how best to return the interface event of the calling function. In my opinion, now you have the appropriate lists for each type of event (buttonEvents, selectEvents) and functions like getNextButtonEvent (), which returns an event-dependent value. interfaceMouse () returns a value depending on the type of event triggered by the mouse event, and then the calling function will have to retrieve this event from the corresponding list using getNextTypeEvent ().

I am not very happy with this approach and wondered if anyone has a better idea or can provide additional foresight?

+3
source share
3 answers

I made a few assumptions from your description, but here is how I would handle this:

interfaceMouse() , , ( , , ). : interfaceMouse() , :

struct 
{
    int event_type; /* Enumerated type */
    void* element; /* Pointer to the element, however it defined in the code */
    void* event_data; /* Pointer to the data about the event */
 } event_result;

, , (, , event_data, ..).

C , , , .

+2

. , ​​ :

     +-------------------------------+
     | Stage():                      |
     |    +-OnButtonAClick(Event)    |
     |    +-OnMenuSelect(Event)      |
     |    +-...                      |
     +------+-------------+----------+
            | Pop()       |
            |             |
          +-V-+         +-V-+ 
          | Q |         | Q |     ...           Logic-Half
   -------| 0 |         | 1 |-----------------------------
          |   |         |   |                     I/O-Half
          +-^-+         +-^-+
            | Push()      |
       +----+---+     +---+----+  
       |Event of|     |Event of|  ...
       |  Mouse |     |  Menu  |
       +--------+     +--------+     

OnXXX() Stage(); . .

: Staged.

+2

, , , ? FIFO , , interfaceMouse(), , , . , interfaceMouse(), ? , - .

+1

Source: https://habr.com/ru/post/1722229/


All Articles