LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-11-2005, 12:22 PM   #1
StarDragon
LQ Newbie
 
Registered: May 2005
Location: Houston
Distribution: Gentoo!
Posts: 24

Rep: Reputation: 15
Packages for GNOME canvas programming in FC3


Anyone know what libraries are necesarry for GNOME canvas programming? I cannot include gnome.h in my code.

Thanks,
 
Old 06-12-2005, 05:35 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
would you belive... libgnomecanvas? ensure you have libgnomecanvas-devel too of course. that' won't include gnome.h though, that'd be libgnome-devel, but that would surely be a dep of libgnomecanvas anyway
 
Old 06-12-2005, 02:31 PM   #3
StarDragon
LQ Newbie
 
Registered: May 2005
Location: Houston
Distribution: Gentoo!
Posts: 24

Original Poster
Rep: Reputation: 15
This is the program I am trying to compile, I got it from a canvas tutorial in the GNOME site:

/* GNOME Piskvorky (gomoku),
A 19x19 board where you have to connect 5 in a row to win
(the board size is arbitrary)
No artificial intelligence, you play both sides */
/* the main gnome include */
#include <gnome.h>

/* we define a version ourselves if we're not using automake/autogen */
#define VERSION "0.1"

/* what can be in a spot */
enum {
NOTHING,
CROSS,
CIRCLE
};

/* the board size */
#define BOARD_SIZE 19
/* border around the board itself */
#define BOARD_BORDER 15
/* cell size on the board */
#define CELL_SIZE 22
/* cell padding */
#define CELL_PAD 6
/* the height of the status area on the bottom of the canvas,
it is the bottom border */
#define BOARD_STATUS (CELL_SIZE+5)
/* the thickness of lines */
#define THICKNESS 3
/* the distance of the drop shadow */
#define DROP_SHADOW 2

/* array of the board */
static int board[BOARD_SIZE][BOARD_SIZE];

/* the player that has the current move, if it's NOTHING, nobody can
play until the user hits "New Game" */
static int current_player = CROSS;

/* the number of the current move */
static int move_number = 0;

/* the winner of the last game */
static int last_winner = NOTHING;

/* the main window pointer */
static GnomeApp *app;
/* the canvas */
static GnomeCanvas *canvas;
/* the canvas group of the marks on the board */
static GnomeCanvasGroup *boardgroup = NULL;

/* the text of the status */
static GnomeCanvasItem *status_text;
/* the group of the image for the status */
static GnomeCanvasGroup *status_image;

/* a utility function to draw a line */
static void
draw_a_line(GnomeCanvasGroup *group,
int x1, int y1, int x2, int y2, char *color)
{
GnomeCanvasPoints *points;

/* allocate a new points array */
points = gnome_canvas_points_new (2);

/* fill out the points */
points->coords[0] = x1;
points->coords[1] = y1;
points->coords[2] = x2;
points->coords[3] = y2;
/* draw the line */
gnome_canvas_item_new(group,
gnome_canvas_line_get_type(),
"points", points,
"fill_color", color,
"width_units", (double)THICKNESS,
NULL);

/* free the points array */
gnome_canvas_points_free(points);
}

/* draw a cross onto group */
static void
draw_cross(GnomeCanvasGroup *group)
{
/* draw the drop shadow */
draw_a_line(group,
CELL_PAD + DROP_SHADOW,
CELL_PAD + DROP_SHADOW,
CELL_SIZE - CELL_PAD + DROP_SHADOW,
CELL_SIZE - CELL_PAD + DROP_SHADOW,
"dark gray");
draw_a_line(group,
CELL_PAD + DROP_SHADOW,
CELL_SIZE - CELL_PAD + DROP_SHADOW,
CELL_SIZE - CELL_PAD + DROP_SHADOW,
CELL_PAD + DROP_SHADOW,
"dark gray");
/* draw the cross itself */
draw_a_line(group,
CELL_PAD,
CELL_PAD,
CELL_SIZE - CELL_PAD,
CELL_SIZE - CELL_PAD,
"blue");
draw_a_line(group,
CELL_PAD,
CELL_SIZE - CELL_PAD,
CELL_SIZE - CELL_PAD,
CELL_PAD,
"blue");
}


/* draw a circle onto group*/
static void
draw_circle(GnomeCanvasGroup *group)
{
/* draw the drop shadow */
gnome_canvas_item_new(group,
gnome_canvas_ellipse_get_type(),
"x1",(double)(CELL_PAD + DROP_SHADOW),
"y1",(double)(CELL_PAD + DROP_SHADOW),
"x2",(double)(CELL_SIZE - CELL_PAD + DROP_SHADOW),
"y2",(double)(CELL_SIZE - CELL_PAD + DROP_SHADOW),
"outline_color", "dark gray",
"width_units", (double)THICKNESS,
NULL);
/* draw the circle itself */
gnome_canvas_item_new(group,
gnome_canvas_ellipse_get_type(),
"x1",(double)CELL_PAD,
"y1",(double)CELL_PAD,
"x2",(double)(CELL_SIZE - CELL_PAD),
"y2",(double)(CELL_SIZE - CELL_PAD),
"outline_color", "dark green",
"width_units", (double)THICKNESS,
NULL);
}

/* draw a red line from x1,y1 to x2,y2 on the board */
static void
draw_strike(int x1, int y1, int x2, int y2)
{
/* draw a red line connecting the centers of the two cells */
draw_a_line(boardgroup,
x1*CELL_SIZE + CELL_SIZE/2,
y1*CELL_SIZE + CELL_SIZE/2,
x2*CELL_SIZE + CELL_SIZE/2,
y2*CELL_SIZE + CELL_SIZE/2,
"red");
}

/* make a mark (CROSS or a CIRCLE) on the board */
static void
make_mark_at(int mark, int x, int y)
{
GnomeCanvasItem *group;

/* update our data */
board[x][y] = mark;

/* make a new group for the mark */
group = gnome_canvas_item_new(boardgroup,
gnome_canvas_group_get_type(),
"x",(double)x*CELL_SIZE,
"y",(double)y*CELL_SIZE,
NULL);

if(mark == CROSS)
draw_cross(GNOME_CANVAS_GROUP(group));
else
draw_circle(GNOME_CANVAS_GROUP(group));
}

/* check for 5 in a row on the axis from (x-4*xincr,y-4*yincr) to
(x+4*xincr,y+4*yincr), return TRUE if it's there and FALSE if not.
it will also draw the red strike line */
static gboolean
check_five_axis(int x, int y, int xincr, int yincr)
{
int i,j,n; /* iteration variables */
int count = 0; /* length of a line */
int x1,y1; /* the start of the line */
/* where do we start. we set these to -5 times the increment,
as we will immediately increment these when we enter
the loop */
i = x-5*xincr;
j = y-5*yincr;
x1 = y1 = -1;
/* loop through the points */
for(n=0;n<9;n++) {
/* increment the loop vars */
i += xincr;
j += yincr;
/* if outside of range go again */
if(i<0 || i>=BOARD_SIZE ||
j<0 || j>=BOARD_SIZE)
continue;
/* if this is the first legal point */
if(x1==-1) {
x1 = i;
y1 = j;
}

/* check this point */
if(board[x1][y1]==board[i][j]) {
count ++;
/* we've found it */
if(count==5) {
/* draw a line through the line of 5 */
draw_strike(x1,y1,i,j);
return TRUE;
}
} else {
count = 1;
x1 = i;
y1 = j;
}
}
return FALSE;
}

/* check for 5 in a row around the point x,y, return TRUE
if it's there and FALSE if not. */
static gboolean
check_five(int x, int y)
{
int ret = FALSE;
/* check all four axis */
if(check_five_axis(x,y,0,1))
ret = TRUE;
if(check_five_axis(x,y,1,0))
ret = TRUE;
if(check_five_axis(x,y,1,1))
ret = TRUE;
if(check_five_axis(x,y,1,-1))
ret = TRUE;
return ret;
}

static void
set_status(void)
{
GnomeCanvasItem *item;
double tw;
char *text;

if(current_player==NOTHING)
text = g_strdup_printf("Game OVER after %d moves! Winner:",
move_number);
else
text = g_strdup_printf("Moves played: %d Current player:",
move_number);

/* set the text */
gnome_canvas_item_set(status_text,
"text",text,
NULL);
g_free(text);

/* get the width of the text */
gtk_object_get(GTK_OBJECT(status_text),
"text_width",&tw,
NULL);

/* if there is an image, destroy it */
if(status_image)
gtk_object_destroy(GTK_OBJECT(status_image));

/* make new group for the status image */
item = gnome_canvas_item_new(gnome_canvas_root(canvas),
gnome_canvas_group_get_type(),
"x",(double)(BOARD_BORDER + tw + CELL_PAD),
"y",(double)(BOARD_SIZE*CELL_SIZE +
BOARD_BORDER +
(BOARD_STATUS -
CELL_SIZE)/2),
NULL);
status_image = GNOME_CANVAS_GROUP(item);
/* draw the proper mark */
if(current_player == CROSS)
draw_cross(status_image);
else if(current_player == CIRCLE)
draw_circle(status_image);
else {
/* the current player is NOTHING so we draw whatever
is the last winner */
if(last_winner == CROSS)
draw_cross(status_image);
else
draw_circle(status_image);
}
}

/* clear the board and set current player to CROSS */
static void
new_game(void)
{
int i,j;
GnomeCanvasItem *item;

current_player = CROSS;
move_number = 0;
for(i=0;i<BOARD_SIZE;i++)
for(j=0;j<BOARD_SIZE;j++)
board[i][j] = NOTHING;
/* clear the board */
if(boardgroup)
gtk_object_destroy(GTK_OBJECT(boardgroup));
/* make a new group for the items */
item = gnome_canvas_item_new(gnome_canvas_root(canvas),
gnome_canvas_group_get_type(),
"x",(double)BOARD_BORDER,
"y",(double)BOARD_BORDER,
NULL);
boardgroup = GNOME_CANVAS_GROUP(item);

/* set the status */
set_status();
}

/* draw the background of the playing board */
static void
draw_background(void)
{
int i;

/* white background */
gnome_canvas_item_new(gnome_canvas_root(canvas),
gnome_canvas_rect_get_type(),
"x1",(double)BOARD_BORDER,
"y1",(double)BOARD_BORDER,
"x2",(double)(BOARD_BORDER +
BOARD_SIZE*CELL_SIZE),
"y2",(double)(BOARD_BORDER +
BOARD_SIZE*CELL_SIZE),
"fill_color", "white",
NULL);

/* draw horizontal lines */
for(i=0;i<=BOARD_SIZE;i++) {
draw_a_line(gnome_canvas_root(canvas),
BOARD_BORDER,
BOARD_BORDER + i*CELL_SIZE,
BOARD_BORDER + BOARD_SIZE*CELL_SIZE,
BOARD_BORDER + i*CELL_SIZE,
"black");
}
/* draw vertical lines */
for(i=0;i<=BOARD_SIZE;i++) {
draw_a_line(gnome_canvas_root(canvas),
BOARD_BORDER + i*CELL_SIZE,
BOARD_BORDER,
BOARD_BORDER + i*CELL_SIZE,
BOARD_BORDER + BOARD_SIZE*CELL_SIZE,
"black");
}

/* draw the status text */
status_text = gnome_canvas_item_new(gnome_canvas_root(canvas),
gnome_canvas_text_get_type(),
"x",(double)BOARD_BORDER,
"y",(double)(BOARD_SIZE*CELL_SIZE +
BOARD_BORDER +
BOARD_STATUS/2),
"anchor",GTK_ANCHOR_WEST,
"font","fixed",
"fill_color", "black",
"text","",
NULL);
status_image = NULL;
}

static gboolean
play_location(int player, int x, int y)
{
/* if something is here already or no player is current*/
if(board[x][y]!=NOTHING)
return FALSE;

/* mark the board */
make_mark_at(player,x,y);

move_number++;

/* check for a line of five */
if(check_five(x,y)) {
if(player == CROSS)
gnome_app_message(app,"Player with crosses wins!");
else
gnome_app_message(app,"Player with circles wins!");
/* set the last winner */
last_winner = player;
/* don't allow further playing */
current_player = NOTHING;
}

/* set the status */
set_status();

return TRUE;
}

/* switch to the next player, if we had some AI, this is where it would go */
static void
swap_players(void)
{
/* swap players if we are still playing */
if(current_player == CROSS)
current_player = CIRCLE;
else if(current_player == CIRCLE)
current_player = CROSS;

/* set the status */
set_status();
}

static int
canvas_event(GnomeCanvas *c, GdkEvent *event, gpointer data)
{
int x,y;
/* we ignore all events except for BUTTON_PRESS */
if(event->type != GDK_BUTTON_PRESS)
return FALSE;

/* check if it's outside our range */
if(event->button.x < BOARD_BORDER ||
event->button.x > BOARD_BORDER + CELL_SIZE*BOARD_SIZE ||
event->button.y < BOARD_BORDER ||
event->button.y > BOARD_BORDER + CELL_SIZE*BOARD_SIZE)
return FALSE;

/* if no player is current then just skip this event */
if(current_player == NOTHING)
return FALSE;

x = (event->button.x - BOARD_BORDER) / CELL_SIZE;
y = (event->button.y - BOARD_BORDER) / CELL_SIZE;

/* play the location, if not successful, just return */
if(!play_location(current_player,x,y))
return FALSE;

swap_players();

/* return true as we have handled it */
return TRUE;
}

static void
about_cb(GtkWidget *widget, gpointer data)
{
static GtkWidget* dialog = NULL;
/* a list of authors */
const char *authors[] = {
"George Lebl <jirka@5z.com>",
NULL
};
/* if the dialog is already created, just show and raise it
(just in case it is obscured or minimized) */
if(dialog) {
gdk_window_show(dialog->window);
gdk_window_raise(dialog->window);
return;
}

/* create the dialog */
dialog = gnome_about_new("Gnome Piskvorky", VERSION,
"(c) 1999 George Lebl",
authors,
"The game of piskvorky which some\n"
"prefer to call gomoku.",
NULL);
/* set the parent of the dialog to be the main application
window, this will help windowmanagers */
gnome_dialog_set_parent(GNOME_DIALOG(dialog), GTK_WINDOW(app));

/* when the dialog gets destroyed, the function gtk_widget_destroyed
is a utility function from gtk that will NULL the pointer that is
passed as the data of the signal */
gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
GTK_SIGNAL_FUNC(gtk_widget_destroyed),
&dialog);

