What are these functions called and how to implement they?
frame
frame86 at live.com
Thu Jan 28 18:56:15 UTC 2021
On Thursday, 28 January 2021 at 18:27:09 UTC, frame wrote:
> Not 100% sure what you mean but I guess you ask how to
> implement a handler? If an event occurs, a routine decides to
> call your onKeyPressed function and pass the keyCode which was
> pressed. The routine must be registered on a event source that
> will emit the events. The routine is basically just a callback
> and that is indeed called every frame again if an event occurs.
A very simple example:
bool myEventA = true;
bool myEventB = false;
// event source that generates the event (must be called to run)
void source() {
observe(myEventA);
}
// routine that decides what handler to call
void observe(bool event) {
switch (event) {
case true:
onMyEventA(event);
break;
case false:
onMyEventB(event);
break;
default:
assert(0);
}
}
// handler
void onMyEventA(bool event) {
// do something
}
void onMyEventB(bool event) {
// do something
}
More information about the Digitalmars-d-learn
mailing list