开发者

Timers in Abstract Gui API

开发者 https://www.devze.com 2023-02-21 21:19 出处:网络
Here is the basic idea of what I want to do: Each widget, when part of the Gui has access to the event manager. The event manager is polymorphic so it contains functions from the underlying graphics

Here is the basic idea of what I want to do:

Each widget, when part of the Gui has access to the event manager. The event manager is polymorphic so it contains functions from the underlying graphics / timer api. What I want to do is, allow Widgets to register timers, where they would call a function which would internally call the event manager to register the timer. Here is the problem, when a widget is first created, it is not part of the Gui. Therefore, no one could ever register timers in the widget constructor.

I thought of the fact that I could queue requests and when the widget becomes part of a gui, and can access the event manager, it can then dequeue the requests, but the problem with this is that it doesn't really allow me to do something like:

Timer *timer = registerTimer(0.17);

if(timer == NULL)
{
   //uh ohs
}
else
{
   tim开发者_如何学JAVAer->start();
}

Are there maybe better ways around my problem?

Thanks


Event management and providing timing facilities are 2 very different functionalities, so I would try to decouple event manager into 2 separate classes. Then you could make TimerManager a singleton and register timers from any places you like.

Alternatively if you cannot decouple event manager class as it is now, you can try to make it a singleton and access timing facilities this way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号