From e28fee069d1a32ddf019e9e665b7508da36524b2 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Sun, 17 Aug 2008 20:25:55 -0400 Subject: [PATCH] Fixed library --- Makefile.am | 8 ++ autom4te.cache/output.2 | 33 ++++--- autom4te.cache/output.3 | 33 ++++--- autom4te.cache/traces.2 | 33 +++---- autom4te.cache/traces.3 | 18 ++-- champlain.pc | 11 +++ champlain.pc.in | 11 +++ configure.ac | 17 +++- src/Makefile.am | 26 +++--- src/champlain_map_zoom_level.c | 67 -------------- src/{champlain_widget.c => champlainview.c} | 67 +++++++------- src/{champlain_widget.h => champlainview.h} | 44 ++++----- src/launcher.c | 2 +- src/{champlain_map.c => map.c} | 44 ++++----- src/{champlain_map.h => map.h} | 24 ++--- src/map_source/debugmap.c | 90 ------------------- src/sources/debugmap.c | 89 ++++++++++++++++++ src/{map_source => sources}/debugmap.h | 4 +- src/{map_source => sources}/openstreetmap.c | 56 ++++++------ src/{map_source => sources}/openstreetmap.h | 4 +- src/{champlain_map_tile.c => tile.c} | 35 ++++---- src/{champlain_map_tile.h => tile.h} | 2 +- src/zoomlevel.c | 67 ++++++++++++++ ...champlain_map_zoom_level.h => zoomlevel.h} | 8 +- 24 files changed, 428 insertions(+), 365 deletions(-) create mode 100644 champlain.pc create mode 100644 champlain.pc.in delete mode 100644 src/champlain_map_zoom_level.c rename src/{champlain_widget.c => champlainview.c} (64%) rename src/{champlain_widget.h => champlainview.h} (52%) rename src/{champlain_map.c => map.c} (55%) rename src/{champlain_map.h => map.h} (67%) delete mode 100644 src/map_source/debugmap.c create mode 100644 src/sources/debugmap.c rename src/{map_source => sources}/debugmap.h (93%) rename src/{map_source => sources}/openstreetmap.c (52%) rename src/{map_source => sources}/openstreetmap.h (93%) rename src/{champlain_map_tile.c => tile.c} (57%) rename src/{champlain_map_tile.h => tile.h} (98%) create mode 100644 src/zoomlevel.c rename src/{champlain_map_zoom_level.h => zoomlevel.h} (79%) diff --git a/Makefile.am b/Makefile.am index 5c179c2..f6d5602 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1,9 @@ SUBDIRS = tidy src + +pcfiles = champlain-1.0.pc + +champlain-1.0.pc: champlain.pc + @cp -f $< $@ + +pkgconfig_DATA = $(pcfiles) +pkgconfigdir = $(libdir)/pkgconfig diff --git a/autom4te.cache/output.2 b/autom4te.cache/output.2 index 583e4c5..183e032 100644 --- a/autom4te.cache/output.2 +++ b/autom4te.cache/output.2 @@ -732,7 +732,7 @@ PACKAGE_VERSION='0.1' PACKAGE_STRING='champlain 0.1' PACKAGE_BUGREPORT='pierre-luc@squidy.info' -ac_unique_file="src/champlain_widget.h" +ac_unique_file="src/champlainview.h" # Factoring default headers for most tests. ac_includes_default="\ #include @@ -20731,14 +20731,14 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + \"") >&5 ($PKG_CONFIG --exists --print-errors " glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 @@ -20748,7 +20748,7 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + " 2>/dev/null` else pkg_failed=yes @@ -20767,14 +20767,14 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + \"") >&5 ($PKG_CONFIG --exists --print-errors " glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 @@ -20784,7 +20784,7 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + " 2>/dev/null` else pkg_failed=yes @@ -20809,7 +20809,7 @@ fi gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + "` else DEPS_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors " glib-2.0 >= 2.2, @@ -20817,7 +20817,7 @@ fi gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + "` fi # Put the nasty error message in config.log where it belongs @@ -20828,7 +20828,7 @@ fi gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ) were not met: $DEPS_PKG_ERRORS @@ -20845,7 +20845,7 @@ echo "$as_me: error: Package requirements ( glib-2.0 >= 2.2, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ) were not met: $DEPS_PKG_ERRORS @@ -20894,7 +20894,7 @@ fi # Checks for library functions. -ac_config_files="$ac_config_files Makefile src/Makefile tidy/Makefile" +ac_config_files="$ac_config_files Makefile src/Makefile tidy/Makefile champlain.pc" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -21491,6 +21491,7 @@ do "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;; "tidy/Makefile") CONFIG_FILES="$CONFIG_FILES tidy/Makefile" ;; + "champlain.pc") CONFIG_FILES="$CONFIG_FILES champlain.pc" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} @@ -22296,3 +22297,11 @@ if test "$no_create" != yes; then $ac_cs_success || { (exit 1); exit 1; } fi + + +echo "" +echo " Champlain $VERSION" +echo "" +echo " Prefix: ${prefix}" +echo " Compiler flags: ${CPPFLAGS}" +echo "" diff --git a/autom4te.cache/output.3 b/autom4te.cache/output.3 index caa7527..3589376 100644 --- a/autom4te.cache/output.3 +++ b/autom4te.cache/output.3 @@ -732,7 +732,7 @@ PACKAGE_VERSION='0.1' PACKAGE_STRING='champlain 0.1' PACKAGE_BUGREPORT='pierre-luc@squidy.info' -ac_unique_file="src/champlain_widget.h" +ac_unique_file="src/champlainview.h" # Factoring default headers for most tests. ac_includes_default="\ #include @@ -20743,14 +20743,14 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + \"") >&5 ($PKG_CONFIG --exists --print-errors " glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 @@ -20760,7 +20760,7 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + " 2>/dev/null` else pkg_failed=yes @@ -20779,14 +20779,14 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + \"") >&5 ($PKG_CONFIG --exists --print-errors " glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 @@ -20796,7 +20796,7 @@ if test -n "$PKG_CONFIG"; then gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + " 2>/dev/null` else pkg_failed=yes @@ -20821,7 +20821,7 @@ fi gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + "` else DEPS_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors " glib-2.0 >= 2.2, @@ -20829,7 +20829,7 @@ fi gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + "` fi # Put the nasty error message in config.log where it belongs @@ -20840,7 +20840,7 @@ fi gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ) were not met: $DEPS_PKG_ERRORS @@ -20857,7 +20857,7 @@ echo "$as_me: error: Package requirements ( glib-2.0 >= 2.2, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ) were not met: $DEPS_PKG_ERRORS @@ -20906,7 +20906,7 @@ fi # Checks for library functions. -ac_config_files="$ac_config_files Makefile src/Makefile tidy/Makefile" +ac_config_files="$ac_config_files Makefile src/Makefile tidy/Makefile champlain.pc" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -21503,6 +21503,7 @@ do "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;; "tidy/Makefile") CONFIG_FILES="$CONFIG_FILES tidy/Makefile" ;; + "champlain.pc") CONFIG_FILES="$CONFIG_FILES champlain.pc" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} @@ -22308,3 +22309,11 @@ if test "$no_create" != yes; then $ac_cs_success || { (exit 1); exit 1; } fi + + +echo "" +echo " Champlain $VERSION" +echo "" +echo " Prefix: ${prefix}" +echo " Compiler flags: ${CPPFLAGS}" +echo "" diff --git a/autom4te.cache/traces.2 b/autom4te.cache/traces.2 index c58ff04..f9574ed 100644 --- a/autom4te.cache/traces.2 +++ b/autom4te.cache/traces.2 @@ -643,19 +643,20 @@ m4trace:configure.ac:23: -1- AC_SUBST_TRACE([DEPS_LIBS]) m4trace:configure.ac:23: -1- m4_pattern_allow([^DEPS_LIBS$]) m4trace:configure.ac:38: -1- AC_CONFIG_FILES([Makefile src/Makefile - tidy/Makefile]) -m4trace:configure.ac:41: -1- AC_SUBST([LIB@&t@OBJS], [$ac_libobjs]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([LIB@&t@OBJS]) -m4trace:configure.ac:41: -1- m4_pattern_allow([^LIB@&t@OBJS$]) -m4trace:configure.ac:41: -1- AC_SUBST([LTLIBOBJS], [$ac_ltlibobjs]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([LTLIBOBJS]) -m4trace:configure.ac:41: -1- m4_pattern_allow([^LTLIBOBJS$]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([top_builddir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([srcdir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([abs_srcdir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([top_srcdir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([abs_top_srcdir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([builddir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([abs_builddir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([abs_top_builddir]) -m4trace:configure.ac:41: -1- AC_SUBST_TRACE([INSTALL]) + tidy/Makefile + champlain.pc]) +m4trace:configure.ac:42: -1- AC_SUBST([LIB@&t@OBJS], [$ac_libobjs]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([LIB@&t@OBJS]) +m4trace:configure.ac:42: -1- m4_pattern_allow([^LIB@&t@OBJS$]) +m4trace:configure.ac:42: -1- AC_SUBST([LTLIBOBJS], [$ac_ltlibobjs]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([LTLIBOBJS]) +m4trace:configure.ac:42: -1- m4_pattern_allow([^LTLIBOBJS$]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([top_builddir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([srcdir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([abs_srcdir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([top_srcdir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([abs_top_srcdir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([builddir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([abs_builddir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([abs_top_builddir]) +m4trace:configure.ac:42: -1- AC_SUBST_TRACE([INSTALL]) diff --git a/autom4te.cache/traces.3 b/autom4te.cache/traces.3 index 1e47330..20457d6 100644 --- a/autom4te.cache/traces.3 +++ b/autom4te.cache/traces.3 @@ -9447,7 +9447,7 @@ m4trace:configure.ac:23: -1- PKG_CHECK_MODULES([DEPS], [ glib-2.0 >= 2.2, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ]) m4trace:configure.ac:23: -1- PKG_PROG_PKG_CONFIG m4trace:configure.ac:23: -1- m4_pattern_forbid([^_?PKG_[A-Z_]+$]) @@ -9461,29 +9461,29 @@ m4trace:configure.ac:23: -1- PKG_CHECK_EXISTS([ glib-2.0 >= 2.2, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ], [pkg_cv_[]DEPS_CFLAGS=`$PKG_CONFIG --[]cflags " glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + " 2>/dev/null`], [pkg_failed=yes]) m4trace:configure.ac:23: -1- PKG_CHECK_EXISTS([ glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + ], [pkg_cv_[]DEPS_LIBS=`$PKG_CONFIG --[]libs " glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - + " 2>/dev/null`], [pkg_failed=yes]) m4trace:configure.ac:23: -1- _PKG_SHORT_ERRORS_SUPPORTED -m4trace:configure.ac:41: -1- m4_pattern_allow([^LIB@&t@OBJS$]) -m4trace:configure.ac:41: -1- m4_pattern_allow([^LTLIBOBJS$]) -m4trace:configure.ac:41: -1- _AC_AM_CONFIG_HEADER_HOOK([$ac_file]) -m4trace:configure.ac:41: -1- _AM_OUTPUT_DEPENDENCY_COMMANDS +m4trace:configure.ac:42: -1- m4_pattern_allow([^LIB@&t@OBJS$]) +m4trace:configure.ac:42: -1- m4_pattern_allow([^LTLIBOBJS$]) +m4trace:configure.ac:42: -1- _AC_AM_CONFIG_HEADER_HOOK([$ac_file]) +m4trace:configure.ac:42: -1- _AM_OUTPUT_DEPENDENCY_COMMANDS diff --git a/champlain.pc b/champlain.pc new file mode 100644 index 0000000..14a4670 --- /dev/null +++ b/champlain.pc @@ -0,0 +1,11 @@ +prefix=/usr/local +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${exec_prefix}/include + +Name: Champlain +Description: Map View for Gtk+ +Version: 0.1 +Libs: -L${libdir} -lchamplain-1.0 +Cflags: -I${includedir}/champlain-1.0 +Requires: gobject-2.0 clutter-0.8 gtk+-2.10 diff --git a/champlain.pc.in b/champlain.pc.in new file mode 100644 index 0000000..de926d5 --- /dev/null +++ b/champlain.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${exec_prefix}/include + +Name: Champlain +Description: Map View for Gtk+ +Version: @VERSION@ +Libs: -L${libdir} -lchamplain-1.0 +Cflags: -I${includedir}/champlain-1.0 +Requires: gobject-2.0 clutter-0.8 gtk+-2.10 diff --git a/configure.ac b/configure.ac index 4699df4..bd15c90 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ(2.61) AC_INIT(champlain, 0.1, pierre-luc@squidy.info) -AC_CONFIG_SRCDIR([src/champlain_widget.h]) +AC_CONFIG_SRCDIR([src/champlainview.h]) AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE @@ -21,12 +21,12 @@ AC_SUBST(DEPS_CFLAGS) AC_SUBST(DEPS_LIBS) PKG_CHECK_MODULES(DEPS, - [ glib-2.0 >= 2.2, + [ glib-2.0 >= 2.2, gobject-2.0 >= 2.10, gtk+-2.0 >= 2.2, clutter-0.8 >= 0.8, clutter-gtk-0.8 >= 0.8 - ] + ] ) # Checks for header files. @@ -37,5 +37,14 @@ PKG_CHECK_MODULES(DEPS, AC_CONFIG_FILES([Makefile src/Makefile - tidy/Makefile]) + tidy/Makefile + champlain.pc]) AC_OUTPUT + + +echo "" +echo " Champlain $VERSION" +echo "" +echo " Prefix: ${prefix}" +echo " Compiler flags: ${CPPFLAGS}" +echo "" diff --git a/src/Makefile.am b/src/Makefile.am index a4f64bf..f5a5942 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,22 +8,26 @@ CLEANFILES = $(BUILT_SOURCES) CHAMPLAIN_MARSHAL = champlain-marshal CHAMPLAIN_MARSHAL_LIST = champlain-marshal.list -bin_PROGRAMS = champlain +lib_LTLIBRARIES = libchamplain-1.0.la -nodist_champlain_SOURCES = \ +bin_PROGRAMS = launcher + +nodist_libchamplain_1_0_la_SOURCES = \ $(BUILT_SOURCES) -champlain_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \ - champlain_widget.c \ - champlain_map.c \ - champlain_map_zoom_level.c \ - champlain_map_tile.c \ - map_source/openstreetmap.c \ - map_source/debugmap.c \ - launcher.c +launcher_SOURCES = launcher.c +launcher_LDADD = $(DEPS_LIBS) libchamplain-1.0.la + +libchamplain_1_0_la_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \ + champlainview.c \ + map.c \ + zoomlevel.c \ + tile.c \ + sources/openstreetmap.c \ + sources/debugmap.c -champlain_LDADD = $(DEPS_LIBS) ../tidy/libtidy-1.0.la +libchamplain_1_0_la_LIBADD = $(DEPS_LIBS) ../tidy/libtidy-1.0.la AM_CPPFLAGS = $(DEPS_CFLAGS) -I../tidy diff --git a/src/champlain_map_zoom_level.c b/src/champlain_map_zoom_level.c deleted file mode 100644 index a4e8f28..0000000 --- a/src/champlain_map_zoom_level.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2008 Pierre-Luc Beaudoin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include - -ChamplainMapZoomLevel* -champlain_map_zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size) -{ - ChamplainMapZoomLevel* level = g_new0(ChamplainMapZoomLevel, 1); - - level->level = zoom_level; - level->row_count = row; - level->column_count = column; - level->tile_size = tile_size; - level->tiles = g_ptr_array_sized_new (row * column); - level->group = clutter_group_new (); - - return level; -} - -void -champlain_map_zoom_level_create(ChamplainMap* map, gint zoom_level) -{ - int i; - for (i = 0; i < map->current_level->row_count * map->current_level->column_count; i++) - { - int x = i % map->current_level->column_count; - int y = i / map->current_level->column_count; - - ChamplainMapTile* tile = map->get_tile(map, zoom_level, x, y); - - clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); - g_ptr_array_add (map->current_level->tiles, tile); - } -} - -guint -champlain_map_zoom_level_get_width(ChamplainMapZoomLevel* level) -{ - return (level->column_count + 1) * level->tile_size; -} - -guint -champlain_map_zoom_level_get_height(ChamplainMapZoomLevel* level) -{ - return (level->row_count + 1) * level->tile_size; -} diff --git a/src/champlain_widget.c b/src/champlainview.c similarity index 64% rename from src/champlain_widget.c rename to src/champlainview.c index d159601..9919041 100644 --- a/src/champlain_widget.c +++ b/src/champlainview.c @@ -20,10 +20,10 @@ #include "config.h" #include "champlain_defines.h" -#include "champlain_map_tile.h" -#include "champlain_map.h" -#include "champlain_map_zoom_level.h" -#include "champlain_widget.h" +#include "champlain_view.h" +#include "map_tile.h" +#include "map.h" +#include "map_zoom_level.h" #include "champlain-marshal.h" #include @@ -49,9 +49,9 @@ enum PROP_TBD }; -static guint champlain_widget_signals[LAST_SIGNAL] = { 0, }; +static guint champlain_view_signals[LAST_SIGNAL] = { 0, }; -#define CHAMPLAIN_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_WIDGET, ChamplainWidgetPrivate)) +#define CHAMPLAIN_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_VIEW, ChamplainViewPrivate)) typedef struct { @@ -60,50 +60,50 @@ typedef struct ClutterUnit y; } ChamplainPoint; -struct _ChamplainWidgetPrivate +struct _ChamplainViewPrivate { GtkWidget *clutterEmbed; ClutterActor *viewport; ChamplainPoint viewportSize; ClutterActor *fingerScroll; - ChamplainMap *map; + Map *map; }; -G_DEFINE_TYPE (ChamplainWidget, champlain_widget, GTK_TYPE_ALIGNMENT); +G_DEFINE_TYPE (ChamplainView, champlain_view, GTK_TYPE_ALIGNMENT); static void -champlain_widget_finalize (GObject * object) +champlain_view_finalize (GObject * object) { - ChamplainWidget *widget = CHAMPLAIN_WIDGET (object); - ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (widget); + ChamplainView *view = CHAMPLAIN_VIEW (object); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); - G_OBJECT_CLASS (champlain_widget_parent_class)->finalize (object); + G_OBJECT_CLASS (champlain_view_parent_class)->finalize (object); } static void -champlain_widget_class_init (ChamplainWidgetClass *champlainWidgetClass) +champlain_view_class_init (ChamplainViewClass *champlainViewClass) { - g_type_class_add_private (champlainWidgetClass, sizeof (ChamplainWidgetPrivate)); + g_type_class_add_private (champlainViewClass, sizeof (ChamplainViewPrivate)); - GObjectClass *objectClass = G_OBJECT_CLASS (champlainWidgetClass); - objectClass->finalize = champlain_widget_finalize; + GObjectClass *objectClass = G_OBJECT_CLASS (champlainViewClass); + objectClass->finalize = champlain_view_finalize; } static void -champlain_widget_init (ChamplainWidget *champlainWidget) +champlain_view_init (ChamplainView *champlainView) { - ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); } static void -widget_size_allocated_cb (GtkWidget *widget, GtkAllocation *allocation, ChamplainWidget *champlainWidget) +view_size_allocated_cb (GtkWidget *view, GtkAllocation *allocation, ChamplainView *champlainView) { gdouble lower, upper; TidyAdjustment *hadjust, *vadjust; - ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (champlainWidget); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); priv->viewportSize.x = allocation->width; priv->viewportSize.y = allocation->height; clutter_actor_set_size (priv->fingerScroll, priv->viewportSize.x, priv->viewportSize.y); @@ -114,26 +114,27 @@ widget_size_allocated_cb (GtkWidget *widget, GtkAllocation *allocation, Champlai tidy_adjustment_get_values (hadjust, NULL, &lower, &upper, NULL, NULL, NULL); lower = 0; - upper = champlain_map_zoom_level_get_width(priv->map->current_level) - priv->viewportSize.x; + upper = map_zoom_level_get_width(priv->map->current_level) - priv->viewportSize.x; g_object_set (hadjust, "lower", lower, "upper", upper, "step-increment", 1.0, "elastic", TRUE, NULL); tidy_adjustment_get_values (vadjust, NULL, &lower, &upper, NULL, NULL, NULL); lower = 0; - upper = champlain_map_zoom_level_get_height(priv->map->current_level) - priv->viewportSize.y; + upper = map_zoom_level_get_height(priv->map->current_level) - priv->viewportSize.y; g_object_set (vadjust, "lower", lower, "upper", upper, "step-increment", 1.0, "elastic", TRUE, NULL); + } GtkWidget * -champlain_widget_new () +champlain_view_new () { ClutterColor stage_color = { 0x34, 0x39, 0x39, 0xff }; - ChamplainWidget *widget; + ChamplainView *view; ClutterActor *stage; - widget = CHAMPLAIN_WIDGET (g_object_new (CHAMPLAIN_TYPE_WIDGET, NULL)); - ChamplainWidgetPrivate *priv = CHAMPLAIN_WIDGET_GET_PRIVATE (widget); + view = CHAMPLAIN_VIEW (g_object_new (CHAMPLAIN_TYPE_VIEW, NULL)); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); priv->viewportSize.x = 640; priv->viewportSize.y = 480; @@ -141,14 +142,14 @@ champlain_widget_new () priv->clutterEmbed = gtk_clutter_embed_new (); g_signal_connect (priv->clutterEmbed, "size-allocate", - G_CALLBACK (widget_size_allocated_cb), - widget); + G_CALLBACK (view_size_allocated_cb), + view); // Setup stage stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutterEmbed)); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); - gtk_container_add (GTK_CONTAINER (widget), priv->clutterEmbed); + gtk_container_add (GTK_CONTAINER (view), priv->clutterEmbed); // Setup viewport priv->viewport = tidy_viewport_new (); @@ -161,9 +162,9 @@ champlain_widget_new () clutter_container_add_actor (CLUTTER_CONTAINER (priv->fingerScroll), priv->viewport); clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->fingerScroll); - priv->map = champlain_map_new(CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP);//OPENSTREETMAP - champlain_map_load(priv->map, 4); + priv->map = map_new(CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP);//OPENSTREETMAP + map_load(priv->map, 4); clutter_container_add_actor (CLUTTER_CONTAINER (group), priv->map->current_level->group); - return GTK_WIDGET (widget); + return GTK_WIDGET (view); } diff --git a/src/champlain_widget.h b/src/champlainview.h similarity index 52% rename from src/champlain_widget.h rename to src/champlainview.h index 7eaeebd..e9622f6 100644 --- a/src/champlain_widget.h +++ b/src/champlainview.h @@ -17,45 +17,45 @@ * Boston, MA 02110-1301, USA. */ -#ifndef CHAMPLAIN_WIDGET_H -#define CHAMPLAIN_WIDGET_H +#ifndef CHAMPLAIN_VIEW_H +#define CHAMPLAIN_VIEW_H #include #include #include #include -G_BEGIN_DECLS -#define CHAMPLAIN_TYPE_WIDGET (champlain_widget_get_type()) -#define CHAMPLAIN_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHAMPLAIN_TYPE_WIDGET, ChamplainWidget)) -#define CHAMPLAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CHAMPLAIN_TYPE_WIDGET, ChamplainWidgetClass)) -#define CHAMPLAIN_IS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHAMPLAIN_TYPE_WIDGET)) -#define CHAMPLAIN_IS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CHAMPLAIN_TYPE_WIDGET)) -#define CHAMPLAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CHAMPLAIN_TYPE_WIDGET, ChamplainWidgetClass)) -typedef struct _ChamplainWidgetPrivate ChamplainWidgetPrivate; +typedef enum +{ + CHAMPLAIN_MAP_SOURCE_DEBUG, + CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, + CHAMPLAIN_MAP_SOURCE_GOOGLE +} ChamplainMapSource; + +#define CHAMPLAIN_TYPE_VIEW (champlain_view_get_type()) +#define CHAMPLAIN_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHAMPLAIN_TYPE_VIEW, ChamplainView)) +#define CHAMPLAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CHAMPLAIN_TYPE_VIEW, ChamplainViewClass)) +#define CHAMPLAIN_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHAMPLAIN_TYPE_VIEW)) +#define CHAMPLAIN_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CHAMPLAIN_TYPE_VIEW)) +#define CHAMPLAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CHAMPLAIN_TYPE_VIEW, ChamplainViewClass)) + +typedef struct _ChamplainViewPrivate ChamplainViewPrivate; -struct _ChamplainWidget +struct _ChamplainView { GtkAlignment bin; - ChamplainWidgetPrivate *priv; + ChamplainViewPrivate *priv; }; -struct _ChamplainWidgetClass +struct _ChamplainViewClass { GtkBinClass parent_class; - ChamplainWidget *(*create_widget) (ChamplainWidget * widget); - - void (*set_scroll_adjustments) (ChamplainWidget * widget, GtkAdjustment * hadjustment, GtkAdjustment * vadjustment); - }; -CHAMPLAIN_API GType champlain_widget_get_type (void); - -CHAMPLAIN_API GtkWidget *champlain_widget_new (void); +CHAMPLAIN_API GType champlain_view_get_type (void); -#define TILE_SIZE 100 -#define ROW_SIZE 5 +CHAMPLAIN_API GtkWidget *champlain_view_new (void); #endif diff --git a/src/launcher.c b/src/launcher.c index a150b49..8a215a3 100644 --- a/src/launcher.c +++ b/src/launcher.c @@ -60,7 +60,7 @@ main (int argc, char *argv[]) */ g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (on_destroy), NULL); - widget = champlain_widget_new (); + widget = champlain_view_new (); /* and insert it into the main window */ gtk_container_add (GTK_CONTAINER (window), widget); diff --git a/src/champlain_map.c b/src/map.c similarity index 55% rename from src/champlain_map.c rename to src/map.c index 13fe929..01f1af6 100644 --- a/src/champlain_map.c +++ b/src/map.c @@ -17,35 +17,35 @@ * Boston, MA 02110-1301, USA. */ -#include -#include +#include +#include -ChamplainMap* -champlain_map_new (ChamplainMapSourceId source) +Map* +map_new (ChamplainMapSource source) { - ChamplainMap* map = g_new0(ChamplainMap, 1); + Map* map = g_new0(Map, 1); - switch(source) - { - case CHAMPLAIN_MAP_SOURCE_DEBUG: - debugmap_init(map); - break; - case CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP: - osm_init(map); - break; - } - - return map; + switch(source) + { + case CHAMPLAIN_MAP_SOURCE_DEBUG: + debugmap_init(map); + break; + case CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP: + osm_init(map); + break; + } + + return map; } void -champlain_map_load(ChamplainMap* map, gint zoom_level) +map_load(Map* map, gint zoom_level) { - guint row_count = map->get_row_count(map, zoom_level); - guint column_count = map->get_column_count(map, zoom_level); - - map->current_level = champlain_map_zoom_level_new(zoom_level, row_count, column_count, map->tile_size); - champlain_map_zoom_level_create(map, zoom_level); + guint row_count = map->get_row_count(map, zoom_level); + guint column_count = map->get_column_count(map, zoom_level); + + map->current_level = zoom_level_new(zoom_level, row_count, column_count, map->tile_size); + zoom_level_create(map, zoom_level); } diff --git a/src/champlain_map.h b/src/map.h similarity index 67% rename from src/champlain_map.h rename to src/map.h index ef6e89c..44d9e7b 100644 --- a/src/champlain_map.h +++ b/src/map.h @@ -17,31 +17,33 @@ * Boston, MA 02110-1301, USA. */ -#ifndef CHAMPLAIN_MAP_H -#define CHAMPLAIN_MAP_H +#ifndef MAP_H +#define MAP_H +#include "champlainview.h" #include "champlain_defines.h" -#include "champlain_map_zoom_level.h" -#include "champlain_map_tile.h" +#include "zoomlevel.h" +#include "tile.h" + #include #include -struct _ChamplainMap +struct _Map { int zoom_levels; const gchar* name; - ChamplainMapZoomLevel* current_level; + ZoomLevel* current_level; int tile_size; - ChamplainMapTile* (* get_tile) (ChamplainMap* map, guint zoom_level, guint x, guint y); - guint (* get_row_count) (ChamplainMap* map, guint zoom_level); - guint (* get_column_count) (ChamplainMap* map, guint zoom_level); + Tile* (* get_tile) (Map* map, guint zoom_level, guint x, guint y); + guint (* get_row_count) (Map* map, guint zoom_level); + guint (* get_column_count) (Map* map, guint zoom_level); -} ; +}; -CHAMPLAIN_API ChamplainMap* champlain_map_new (ChamplainMapSourceId source); +CHAMPLAIN_API Map* champlain_map_new (ChamplainMapSource source); #endif diff --git a/src/map_source/debugmap.c b/src/map_source/debugmap.c deleted file mode 100644 index a66ca3b..0000000 --- a/src/map_source/debugmap.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2008 Pierre-Luc Beaudoin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "map_source/debugmap.h" -#include - -guint debugmap_row_count(ChamplainMap* map, guint zoom_level); -guint debugmap_column_count(ChamplainMap* map, guint zoom_level); -ChamplainMapTile* debugmap_get_tile (ChamplainMap* map, guint zoom_level, guint x, guint y); - -void -debugmap_init(ChamplainMap* map) -{ - map->name = "Debug"; - map->zoom_levels = 1; - map->tile_size = 256; - - map->get_row_count = debugmap_row_count; - map->get_column_count = debugmap_column_count; - map->get_tile = debugmap_get_tile; -} - -guint debugmap_row_count(ChamplainMap* map, guint zoom_level) -{ - return pow (2, zoom_level); -} - -guint debugmap_column_count(ChamplainMap* map, guint zoom_level) -{ - return pow (2, zoom_level); -} - -ChamplainMapTile* debugmap_get_tile (ChamplainMap* map, guint zoom_level, guint x, guint y) -{ - - ChamplainMapTile* tile = g_new0(ChamplainMapTile, 1); - - ClutterColor white; - clutter_color_parse ("white", &white); - ClutterColor blue; - clutter_color_parse ("blue", &blue); - - ClutterColor * color, * textColor; - if ((y + x) % 2) - { - color = &blue; - textColor = &white; - } - else - { - color = &white; - textColor = &blue; - } - - - tile->x = x; - tile->y = y; - tile->visible = FALSE; - tile->actor = clutter_group_new(); - - ClutterActor* actor = clutter_rectangle_new_with_color (color); - clutter_actor_set_position (actor, x * map->tile_size, y * map->tile_size); - clutter_actor_set_size (actor, map->tile_size, map->tile_size); - clutter_actor_show (actor); - clutter_container_add_actor (CLUTTER_CONTAINER (tile->actor), actor); - - actor = clutter_label_new_full ("Arial", g_strdup_printf("%d, %d", x, y), textColor); - clutter_actor_set_position (actor, x * map->tile_size + map->tile_size/2.25, y * map->tile_size + map->tile_size/2.25); - clutter_container_add_actor (CLUTTER_CONTAINER (tile->actor), actor); - - g_object_ref(tile->actor); // to prevent actors to be destroyed when they are removed from groups - - return tile; -} diff --git a/src/sources/debugmap.c b/src/sources/debugmap.c new file mode 100644 index 0000000..5abc2ee --- /dev/null +++ b/src/sources/debugmap.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "sources/debugmap.h" +#include + +guint debugmap_row_count(Map* map, guint zoom_level); +guint debugmap_column_count(Map* map, guint zoom_level); +Tile* debugmap_get_tile (Map* map, guint zoom_level, guint x, guint y); + +void +debugmap_init(Map* map) +{ + map->name = "Debug"; + map->zoom_levels = 1; + map->tile_size = 256; + + map->get_row_count = debugmap_row_count; + map->get_column_count = debugmap_column_count; + map->get_tile = debugmap_get_tile; +} + +guint debugmap_row_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +guint debugmap_column_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +Tile* debugmap_get_tile (Map* map, guint zoom_level, guint x, guint y) +{ + + Tile* tile = g_new0(Tile, 1); + + ClutterColor white; + clutter_color_parse ("white", &white); + ClutterColor blue; + clutter_color_parse ("blue", &blue); + + ClutterColor * color, * textColor; + if ((y + x) % 2) + { + color = &blue; + textColor = &white; + } + else + { + color = &white; + textColor = &blue; + } + + tile->x = x; + tile->y = y; + tile->visible = FALSE; + tile->actor = clutter_group_new(); + + ClutterActor* actor = clutter_rectangle_new_with_color (color); + clutter_actor_set_position (actor, x * map->tile_size, y * map->tile_size); + clutter_actor_set_size (actor, map->tile_size, map->tile_size); + clutter_actor_show (actor); + clutter_container_add_actor (CLUTTER_CONTAINER (tile->actor), actor); + + actor = clutter_label_new_full ("Arial", g_strdup_printf("%d, %d", x, y), textColor); + clutter_actor_set_position (actor, x * map->tile_size + map->tile_size/2.25, y * map->tile_size + map->tile_size/2.25); + clutter_container_add_actor (CLUTTER_CONTAINER (tile->actor), actor); + + g_object_ref(tile->actor); // to prevent actors to be destroyed when they are removed from groups + + return tile; +} diff --git a/src/map_source/debugmap.h b/src/sources/debugmap.h similarity index 93% rename from src/map_source/debugmap.h rename to src/sources/debugmap.h index 0ca96d4..e30ba8f 100644 --- a/src/map_source/debugmap.h +++ b/src/sources/debugmap.h @@ -20,8 +20,8 @@ #ifndef OPENSTREETMAP_H #define OPENSTREETMAP_H -#include +#include -void debugmap_init(ChamplainMap* map); +void debugmap_init(Map* map); #endif diff --git a/src/map_source/openstreetmap.c b/src/sources/openstreetmap.c similarity index 52% rename from src/map_source/openstreetmap.c rename to src/sources/openstreetmap.c index 538e403..c55010f 100644 --- a/src/map_source/openstreetmap.c +++ b/src/sources/openstreetmap.c @@ -17,21 +17,21 @@ * Boston, MA 02110-1301, USA. */ -#include "map_source/openstreetmap.h" -#include +#include "sources/openstreetmap.h" +#include #include //http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames#C.2FC.2B.2B -guint osm_row_count(ChamplainMap* map, guint zoom_level); -guint osm_column_count(ChamplainMap* map, guint zoom_level); -ChamplainMapTile* osm_get_tile (ChamplainMap* map, guint zoom_level, guint x, guint y); +guint osm_row_count(Map* map, guint zoom_level); +guint osm_column_count(Map* map, guint zoom_level); +Tile* osm_get_tile (Map* map, guint zoom_level, guint x, guint y); void -osm_init(ChamplainMap* map) +osm_init(Map* map) { - map->name = "OpenStreetMap"; - map->zoom_levels = 17; + map->name = "OpenStreetMap"; + map->zoom_levels = 17; map->tile_size = 256; map->get_row_count = osm_row_count; @@ -39,35 +39,35 @@ osm_init(ChamplainMap* map) map->get_tile = osm_get_tile; } -guint osm_row_count(ChamplainMap* map, guint zoom_level) +guint osm_row_count(Map* map, guint zoom_level) { - return pow (2, zoom_level); + return pow (2, zoom_level); } -guint osm_column_count(ChamplainMap* map, guint zoom_level) +guint osm_column_count(Map* map, guint zoom_level) { - return pow (2, zoom_level); + return pow (2, zoom_level); } -ChamplainMapTile* osm_get_tile (ChamplainMap* map, guint zoom_level, guint x, guint y) +Tile* osm_get_tile (Map* map, guint zoom_level, guint x, guint y) { - ChamplainMapTile* tile = g_new0(ChamplainMapTile, 1); - - tile->x = x; - tile->y = y; - tile->visible = FALSE; + Tile* tile = g_new0(Tile, 1); + + tile->x = x; + tile->y = y; + tile->visible = FALSE; // For no apparent reason, the group is necessary even if // it contains only one actor... if missing, the viewport will break - tile->actor = clutter_group_new(); - - ClutterActor* actor = clutter_texture_new_from_file(g_strdup_printf("/home/plbeaudoin/champlain/tiles/%d/%d/%d.png", zoom_level, x, y), NULL); - clutter_actor_set_position (actor, x * map->tile_size, y * map->tile_size); - clutter_actor_set_size (actor, map->tile_size, map->tile_size); - clutter_actor_show (actor); + tile->actor = clutter_group_new(); + + ClutterActor* actor = clutter_texture_new_from_file(g_strdup_printf("/home/plbeaudoin/champlain/tiles/%d/%d/%d.png", zoom_level, x, y), NULL); + clutter_actor_set_position (actor, x * map->tile_size, y * map->tile_size); + clutter_actor_set_size (actor, map->tile_size, map->tile_size); + clutter_actor_show (actor); clutter_container_add_actor (CLUTTER_CONTAINER (tile->actor), actor); - g_object_ref(tile->actor); // to prevent actors to be destroyed when they are removed from groups - - return tile; - + g_object_ref(tile->actor); // to prevent actors to be destroyed when they are removed from groups + + return tile; + } diff --git a/src/map_source/openstreetmap.h b/src/sources/openstreetmap.h similarity index 93% rename from src/map_source/openstreetmap.h rename to src/sources/openstreetmap.h index ed351dd..e8c26ba 100644 --- a/src/map_source/openstreetmap.h +++ b/src/sources/openstreetmap.h @@ -20,8 +20,8 @@ #ifndef OPENSTREETMAP_H #define OPENSTREETMAP_H -#include +#include -void osm_init(ChamplainMap* map); +void osm_init(Map* map); #endif diff --git a/src/champlain_map_tile.c b/src/tile.c similarity index 57% rename from src/champlain_map_tile.c rename to src/tile.c index ddc4fda..ad1386c 100644 --- a/src/champlain_map_tile.c +++ b/src/tile.c @@ -18,29 +18,28 @@ */ -#include "champlain_map_tile.h" +#include "tile.h" /* gboolean -tile_is_visible(ClutterUnit viewport_w, ClutterUnit viewport_h, ChamplainPoint position, ChamplainMapTile* tile) +tile_is_visible(ClutterUnit viewport_w, ClutterUnit viewport_h, ChamplainPoint position, MapTile* tile) { - ClutterUnit size = CLUTTER_UNITS_FROM_INT(tile->size); + ClutterUnit size = CLUTTER_UNITS_FROM_INT(tile->size); - - if( ((tile->x + 1)* size + position.x < 0 || tile->x* size + position.x > viewport_w) || - ((tile->y + 1)* size + position.y < 0 || tile->y* size + position.y > viewport_h)) - { - g_print ("Tile I: %d, %d\t p: %d, %d \n", - tile->x, tile->y, - CLUTTER_UNITS_TO_INT (position.x), - CLUTTER_UNITS_TO_INT (position.y)); - return FALSE; - } - //g_print ("Tile V: %d, %d\t p: %d, %d \n", - //tile->x, tile->y, - //CLUTTER_UNITS_TO_INT (position.x), - //CLUTTER_UNITS_TO_INT (position.y)); - return TRUE; + if( ((tile->x + 1)* size + position.x < 0 || tile->x* size + position.x > viewport_w) || + ((tile->y + 1)* size + position.y < 0 || tile->y* size + position.y > viewport_h)) + { + g_print ("Tile I: %d, %d\t p: %d, %d \n", + tile->x, tile->y, + CLUTTER_UNITS_TO_INT (position.x), + CLUTTER_UNITS_TO_INT (position.y)); + return FALSE; + } + //g_print ("Tile V: %d, %d\t p: %d, %d \n", + //tile->x, tile->y, + //CLUTTER_UNITS_TO_INT (position.x), + //CLUTTER_UNITS_TO_INT (position.y)); + return TRUE; }*/ diff --git a/src/champlain_map_tile.h b/src/tile.h similarity index 98% rename from src/champlain_map_tile.h rename to src/tile.h index c31e903..7065c3b 100644 --- a/src/champlain_map_tile.h +++ b/src/tile.h @@ -31,6 +31,6 @@ typedef struct int size; gboolean visible; // Wether the tile is visible in the viewport -} ChamplainMapTile; +} Tile; #endif diff --git a/src/zoomlevel.c b/src/zoomlevel.c new file mode 100644 index 0000000..e56d47c --- /dev/null +++ b/src/zoomlevel.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include "map.h" +#include +#include + +ZoomLevel* +zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size) +{ + ZoomLevel* level = g_new0(ZoomLevel, 1); + + level->level = zoom_level; + level->row_count = row; + level->column_count = column; + level->tile_size = tile_size; + level->tiles = g_ptr_array_sized_new (row * column); + level->group = clutter_group_new (); + + return level; +} + +void +zoom_level_create(Map* map, gint zoom_level) +{ + int i; + for (i = 0; i < map->current_level->row_count * map->current_level->column_count; i++) + { + int x = i % map->current_level->column_count; + int y = i / map->current_level->column_count; + + Tile* tile = map->get_tile(map, zoom_level, x, y); + + clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); + g_ptr_array_add (map->current_level->tiles, tile); + } +} + +guint +zoom_level_get_width(ZoomLevel* level) +{ + return (level->column_count + 1) * level->tile_size; +} + +guint +zoom_level_get_height(ZoomLevel* level) +{ + return (level->row_count + 1) * level->tile_size; +} diff --git a/src/champlain_map_zoom_level.h b/src/zoomlevel.h similarity index 79% rename from src/champlain_map_zoom_level.h rename to src/zoomlevel.h index 0834927..1aa5482 100644 --- a/src/champlain_map_zoom_level.h +++ b/src/zoomlevel.h @@ -33,12 +33,12 @@ typedef struct GPtrArray *tiles; ClutterActor* group; -} ChamplainMapZoomLevel; +} ZoomLevel; -guint champlain_map_zoom_level_get_width(ChamplainMapZoomLevel* level); +guint zoom_level_get_width(ZoomLevel* level); -guint champlain_map_zoom_level_get_height(ChamplainMapZoomLevel* level); +guint zoom_level_get_height(ZoomLevel* level); -ChamplainMapZoomLevel* champlain_map_zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size); +ZoomLevel* zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size); #endif -- 2.39.5