Primary output is now via GDK/GTK!
This commit is contained in:
parent
8da561ed7c
commit
4cd6eca4ed
2 changed files with 137 additions and 67 deletions
6
Makefile
6
Makefile
|
@ -36,11 +36,11 @@ BUILD_RELEASE_DIR=.release
|
|||
|
||||
CC=gcc -m32
|
||||
|
||||
override BASE_CFLAGS += -Dstricmp=strcasecmp -Wunused -I./include/
|
||||
override BASE_CFLAGS += -Dstricmp=strcasecmp -Wunused -I./include/ `pkg-config --cflags gtk+-2.0`
|
||||
RELEASE_CFLAGS=$(BASE_CFLAGS) -funroll-loops -ffast-math -fomit-frame-pointer -funsigned-char -fno-strength-reduce
|
||||
DEBUG_CFLAGS=$(BASE_CFLAGS) -g
|
||||
override LDFLAGS += -lm -ldl
|
||||
XLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext -lXxf86dga
|
||||
XLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext -lXxf86dga `pkg-config --libs gtk+-2.0`
|
||||
XCFLAGS=-DX11
|
||||
|
||||
DO_CC=$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
@ -552,7 +552,7 @@ $(BUILDDIR)/tracker_main.o :$(MOUNT_DIR)/../tracker/tracker_main.c
|
|||
$(BUILDDIR)/sys_linux.o :$(MOUNT_DIR)/../system/sys_linux.c
|
||||
$(DO_CC)
|
||||
|
||||
$(BUILDDIR)/vid_x.o: $(MOUNT_DIR)/../video/vid_x.c
|
||||
$(BUILDDIR)/vid_x.o: $(MOUNT_DIR)/../video/vid_gdk.c
|
||||
$(DO_O_CC)
|
||||
|
||||
$(BUILDDIR)/snd_dma.o : $(MOUNT_DIR)/../audio/snd_dma.c
|
||||
|
|
198
video/vid_gdk.c
198
video/vid_gdk.c
|
@ -36,39 +36,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "globaldef.h"
|
||||
#include "d_local.h"
|
||||
#include "../splash.xpm"
|
||||
|
||||
viddef_t vid; // global video state
|
||||
unsigned short d_8to16table[256];
|
||||
|
||||
int num_shades = 32;
|
||||
int gdk_initialized = 0;
|
||||
static int vid_frame[4];
|
||||
|
||||
float mouse_x, mouse_y;
|
||||
float old_mouse_x, old_mouse_y;
|
||||
qboolean mouse_enabled;
|
||||
cvar_t *m_filter;
|
||||
extern int deathcam_yesiamdead; // eukara - deathca
|
||||
|
||||
extern int deathcam_yesiamdead;
|
||||
int p_mouse_x;
|
||||
int p_mouse_y;
|
||||
int d_con_indirect = 0;
|
||||
|
||||
int vid_buffersize;
|
||||
|
||||
static GtkWidget *x_win;
|
||||
static GtkWidget *x_splash_image, *x_splash;
|
||||
|
||||
static GdkGC *x_gc;
|
||||
|
||||
GdkDisplay *x_disp;
|
||||
GdkScreen *x_screen;
|
||||
|
||||
static GdkRgbCmap *x_cmap = NULL;
|
||||
static GdkDisplay *display = NULL;
|
||||
static GdkScreen *screen = NULL;
|
||||
|
||||
static unsigned char *x_framebuffer = NULL;
|
||||
|
||||
static int verbose = 0;
|
||||
|
||||
static long X11_highhunkmark;
|
||||
static long X11_buffersize;
|
||||
|
||||
|
@ -90,9 +85,7 @@ void TragicDeath(int signal_num)
|
|||
|
||||
void ResetFrameBuffer(void)
|
||||
{
|
||||
int mem;
|
||||
if (x_framebuffer)
|
||||
free(x_framebuffer);
|
||||
//int mem;
|
||||
|
||||
if (d_pzbuffer) {
|
||||
D_FlushCaches();
|
||||
|
@ -108,35 +101,41 @@ void ResetFrameBuffer(void)
|
|||
d_pzbuffer = Hunk_HighAllocName(X11_buffersize, "video");
|
||||
|
||||
if (d_pzbuffer == NULL)
|
||||
Sys_Error("Not enough memory for video mode\n");
|
||||
Sys_Error ("[VIDEO] Not enough memory for video mode\n");
|
||||
|
||||
vid_surfcache = (byte *) d_pzbuffer + vid.width * vid.height * sizeof(*d_pzbuffer);
|
||||
|
||||
D_InitCaches(vid_surfcache, vid_surfcachesize);
|
||||
|
||||
mem = ((vid.width + 7) & ~7) * vid.height;
|
||||
//mem = ((vid.width + 7) & ~7) * vid.height;
|
||||
|
||||
if (x_framebuffer)
|
||||
free(x_framebuffer);
|
||||
|
||||
x_framebuffer = malloc(vid.width * vid.height * 3);
|
||||
|
||||
if (!x_framebuffer)
|
||||
Sys_Error("VID: gdk_image_new failed\n");
|
||||
Sys_Error("[VIDE] Failed to reset framebuffer!\n");
|
||||
|
||||
vid.buffer = (byte *) (x_framebuffer);
|
||||
vid.conbuffer = vid.buffer;
|
||||
//vid.buffer = (byte *) (x_framebuffer);
|
||||
// vid.conbuffer = vid.buffer;
|
||||
}
|
||||
|
||||
// Called at startup to set up translation tables, takes 256 8 bit RGB values
|
||||
// the palette data will go away after the call, so it must be copied off if
|
||||
// the video driver will need it again
|
||||
|
||||
int config_notify=0;
|
||||
int config_notify_width;
|
||||
int config_notify_height;
|
||||
|
||||
void VID_Init(unsigned char *palette)
|
||||
{
|
||||
int pnum;
|
||||
GdkWindowAttr attr;
|
||||
struct sigaction sa;
|
||||
XWMHints wmhints;
|
||||
|
||||
vid.width = 320;
|
||||
vid.height = 200;
|
||||
|
||||
vid.width = 640;
|
||||
vid.height = 480;
|
||||
|
||||
if ((pnum=COM_CheckParm("-winsize")))
|
||||
{
|
||||
|
@ -182,22 +181,50 @@ void VID_Init(unsigned char *palette)
|
|||
sigaction(SIGINT, &sa, 0);
|
||||
sigaction(SIGTERM, &sa, 0);
|
||||
|
||||
/* setup attributes for main window */
|
||||
memset(&attr, 0, sizeof(attr));
|
||||
display = gdk_display_get_default ();
|
||||
screen = gdk_display_get_default_screen (display);
|
||||
|
||||
/* create the main window */
|
||||
/* create the main window */
|
||||
x_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(GTK_WINDOW(x_win), "NGUNIX X11");
|
||||
gtk_window_set_default_size(GTK_WINDOW(x_win), vid.width, vid.height);
|
||||
gtk_window_set_title(x_win, "NGUNIX X11");
|
||||
gtk_window_set_default_size(x_win, vid.width, vid.height);
|
||||
gtk_widget_set_size_request(x_win, 320, 200);
|
||||
gtk_window_set_position(x_win,GTK_WIN_POS_CENTER_ALWAYS);
|
||||
g_signal_connect (x_win, "destroy", G_CALLBACK (exit), NULL);
|
||||
gtk_widget_set_events(x_win, GDK_BUTTON_PRESS_MASK);
|
||||
|
||||
// FOR LATER!
|
||||
/*
|
||||
GtkWidget *menubar;
|
||||
GtkWidget *fileMenu;
|
||||
GtkWidget *fileMi;
|
||||
GtkWidget *quitMi;
|
||||
GtkWidget *vbox;
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(x_win), vbox);
|
||||
|
||||
menubar = gtk_menu_bar_new();
|
||||
fileMenu = gtk_menu_new();
|
||||
|
||||
fileMi = gtk_menu_item_new_with_label("File");
|
||||
quitMi = gtk_menu_item_new_with_label("Quit");
|
||||
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileMi), fileMenu);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), quitMi);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), fileMi);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);*/
|
||||
|
||||
if ((pnum=COM_CheckParm("-noborder")))
|
||||
gtk_window_set_decorated(x_win, FALSE);
|
||||
|
||||
gtk_widget_realize(x_win);
|
||||
/* create the GC */
|
||||
/* create the GC */
|
||||
x_gc = gdk_gc_new(gtk_widget_get_window(x_win));
|
||||
if (!x_gc)
|
||||
Sys_Error("VID: Cannot make GC\n");
|
||||
|
||||
/* map the window */
|
||||
/* map the window */
|
||||
gtk_widget_show_all(x_win);
|
||||
|
||||
ResetFrameBuffer();
|
||||
|
||||
vid.rowbytes = vid.width;
|
||||
|
@ -209,10 +236,8 @@ void VID_Init(unsigned char *palette)
|
|||
vid.conheight = vid.height;
|
||||
vid.aspect =
|
||||
((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
||||
|
||||
// x_disp = gdk_display_get_default();
|
||||
// x_screen = gdk_display_get_default_screen(x_disp);
|
||||
// mouse_enabled = true;
|
||||
mouse_enabled = true;
|
||||
gtk_main_iteration ();
|
||||
}
|
||||
|
||||
void VID_ShiftPalette(unsigned char *p)
|
||||
|
@ -243,10 +268,9 @@ void VID_SetPalette(unsigned char *palette)
|
|||
x_cmap = gdk_rgb_cmap_new(colors, 256);
|
||||
}
|
||||
|
||||
/* Called at shutdown */
|
||||
void VID_Shutdown(void)
|
||||
{
|
||||
Con_Printf("VID_Shutdown\n");
|
||||
Con_Printf("[VIDEO] Shutting down...\n");
|
||||
}
|
||||
|
||||
int XLateKey(int keysym)
|
||||
|
@ -374,11 +398,13 @@ int keyq_tail = 0;
|
|||
|
||||
void GetEvent(void)
|
||||
{
|
||||
int x, y;
|
||||
int w, h;
|
||||
|
||||
GdkEvent *event;
|
||||
event = gdk_event_get();
|
||||
gtk_window_get_size(GTK_WINDOW(x_win), &w, &h);
|
||||
|
||||
if (event)
|
||||
if (event)
|
||||
switch (event->type) {
|
||||
case GDK_KEY_PRESS:
|
||||
keyq[keyq_head].key = XLateKey(event->key.keyval);
|
||||
|
@ -399,32 +425,54 @@ void GetEvent(void)
|
|||
XSetInputFocus(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(x_win)),
|
||||
None, RevertToNone, CurrentTime);
|
||||
break;
|
||||
case GDK_MOTION_NOTIFY:
|
||||
if (mouse_enabled == true) {
|
||||
//mouse_x = (float) ((int)x - (int)(vid.width/2));
|
||||
//mouse_y = (float) ((int)y - (int)(vid.height/2));
|
||||
/*XWarpPointer(GDK_WINDOW_XDISPLAY(x_win), None,
|
||||
GDK_WINDOW_XWINDOW(x_win),0,0,0,0,
|
||||
(vid.width/2),(vid.height/2));*/
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(config_notify_width != w || config_notify_height != h){
|
||||
config_notify_width = w;
|
||||
config_notify_height = h;
|
||||
config_notify = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// flushes the given rectangles from the view buffer to the screen
|
||||
void VID_Update(vrect_t * rects)
|
||||
{
|
||||
gtk_window_get_position(x_win, &vid_frame[0], &vid_frame[1]);
|
||||
vid_frame[2] = vid_frame[0] + vid.width;
|
||||
vid_frame[3] = vid_frame[1] + vid.height;
|
||||
|
||||
if (config_notify)
|
||||
{
|
||||
config_notify = 0;
|
||||
vid.width = config_notify_width & ~7;
|
||||
vid.height = config_notify_height;
|
||||
|
||||
ResetFrameBuffer();
|
||||
|
||||
vid.rowbytes = vid.width;
|
||||
vid.buffer = x_framebuffer;
|
||||
vid.conbuffer = x_framebuffer;
|
||||
vid.conrowbytes = vid.rowbytes;
|
||||
vid.conwidth = vid.width;
|
||||
vid.conheight = vid.height;
|
||||
|
||||
vid.recalc_refdef = 1;
|
||||
Con_CheckResize();
|
||||
//Con_Clear_f();
|
||||
return;
|
||||
}
|
||||
|
||||
scr_fullupdate = 0;
|
||||
while (rects) {
|
||||
gdk_draw_indexed_image(gtk_widget_get_window(x_win), x_gc, rects->x, rects->y, rects->width, rects->height, GDK_RGB_DITHER_NONE, x_framebuffer, vid.width, x_cmap);
|
||||
rects = rects->pnext;
|
||||
gdk_draw_indexed_image(gtk_widget_get_window(x_win),
|
||||
x_gc, rects->x, rects->y, rects->width, rects->height, GDK_RGB_DITHER_NONE, x_framebuffer, vid.width, x_cmap);
|
||||
rects = rects->pnext;
|
||||
}
|
||||
}
|
||||
|
||||
static int dither;
|
||||
|
||||
void VID_DitherOn(void)
|
||||
{
|
||||
if (dither == 0)
|
||||
|
@ -465,7 +513,6 @@ void Sys_SendKeyEvents(void)
|
|||
if (gdk_initialized) {
|
||||
while (gdk_events_pending()) {
|
||||
GetEvent();
|
||||
|
||||
while (keyq_head != keyq_tail) {
|
||||
Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].down);
|
||||
keyq_tail = (keyq_tail + 1) & 63;
|
||||
|
@ -504,6 +551,7 @@ void VID_HandlePause (qboolean pause)
|
|||
}
|
||||
}
|
||||
|
||||
static int vid_mouseposx, vid_mouseposy;
|
||||
extern vec3_t deathcam_angles; //eukara - deathcam
|
||||
void IN_Move (usercmd_t *cmd)
|
||||
{
|
||||
|
@ -514,18 +562,27 @@ void IN_Move (usercmd_t *cmd)
|
|||
mouse_y = (mouse_y + old_mouse_y) * 0.5;
|
||||
}
|
||||
*/
|
||||
old_mouse_x = mouse_x;
|
||||
old_mouse_y = mouse_y;
|
||||
|
||||
mouse_x *= sensitivity->value;
|
||||
mouse_y *= sensitivity->value;
|
||||
if (mouse_enabled == true)
|
||||
{
|
||||
gdk_window_get_pointer (gtk_widget_get_window(x_win), &vid_mouseposx, &vid_mouseposy, NULL);
|
||||
|
||||
mouse_x = (float)(vid_mouseposx - ((float)vid.width / 2)) +1;
|
||||
mouse_y = (float)(vid_mouseposy - ((float)vid.height / 2)) +18;
|
||||
|
||||
old_mouse_x = mouse_x;
|
||||
old_mouse_y = mouse_y;
|
||||
|
||||
mouse_x *= sensitivity->value;
|
||||
mouse_y *= sensitivity->value;
|
||||
}
|
||||
|
||||
if (deathcam_yesiamdead){
|
||||
tangles[0] = deathcam_angles[0]; tangles[1] = deathcam_angles[1]; tangles[2] = deathcam_angles[2];
|
||||
}
|
||||
else{
|
||||
tangles[0] = cl.viewangles[0]; tangles[1] = cl.viewangles[1]; tangles[2] = cl.viewangles[2];
|
||||
}
|
||||
}
|
||||
|
||||
if ( (in_strafe.state & 1) || (lookstrafe->value && ((in_mlook.state & 1) ^ ((int)m_look->value & 1)) ))
|
||||
cmd->sidemove += m_side->value * mouse_x;
|
||||
|
@ -556,7 +613,8 @@ void IN_Move (usercmd_t *cmd)
|
|||
cl.viewangles[0] = tangles[0]; cl.viewangles[1] = tangles[1]; cl.viewangles[2] = tangles[2];
|
||||
}
|
||||
|
||||
mouse_x = mouse_y = 0.0;
|
||||
if(mouse_x || mouse_y)
|
||||
gdk_display_warp_pointer (display, screen, (int)(vid_frame[0] + (float)(vid.width / 2)), (int)(vid_frame[1] + (float)(vid.height / 2)));
|
||||
}
|
||||
void IN_Commands(){}
|
||||
void IN_Init(){}
|
||||
|
@ -569,13 +627,21 @@ gboolean VID_KillSplash(gpointer data){
|
|||
}
|
||||
void VID_CreateSplash()
|
||||
{
|
||||
GdkBitmap *splash_mask;
|
||||
GdkPixmap *splash_image;
|
||||
GtkWidget *x_splash, *x_splash_image;
|
||||
|
||||
gtk_init(NULL, NULL);
|
||||
x_splash = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_widget_set_size_request (x_splash, 440, 116);
|
||||
gtk_window_set_decorated(GTK_WINDOW (x_splash), FALSE);
|
||||
gtk_window_set_position(GTK_WINDOW(x_splash),GTK_WIN_POS_CENTER_ALWAYS);
|
||||
gtk_window_set_resizable(GTK_WINDOW(x_splash), FALSE);
|
||||
x_splash_image = gtk_image_new_from_file("./splash.xpm");
|
||||
gtk_window_set_decorated(x_splash, FALSE);
|
||||
gtk_window_set_position(x_splash,GTK_WIN_POS_CENTER_ALWAYS);
|
||||
gtk_window_set_resizable(x_splash, FALSE);
|
||||
gtk_widget_realize(x_splash);
|
||||
|
||||
splash_image = gdk_pixmap_create_from_xpm_d(x_splash->window, &splash_mask, NULL, (gchar **)splash_xpm );
|
||||
x_splash_image = gtk_image_new_from_pixmap(splash_image, splash_mask);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(x_splash), x_splash_image);
|
||||
gtk_widget_show_all (x_splash);
|
||||
g_timeout_add (1000, VID_KillSplash, x_splash);
|
||||
|
@ -593,6 +659,7 @@ IN_DeactivateMouse --eukara
|
|||
void IN_DeactivateMouse (void)
|
||||
{
|
||||
mouse_enabled = false;
|
||||
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -603,14 +670,17 @@ IN_DeactivateMouse --eukara
|
|||
void IN_ActivateMouse (void)
|
||||
{
|
||||
mouse_enabled = true;
|
||||
gdk_pointer_grab(gtk_widget_get_window(x_win), TRUE, (GdkEventMask)(GDK_BUTTON_PRESS_MASK ), (GdkWindow *)NULL, NULL, GDK_CURRENT_TIME);
|
||||
}
|
||||
|
||||
void IN_HideMouse (void)
|
||||
{
|
||||
//XDefineCursor(GDK_WINDOW_XDISPLAY(x_win), GDK_WINDOW_XWINDOW(x_win), CreateNullCursor(x_disp, x_win));
|
||||
GdkCursor* cursor_blank = gdk_cursor_new(GDK_BLANK_CURSOR);
|
||||
gdk_window_set_cursor(gtk_widget_get_window(x_win), cursor_blank);
|
||||
}
|
||||
|
||||
void IN_ShowMouse (void)
|
||||
{
|
||||
//XDefineCursor (GDK_WINDOW_XDISPLAY(x_win), GDK_WINDOW_XWINDOW(x_win), None);
|
||||
GdkCursor* cursor_arrow = gdk_cursor_new(GDK_ARROW);
|
||||
gdk_window_set_cursor(gtk_widget_get_window(x_win), cursor_arrow);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue