Good day,
I am trying to programmatically set focus on a VG_View widget that takes
up a whole window. It does not seem to work as expected. Below is a
test program to demonstrate the problem. I compile and run this program
on Linux. It opens an SDL window, which has focus. If I press a key,
the program prints no key-down lines. If I click anywhere in the window
and press a key, then the program generates key-down lines.
The debug messages show that AG_WidgetFocus() returns 1 for success, and
window->nFocused increases from 0 to 1. However, the debug messages
also show that AG_WidgetIsFocused() returns 0, which seems to contradict
the other results.
Am I missing a step to set focus on the VG_View widget? Any help would
be appreciated.
Thank you,
-Ben
/* *****
Compilation:
cc -g $(agar-config --cflags) $(agar-vg-config --cflags) vg.c
-L/home/ben/local/lib -Wl,-R/home/ben/local/lib $(agar-config --libs)
$(agar-vg-config --libs) -lSDL_image
Output:
DEBUG before AG_WindowFocus
DEBUG Window focus=0
DEBUG Widget focus=0
DEBUG Window nFocused=0
DEBUG result=0
DEBUG after AG_WindowFocus, before AG_WidgetFocus
DEBUG Window focus=0
DEBUG Widget focus=0
DEBUG Window nFocused=0
DEBUG result=0
DEBUG after AG_WidgetFocus
DEBUG Window focus=0
DEBUG Widget focus=0
DEBUG Window nFocused=1
DEBUG result=1
DEBUG key-down unicode=103
***** */
#include <stdio.h>
#include <agar/core.h>
#include <agar/gui.h>
#include <agar/vg.h>
void callback(AG_Event *event) {
unsigned long unicode = AG_ULONG_NAMED("unicode");
printf("DEBUG key-down unicode=%ld\n", unicode);
return;
}
void debugme(AG_Window *win, VG_View *view, int result, char *text) {
printf("DEBUG %s\n", text);
printf("DEBUG Window focus=%d\n", AG_WindowIsFocused(win));
printf("DEBUG Widget focus=%d\n", AG_WidgetIsFocused(view));
printf("DEBUG Window nFocused=%d\n", win->nFocused);
printf("DEBUG result=%d\n\n", result);
return;
}
int main(int argc, char *argv[]) {
int result;
AG_Window *win;
VG *vg;
VG_Circle *circle;
VG_Color color;
VG_Point *point;
VG_Vector pos;
VG_View *view;
result = AG_InitCore("agarswig-vg-demo", AG_NO_CFG_AUTOLOAD);
if (result == -1) {
puts(AG_GetError());
exit(1);
}
result = AG_InitGraphics("sdlfb(width=256:height=176:depth=32");
if (result == -1) {
puts(AG_GetError());
exit(1);
}
VG_InitSubsystem();
vg = VG_New(0);
pos = VG_GetVector(128.0, 88.0);
point = VG_PointNew(vg->root, pos);
circle = VG_CircleNew(vg->root, point, 50);
color = VG_GetColorRGB(255, 0, 0);
VG_SetColorv(circle, &color);
win = AG_WindowNew(AG_WINDOW_PLAIN);
AG_WindowSetGeometryMax(win);
view = VG_ViewNew(win, vg, VG_VIEW_EXPAND);
AG_SetEvent(view, "key-down", callback, NULL);
debugme(win, view, 0, "before AG_WindowFocus");
AG_WindowFocus(win);
debugme(win, view, 0, "after AG_WindowFocus, before AG_WidgetFocus");
AG_WidgetSetFocusable(view, 1);
result = AG_WidgetFocus(view);
debugme(win, view, result, "after AG_WidgetFocus");
AG_WindowShow(win);
AG_EventLoop();
VG_Destroy(vg);
VG_DestroySubsystem();
AG_QuitGUI();
exit(0);
}
_______________________________________________
Agar mailing list
[email protected]
http://libagar.org/lists.html