gaim/gaim

3fdd702fb7dc
Parents 4d9ea3462c35
Children a75ee5623db1
Local client now uses recieved drawing data to draw to whiteboard canvas.
Fixed a foolish bug (when freeing GaimGtkWhiteboard memory).
--- a/src/gtkwhiteboard.c Fri Jul 22 17:25:16 2005 -0400
+++ b/src/gtkwhiteboard.c Sat Jul 23 03:37:49 2005 -0400
@@ -39,7 +39,8 @@
gaim_gtk_whiteboard_create,
gaim_gtk_whiteboard_destroy,
gaim_gtk_whiteboard_draw_brush_point,
- gaim_gtk_whiteboard_draw_brush_line
+ gaim_gtk_whiteboard_draw_brush_line,
+ gaim_gtk_whiteboard_clear
};
// FUNCTIONS ============================================================================================
@@ -54,7 +55,7 @@
void gaim_gtk_whiteboard_create( GaimWhiteboard *wb )
{
//int i;
- g_print( "gaim_gtk_whiteboard_create()\n" );
+ //g_print( "gaim_gtk_whiteboard_create()\n" );
GtkWidget *window;
GtkWidget *drawing_area;
@@ -80,10 +81,12 @@
//GtkWidget *color_box[PALETTE_NUM_OF_COLORS];
GaimGtkWhiteboard *gtkwb = g_new0( GaimGtkWhiteboard, 1 );
- gtkwb->wb = wb; // NOTE Pointer wrong address to link?
+ gtkwb->wb = wb;
wb->ui_data = gtkwb;
- g_print( "-->wb=%p\n", wb );
- g_print( "-->ui_data=%p\n", wb->ui_data );
+
+ // Protocol specific ui_ops?
+ gtkwb->width = 368;
+ gtkwb->height = 256;
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtkwb->window = window;
@@ -112,7 +115,7 @@
for( i = 0; i < PALETTE_NUM_OF_COLORS; i++ )
{
color_box[i] = gtk_label_new( NULL );
- gtk_widget_set_size_request( color_box[i], DOODLE_CANVAS_WIDTH / PALETTE_NUM_OF_COLORS ,32 );
+ gtk_widget_set_size_request( color_box[i], gtkwb->width / PALETTE_NUM_OF_COLORS ,32 );
gtk_container_add( GTK_CONTAINER( hbox_palette ), color_box[i] );
gtk_widget_show( color_box[i] );
}
@@ -121,7 +124,7 @@
drawing_area = gtk_drawing_area_new();
gtkwb->drawing_area = drawing_area;
// NOTE Protocol specific needs UI_OP?
- gtk_widget_set_size_request( GTK_WIDGET( drawing_area ), 320, 240 );
+ gtk_widget_set_size_request( GTK_WIDGET( drawing_area ), gtkwb->width, gtkwb->height );
gtk_box_pack_start( GTK_BOX( hbox_canvas_and_controls ), drawing_area, TRUE, TRUE, 8 );
gtk_widget_show( drawing_area );
@@ -185,31 +188,27 @@
void gaim_gtk_whiteboard_destroy( GaimWhiteboard *wb )
{
- g_print( "gaim_gtk_whiteboard_destroy()\n" );
+ //g_print( "gaim_gtk_whiteboard_destroy()\n" );
GaimGtkWhiteboard *gtkwb = wb->ui_data;
- g_print( "-->wb =%p\n", wb );
- g_print( "-->ui_data=%p\n", wb->ui_data );
- g_print( "-->gtkwb =%p\n", gtkwb );
// TODO Ask if user wants to save picture before the session is closed
- // Clear pixmap memory before we remove this session from the Doodle session list
+ // Clear graphical memory
if( gtkwb->pixmap )
g_object_unref( gtkwb->pixmap );
+ gaim_whiteboard_destroy( gtkwb->wb );
+
if( gtkwb )
g_free( gtkwb );
-
- // NOTE Correct order below? Will it break anything?
- gaim_whiteboard_destroy( gtkwb->wb );
}
// ------------------------------------------------------------------------------------------------------
void gaim_gtk_whiteboard_exit( GtkWidget *widget, gpointer data )
{
- g_print( "gaim_gtk_whiteboard_exit()\n" );
+ //g_print( "gaim_gtk_whiteboard_exit()\n" );
GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data );
@@ -245,12 +244,12 @@
gboolean gaim_gtk_whiteboard_configure_event( GtkWidget *widget, GdkEventConfigure *event, gpointer data )
{
+ //g_print( "gaim_gtk_whiteboard_configure_event | %s\n", ds->who );
+
GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data );
GdkPixmap *pixmap = gtkwb->pixmap;
- //g_print( "goodle_doodle_session_configure_event | %s\n", ds->who );
-
if( pixmap )
g_object_unref( pixmap );
@@ -275,11 +274,11 @@
gboolean gaim_gtk_whiteboard_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer data )
{
+ //g_print( "gaim_gtk_whiteboard_expose_event | %s\n", ds->who );
+
GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data );
GdkPixmap *pixmap = gtkwb->pixmap;
- //g_print( "goodle_doodle_session_expose_event | %s\n", ds->who );
-
gdk_draw_drawable( widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE( widget )],
pixmap,
@@ -294,6 +293,8 @@
gboolean gaim_gtk_whiteboard_brush_down( GtkWidget *widget, GdkEventButton *event, gpointer data )
{
+ //g_print( "BRUSH_DOWN | %s\n", ds->who );
+
GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data );
GdkPixmap *pixmap = gtkwb->pixmap;
@@ -317,8 +318,6 @@
BrushState = BRUSH_STATE_DOWN;
- //g_print( "BRUSH_DOWN | %s\n", ds->who );
-
if( event->button == 1 && pixmap != NULL )
{
/* // Check if draw_list has contents; if so, clear it
@@ -357,6 +356,8 @@
gboolean gaim_gtk_whiteboard_brush_motion( GtkWidget *widget, GdkEventMotion *event, gpointer data )
{
+ //g_print( "BRUSH_MOTION | %s\n", ds->who );
+
int x;
int y;
// int *dx;
@@ -367,8 +368,6 @@
GdkPixmap *pixmap = gtkwb->pixmap;
// GList *d_list = gtkwb->wb->draw_list;
-
- //g_print( "BRUSH_MOTION | %s\n", ds->who );
if( event->is_hint )
gdk_window_get_pointer( event->window, &x, &y, &state );
@@ -460,13 +459,13 @@
gboolean gaim_gtk_whiteboard_brush_up( GtkWidget *widget, GdkEventButton *event, gpointer data )
{
+ //g_print( "BRUSH_UP | %s\n", ds->who );
+
GaimGtkWhiteboard *gtkwb = ( GaimGtkWhiteboard* )( data );
GdkPixmap *pixmap = gtkwb->pixmap;
// GList *d_list = gtkwb->wb->draw_list;
- //g_print( "BRUSH_UP | %s\n", ds->who );
-
if( ( BrushState != BRUSH_STATE_DOWN ) && ( BrushState != BRUSH_STATE_MOTION ) )
{
g_print( "***Bad brush state transition %d to UP\n", BrushState );
@@ -519,6 +518,8 @@
// int x, int y, int color, int size )
void gaim_gtk_whiteboard_draw_brush_point( GaimWhiteboard *wb, int x, int y, int color, int size )
{
+ //g_print( "goodle_doodle_session_draw_brush | %s\n", ds->who );
+
GaimGtkWhiteboard *gtkwb = wb->ui_data;
GtkWidget *widget = gtkwb->drawing_area;
GdkPixmap *pixmap = gtkwb->pixmap;
@@ -530,11 +531,9 @@
update_rect.width = size;
update_rect.height = size;
- //g_print( "goodle_doodle_session_draw_brush | %s\n", ds->who );
-
// Interpret and convert color
- GdkGC *gfx_con = gdk_gc_new( pixmap );
- GdkColor col;
+ GdkGC *gfx_con = gdk_gc_new( pixmap );
+ GdkColor col;
gaim_gtk_whiteboard_rgb24_to_rgb48( color, &col );
@@ -632,10 +631,11 @@
// ------------------------------------------------------------------------------------------------------
-void gaim_gtk_whiteboard_clear_canvas( GaimGtkWhiteboard *gtkwb )
+void gaim_gtk_whiteboard_clear( GaimWhiteboard *wb )
{
- GdkPixmap *pixmap = gtkwb->pixmap;
- GtkWidget *drawing_area = gtkwb->drawing_area;
+ GaimGtkWhiteboard *gtkwb = wb->ui_data;
+ GdkPixmap *pixmap = gtkwb->pixmap;
+ GtkWidget *drawing_area = gtkwb->drawing_area;
gdk_draw_rectangle( pixmap,
drawing_area->style->white_gc,
@@ -657,7 +657,7 @@
// Proto specific? UI Ops?
//goodle_send_command_clear( ds->gc, ds->who );
- gaim_gtk_whiteboard_clear_canvas( gtkwb );
+ gaim_gtk_whiteboard_clear( gtkwb->wb );
gaim_gtk_whiteboard_set_canvas_as_icon( gtkwb );
}
@@ -674,7 +674,7 @@
gdk_drawable_get_colormap( gtkwb->pixmap ),
0, 0,
0, 0,
- 320, 240 ); //Constants for protocol specific UI_Ops?
+ gtkwb->width, gtkwb->height ); //Constants for protocol specific UI_Ops?
gtk_window_set_icon( ( GtkWindow* )( gtkwb->window ), pixbuf );
}
--- a/src/gtkwhiteboard.h Fri Jul 22 17:25:16 2005 -0400
+++ b/src/gtkwhiteboard.h Sat Jul 23 03:37:49 2005 -0400
@@ -47,6 +47,9 @@
GtkWidget *drawing_area; // Drawing area
GdkPixmap *pixmap; // Memory for drawing area
+
+ int width; // Canvas width
+ int height; // Canvas height
} GaimGtkWhiteboard;
// PROTOTYPES ==========================================================================================
@@ -71,7 +74,7 @@
void gaim_gtk_whiteboard_draw_brush_line( GaimWhiteboard *wb,
int x0, int y0, int x1, int y1, int color, int size );
-void gaim_gtk_whiteboard_clear_canvas( GaimGtkWhiteboard *gtkwb );
+void gaim_gtk_whiteboard_clear( GaimWhiteboard *wb );
void gaim_gtk_whiteboard_button_clear_press( GtkWidget *widget, gpointer data );
Binary file src/gtkwhiteboard.o has changed
--- a/src/protocols/yahoo/yahoo_doodle.c Fri Jul 22 17:25:16 2005 -0400
+++ b/src/protocols/yahoo/yahoo_doodle.c Sat Jul 23 03:37:49 2005 -0400
@@ -75,7 +75,6 @@
//GdkColor DefaultColor[PALETTE_NUM_OF_COLORS];
// FUNCTIONS ============================================================================================
-
/*
// This function is called at the start of Gaim (twice?)
// Anyhow... this is the biggy... I think :P
@@ -115,9 +114,10 @@
return( TRUE );
}
+
// ------------------------------------------------------------------------------------------------------
-*/
-/*
+
+
// plugin_destroy is called when plugin is unloaded (unselected)
gboolean goodle_unload( GaimPlugin *plugin )
{
@@ -338,7 +338,7 @@
// TODO Call clear function (requires function to clear canvas (but not send clear command packet)
// Ask whether to save picture too
- //goodle_doodle_session_clear_canvas( ds );
+ gaim_whiteboard_clear( wb );
}
}
@@ -390,10 +390,10 @@
message = token_end + 1;
}
- //goodle_doodle_draw_stroke( ds, d_list );
+ yahoo_doodle_draw_stroke( wb, d_list );
//goodle_doodle_session_set_canvas_as_icon( ds );
-
+
// Remove that shit
int *n = NULL;
GList *l = d_list;
@@ -429,7 +429,7 @@
{
// TODO Ask user whether to save the image before clearing it
- //goodle_doodle_session_clear_canvas( ds );
+ gaim_whiteboard_clear( wb );
}
}
@@ -810,18 +810,19 @@
// Make all this (window) visible
gtk_widget_show( window );
- goodle_doodle_session_set_canvas_as_icon( ds );
-
// Set default brush size and color
ds->brush_size = DOODLE_BRUSH_MEDIUM;
ds->brush_color = 0; // black
}
-
+*/
// ------------------------------------------------------------------------------------------------------
-void goodle_doodle_draw_stroke( doodle_session *ds, GList *d_list )
+void yahoo_doodle_draw_stroke( GaimWhiteboard *wb, GList *d_list )
{
// Traverse through the list and draw the points and lines
+
+ //g_print( "Drawing: color=%d, size=%d, (%d,%d)\n", brush_color, brush_size, x, y );
+
GList *l = d_list;
int *n = NULL;
@@ -840,8 +841,6 @@
int count = 0;
- //g_print( "Drawing: color=%d, size=%d, (%d,%d)\n", brush_color, brush_size, x, y );
-
// Pray this works and pray that the list has an even number of elements
while( l )
{
@@ -850,20 +849,20 @@
n = l->data; dx = *n; l = l->next;
n = l->data; dy = *n; l = l->next;
- goodle_doodle_session_draw_brush_line( ds->drawing_area, ds,
- x, y,
- x + dx, y + dy,
- brush_color, brush_size );
+ gaim_whiteboard_draw_line( wb,
+ x, y,
+ x + dx, y + dy,
+ brush_color, brush_size );
x = x + dx;
y = y + dy;
}
- g_print( "Counted %d deltas\n", count );
+ //g_print( "Counted %d deltas\n", count );
}
// ------------------------------------------------------------------------------------------------------
-
+/*
char *goodle_doodle_session_build_draw_string( GList *d_list )
{
GList *l = d_list;
@@ -908,7 +907,7 @@
yahoo_doodle_command_send_clear( ds->gc, ds->who );
- goodle_doodle_session_clear_canvas( ds );
+ gaim_whiteboard_clear( wb );
}
// ------------------------------------------------------------------------------------------------------
--- a/src/protocols/yahoo/yahoo_doodle.h Fri Jul 22 17:25:16 2005 -0400
+++ b/src/protocols/yahoo/yahoo_doodle.h Sat Jul 23 03:37:49 2005 -0400
@@ -25,6 +25,9 @@
#ifndef _YAHOO_DOODLE_H_
#define _YAHOO_DOODLE_H_
+// INCLUDES ============================================================================================
+#include "whiteboard.h"
+
// DEFINES =============================================================================================
// Doodle communication commands
@@ -114,11 +117,10 @@
void yahoo_doodle_command_send_confirm( GaimConnection *gc, char *to );
void yahoo_doodle_command_send_shutdown( GaimConnection *gc, char *to );
-/*
-void goodle_doodle_session_start( doodle_session *ds );
+//void goodle_doodle_session_start( doodle_session *ds );
-void goodle_doodle_draw_stroke( doodle_session *ds, GList *d_list );
-char *goodle_doodle_session_build_draw_string( GList *d_list );
-*/
+void yahoo_doodle_draw_stroke( GaimWhiteboard *wb, GList *d_list );
+//char *goodle_doodle_session_build_draw_string( GList *d_list );
+
#endif // _YAHOO_DOODLE_H_
--- a/src/whiteboard.c Fri Jul 22 17:25:16 2005 -0400
+++ b/src/whiteboard.c Sat Jul 23 03:37:49 2005 -0400
@@ -46,17 +46,13 @@
GaimWhiteboard *gaim_whiteboard_create( GaimAccount *account, char *who, int state )
{
- g_print( "gaim_whiteboard_create()\n" );
+ //g_print( "gaim_whiteboard_create()\n" );
GaimWhiteboard *wb = g_new0( GaimWhiteboard, 1 );
- g_print( "-->wb=%p\n", wb );
wb->account = account;
-
- wb->who = g_new0( char, strlen( who ) + 1 );
- strcpy( wb->who, who );
-
wb->state = state;
+ wb->who = g_strdup( who );
wbList = g_list_append( wbList, ( gpointer )( wb ) );
@@ -67,27 +63,27 @@
void gaim_whiteboard_destroy( GaimWhiteboard *wb )
{
- g_print( "gaim_whiteboard_destroy()\n" );
- g_print( "-->wb=%p\n", wb );
-
- wbList = g_list_remove( wbList, wb );
+ //g_print( "gaim_whiteboard_destroy()\n" );
wb->account = NULL;
-
- g_free( wb->who );
- g_print( "freed (wb->who)\n" );
-
wb->state = 0;
- g_free( wb );
- g_print( "freed (wb)\n" );
+ if( wb->who )
+ g_free( wb->who );
+
+ if( wb )
+ {
+ wbList = g_list_remove( wbList, wb );
+
+ g_free( wb );
+ }
}
// ------------------------------------------------------------------------------------------------------
void gaim_whiteboard_start( GaimWhiteboard *wb )
{
- g_print( "gaim_whiteboard_start()\n" );
+ //g_print( "gaim_whiteboard_start()\n" );
// Create frontend for whiteboard
if( whiteboard_ui_ops && whiteboard_ui_ops->create )
@@ -100,7 +96,7 @@
// Returns a pointer to a matching whiteboard session; if none match, it returns NULL
GaimWhiteboard *gaim_whiteboard_get_session( GaimAccount *account, char *who )
{
- g_print( "gaim_whiteboard_get_session()\n" );
+ //g_print( "gaim_whiteboard_get_session()\n" );
GaimWhiteboard *wb = NULL;
@@ -114,7 +110,7 @@
if( !strcmp( gaim_account_get_username( wb->account ), gaim_account_get_username( account ) ) &&
!strcmp( wb->who, who ) )
{
- g_print( "@Found whiteboard session\n" );
+ //g_print( "@Found whiteboard session\n" );
return( wb );
}
@@ -161,3 +157,11 @@
}
// ------------------------------------------------------------------------------------------------------
+
+void gaim_whiteboard_clear( GaimWhiteboard *wb )
+{
+ if( whiteboard_ui_ops && whiteboard_ui_ops->clear )
+ whiteboard_ui_ops->clear( wb );
+}
+
+// ------------------------------------------------------------------------------------------------------
--- a/src/whiteboard.h Fri Jul 22 17:25:16 2005 -0400
+++ b/src/whiteboard.h Sat Jul 23 03:37:49 2005 -0400
@@ -47,13 +47,13 @@
GList *draw_list; // List of drawing elements/deltas to send
} GaimWhiteboard;
-
typedef struct _GaimWhiteboardUiOps
{
void ( *create )( GaimWhiteboard *wb );
void ( *destroy )( GaimWhiteboard *wb );
void ( *draw_point )( GaimWhiteboard *wb, int x, int y, int color, int size );
void ( *draw_line )( GaimWhiteboard *wb, int x1, int y1, int x2, int y2, int color, int size );
+ void ( *clear )( GaimWhiteboard *wb );
} GaimWhiteboardUiOps;
// PROTOTYPES ==========================================================================================
@@ -63,10 +63,13 @@
GaimWhiteboard *gaim_whiteboard_create( GaimAccount *account, char *who, int state );
void gaim_whiteboard_destroy( GaimWhiteboard *wb );
void gaim_whiteboard_start( GaimWhiteboard *wb );
+
GaimWhiteboard *gaim_whiteboard_get_session( GaimAccount *account, char *who );
void gaim_whiteboard_draw_list_destroy( GList *d_list );
+void gaim_whiteboard_draw_point( GaimWhiteboard *wb, int x, int y, int color, int size );
void gaim_whiteboard_draw_line( GaimWhiteboard *wb, int x1, int y1, int x2, int y2, int color, int size );
+void gaim_whiteboard_clear( GaimWhiteboard *wb );
#endif // _GAIM_WHITEBOARD_H_
Binary file src/whiteboard.o has changed