gtk_widget_show(dialog);
}

/* define the Game menu */
static GnomeUIInfo game_menu[] = {
GNOMEUIINFO_MENU_NEW_GAME_ITEM(new_game, NULL),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_MENU_EXIT_ITEM(gtk_main_quit, NULL),
GNOMEUIINFO_END
};

/* the Help menu */
static GnomeUIInfo help_menu[] = {
GNOMEUIINFO_HELP("gnome-piskvorky"),
GNOMEUIINFO_MENU_ABOUT_ITEM(about_cb, NULL),
GNOMEUIINFO_END
};

/* define the main menubar */
static GnomeUIInfo main_menu[] = {
GNOMEUIINFO_MENU_GAME_TREE(game_menu),
GNOMEUIINFO_MENU_HELP_TREE(help_menu),
GNOMEUIINFO_END
};

/* create the main window */
static GnomeApp *
create_window(void)
{
GtkWidget *app;
GtkWidget *w;

app = gnome_app_new("gnome-piskvorky",
"Gnome Piskvorky");

/* we bind the delete event directly to gtk_main_quit,
since this function takes no arguments, there will be
no conflict in argument lists */
gtk_signal_connect(GTK_OBJECT(app), "delete_event",
GTK_SIGNAL_FUNC(gtk_main_quit),
NULL);

/* add the menus to the main window */
gnome_app_create_menus(GNOME_APP(app), main_menu);

/* setup appbar (bottom of window bar for status, menu hints and
* progress display) */
w = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER);
gnome_app_set_statusbar(GNOME_APP(app), w);

/* make menu hints display on the appbar */
gnome_app_install_menu_hints(GNOME_APP(app), main_menu);

/* create a new canvas */
w = gnome_canvas_new();
canvas = GNOME_CANVAS(w);

/* connect the signal handler we use to capture button presses */
gtk_signal_connect(GTK_OBJECT(w),"event",
GTK_SIGNAL_FUNC(canvas_event),
NULL);

/* set where can the canvas scroll (our usable area) */
gnome_canvas_set_scroll_region(canvas, 0.0, 0.0,
BOARD_SIZE*CELL_SIZE + 2*BOARD_BORDER,
BOARD_SIZE*CELL_SIZE + BOARD_BORDER +
BOARD_STATUS);
/* set the size of the widget */
gtk_widget_set_usize(w,
BOARD_SIZE*CELL_SIZE + 2*BOARD_BORDER,
BOARD_SIZE*CELL_SIZE + BOARD_BORDER +
BOARD_STATUS);

/* set the contents of the app window to the canvas */
gnome_app_set_contents(GNOME_APP(app), w);

return GNOME_APP(app);
}

/* our main function */
int
main(int argc, char *argv[])
{
gnome_init("gnome-piskvorky",VERSION,argc,argv);

app = create_window();

gtk_widget_show_all(GTK_WIDGET(app));

draw_background();

new_game();

gtk_main();

return 0;
}

The include <gnome.h> does not work on my compiler, also the Makefile for this goes like this:

CFLAGS=-g -Wall `gnome-config --cflags gnome gnomeui`
LDFLAGS=`pkg-config --libs gnome gnomeui`

all: gnome-piskvorky

clean:
rm -f *.o core gnome-piskvorky
 
Old 06-12-2005, 04:51 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well this is OLD gnome stuff, i'd advise you to find a new gnome2 / gtk2 based tutorial. everything you'll learn here about gnome or gtk is deprecated already, so why bother? compiles absolutely fine for me though... i'd guess you've actually only got gnome 2 installed.
 
Old 06-12-2005, 09:41 PM   #5
StarDragon
LQ Newbie
 
Registered: May 2005
Location: Houston
Distribution: Gentoo!
Posts: 24

Original Poster
Rep: Reputation: 15
Good point, it's probably better to stick to the new technology. ;-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gnome 2.10 Released . when gnome packages on ftp? Dr3n Debian 15 03-24-2005 12:15 PM
programming packages fakie_flip Fedora - Installation 5 02-14-2005 11:30 PM
I am a blank canvas... jasendorf Linux - Hardware 4 10-13-2004 09:35 AM
programming packages in sarge levicc00123 Debian 3 08-10-2004 01:12 AM
What packages do I need to install to start programming in emacs? O_o Linux - Newbie 7 11-10-2003 03:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration