+
+
+static int hittest(rtk_widget *w, int x, int y)
+{
+ if(x < w->any.x || y < w->any.y) return 0;
+ if(x >= w->any.x + w->any.width) return 0;
+ if(y >= w->any.y + w->any.height) return 0;
+ return 1;
+}
+
+static void sethover(rtk_widget *w)
+{
+ if(hover == w) return;
+
+ if(hover) {
+ hover->any.flags &= ~HOVER;
+ }
+ hover = w;
+ if(w) {
+ w->any.flags |= HOVER;
+ }
+}
+
+static void setpress(rtk_widget *w)
+{
+ if(pressed == w) return;
+
+ if(pressed) {
+ pressed->any.flags &= ~PRESS;
+ }
+ pressed = w;
+ if(w) {
+ w->any.flags |= PRESS;
+ }
+}
+
+static void click(rtk_widget *w, int x, int y)
+{
+ switch(w->type) {
+ case RTK_BUTTON:
+ if(w->bn.mode == RTK_TOGGLEBN) {
+ case RTK_CHECKBOX:
+ w->any.value ^= 1;
+ }
+ if(w->any.cbfunc) {
+ w->any.cbfunc(w, w->any.cbcls);
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+int rtk_input_key(rtk_widget *w, int key, int press)
+{
+ return 0;
+}
+
+int rtk_input_mbutton(rtk_widget *w, int bn, int press, int x, int y)
+{
+ if(!hittest(w, x, y)) {
+ return 0;
+ }
+
+ if(press) {
+ if(hover && hittest(hover, x, y)) {
+ setpress(hover);
+ }
+ } else {
+ if(pressed && hittest(pressed, x, y)) {
+ click(pressed, x, y);
+ }
+ setpress(0);
+ }
+
+ return 1;
+}
+
+int rtk_input_mmotion(rtk_widget *w, int x, int y)
+{
+ rtk_widget *c;
+
+ if(!hittest(w, x, y)) {
+ int res = hover ? 1 : 0;
+ sethover(0);
+ return res;
+ }
+
+ if(w->type == RTK_WIN) {
+ c = w->win.clist;
+ while(c) {
+ if(hittest(c, x, y)) {
+ return rtk_input_mmotion(c, x, y);
+ }
+ c = c->any.next;
+ }
+ }
+
+ if(hover != w) {
+ sethover(w);
+ return 1;
+ }
+ return 0;
+}