dia-newcanvas-0.6.10/ 0040755 0001750 0001750 00000000000 07542443060 014674 5 ustar xordoquy xordoquy dia-newcanvas-0.6.10/doc/ 0040755 0001750 0001750 00000000000 07542442521 015442 5 ustar xordoquy xordoquy dia-newcanvas-0.6.10/doc/.cvsignore 0100644 0001750 0001750 00000000025 07324042636 017435 0 ustar xordoquy xordoquy Makefile
Makefile.in
dia-newcanvas-0.6.10/doc/Makefile.am 0100644 0001750 0001750 00000012344 07323670324 017500 0 ustar xordoquy xordoquy ## Process this file with automake to produce Makefile.in
# This is a blank Makefile.am for using gtk-doc.
# Copy this to your project's API docs directory and modify the variables to
# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples
# of using the various options.
# The name of the module, e.g. 'glib'.
DOC_MODULE=dia-newcanvas
# The top-level SGML file. Change it if you want.
DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
# The directory containing the source code. Relative to $(srcdir).
# gtk-doc will search all .c & .h files beneath here for inline comments
# documenting functions and macros.
DOC_SOURCE_DIR=../
# Extra options to supply to gtkdoc-scan.
SCAN_OPTIONS=
# Extra options to supply to gtkdoc-mkdb.
MKDB_OPTIONS=
# Extra options to supply to gtkdoc-fixref.
FIXXREF_OPTIONS=
# Used for dependencies.
HFILE_GLOB=
CFILE_GLOB=
# Header files to ignore when scanning.
IGNORE_HFILES=
# Images to copy into HTML directory.
HTML_IMAGES =
# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
content_files =
# Other files to distribute.
extra_files =
# CFLAGS and LDFLAGS for compiling scan program. Only needed if your app/lib
# contains GtkObjects/GObjects and you want to document signals and properties.
GTKDOC_CFLAGS =
GTKDOC_LIBS =
GTKDOC_CC=$(LIBTOOL) --mode=compile $(CC)
GTKDOC_LD=$(LIBTOOL) --mode=link $(CC)
# If you need to override some of the declarations, place them in this file
# and uncomment this line.
#DOC_OVERRIDES = $(DOC_MODULE)-overrides.txt
###########################################################################
# Everything below here is generic and you shouldn't need to change it.
###########################################################################
TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE)
EXTRA_DIST = \
$(content_files) \
$(extra_files) \
$(HTML_IMAGES) \
$(DOC_MAIN_SGML_FILE) \
$(DOC_MODULE).types \
$(DOC_MODULE)-sections.txt \
$(DOC_OVERRIDES)
DOC_STAMPS=scan-build.stamp tmpl-build.stamp sgml-build.stamp html-build.stamp \
$(srcdir)/tmpl.stamp $(srcdir)/sgml.stamp $(srcdir)/html.stamp
SCANOBJ_FILES = \
$(DOC_MODULE).args \
$(DOC_MODULE).hierarchy \
$(DOC_MODULE).signals
if ENABLE_GTK_DOC
all-local: html-build.stamp
#### scan ####
scan-build.stamp: $(HFILE_GLOB)
@echo '*** Scanning header files ***'
if grep -l '^..*$$' $(srcdir)/$(DOC_MODULE).types > /dev/null ; then \
CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" CFLAGS="$(GTKDOC_CFLAGS)" LDFLAGS="$(GTKDOC_LIBS)" gtkdoc-scanobj --module=$(DOC_MODULE) --output-dir=$(srcdir) ; \
else \
cd $(srcdir) ; \
for i in $(SCANOBJ_FILES) ; do \
test -f $$i || touch $$i ; \
done \
fi
cd $(srcdir) && \
gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="$(IGNORE_HFILES)" $(SCAN_OPTIONS) $(EXTRA_HFILES)
touch scan-build.stamp
$(DOC_MODULE)-decl.txt $(SCANOBJ_FILES): scan-build.stamp
@true
#### templates ####
tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_OVERRIDES)
@echo '*** Rebuilding template files ***'
cd $(srcdir) && gtkdoc-mktmpl --module=$(DOC_MODULE)
touch tmpl-build.stamp
tmpl.stamp: tmpl-build.stamp
@true
#### sgml ####
sgml-build.stamp: tmpl.stamp $(CFILE_GLOB) $(srcdir)/tmpl/*.sgml
@echo '*** Building SGML ***'
cd $(srcdir) && \
gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --main-sgml-file=$(DOC_MAIN_SGML_FILE) $(MKDB_OPTIONS)
touch sgml-build.stamp
sgml.stamp: sgml-build.stamp
@true
#### html ####
html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
@echo '*** Building HTML ***'
test -d $(srcdir)/html || mkdir $(srcdir)/html
cd $(srcdir)/html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html )
@echo '-- Fixing Crossreferences'
cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
touch html-build.stamp
endif
##############
clean-local:
rm -f *~ *.bak $(SCANOBJ_FILES) *-unused.txt $(DOC_STAMPS)
maintainer-clean-local: clean
cd $(srcdir) && rm -rf sgml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(TARGET_DIR)
(installfiles=`echo $(srcdir)/html/*.html`; \
if test "$$installfiles" = '$(srcdir)/html/*.html'; \
then echo '-- Nothing to install' ; \
else \
for i in $$installfiles; do \
echo '-- Installing '$$i ; \
$(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \
done; \
echo '-- Installing $(srcdir)/html/index.sgml' ; \
$(INSTALL_DATA) $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR); \
fi)
#
# Require gtk-doc when making dist
#
if ENABLE_GTK_DOC
dist-check-gtkdoc:
else
dist-check-gtkdoc:
@echo "*** gtk-doc must be installed and enabled in order to make dist"
@false
endif
dist-hook: dist-check-gtkdoc dist-hook-local
mkdir $(distdir)/tmpl
mkdir $(distdir)/sgml
mkdir $(distdir)/html
-cp $(srcdir)/tmpl/*.sgml $(distdir)/tmpl
-cp $(srcdir)/sgml/*.sgml $(distdir)/sgml
-cp $(srcdir)/html/index.sgml $(distdir)/html
-cp $(srcdir)/html/*.html $(srcdir)/html/*.css $(distdir)/html
images=$(HTML_IMAGES) ; \
for i in $$images ; do \
cp $(srcdir)/$$i $(distdir)/html ; \
done
.PHONY : dist-hook-local
dia-newcanvas-0.6.10/doc/new-canvas.dia 0100644 0001750 0001750 00000140705 07100263256 020163 0 ustar xordoquy xordoquy
#A4#
dia-newcanvas-0.6.10/src/ 0040755 0001750 0001750 00000000000 07542442635 015472 5 ustar xordoquy xordoquy dia-newcanvas-0.6.10/src/Makefile.in 0100644 0001750 0001750 00000047775 07542442635 017560 0 ustar xordoquy xordoquy # Makefile.in generated by automake 1.6.3 from Makefile.am.
# @configure_input@
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_HEADER = $(INSTALL_DATA)
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_alias = @host_alias@
host_triplet = @host@
EXEEXT = @EXEEXT@
OBJEXT = @OBJEXT@
PATH_SEPARATOR = @PATH_SEPARATOR@
AMTAR = @AMTAR@
AS = @AS@
AWK = @AWK@
CC = @CC@
DEPDIR = @DEPDIR@
DIANEWCANVAS_CFLAGS = @DIANEWCANVAS_CFLAGS@
DIANEWCANVAS_LIBS = @DIANEWCANVAS_LIBS@
DLLTOOL = @DLLTOOL@
ECHO = @ECHO@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
MAINT = @MAINT@
OBJDUMP = @OBJDUMP@
PACKAGE = @PACKAGE@
PKG_CONFIG = @PKG_CONFIG@
PYGTK_CFLAGS = @PYGTK_CFLAGS@
PYGTK_CODEGEN = @PYGTK_CODEGEN@
PYGTK_DEFSDIR = @PYGTK_DEFSDIR@
PYTHON = @PYTHON@
PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
PYTHON_INCLUDES = @PYTHON_INCLUDES@
PYTHON_PLATFORM = @PYTHON_PLATFORM@
PYTHON_PREFIX = @PYTHON_PREFIX@
PYTHON_VERSION = @PYTHON_VERSION@
RANLIB = @RANLIB@
STRIP = @STRIP@
VERSION = @VERSION@
am__include = @am__include@
am__quote = @am__quote@
install_sh = @install_sh@
pkgpyexecdir = @pkgpyexecdir@
pkgpythondir = @pkgpythondir@
pyexecdir = @pyexecdir@
pythondir = @pythondir@
INCLUDES = -DG_LOG_DOMAIN=\"dianewcanvas2\" @LIBGLADE_CFLAGS@ $(DIANEWCANVAS_CFLAGS) -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations
#glademoduledir = `pkg-config --variable moduledir libglade-2.0`
glademoduledir = $(libdir)/libglade/2.0
@BUILD_LIBGLADE_MODULE_TRUE@libgladedianewcanvas2_la = libgladedianewcanvas2.la
lib_LTLIBRARIES = libdianewcanvas2.la
glademodule_LTLIBRARIES = libgladedianewcanvas2.la
libdianewcanvas2_la_SOURCES = \
dia-canvas.c \
dia-canvas-item.c \
dia-canvas-group.c \
dia-canvas-point.c \
dia-canvas-line.c \
dia-canvas-rectangle.c \
dia-canvas-polygon.c \
dia-canvas-ellipse.c \
dia-canvas-arc.c \
dia-canvas-view.c \
dia-canvas-view-gdk.c \
dia-renderer.c \
dia-geometry.c \
dia-canvas-grid.c \
dia-canvas-connection.c \
dia-canvas-attracted.c \
dia-canvas-attract.c \
dia-canvas-text.c
# dia-canvas-bezier.c
# dia-canvas-pixbuf.c
libdianewcanvas2includedir = $(includedir)/dia-newcanvas-1.0/dia-newcanvas
libdianewcanvas2include_HEADERS = \
dia-newcanvas.h \
dia-canvas.h \
dia-canvas-item.h \
dia-canvas-group.h \
dia-canvas-point.h \
dia-canvas-line.h \
dia-canvas-rectangle.h \
dia-canvas-polygon.h \
dia-canvas-ellipse.h \
dia-canvas-arc.h \
dia-canvas-view.h \
dia-canvas-view-gdk.h \
dia-canvas-view-aa.h \
dia-renderer.h \
dia-geometry.h \
dia-canvas-grid.h \
dia-canvas-connection.h \
dia-canvas-attracted.h \
dia-canvas-attract.h \
dia-marshal.h \
dia-canvas-text.h
# dia-canvas-bezier.h
# dia-canvas-pixbuf.h
libgladedianewcanvas2_la_SOURCES = libglade.c
libgladedianewcanvas2_la_LIBADD = libdianewcanvas2.la
libgladedianewcanvas2_la_LDFALGS = -export-dynamic -module -avoid-version
noinst_PROGRAMS = test-diacanvas test-diacanvas2
test_diacanvas_SOURCES = test-diacanvas.c
test_diacanvas_LDADD = libdianewcanvas2.la -lm $(DIANEWCANVAS_LIBS)
test_diacanvas2_SOURCES = test-diacanvas2.c
test_diacanvas2_LDADD = libdianewcanvas2.la -lm $(DIANEWCANVAS_LIBS)
EXTRA_DIST = dia-marshal.list
subdir = src
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(glademodule_LTLIBRARIES) $(lib_LTLIBRARIES)
libdianewcanvas2_la_LDFLAGS =
libdianewcanvas2_la_LIBADD =
am_libdianewcanvas2_la_OBJECTS = dia-canvas.lo dia-canvas-item.lo \
dia-canvas-group.lo dia-canvas-point.lo dia-canvas-line.lo \
dia-canvas-rectangle.lo dia-canvas-polygon.lo \
dia-canvas-ellipse.lo dia-canvas-arc.lo dia-canvas-view.lo \
dia-canvas-view-gdk.lo dia-renderer.lo dia-geometry.lo \
dia-canvas-grid.lo dia-canvas-connection.lo \
dia-canvas-attracted.lo dia-canvas-attract.lo \
dia-canvas-text.lo
libdianewcanvas2_la_OBJECTS = $(am_libdianewcanvas2_la_OBJECTS)
libgladedianewcanvas2_la_LDFLAGS =
libgladedianewcanvas2_la_DEPENDENCIES = libdianewcanvas2.la
am_libgladedianewcanvas2_la_OBJECTS = libglade.lo
libgladedianewcanvas2_la_OBJECTS = \
$(am_libgladedianewcanvas2_la_OBJECTS)
noinst_PROGRAMS = test-diacanvas$(EXEEXT) test-diacanvas2$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS)
am_test_diacanvas_OBJECTS = test-diacanvas.$(OBJEXT)
test_diacanvas_OBJECTS = $(am_test_diacanvas_OBJECTS)
test_diacanvas_DEPENDENCIES = libdianewcanvas2.la
test_diacanvas_LDFLAGS =
am_test_diacanvas2_OBJECTS = test-diacanvas2.$(OBJEXT)
test_diacanvas2_OBJECTS = $(am_test_diacanvas2_OBJECTS)
test_diacanvas2_DEPENDENCIES = libdianewcanvas2.la
test_diacanvas2_LDFLAGS =
DEFS = @DEFS@
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/dia-canvas-arc.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-attract.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-attracted.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-connection.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-ellipse.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-grid.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-group.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-item.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-line.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-point.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-polygon.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-rectangle.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-text.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-view-gdk.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas-view.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-canvas.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-geometry.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/dia-renderer.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/libglade.Plo \
@AMDEP_TRUE@ ./$(DEPDIR)/test-diacanvas.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/test-diacanvas2.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
DIST_SOURCES = $(libdianewcanvas2_la_SOURCES) \
$(libgladedianewcanvas2_la_SOURCES) $(test_diacanvas_SOURCES) \
$(test_diacanvas2_SOURCES)
HEADERS = $(libdianewcanvas2include_HEADERS)
DIST_COMMON = $(libdianewcanvas2include_HEADERS) Makefile.am \
Makefile.in
SOURCES = $(libdianewcanvas2_la_SOURCES) $(libgladedianewcanvas2_la_SOURCES) $(test_diacanvas_SOURCES) $(test_diacanvas2_SOURCES)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu src/Makefile
Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
glademoduleLTLIBRARIES_INSTALL = $(INSTALL)
install-glademoduleLTLIBRARIES: $(glademodule_LTLIBRARIES)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(glademoduledir)
@list='$(glademodule_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(LIBTOOL) --mode=install $(glademoduleLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(glademoduledir)/$$f"; \
$(LIBTOOL) --mode=install $(glademoduleLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(glademoduledir)/$$f; \
else :; fi; \
done
uninstall-glademoduleLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@list='$(glademodule_LTLIBRARIES)'; for p in $$list; do \
p="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(glademoduledir)/$$p"; \
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(glademoduledir)/$$p; \
done
clean-glademoduleLTLIBRARIES:
-test -z "$(glademodule_LTLIBRARIES)" || rm -f $(glademodule_LTLIBRARIES)
@list='$(glademodule_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test -z "$dir" && dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libLTLIBRARIES_INSTALL = $(INSTALL)
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(libdir)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(libdir)/$$f"; \
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(libdir)/$$f; \
else :; fi; \
done
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
p="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p"; \
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test -z "$dir" && dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libdianewcanvas2.la: $(libdianewcanvas2_la_OBJECTS) $(libdianewcanvas2_la_DEPENDENCIES)
$(LINK) -rpath $(libdir) $(libdianewcanvas2_la_LDFLAGS) $(libdianewcanvas2_la_OBJECTS) $(libdianewcanvas2_la_LIBADD) $(LIBS)
libgladedianewcanvas2.la: $(libgladedianewcanvas2_la_OBJECTS) $(libgladedianewcanvas2_la_DEPENDENCIES)
$(LINK) -rpath $(glademoduledir) $(libgladedianewcanvas2_la_LDFLAGS) $(libgladedianewcanvas2_la_OBJECTS) $(libgladedianewcanvas2_la_LIBADD) $(LIBS)
clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
test-diacanvas$(EXEEXT): $(test_diacanvas_OBJECTS) $(test_diacanvas_DEPENDENCIES)
@rm -f test-diacanvas$(EXEEXT)
$(LINK) $(test_diacanvas_LDFLAGS) $(test_diacanvas_OBJECTS) $(test_diacanvas_LDADD) $(LIBS)
test-diacanvas2$(EXEEXT): $(test_diacanvas2_OBJECTS) $(test_diacanvas2_DEPENDENCIES)
@rm -f test-diacanvas2$(EXEEXT)
$(LINK) $(test_diacanvas2_LDFLAGS) $(test_diacanvas2_OBJECTS) $(test_diacanvas2_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT) core *.core
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-arc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-attract.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-attracted.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-connection.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-ellipse.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-grid.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-group.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-item.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-line.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-point.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-polygon.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-rectangle.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-text.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-view-gdk.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas-view.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-canvas.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-geometry.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dia-renderer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libglade.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-diacanvas.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-diacanvas2.Po@am__quote@
distclean-depend:
-rm -rf ./$(DEPDIR)
.c.o:
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
.c.obj:
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
$(COMPILE) -c `cygpath -w $<`
.c.lo:
@AMDEP_TRUE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
CCDEPMODE = @CCDEPMODE@
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
libdianewcanvas2includeHEADERS_INSTALL = $(INSTALL_HEADER)
install-libdianewcanvas2includeHEADERS: $(libdianewcanvas2include_HEADERS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(libdianewcanvas2includedir)
@list='$(libdianewcanvas2include_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(libdianewcanvas2includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(libdianewcanvas2includedir)/$$f"; \
$(libdianewcanvas2includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(libdianewcanvas2includedir)/$$f; \
done
uninstall-libdianewcanvas2includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(libdianewcanvas2include_HEADERS)'; for p in $$list; do \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " rm -f $(DESTDIR)$(libdianewcanvas2includedir)/$$f"; \
rm -f $(DESTDIR)$(libdianewcanvas2includedir)/$$f; \
done
ETAGS = etags
ETAGSFLAGS =
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$tags$$unique" \
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
distdir: $(DISTFILES)
@list='$(DISTFILES)'; for file in $$list; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkinstalldirs) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS)
installdirs:
$(mkinstalldirs) $(DESTDIR)$(glademoduledir) $(DESTDIR)$(libdir) $(DESTDIR)$(libdianewcanvas2includedir)
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-glademoduleLTLIBRARIES \
clean-libLTLIBRARIES clean-libtool clean-noinstPROGRAMS \
mostlyclean-am
distclean: distclean-am
distclean-am: clean-am distclean-compile distclean-depend \
distclean-generic distclean-libtool distclean-tags
dvi: dvi-am
dvi-am:
info: info-am
info-am:
install-data-am: install-glademoduleLTLIBRARIES \
install-libdianewcanvas2includeHEADERS
install-exec-am: install-libLTLIBRARIES
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
uninstall-am: uninstall-glademoduleLTLIBRARIES uninstall-info-am \
uninstall-libLTLIBRARIES \
uninstall-libdianewcanvas2includeHEADERS
.PHONY: GTAGS all all-am check check-am clean clean-generic \
clean-glademoduleLTLIBRARIES clean-libLTLIBRARIES clean-libtool \
clean-noinstPROGRAMS distclean distclean-compile \
distclean-depend distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am info info-am install \
install-am install-data install-data-am install-exec \
install-exec-am install-glademoduleLTLIBRARIES install-info \
install-info-am install-libLTLIBRARIES \
install-libdianewcanvas2includeHEADERS install-man \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
tags uninstall uninstall-am uninstall-glademoduleLTLIBRARIES \
uninstall-info-am uninstall-libLTLIBRARIES \
uninstall-libdianewcanvas2includeHEADERS
dia-canvas.c: dia-marshal.h dia-marshal.c
dia-marshal.h: dia-marshal.list
cd $(srcdir) \
&& glib-genmarshal --prefix=dia_marshal dia-marshal.list --header >> xgen-dmh \
&& cp xgen-dmh dia-marshal.h \
&& rm -f xgen-dmh xgen-dmh~
dia-marshal.c: dia-marshal.list
cd $(srcdir) \
&& glib-genmarshal --prefix=dia_marshal dia-marshal.list --body >> xgen-dmc \
&& cp xgen-dmc dia-marshal.c \
&& rm -f xgen-dmc xgen-dmc~
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
dia-newcanvas-0.6.10/src/Makefile.am 0100644 0001750 0001750 00000004555 07537446061 017535 0 ustar xordoquy xordoquy
INCLUDES = -DG_LOG_DOMAIN=\"dianewcanvas2\" @LIBGLADE_CFLAGS@ $(DIANEWCANVAS_CFLAGS) -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations
#glademoduledir = `pkg-config --variable moduledir libglade-2.0`
glademoduledir = $(libdir)/libglade/2.0
if BUILD_LIBGLADE_MODULE
libgladedianewcanvas2_la = libgladedianewcanvas2.la
endif
lib_LTLIBRARIES = libdianewcanvas2.la
glademodule_LTLIBRARIES = libgladedianewcanvas2.la
libdianewcanvas2_la_SOURCES = \
dia-canvas.c \
dia-canvas-item.c \
dia-canvas-group.c \
dia-canvas-point.c \
dia-canvas-line.c \
dia-canvas-rectangle.c \
dia-canvas-polygon.c \
dia-canvas-ellipse.c \
dia-canvas-arc.c \
dia-canvas-view.c \
dia-canvas-view-gdk.c \
dia-renderer.c \
dia-geometry.c \
dia-canvas-grid.c \
dia-canvas-connection.c \
dia-canvas-attracted.c \
dia-canvas-attract.c \
dia-canvas-text.c
# dia-canvas-bezier.c
# dia-canvas-pixbuf.c
libdianewcanvas2includedir=$(includedir)/dia-newcanvas-1.0/dia-newcanvas
libdianewcanvas2include_HEADERS = \
dia-newcanvas.h \
dia-canvas.h \
dia-canvas-item.h \
dia-canvas-group.h \
dia-canvas-point.h \
dia-canvas-line.h \
dia-canvas-rectangle.h \
dia-canvas-polygon.h \
dia-canvas-ellipse.h \
dia-canvas-arc.h \
dia-canvas-view.h \
dia-canvas-view-gdk.h \
dia-canvas-view-aa.h \
dia-renderer.h \
dia-geometry.h \
dia-canvas-grid.h \
dia-canvas-connection.h \
dia-canvas-attracted.h \
dia-canvas-attract.h \
dia-marshal.h \
dia-canvas-text.h
# dia-canvas-bezier.h
# dia-canvas-pixbuf.h
libgladedianewcanvas2_la_SOURCES = libglade.c
libgladedianewcanvas2_la_LIBADD = libdianewcanvas2.la
libgladedianewcanvas2_la_LDFALGS = -export-dynamic -module -avoid-version
dia-canvas.c: dia-marshal.h dia-marshal.c
noinst_PROGRAMS = test-diacanvas test-diacanvas2
test_diacanvas_SOURCES = test-diacanvas.c
test_diacanvas_LDADD = libdianewcanvas2.la -lm $(DIANEWCANVAS_LIBS)
test_diacanvas2_SOURCES = test-diacanvas2.c
test_diacanvas2_LDADD = libdianewcanvas2.la -lm $(DIANEWCANVAS_LIBS)
EXTRA_DIST = dia-marshal.list
dia-marshal.h: dia-marshal.list
cd $(srcdir) \
&& glib-genmarshal --prefix=dia_marshal dia-marshal.list --header >> xgen-dmh \
&& cp xgen-dmh dia-marshal.h \
&& rm -f xgen-dmh xgen-dmh~
dia-marshal.c: dia-marshal.list
cd $(srcdir) \
&& glib-genmarshal --prefix=dia_marshal dia-marshal.list --body >> xgen-dmc \
&& cp xgen-dmc dia-marshal.c \
&& rm -f xgen-dmc xgen-dmc~
dia-newcanvas-0.6.10/src/dia-canvas-arc.c 0100644 0001750 0001750 00000031025 07537446061 020406 0 ustar xordoquy xordoquy /* dia-canvas-arc.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-arc.h"
#include "dia-canvas-group.h"
#include
#define _(s) (s)
#define sqr(x) ((x)*(x))
/* properties */
enum {
PROP_NONE,
PROP_X,
PROP_Y,
PROP_WIDTH,
PROP_HEIGHT,
PROP_ANGLE1,
PROP_ANGLE2,
PROP_FILL_COLOR,
PROP_LINE_COLOR,
PROP_LINE_WIDTH,
PROP_TEST_FILL,
PROP_TEST_LINE,
PROP_LAST
};
static void dia_canvas_arc_init (DiaCanvasArc *arc);
static void dia_canvas_arc_class_init (DiaCanvasArcClass *klass);
static void dia_canvas_arc_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_arc_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_arc_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static gdouble dia_canvas_arc_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_arc_real_update (DiaCanvasItem *item);
static void dia_canvas_arc_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_arc_get_type (void)
{
static GtkType canvas_arc_type = 0;
if (!canvas_arc_type)
{
static const GTypeInfo canvas_arc_info =
{
sizeof (DiaCanvasArcClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_arc_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasArc),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_arc_init,
};
canvas_arc_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasArc",
&canvas_arc_info,
0);
}
return canvas_arc_type;
}
static void
dia_canvas_arc_class_init (DiaCanvasArcClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_arc_set_property;
object_class->get_property = dia_canvas_arc_get_property;
item_class->render = dia_canvas_arc_real_render;
item_class->update = dia_canvas_arc_real_update;
item_class->distance = dia_canvas_arc_real_distance;
item_class->move = dia_canvas_arc_real_move;
g_object_class_install_property (object_class,
PROP_X,
g_param_spec_double ("x", _("Center"),
_("The position of the center"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y,
g_param_spec_double ("y", _("Center"),
_("The position of the center"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_WIDTH,
g_param_spec_double ("width", _("Width"),
_("The width of the arc"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_HEIGHT,
g_param_spec_double ("height", _("Height"),
_("The height of the arc"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_ANGLE1,
g_param_spec_double ("angle1", _("The first angle"),
_("The first angle in the arc"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_ANGLE2,
g_param_spec_double ("angle2", _("The second angle"),
_("The second angle in the arc"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FILL_COLOR,
g_param_spec_boxed ("fill_color", _("Fill color"),
_("The fill color of the rectangle (or NULL for empty)"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_COLOR,
g_param_spec_boxed ("line_color", _("Line color"),
_("The color of the line around the arc"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_WIDTH,
g_param_spec_double ("line_width", _("Line width"),
_("The thickness of line around the arc"),
0, G_MAXDOUBLE, 0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TEST_FILL,
g_param_spec_boolean ("test_fill", _("Test fill"),
_("Test if the rectangle is filled or not"),
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_TEST_LINE,
g_param_spec_boolean ("test_line", _("Test line"),
_("Test if the rectangle has border or not"),
FALSE,
G_PARAM_READABLE));
}
static void
dia_canvas_arc_init (DiaCanvasArc *arc)
{
GdkColor red = { 0, 0xffff, 0, 0 };
arc->line_color = red;
arc->line_width = 1;
}
static void
dia_canvas_arc_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasArc *arc = DIA_CANVAS_ARC(object);
gdouble val;
GdkColor *color;
switch (property_id)
{
case PROP_X:
val = g_value_get_double(value);
if (val != arc->center.x) {
arc->center.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
}
break;
case PROP_Y:
val = g_value_get_double(value);
if (val != arc->center.y) {
arc->center.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
}
break;
case PROP_WIDTH:
val = g_value_get_double(value);
if (val != arc->width) {
arc->width = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
}
break;
case PROP_HEIGHT:
val = g_value_get_double(value);
if (val != arc->height) {
arc->height = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
}
break;
case PROP_ANGLE1:
val = g_value_get_double(value);
if (val != arc->angle1) {
arc->angle1 = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
}
break;
case PROP_ANGLE2:
val = g_value_get_double(value);
if (val != arc->angle2) {
arc->angle2 = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
}
break;
case PROP_FILL_COLOR:
color = g_value_get_boxed(value);
if (color) {
arc->fill_color = *color;
arc->fill = TRUE;
} else {
arc->fill = FALSE;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
break;
case PROP_LINE_COLOR:
color = g_value_get_boxed(value);
if (color) {
arc->line_color = *color;
arc->line = TRUE;
} else {
arc->line = FALSE;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
break;
case PROP_LINE_WIDTH:
val = g_value_get_double(value);
arc->line_width = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_arc_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasArc *arc = DIA_CANVAS_ARC(object);
switch (property_id)
{
case PROP_X:
g_value_set_double(value, arc->center.x);
break;
case PROP_Y:
g_value_set_double(value, arc->center.y);
break;
case PROP_WIDTH:
g_value_set_double(value, arc->width);
break;
case PROP_HEIGHT:
g_value_set_double(value, arc->height);
break;
case PROP_ANGLE1:
g_value_set_double(value, arc->angle1);
break;
case PROP_ANGLE2:
g_value_set_double(value, arc->angle2);
break;
case PROP_FILL_COLOR:
if (arc->fill)
g_value_set_boxed(value, &arc->fill_color);
else
g_value_set_boxed(value, NULL);
break;
case PROP_LINE_COLOR:
if (arc->line)
g_value_set_boxed(value, &arc->line_color);
else
g_value_set_boxed(value, NULL);
break;
case PROP_LINE_WIDTH:
g_value_set_double(value, arc->line_width);
break;
case PROP_TEST_FILL:
if (arc->fill)
g_value_set_boolean(value, TRUE);
else
g_value_set_boolean(value, FALSE);
break;
case PROP_TEST_LINE:
if (arc->line)
g_value_set_boolean(value, TRUE);
else
g_value_set_boolean(value, FALSE);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_arc_real_render (DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rect)
{
DiaCanvasArc *arc = DIA_CANVAS_ARC(item);
if( arc->fill ) {
dia_renderer_set_color(renderer, &arc->fill_color);
dia_renderer_draw_arc(renderer, TRUE, &(arc->center), arc->width, arc->height, arc->angle1, arc->angle2);
}
dia_renderer_set_color(renderer, &arc->line_color);
dia_renderer_set_line_width(renderer, arc->line_width);
dia_renderer_draw_arc(renderer, FALSE, &(arc->center), arc->width, arc->height, arc->angle1, arc->angle2);
}
static void
dia_canvas_arc_real_update (DiaCanvasItem *item)
{
DiaCanvasArc *arc = DIA_CANVAS_ARC(item);
gdouble half_width, tmp;
/* the arc may have been moved, so dirty its former location */
dia_canvas_dirty_region(item->canvas, &item->bounds);
item->bounds.left = arc->center.x + (arc->width / 2.0);
item->bounds.top = arc->center.y - (arc->height / 2.0);
item->bounds.right = arc->center.x - (arc->width / 2.0);
item->bounds.bottom = arc->center.y + (arc->height / 2.0);
if( item->bounds.left > item->bounds.right ) {
tmp = item->bounds.left;
item->bounds.left = item->bounds.right;
item->bounds.right = tmp;
}
if( item->bounds.top > item->bounds.bottom ) {
tmp = item->bounds.top;
item->bounds.top = item->bounds.bottom;
item->bounds.bottom = tmp;
}
half_width = arc->line_width / 2;
item->bounds.left -= half_width;
item->bounds.top -= half_width;
item->bounds.right += half_width;
item->bounds.bottom += half_width;
/* dirty the new location to redraw ... */
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
static gdouble
dia_canvas_arc_real_distance (DiaCanvasItem *item, gdouble x,gdouble y)
{
DiaCanvasArc *arc = DIA_CANVAS_ARC(item);
//DiaPoint *endpoints;
DiaPoint from_center;
gdouble angle;
gdouble d;
gdouble radius;
from_center.x = x - arc->center.x;
from_center.y = y - arc->center.y;
angle = -atan2(from_center.y, from_center.x)*180.0/M_PI;
if (angle<0)
angle+=360.0;
if( arc->angle1 > arc->angle2 ) { /* passes 360 degrees */
angle += 360.0;
if( angle < arc->angle1 )
angle += 360;
}
radius = ((arc->width/2.0)*(arc->height/2.0)) /
(sqrt(sqr((arc->height/2.0) * cos(angle*(M_PI/180.0))) +
sqr((arc->width/2.0) * sin(angle*(M_PI/180.0)))));
if( ( angle >= arc->angle1 ) &&
( angle <= arc->angle2 ) ) {
d = sqrt(sqr(from_center.x)+sqr(from_center.y)) - radius;
if( arc->fill ) {
d -= arc->line_width/2.0;
if( d < 0.0 )
d = 0.0;
return d;
} else {
d = fabs(d);
d -= arc->line_width/2.0;
if (d<0)
d = 0.0;
return d;
}
} else {
/*
d = distance_point_point(&endpoints[0], point);
d2 = distance_point_point(&endpoints[1], point);
return MIN(d,d2);
*/
return G_MAXDOUBLE;
}
}
static void
dia_canvas_arc_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasArc *arc = DIA_CANVAS_ARC(item);
arc->center.x += dx;
arc->center.y += dy;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(arc));
}
dia-newcanvas-0.6.10/src/dia-canvas-arc.h 0100644 0001750 0001750 00000003603 07537446061 020414 0 ustar xordoquy xordoquy /* dia-canvas-arc.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_ARC_H__
#define __DIA_CANVAS_ARC_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_ARC (dia_canvas_arc_get_type ())
#define DIA_CANVAS_ARC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_ARC, DiaCanvasArc))
#define DIA_CANVAS_ARC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_ARC, DiaCanvasArcClass))
#define DIA_IS_CANVAS_ARC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_ARC))
#define DIA_IS_CANVAS_ARC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_ARC))
#define DIA_CANVAS_ARC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_ARC, DiaCanvasArcClass))
typedef struct _DiaCanvasArc DiaCanvasArc;
typedef struct _DiaCanvasArcClass DiaCanvasArcClass;
struct _DiaCanvasArc
{
DiaCanvasItem item;
DiaPoint center;
gdouble width, height;
gdouble angle1, angle2;
gboolean line;
gboolean fill;
gdouble line_width;
GdkColor line_color;
GdkColor fill_color;
};
struct _DiaCanvasArcClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_arc_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-attract.c 0100644 0001750 0001750 00000015115 07537446061 021305 0 ustar xordoquy xordoquy /* dia-canvas-attract.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-attract.h"
#include "dia-canvas.h"
#include "dia-canvas-group.h"
#define _(s) (s)
/* properties */
enum {
PROP_NONE,
PROP_X,
PROP_Y,
PROP_LAST
};
static void dia_canvas_attract_init (DiaCanvasAttract *attract);
static void dia_canvas_attract_class_init (DiaCanvasAttractClass *klass);
static void dia_canvas_attract_finalize (GObject *object);
static void dia_canvas_attract_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_attract_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gdouble dia_canvas_attract_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_attract_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static gdouble dia_canvas_attract_real_attract (DiaCanvasItem *item,
gdouble *x, gdouble *y);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_attract_get_type (void)
{
static GtkType dia_canvas_attract_type = 0;
if (!dia_canvas_attract_type)
{
static const GTypeInfo dia_canvas_attract_info =
{
sizeof (DiaCanvasAttractClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_attract_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasAttract),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_attract_init,
};
dia_canvas_attract_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasAttract",
&dia_canvas_attract_info,
0);
}
return dia_canvas_attract_type;
}
static void
dia_canvas_attract_class_init (DiaCanvasAttractClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_attract_set_property;
object_class->get_property = dia_canvas_attract_get_property;
object_class->finalize = dia_canvas_attract_finalize;
item_class->distance = dia_canvas_attract_real_distance;
item_class->move = dia_canvas_attract_real_move;
item_class->attract = dia_canvas_attract_real_attract;
g_object_class_install_property (object_class,
PROP_X,
g_param_spec_double ("x", _("Position"),
_("The position of the attraction point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y,
g_param_spec_double ("y", _("Position"),
_("The position of the attraction point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
}
static void
dia_canvas_attract_init (DiaCanvasAttract *attract)
{
DiaCanvasItem *item = DIA_CANVAS_ITEM(attract);
item->independant_move = FALSE;
}
static void
dia_canvas_attract_finalize(GObject *object)
{
DiaCanvasAttract *attract;
DiaCanvasItem *item;
g_return_if_fail(object != NULL);
g_return_if_fail(DIA_IS_CANVAS_ATTRACT(object));
attract = DIA_CANVAS_ATTRACT(object);
item = DIA_CANVAS_ITEM(object);
if (parent_class->finalize)
(* parent_class->finalize) (object);
}
static void
dia_canvas_attract_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasAttract *attract = DIA_CANVAS_ATTRACT(object);
gdouble val;
switch (property_id)
{
case PROP_X:
val = g_value_get_double(value);
if (val != attract->pos.x) {
attract->pos.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(attract));
}
break;
case PROP_Y:
val = g_value_get_double(value);
if (val != attract->pos.y) {
attract->pos.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(attract));
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_attract_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasAttract *attract = DIA_CANVAS_ATTRACT(object);
switch (property_id)
{
case PROP_X:
g_value_set_double(value, attract->pos.x);
break;
case PROP_Y:
g_value_set_double(value, attract->pos.y);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/*****************************************************************************
******************************* S I G N A L S *******************************
*****************************************************************************/
static gdouble
dia_canvas_attract_real_distance (DiaCanvasItem *item,
gdouble x,gdouble y)
{
double dx = 0.0, dy = 0.0;
/* not the exact distance, but close enough for our checks */
if (x < item->bounds.left)
dx = item->bounds.left - x;
else if (x > item->bounds.right)
dx = x - item->bounds.right;
if (y < item->bounds.top)
dy = item->bounds.top - y;
else if (y > item->bounds.bottom)
dy = y - item->bounds.bottom;
return dx*dx + dy*dy;
}
static void
dia_canvas_attract_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasAttract *attract = DIA_CANVAS_ATTRACT(item);
attract->pos.x += dx;
attract->pos.y += dy;
}
static gdouble
dia_canvas_attract_real_attract (DiaCanvasItem *item,
gdouble *x, gdouble *y)
{
gdouble x2, y2;
DiaCanvasAttract *attract = DIA_CANVAS_ATTRACT(item);
if( item->attract_source != TRUE ) {
x2 = *x;
y2 = *y;
*x = attract->pos.x;
*y = attract->pos.y;
return ((x2-*x)*(x2-*x) + (y2-*y)*(y2-*y));
} else {
return G_MAXDOUBLE;
}
}
dia-newcanvas-0.6.10/src/dia-canvas-attract.h 0100644 0001750 0001750 00000003623 07537446061 021313 0 ustar xordoquy xordoquy /* dia-canvas-attract.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_ATTRACT_H__
#define __DIA_CANVAS_ATTRACT_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_ATTRACT (dia_canvas_attract_get_type ())
#define DIA_CANVAS_ATTRACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_ATTRACT, DiaCanvasAttract))
#define DIA_CANVAS_ATTRACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_ATTRACT, DiaCanvasAttractClass))
#define DIA_IS_CANVAS_ATTRACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_ATTRACT))
#define DIA_IS_CANVAS_ATTRACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_ATTRACT))
#define DIA_CANVAS_ATTRACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_ATTRACT, DiaCanvasAttractClass))
typedef struct _DiaCanvasAttract DiaCanvasAttract;
typedef struct _DiaCanvasAttractClass DiaCanvasAttractClass;
struct _DiaCanvasAttract
{
DiaCanvasItem item;
/* Position of the attraction point */
DiaPoint pos;
};
struct _DiaCanvasAttractClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_attract_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-attracted.c 0100644 0001750 0001750 00000015460 07537446061 021621 0 ustar xordoquy xordoquy /* dia-canvas-attracted.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-attracted.h"
#include "dia-canvas.h"
#include "dia-canvas-group.h"
#define _(s) (s)
/* properties */
enum {
PROP_NONE,
PROP_X,
PROP_Y,
PROP_LAST
};
static void dia_canvas_attracted_init (DiaCanvasAttracted *attracted);
static void dia_canvas_attracted_class_init (DiaCanvasAttractedClass *klass);
static void dia_canvas_attracted_finalize (GObject *object);
static void dia_canvas_attracted_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_attracted_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gdouble dia_canvas_attracted_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_attracted_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static gdouble dia_canvas_attracted_real_snapmove (DiaCanvasItem *item,
gdouble *dx, gdouble *dy);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_attracted_get_type (void)
{
static GtkType dia_canvas_attracted_type = 0;
if (!dia_canvas_attracted_type)
{
static const GTypeInfo dia_canvas_attracted_info =
{
sizeof (DiaCanvasAttractedClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_attracted_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasAttracted),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_attracted_init,
};
dia_canvas_attracted_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasAttracted",
&dia_canvas_attracted_info,
0);
}
return dia_canvas_attracted_type;
}
static void
dia_canvas_attracted_class_init (DiaCanvasAttractedClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_attracted_set_property;
object_class->get_property = dia_canvas_attracted_get_property;
object_class->finalize = dia_canvas_attracted_finalize;
item_class->distance = dia_canvas_attracted_real_distance;
item_class->move = dia_canvas_attracted_real_move;
item_class->snapmove = dia_canvas_attracted_real_snapmove;
g_object_class_install_property (object_class,
PROP_X,
g_param_spec_double ("x", _("Position"),
_("The position of the attracted point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y,
g_param_spec_double ("y", _("Position"),
_("The position of the attracted point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
}
static void
dia_canvas_attracted_init (DiaCanvasAttracted *attracted)
{
DiaCanvasItem *item = DIA_CANVAS_ITEM(attracted);
item->independant_move = FALSE;
}
static void
dia_canvas_attracted_finalize(GObject *object)
{
DiaCanvasAttracted *attracted;
DiaCanvasItem *item;
g_return_if_fail(object != NULL);
g_return_if_fail(DIA_IS_CANVAS_ATTRACTED(object));
attracted = DIA_CANVAS_ATTRACTED(object);
item = DIA_CANVAS_ITEM(object);
if (parent_class->finalize)
(* parent_class->finalize) (object);
}
static void
dia_canvas_attracted_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasAttracted *attracted = DIA_CANVAS_ATTRACTED(object);
gdouble val;
switch (property_id)
{
case PROP_X:
val = g_value_get_double(value);
if (val != attracted->pos.x) {
attracted->pos.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(attracted));
}
break;
case PROP_Y:
val = g_value_get_double(value);
if (val != attracted->pos.y) {
attracted->pos.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(attracted));
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_attracted_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasAttracted *attracted = DIA_CANVAS_ATTRACTED(object);
switch (property_id)
{
case PROP_X:
g_value_set_double(value, attracted->pos.x);
break;
case PROP_Y:
g_value_set_double(value, attracted->pos.y);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/*****************************************************************************
******************************* S I G N A L S *******************************
*****************************************************************************/
static gdouble
dia_canvas_attracted_real_distance (DiaCanvasItem *item,
gdouble x,gdouble y)
{
double dx = 0.0, dy = 0.0;
/* not the exact distance, but close enough for our checks */
if (x < item->bounds.left)
dx = item->bounds.left - x;
else if (x > item->bounds.right)
dx = x - item->bounds.right;
if (y < item->bounds.top)
dy = item->bounds.top - y;
else if (y > item->bounds.bottom)
dy = y - item->bounds.bottom;
return dx*dx + dy*dy;
}
static void
dia_canvas_attracted_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasAttracted *attracted = DIA_CANVAS_ATTRACTED(item);
attracted->pos.x += dx;
attracted->pos.y += dy;
}
static gdouble
dia_canvas_attracted_real_snapmove (DiaCanvasItem *item,
gdouble *dx, gdouble *dy)
{
gdouble x, y, result;
DiaCanvasAttracted *attracted = DIA_CANVAS_ATTRACTED(item);
x = attracted->pos.x + *dx;
y = attracted->pos.y + *dy;
item->attract_source = TRUE;
result = dia_canvas_snap(item->canvas, &x, &y);
item->attract_source = FALSE;
*dx = x - attracted->pos.x;
*dy = y - attracted->pos.y;
return result;
}
dia-newcanvas-0.6.10/src/dia-canvas-attracted.h 0100644 0001750 0001750 00000003654 07537446061 021630 0 ustar xordoquy xordoquy /* dia-canvas-attracted.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_ATTRACTED_H__
#define __DIA_CANVAS_ATTRACTED_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_ATTRACTED (dia_canvas_attracted_get_type ())
#define DIA_CANVAS_ATTRACTED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_ATTRACTED, DiaCanvasAttracted))
#define DIA_CANVAS_ATTRACTED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_ATTRACTED, DiaCanvasAttractedClass))
#define DIA_IS_CANVAS_ATTRACTED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_ATTRACTED))
#define DIA_IS_CANVAS_ATTRACTED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_ATTRACTED))
#define DIA_CANVAS_ATTRACTED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_ATTRACTED, DiaCanvasAttractedClass))
typedef struct _DiaCanvasAttracted DiaCanvasAttracted;
typedef struct _DiaCanvasAttractedClass DiaCanvasAttractedClass;
struct _DiaCanvasAttracted
{
DiaCanvasItem item;
/* Position of the attracted point */
DiaPoint pos;
};
struct _DiaCanvasAttractedClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_attracted_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-connection.c 0100644 0001750 0001750 00000025751 07537446061 022011 0 ustar xordoquy xordoquy /* dia-canvas-connection.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-connection.h"
//#include "dia-canvas.h"
#include "dia-canvas-group.h"
#define _(s) (s)
/* properties */
enum {
PROP_NONE,
PROP_X,
PROP_Y,
PROP_FILL_COLOR,
PROP_TYPE,
PROP_LAST
};
static void dia_canvas_connection_init (DiaCanvasConnection *connection);
static void dia_canvas_connection_class_init (DiaCanvasConnectionClass *klass);
static void dia_canvas_connection_finalize (GObject *object);
static void dia_canvas_connection_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_connection_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_connection_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rectangle);
static void dia_canvas_connection_real_update (DiaCanvasItem *item);
static gdouble dia_canvas_connection_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_connection_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static void dia_canvas_connection_real_connect (DiaCanvasItem *item,
DiaCanvasConnection *connection);
static void dia_canvas_connection_real_connection (DiaCanvasItem *item);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_connection_get_type (void)
{
static GtkType canvas_connection_type = 0;
if (!canvas_connection_type)
{
static const GTypeInfo canvas_connection_info =
{
sizeof (DiaCanvasConnectionClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_connection_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasConnection),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_connection_init,
};
canvas_connection_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasConnection",
&canvas_connection_info,
0);
}
return canvas_connection_type;
}
static void
dia_canvas_connection_class_init (DiaCanvasConnectionClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_connection_set_property;
object_class->get_property = dia_canvas_connection_get_property;
object_class->finalize = dia_canvas_connection_finalize;
item_class->render = dia_canvas_connection_real_render;
item_class->update = dia_canvas_connection_real_update;
item_class->distance = dia_canvas_connection_real_distance;
item_class->move = dia_canvas_connection_real_move;
item_class->connect = dia_canvas_connection_real_connect;
item_class->connection = dia_canvas_connection_real_connection;
g_object_class_install_property (object_class,
PROP_X,
g_param_spec_double ("x", _("Position"),
_("The position of the connection point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y,
g_param_spec_double ("y", _("Position"),
_("The position of the connection point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FILL_COLOR,
g_param_spec_boxed ("fill_color", _("Fill color"),
_("The fill color of the connection (or NULL for empty)"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TYPE,
g_param_spec_int ("type", _("Type"),
_("Type of the connection point"),
-G_MAXINT,
G_MAXINT,
0,
G_PARAM_READWRITE));
}
static void
dia_canvas_connection_init (DiaCanvasConnection *connection)
{
DiaCanvasItem *item = DIA_CANVAS_ITEM(connection);
item->independant_move = FALSE;
connection->connections = NULL;
connection->type = UNKNOWN;
}
static void
dia_canvas_connection_finalize(GObject *object)
{
DiaCanvasConnection *connection;
DiaCanvasItem *item;
GList *tmp, *next;
g_return_if_fail(object != NULL);
g_return_if_fail(DIA_IS_CANVAS_CONNECTION(object));
connection = DIA_CANVAS_CONNECTION(object);
item = DIA_CANVAS_ITEM(object);
tmp = connection->connections;
while( tmp != NULL ) {
next = tmp->next;
((DiaCanvasConnection*)tmp->data)->connections = g_list_remove(((DiaCanvasConnection*)tmp->data)->connections,connection);
connection->connections = g_list_remove(connection->connections,((DiaCanvasConnection*)tmp->data));
tmp = next;
}
if (parent_class->finalize)
(* parent_class->finalize) (object);
}
static void
dia_canvas_connection_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasConnection *connection = DIA_CANVAS_CONNECTION(object);
gdouble val;
GdkColor *color;
switch (property_id)
{
case PROP_X:
val = g_value_get_double(value);
if (val != connection->pos.x) {
connection->pos.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(connection));
}
break;
case PROP_Y:
val = g_value_get_double(value);
if (val != connection->pos.y) {
connection->pos.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(connection));
}
break;
case PROP_FILL_COLOR:
color = g_value_get_boxed(value);
connection->fill_color = *color;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(connection));
break;
case PROP_TYPE:
connection->type = g_value_get_int(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_connection_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasConnection *connection = DIA_CANVAS_CONNECTION(object);
switch (property_id)
{
case PROP_X:
g_value_set_double(value, connection->pos.x);
break;
case PROP_Y:
g_value_set_double(value, connection->pos.y);
break;
case PROP_FILL_COLOR:
g_value_set_boxed(value, &connection->fill_color);
break;
case PROP_TYPE:
g_value_set_int(value, connection->type);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/*****************************************************************************
******************************* S I G N A L S *******************************
*****************************************************************************/
static void
dia_canvas_connection_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rectangle)
{
DiaCanvasConnection *connection = DIA_CANVAS_CONNECTION(item);
DiaPoint p1,p2;
p1.x = connection->pos.x - 5;
p1.y = connection->pos.y - 5;
p2.x = connection->pos.x + 5;
p2.y = connection->pos.y + 5;
dia_renderer_set_color(renderer, &connection->fill_color);
dia_renderer_draw_rectangle(renderer, TRUE, &p1, &p2);
}
static void
dia_canvas_connection_real_update (DiaCanvasItem *item)
{
DiaCanvasConnection *connection = DIA_CANVAS_CONNECTION(item);
/* the connection may have been moved, so dirty its former location */
dia_canvas_dirty_region(item->canvas, &item->bounds);
item->bounds.left = connection->pos.x - 5;
item->bounds.top = connection->pos.y - 5;
item->bounds.right = connection->pos.x + 5;
item->bounds.bottom = connection->pos.y + 5;
/* dirty the new location to redraw ... */
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
static gdouble
dia_canvas_connection_real_distance (DiaCanvasItem *item,
gdouble x,gdouble y)
{
//DiaCanvasConnection *connection = DIA_CANVAS_CONNECTION(item);
double dx = 0.0, dy = 0.0;
/* not the exact distance, but close enough for our checks */
if (x < item->bounds.left)
dx = item->bounds.left - x;
else if (x > item->bounds.right)
dx = x - item->bounds.right;
if (y < item->bounds.top)
dy = item->bounds.top - y;
else if (y > item->bounds.bottom)
dy = y - item->bounds.bottom;
return dx*dx + dy*dy;
}
static void
dia_canvas_connection_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
static guint connection_moved_signal_id = 0;
DiaCanvasConnection *connection = DIA_CANVAS_CONNECTION(item);
GList *tmp;
connection->pos.x += dx;
connection->pos.y += dy;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(connection));
if( !item->connection_moved ) {
if (connection_moved_signal_id == 0)
connection_moved_signal_id = gtk_signal_lookup("connection_moved", DIA_TYPE_CANVAS_ITEM);
tmp = connection->connections;
while( tmp != NULL ) {
DiaCanvasConnection *save;
save = tmp->data;
tmp = tmp->next;
DIA_CANVAS_ITEM(save)->connection_moved = TRUE;
g_signal_emit(DIA_CANVAS_ITEM(save), connection_moved_signal_id, 0, connection, dx, dy);
DIA_CANVAS_ITEM(save)->connection_moved = FALSE;
}
}
}
static void
dia_canvas_connection_real_connect (DiaCanvasItem *item,
DiaCanvasConnection *connection)
{
DiaCanvasConnection *this;
GList *tmp;
g_return_if_fail( item != NULL );
g_return_if_fail( connection != NULL );
if( item == DIA_CANVAS_ITEM(connection) )
return;
this = DIA_CANVAS_CONNECTION(item);
if( (this->pos.x == connection->pos.x) &&
(this->pos.y == connection->pos.y) ) {
/*
* Check that the connection doesn't already exists.
*/
tmp = this->connections;
while( tmp != NULL ) {
if( tmp->data == connection )
return;
tmp = tmp->next;
}
this->connections = g_list_append(this->connections,connection);
connection->connections = g_list_append(connection->connections,this);
}
}
static void
dia_canvas_connection_real_connection (DiaCanvasItem *item)
{
g_return_if_fail( item != NULL );
dia_canvas_connect( item->canvas, DIA_CANVAS_CONNECTION(item) );
}
dia-newcanvas-0.6.10/src/dia-canvas-connection.h 0100644 0001750 0001750 00000004244 07537446061 022010 0 ustar xordoquy xordoquy /* dia-canvas-connection.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_CONNECTION_H__
#define __DIA_CANVAS_CONNECTION_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_CONNECTION (dia_canvas_connection_get_type ())
#define DIA_CANVAS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_CONNECTION, DiaCanvasConnection))
#define DIA_CANVAS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_CONNECTION, DiaCanvasConnectionClass))
#define DIA_IS_CANVAS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_CONNECTION))
#define DIA_IS_CANVAS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_CONNECTION))
#define DIA_CANVAS_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_CONNECTION, DiaCanvasConnectionClass))
typedef enum {
UNKNOWN,
COMPONENT,
LINE
} connectionection_type;
//typedef struct _DiaCanvasConnection DiaCanvasConnection;
typedef struct _DiaCanvasConnectionClass DiaCanvasConnectionClass;
struct _DiaCanvasConnection
{
DiaCanvasItem item;
/* Position of the connection point */
DiaPoint pos;
/* List of connections */
GList *connections;
/* Color of the connection point */
GdkColor fill_color;
/* connection behaviour */
gint type;
};
struct _DiaCanvasConnectionClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_connection_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-ellipse.c 0100644 0001750 0001750 00000010221 07537446061 021271 0 ustar xordoquy xordoquy /* dia-canvas-ellipse.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include "dia-canvas-ellipse.h"
static void dia_canvas_ellipse_init (DiaCanvasEllipse *rect);
static void dia_canvas_ellipse_class_init (DiaCanvasEllipseClass *klass);
GType
dia_canvas_ellipse_get_type (void)
{
static GtkType canvas_ellipse_type = 0;
if (!canvas_ellipse_type)
{
static const GTypeInfo canvas_ellipse_info =
{
sizeof (DiaCanvasEllipseClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_ellipse_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasEllipse),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_ellipse_init,
};
canvas_ellipse_type = g_type_register_static (DIA_TYPE_CANVAS_RECTANGLE,
"DiaCanvasEllipse",
&canvas_ellipse_info,
0);
}
return canvas_ellipse_type;
}
static void dia_canvas_ellipse_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rectangle);
static double dia_canvas_ellipse_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void
dia_canvas_ellipse_class_init (DiaCanvasEllipseClass *klass)
{
DiaCanvasItemClass *item_class;
item_class = DIA_CANVAS_ITEM_CLASS(klass);
item_class->render = dia_canvas_ellipse_render;
item_class->distance = dia_canvas_ellipse_distance;
}
static void
dia_canvas_ellipse_init (DiaCanvasEllipse *ellipse)
{
}
static void
dia_canvas_ellipse_render (DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rectangle)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(item);
DiaPoint centre;
gdouble width, height;
centre.x = (rect->topleft.x + rect->bottomright.x) / 2;
centre.y = (rect->topleft.y + rect->bottomright.y) / 2;
width = rect->bottomright.x - rect->topleft.x;
height = rect->bottomright.y - rect->topleft.y;
if (rect->fill) {
dia_renderer_set_color(renderer, &rect->fill_color);
dia_renderer_draw_ellipse(renderer, TRUE, ¢re, width, height);
}
if (rect->line) {
dia_renderer_set_color(renderer, &rect->line_color);
dia_renderer_set_line_width(renderer, rect->line_width);
dia_renderer_draw_ellipse(renderer, FALSE, ¢re, width, height);
}
}
static double
dia_canvas_ellipse_distance (DiaCanvasItem *item, gdouble x,gdouble y)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(item);
gdouble cx, cy, width, height;
/* computed values */
gdouble w2, h2, scale, rad, dist, px, py, half_width;
cx = (rect->topleft.x + rect->bottomright.x) / 2;
cy = (rect->topleft.y + rect->bottomright.y) / 2;
width = rect->bottomright.x - rect->topleft.x;
height = rect->bottomright.y - rect->topleft.y;
w2 = width*width;
h2 = height*height;
half_width = rect->line ? rect->line_width / 2 : 0.0;
/* find the point of intersection between line (x=cx+(px-cx)t; y=cy+(py-cy)t)
* and ellipse ((x-cx)^2)/(w/2)^2 + ((y-cy)^2)/(h/2)^2 = 1 */
/* radius along ray is sqrt((px-cx)^2 * t^2 + (py-cy)^2 * t^2) */
px = x - cx; px *= px;
py = y - cy; py *= py;
scale = w2 * h2 / (4*h2*px + 4*w2*py);
rad = sqrt((px + py) * scale);
dist = sqrt(px + py);
if (dist > rad + half_width)
return dist - (rad + half_width);
/* if the ellipse is not filled, then check for distance from edge */
if (!rect->fill) {
if (dist < rad - half_width)
return (rad - half_width) - dist;
}
/* the point is in the ellipse. */
return 0.0;
}
dia-newcanvas-0.6.10/src/dia-canvas-ellipse.h 0100644 0001750 0001750 00000003631 07537446061 021305 0 ustar xordoquy xordoquy /* dia-canvas-ellipse.h
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_ELLIPSE_H__
#define __DIA_CANVAS_ELLIPSE_H__
#include
#include "dia-canvas-item.h"
#include "dia-canvas-rectangle.h"
#define DIA_TYPE_CANVAS_ELLIPSE (dia_canvas_ellipse_get_type ())
#define DIA_CANVAS_ELLIPSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_ELLIPSE, DiaCanvasEllipse))
#define DIA_CANVAS_ELLIPSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_ELLIPSE, DiaCanvasEllipseClass))
#define DIA_IS_CANVAS_ELLIPSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_ELLIPSE))
#define DIA_IS_CANVAS_ELLIPSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_ELLIPSE))
#define DIA_CANVAS_ELLIPSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_ELLIPSE, DiaCanvasEllipseClass))
typedef struct _DiaCanvasEllipse DiaCanvasEllipse;
typedef struct _DiaCanvasEllipseClass DiaCanvasEllipseClass;
struct _DiaCanvasEllipse
{
DiaCanvasRectangle rectangle;
};
struct _DiaCanvasEllipseClass
{
DiaCanvasRectangleClass parent_class;
};
GType dia_canvas_ellipse_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-grid.c 0100644 0001750 0001750 00000016713 07537446061 020575 0 ustar xordoquy xordoquy /* dia-canvas-grid.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-grid.h"
#include "dia-marshal.h"
#include
#include
#define _(s) (s)
/* properties */
enum {
PROP_NONE,
PROP_SPACING,
PROP_COLOR,
PROP_SNAPPING,
PROP_LAST
};
static void dia_canvas_grid_init (DiaCanvasGrid *rect);
static void dia_canvas_grid_class_init (DiaCanvasGridClass *klass);
static void dia_canvas_grid_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_grid_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_grid_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static gdouble dia_canvas_grid_real_attract (DiaCanvasItem *item,
gdouble *x, gdouble *y);
static void dia_canvas_grid_real_connection_moved (DiaCanvasItem *item,
DiaCanvasConnection *connection,
gdouble dx, gdouble dy);
static DiaCanvasItemClass *grand_parent_class = NULL;
static DiaCanvasGroupClass *parent_class = NULL;
GType
dia_canvas_grid_get_type (void)
{
static GtkType canvas_grid_type = 0;
if (!canvas_grid_type)
{
static const GTypeInfo canvas_grid_info =
{
sizeof (DiaCanvasGridClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_grid_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasGrid),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_grid_init,
};
canvas_grid_type = g_type_register_static (DIA_TYPE_CANVAS_GROUP,
"DiaCanvasGrid",
&canvas_grid_info,
0);
}
return canvas_grid_type;
}
static void
dia_canvas_grid_class_init (DiaCanvasGridClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
grand_parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_GROUP);
object_class->set_property = dia_canvas_grid_set_property;
object_class->get_property = dia_canvas_grid_get_property;
item_class->render = dia_canvas_grid_real_render;
item_class->attract = dia_canvas_grid_real_attract;
item_class->connection_moved = dia_canvas_grid_real_connection_moved;
g_object_class_install_property (object_class,
PROP_SPACING,
g_param_spec_double ("spacing", _("Grid spacing"),
_("The grid spacing between dots"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_COLOR,
g_param_spec_boxed ("color", _("Drawing color"),
_("The color used to draw the dot"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_SNAPPING,
g_param_spec_boolean ("snapping", _("Snapping on/off"),
_("Turn the snapping mode on or off"),
TRUE,
G_PARAM_READWRITE));
}
static void
dia_canvas_grid_init (DiaCanvasGrid *rect)
{
GdkColor color = { 0, 0x0000, 0x0000, 0x00000 };
memcpy(&(rect->color),&color,sizeof(GdkColor));
rect->spacing = 50;
rect->snapping = TRUE;
}
static void
dia_canvas_grid_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasGrid *rect = DIA_CANVAS_GRID(object);
gdouble val;
//GdkColor *color;
switch (property_id)
{
case PROP_SPACING:
val = g_value_get_double(value);
if (val != rect->spacing) {
rect->spacing = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
}
break;
case PROP_COLOR:
g_warning("dia_canvas_grid_set_property: implement PROP_COLOR");
break;
case PROP_SNAPPING:
val = g_value_get_boolean(value);
rect->snapping = val;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_grid_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasGrid *rect = DIA_CANVAS_GRID(object);
switch (property_id)
{
case PROP_SPACING:
g_value_set_double(value, rect->spacing);
break;
case PROP_COLOR:
g_warning("dia_canvas_grid_get_property: PROP_COLOR");
break;
case PROP_SNAPPING:
g_value_set_boolean(value, rect->snapping);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_grid_real_render (DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rectangle)
{
gint i, j, x, y;
DiaCanvasGrid *grid = DIA_CANVAS_GRID(item);
DiaPoint pt;
if (rectangle == NULL) {
g_warning("RECTANGLE NULL");
return;
}
dia_renderer_set_color(renderer, &(grid->color));
dia_renderer_set_line_width(renderer, 1);
x = floor(rectangle->left/grid->spacing);
y = floor(rectangle->top/grid->spacing);
for( i=x; (i*grid->spacing)right; i++ ) {
pt.x = i*grid->spacing;
for( j=y; (j*grid->spacing)bottom; j++ ) {
pt.y = j*grid->spacing;
dia_renderer_draw_point(renderer,&pt);
}
}
parent_class->parent_class.render(item,renderer,rectangle);
}
static gdouble
dia_canvas_grid_real_attract(DiaCanvasItem *item,
gdouble *x, gdouble *y)
{
gdouble ddx,ddy;
DiaCanvasGrid *grid = DIA_CANVAS_GRID(item);
GList *tmp, *best;
gdouble x2, y2;
gdouble signaled, result;
static guint event_signal_id = 0;
DiaCanvasGroup *group = DIA_CANVAS_GROUP(item);
guint i;
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("attract", DIA_TYPE_CANVAS_ITEM);
result = G_MAXDOUBLE;
best = NULL;
i = 0;
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
DiaCanvasItem *child = tmp->data;
x2 = *x;
y2 = *y;
g_signal_emit(child, event_signal_id, 0, &x2, &y2, &signaled);
if( result >= signaled ) {
best = tmp;
result = signaled;
}
}
if( grid->snapping ) {
ddx = rint((*x)/grid->spacing)*grid->spacing;
ddy = rint((*y)/grid->spacing)*grid->spacing;
ddx = ddx - *x;
ddy = ddy - *y;
} else {
ddx = 0;
ddy = 0;
}
signaled = ((ddx)*(ddx)+(ddy)*(ddy));
if( (result < 400) && !(signaled < result) ) {
g_signal_emit(best->data, event_signal_id, 0, x, y, &signaled);
} else {
*x += ddx;
*y += ddy;
}
return signaled;
}
static void
dia_canvas_grid_real_connection_moved (DiaCanvasItem *item,
DiaCanvasConnection *connection,
gdouble dx, gdouble dy)
{
}
dia-newcanvas-0.6.10/src/dia-canvas-grid.h 0100644 0001750 0001750 00000003550 07537446061 020575 0 ustar xordoquy xordoquy /* dia-canvas-grid.h
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_GRID_H__
#define __DIA_CANVAS_GRID_H__
#include
#include "dia-canvas-item.h"
#include "dia-canvas-group.h"
#define DIA_TYPE_CANVAS_GRID (dia_canvas_grid_get_type ())
#define DIA_CANVAS_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_GRID, DiaCanvasGrid))
#define DIA_CANVAS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_GRID, DiaCanvasGridClass))
#define DIA_IS_CANVAS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_GRID))
#define DIA_IS_CANVAS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_GRID))
#define DIA_CANVAS_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_GRID, DiaCanvasGridClass))
typedef struct _DiaCanvasGrid DiaCanvasGrid;
typedef struct _DiaCanvasGridClass DiaCanvasGridClass;
struct _DiaCanvasGrid
{
DiaCanvasGroup group;
gdouble spacing;
GdkColor color;
gboolean snapping;
};
struct _DiaCanvasGridClass
{
DiaCanvasGroupClass parent_class;
};
GType dia_canvas_grid_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-group.c 0100644 0001750 0001750 00000030657 07537446061 021007 0 ustar xordoquy xordoquy /* dia-canvas-group.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include "dia-canvas-item.h"
#include "dia-canvas-group.h"
#include "dia-canvas-rectangle.h"
#include "dia-canvas-line.h"
//#include "dia-conn.h"
static void dia_canvas_group_init (DiaCanvasGroup *canvas_group);
static void dia_canvas_group_class_init (DiaCanvasGroupClass *klass);
static void dia_canvas_group_finalize(GObject *object);
static void dia_canvas_group_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static void dia_canvas_group_real_update (DiaCanvasItem *item);
static void dia_canvas_group_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static gdouble dia_canvas_group_real_snapmove (DiaCanvasItem *item,
gdouble *dx, gdouble *dy);
static gdouble dia_canvas_group_real_attract (DiaCanvasItem *item,
gdouble *dx, gdouble *dy);
static void dia_canvas_group_real_connect (DiaCanvasItem *item,
DiaCanvasConnection *connection);
static void dia_canvas_group_real_connection (DiaCanvasItem *item);
static void dia_canvas_group_foreach_function (gpointer data,
gpointer user_data);
static DiaCanvasItemClass *parent_class = NULL;
GtkType
dia_canvas_group_get_type (void)
{
static GtkType canvas_group_type = 0;
if (!canvas_group_type)
{
static const GTypeInfo canvas_group_info =
{
sizeof (DiaCanvasGroupClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_group_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasGroup),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_group_init,
};
canvas_group_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasGroup",
&canvas_group_info, 0);
}
return canvas_group_type;
}
static void
dia_canvas_group_class_init (DiaCanvasGroupClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref (DIA_TYPE_CANVAS_ITEM);
object_class->finalize = dia_canvas_group_finalize;
item_class->render = dia_canvas_group_real_render;
item_class->update = dia_canvas_group_real_update;
item_class->attract = dia_canvas_group_real_attract;
item_class->move = dia_canvas_group_real_move;
item_class->snapmove = dia_canvas_group_real_snapmove;
item_class->connect = dia_canvas_group_real_connect;
item_class->connection = dia_canvas_group_real_connection;
}
static void
dia_canvas_group_init (DiaCanvasGroup *canvas_group)
{
}
static void
dia_canvas_group_finalize(GObject *object)
{
GList *list;
DiaCanvasGroup *group;
g_return_if_fail(object != NULL);
g_return_if_fail(DIA_IS_CANVAS_GROUP(object));
group = DIA_CANVAS_GROUP(object);
/* unref all children */
list = group->children;
while( list != NULL ) {
group->children = g_list_remove_link(group->children,list);
g_object_unref(list->data);
list = group->children;
}
if (G_OBJECT_CLASS(parent_class)->finalize)
(* G_OBJECT_CLASS(parent_class)->finalize) (object);
}
/*****************************************************************************
******************************* S I G N A L S *******************************
*****************************************************************************/
static void
dia_canvas_group_real_render(DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rect)
{
DiaCanvasGroup *group;
GList *tmp;
static guint render_signal_id = 0;
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_GROUP(item));
g_return_if_fail(rect != NULL);
group = DIA_CANVAS_GROUP(item);
/* if we are not visible, don't do anything */
if (!item->visible)
return;
if (!render_signal_id)
render_signal_id = g_signal_lookup("render", DIA_TYPE_CANVAS_ITEM);
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
DiaCanvasItem *child = tmp->data;
DiaRectangle intersect;
/* if child is visible, and its bouding box intersects the redraw region */
if (child->visible &&
dia_rectangle_intersect(rect, &child->bounds, &intersect))
g_signal_emit(child, render_signal_id, 0, renderer, &intersect);
}
}
static void
dia_canvas_group_real_update(DiaCanvasItem *item)
{
DiaCanvasGroup *group;
DiaRectangle new_bounds = { G_MAXDOUBLE, G_MAXDOUBLE,
G_MINDOUBLE, G_MINDOUBLE };
gboolean set = FALSE;
static guint update_signal_id = 0;
GList *tmp;
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_GROUP(item));
group = DIA_CANVAS_GROUP(item);
if (!update_signal_id)
update_signal_id = g_signal_lookup("update", DIA_TYPE_CANVAS_ITEM);
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
DiaCanvasItem *child = tmp->data;
if (child->need_update) {
child->need_update = FALSE;
g_signal_emit(child, update_signal_id, 0);
}
if (child->visible) {
set = TRUE;
new_bounds.left = MIN(new_bounds.left, child->bounds.left);
new_bounds.top = MIN(new_bounds.top, child->bounds.top);
new_bounds.right = MAX(new_bounds.right, child->bounds.right);
new_bounds.bottom = MAX(new_bounds.bottom, child->bounds.bottom);
}
}
if (!set) {
new_bounds.left = 0.0;
new_bounds.top = 0.0;
new_bounds.right = 0.0;
new_bounds.bottom = 0.0;
}
item->bounds = new_bounds;
}
static void
dia_canvas_group_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
GList *tmp;
static guint event_signal_id = 0;
DiaCanvasGroup *group = DIA_CANVAS_GROUP(item);
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("move", DIA_TYPE_CANVAS_ITEM);
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
g_signal_emit(tmp->data, event_signal_id, 0, dx, dy);
}
}
static gdouble
dia_canvas_group_real_snapmove (DiaCanvasItem *item,
gdouble *dx, gdouble *dy)
{
gdouble result, best;
gdouble dx2, dy2;
gdouble dx_best, dy_best;
GList *tmp;
static guint event_signal_id = 0;
DiaCanvasGroup *group = DIA_CANVAS_GROUP(item);
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("snapmove", DIA_TYPE_CANVAS_ITEM);
best = G_MAXDOUBLE;
dx_best = *dx;
dy_best = *dy;
item->attract_source = TRUE;
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
dx2 = *dx;
dy2 = *dy;
g_signal_emit(tmp->data, event_signal_id, 0, &dx2, &dy2, &result);
if( result < best ) {
best = result;
dx_best = dx2;
dy_best = dy2;
}
}
item->attract_source = FALSE;
*dx = dx_best;
*dy = dy_best;
return best;
}
static gdouble
dia_canvas_group_real_attract (DiaCanvasItem *item,
gdouble *dx, gdouble *dy)
{
GList *tmp, *best;
gdouble x, y, x_save, y_save;
gdouble signaled, result;
static guint event_signal_id = 0;
DiaCanvasGroup *group = DIA_CANVAS_GROUP(item);
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("attract", DIA_TYPE_CANVAS_ITEM);
result = G_MAXDOUBLE;
best = NULL;
x_save = *dx;
y_save = *dy;
if( item->attract_source == FALSE ) {
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
DiaCanvasItem *child = tmp->data;
x = *dx;
y = *dy;
g_signal_emit(child, event_signal_id, 0, &x, &y, &signaled);
if( result >= signaled ) {
best = tmp;
result = signaled;
x_save = x;
y_save = y;
}
}
}
*dx = x_save;
*dy = y_save;
return result;
}
static void
dia_canvas_group_real_connect (DiaCanvasItem *item,
DiaCanvasConnection *connection)
{
GList *tmp;
static guint event_signal_id = 0;
DiaCanvasGroup *group = DIA_CANVAS_GROUP(item);
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("connect", DIA_TYPE_CANVAS_ITEM);
if( item->connect_source == FALSE ) {
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
g_signal_emit(tmp->data, event_signal_id, 0, connection);
}
}
}
static void
dia_canvas_group_real_connection (DiaCanvasItem *item)
{
GList *tmp;
static guint event_signal_id = 0;
DiaCanvasGroup *group = DIA_CANVAS_GROUP(item);
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("connection", DIA_TYPE_CANVAS_ITEM);
item->connect_source = TRUE;
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
g_signal_emit(tmp->data, event_signal_id, 0);
}
item->connect_source = FALSE;
}
/*****************************************************************************
***************************** F O N C T I O N S *****************************
*****************************************************************************/
/**
* dia_canvas_group_add_item:
* @group: a #DiaCanvasGroup.
* @item: the #DiaCanvasItem to add.
*
* Adds a #DiaCanvasItem to the @group.
**/
void
dia_canvas_group_add_item (DiaCanvasGroup *group, DiaCanvasItem *item)
{
g_return_if_fail(group != NULL);
g_return_if_fail(DIA_IS_CANVAS_GROUP(group));
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_ITEM(item));
g_return_if_fail(item->parent == NULL);
g_object_ref(G_OBJECT(item));
dia_canvas_item_sink(item);
group->children = g_list_append(group->children, item);
item->parent = group;
item->canvas = DIA_CANVAS_ITEM(group)->canvas;
g_object_notify(G_OBJECT(item), "parent");
dia_canvas_item_request_update (item);
}
/**
* dia_canvas_group_remove_item:
* @group: a #DiaCanvasGroup.
* @item: the #DiaCanvasItem to remove.
*
* Removes a #DiaCanvasItem from the @group.
**/
void
dia_canvas_group_remove_item (DiaCanvasGroup *group, DiaCanvasItem *item)
{
g_return_if_fail(group != NULL);
g_return_if_fail(DIA_IS_CANVAS_GROUP(group));
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_ITEM(item));
g_return_if_fail(item->parent == group);
if( item->canvas != NULL ) {
/* if the item to be removed is currently focused, unfocus it */
if (item->canvas->focus_item == item) {
/* if a view is focused, synthesise the focus_out and in events */
if (item->canvas->focus_view != NULL) {
DiaCanvasView *focus_view = item->canvas->focus_view;
GdkEventFocus fevent;
/* synthesise focus leaving the focused view */
fevent.type = GDK_FOCUS_CHANGE;
fevent.window = GTK_WIDGET(focus_view)->window;
fevent.in = FALSE;
gtk_widget_event(GTK_WIDGET(focus_view), (GdkEvent *)&fevent);
item->canvas->focus_item = NULL;
/* synthesise focus entering the view again */
fevent.type = GDK_FOCUS_CHANGE;
fevent.window = GTK_WIDGET(focus_view)->window;
fevent.in = TRUE;
gtk_widget_event(GTK_WIDGET(focus_view), (GdkEvent *)&fevent);
} else {
/* else, just unset the focus_item */
item->canvas->focus_item = NULL;
}
}
}
if( g_list_find(group->children, item) == NULL ) {
return;
}
group->children = g_list_remove(group->children, item);
item->parent = NULL;
if( item->canvas != NULL ) {
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
item->canvas = NULL;
g_object_notify(G_OBJECT(item), "parent");
g_object_unref(G_OBJECT(item));
//dia_canvas_item_request_update(DIA_CANVAS_ITEM(group));
}
static void
dia_canvas_group_foreach_function (gpointer data,
gpointer user_data)
{
GFunc function = ((gpointer*)user_data)[0];
if( DIA_IS_CANVAS_GROUP(data) ) {
dia_canvas_group_foreach(DIA_CANVAS_GROUP(data),((gpointer*)user_data)[0],((gpointer*)user_data)[1]);
}
function(data,((gpointer*)user_data)[1]);
}
void
dia_canvas_group_foreach (DiaCanvasGroup *group,
GFunc function,
gpointer user_data)
{
gpointer hack[2];
g_return_if_fail(DIA_IS_CANVAS_GROUP(group));
hack[0] = function;
hack[1] = user_data;
g_list_foreach(group->children,dia_canvas_group_foreach_function,&hack);
function(group,user_data);
}
dia-newcanvas-0.6.10/src/dia-canvas-group.h 0100644 0001750 0001750 00000004324 07537446061 021004 0 ustar xordoquy xordoquy /* dia-canvas-group.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_GROUP_H__
#define __DIA_CANVAS_GROUP_H__
#include
#include "dia-canvas.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define DIA_TYPE_CANVAS_GROUP (dia_canvas_group_get_type ())
#define DIA_CANVAS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_GROUP, DiaCanvasGroup))
#define DIA_CANVAS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_GROUP, DiaCanvasGroupClass))
#define DIA_IS_CANVAS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_GROUP))
#define DIA_IS_CANVAS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_GROUP))
#define DIA_CANVAS_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_GROUP, DiaCanvasGroupClass))
//typedef struct _DiaCanvasGroup DiaCanvasGroup;
typedef struct _DiaCanvasGroupClass DiaCanvasGroupClass;
struct _DiaCanvasGroup
{
DiaCanvasItem parent;
GList *children;
};
struct _DiaCanvasGroupClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_group_get_type (void);
void dia_canvas_group_add_item (DiaCanvasGroup *group,
DiaCanvasItem *item);
void dia_canvas_group_remove_item (DiaCanvasGroup *group,
DiaCanvasItem *item);
void dia_canvas_group_foreach (DiaCanvasGroup *group,
GFunc function,
gpointer user_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_CANVAS_ITEM_H__ */
dia-newcanvas-0.6.10/src/dia-canvas-item.c 0100644 0001750 0001750 00000041241 07537446061 020600 0 ustar xordoquy xordoquy /* dia-canvas-item.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include "dia-canvas-item.h"
#include "dia-canvas-group.h"
#include "dia-canvas-view.h"
#include "dia-canvas-connection.h"
#include "dia-marshal.h"
#define _(s) (s)
/* signals */
enum {
RENDER,
DISTANCE,
UPDATE,
EVENT,
MOVE,
ATTRACT,
SNAPMOVE,
CONNECT,
CONNECTION,
CONNECTION_MOVED,
SELECT,
LAST_SIGNAL
};
/* properties */
enum {
PROP_NONE,
PROP_PARENT,
PROP_MOVE_INDEP,
PROP_VISIBLE
};
static void dia_canvas_item_init (DiaCanvasItem *item);
static void dia_canvas_item_class_init (DiaCanvasItemClass *klass);
static void dia_canvas_item_finalize (GObject *object);
static void dia_canvas_item_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_item_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_item_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static gdouble dia_canvas_item_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_item_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static gdouble dia_canvas_item_real_attract (DiaCanvasItem *item,
gdouble *dx, gdouble *dy);
static gdouble dia_canvas_item_real_snapmove (DiaCanvasItem *item,
gdouble *dx, gdouble *dy);
static void dia_canvas_item_real_connect (DiaCanvasItem *item,
DiaCanvasConnection *connection);
static void dia_canvas_item_real_connection (DiaCanvasItem *item);
static void dia_canvas_item_real_connection_moved (DiaCanvasItem *item,
DiaCanvasConnection *connection,
gdouble dx, gdouble dy);
static void dia_canvas_item_real_select (DiaCanvasItem *item, gboolean selected);
static GObjectClass *parent_class = NULL;
static guint canvas_item_signals[LAST_SIGNAL] = { 0 };
GType
dia_canvas_item_get_type (void)
{
static GtkType canvas_item_type = 0;
if (!canvas_item_type)
{
static const GTypeInfo canvas_item_info =
{
sizeof (DiaCanvasItemClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_item_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasItem),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_item_init,
};
canvas_item_type = g_type_register_static (G_TYPE_OBJECT,
"DiaCanvasItem",
&canvas_item_info, 0);
}
return canvas_item_type;
}
static void
dia_canvas_item_class_init (DiaCanvasItemClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS(klass);
parent_class = g_type_class_ref (G_TYPE_OBJECT);
object_class->set_property = dia_canvas_item_set_property;
object_class->get_property = dia_canvas_item_get_property;
object_class->finalize = dia_canvas_item_finalize;
klass->render = dia_canvas_item_real_render;
klass->distance = dia_canvas_item_real_distance;
klass->move = dia_canvas_item_real_move;
klass->attract = dia_canvas_item_real_attract;
klass->snapmove = dia_canvas_item_real_snapmove;
klass->connect = dia_canvas_item_real_connect;
klass->connection = dia_canvas_item_real_connection;
klass->connection_moved = dia_canvas_item_real_connection_moved;
klass->select = dia_canvas_item_real_select;
canvas_item_signals[RENDER] =
g_signal_new ("render",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (DiaCanvasItemClass, render), NULL, NULL,
dia_marshal_VOID__OBJECT_POINTER,
G_TYPE_NONE, 2,
DIA_TYPE_RENDERER, G_TYPE_POINTER /* rectangle */);
canvas_item_signals[DISTANCE] =
g_signal_new ("distance",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, distance), NULL, NULL,
dia_marshal_DOUBLE__DOUBLE_DOUBLE,
G_TYPE_DOUBLE, 2,
G_TYPE_DOUBLE, G_TYPE_DOUBLE);
canvas_item_signals[UPDATE] =
g_signal_new ("update",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(DiaCanvasItemClass, update), NULL, NULL,
gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
canvas_item_signals[EVENT] =
g_signal_new ("event",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(DiaCanvasItemClass, event), NULL, NULL,
dia_marshal_BOOLEAN__BOXED_OBJECT,
G_TYPE_BOOLEAN, 2,
GDK_TYPE_EVENT, DIA_TYPE_CANVAS_VIEW);
canvas_item_signals[MOVE] =
g_signal_new ("move",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, move), NULL, NULL,
dia_marshal_VOID__DOUBLE_DOUBLE,
G_TYPE_NONE, 2,
G_TYPE_DOUBLE, G_TYPE_DOUBLE);
canvas_item_signals[ATTRACT] =
g_signal_new ("attract",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, attract), NULL, NULL,
dia_marshal_DOUBLE__POINTER_POINTER,
G_TYPE_DOUBLE, 2,
G_TYPE_POINTER, G_TYPE_POINTER);
canvas_item_signals[SNAPMOVE] =
g_signal_new ("snapmove",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, snapmove), NULL, NULL,
dia_marshal_DOUBLE__POINTER_POINTER,
G_TYPE_DOUBLE, 2,
G_TYPE_POINTER, G_TYPE_POINTER);
canvas_item_signals[CONNECT] =
g_signal_new ("connect",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, connect), NULL, NULL,
dia_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
DIA_TYPE_CANVAS_CONNECTION);
canvas_item_signals[CONNECTION] =
g_signal_new ("connection",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, connection), NULL, NULL,
dia_marshal_VOID__VOID,
G_TYPE_NONE, 0);
canvas_item_signals[CONNECTION_MOVED] =
g_signal_new ("connection_moved",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, connection_moved), NULL, NULL,
dia_marshal_VOID__OBJECT_DOUBLE_DOUBLE,
G_TYPE_NONE, 3,
DIA_TYPE_CANVAS_CONNECTION, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
canvas_item_signals[SELECT] =
g_signal_new ("select",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DiaCanvasItemClass, select), NULL, NULL,
dia_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
g_object_class_install_property (object_class,
PROP_PARENT,
g_param_spec_object ("parent", _("Parent item"),
_("The parent group of this canvas item"),
DIA_TYPE_CANVAS_GROUP,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_VISIBLE,
g_param_spec_boolean ("visible", _("Visible"),
_("Whether the canvas item is visible"),
TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_MOVE_INDEP,
g_param_spec_boolean ("move_indep", _("Independant move"),
_("Whether the item moves does not move the all group"),
TRUE,
G_PARAM_READWRITE));
}
static void
dia_canvas_item_init (DiaCanvasItem *item)
{
item->canvas = NULL;
item->parent = NULL;
item->floating = TRUE;
item->visible = TRUE;
item->independant_move = TRUE;
item->attract_source = FALSE;
item->connect_source = FALSE;
item->connection_moved = FALSE;
item->selected = FALSE;
}
static void
dia_canvas_item_finalize(GObject *object)
{
DiaCanvasItem *item;
g_return_if_fail(object != NULL);
g_return_if_fail(DIA_IS_CANVAS_ITEM(object));
item = DIA_CANVAS_ITEM(object);
if( (item->canvas != NULL) &&
(item == item->canvas->focus_item) ) {
item->canvas->focus_item = NULL;
}
if( (item->canvas != NULL) &&
(item->canvas->focus_view != NULL) &&
(item == item->canvas->focus_view->event_item) ) {
item->canvas->focus_view->event_item = NULL;
}
if( item->canvas != NULL ) {
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
if (item->parent != NULL) {
dia_canvas_group_remove_item(item->parent,item);
}
/* TODO: remove the item of the selection if it is selected */
if (parent_class->finalize)
(* parent_class->finalize) (object);
}
static void
dia_canvas_item_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasItem *item = DIA_CANVAS_ITEM(object);
DiaCanvasGroup *parent;
switch (property_id)
{
case PROP_PARENT:
/* this won't destroy item, as g_object_set_prop refs the object */
if (item->parent != NULL)
dia_canvas_group_remove_item(item->parent, item);
parent = DIA_CANVAS_GROUP(g_value_get_object(value));
if (parent)
dia_canvas_group_add_item(parent, item);
break;
case PROP_VISIBLE:
if (g_value_get_boolean(value))
dia_canvas_item_show(item);
else
dia_canvas_item_hide(item);
break;
case PROP_MOVE_INDEP:
if (g_value_get_boolean(value))
item->independant_move = TRUE;
else
item->independant_move = FALSE;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_item_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasItem *item = DIA_CANVAS_ITEM(object);
switch (property_id)
{
case PROP_PARENT:
if (item->parent)
g_value_set_object(value, G_OBJECT(item->parent));
else
g_value_set_object(value, NULL);
break;
case PROP_VISIBLE:
g_value_set_boolean(value, item->visible);
break;
case PROP_MOVE_INDEP:
g_value_set_boolean(value, item->independant_move);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/*****************************************************************************
******************************* S I G N A L S *******************************
*****************************************************************************/
static void
dia_canvas_item_real_render (DiaCanvasItem *item,
DiaRenderer *renderer, DiaRectangle *rect)
{
}
static gdouble
dia_canvas_item_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y)
{
return G_MAXDOUBLE;
}
static void
dia_canvas_item_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
}
static gdouble
dia_canvas_item_real_attract (DiaCanvasItem *item,
gdouble *x, gdouble *y)
{
return G_MAXDOUBLE;
}
static gdouble
dia_canvas_item_real_snapmove (DiaCanvasItem *item,
gdouble *x, gdouble *y)
{
return G_MAXDOUBLE;
}
static void
dia_canvas_item_real_connect (DiaCanvasItem *item,
DiaCanvasConnection *connection)
{
}
static void
dia_canvas_item_real_connection (DiaCanvasItem *item)
{
}
static void
dia_canvas_item_real_connection_moved (DiaCanvasItem *item,
DiaCanvasConnection *connection,
gdouble dx, gdouble dy)
{
static guint connection_moved_signal_id = 0;
if (connection_moved_signal_id == 0)
connection_moved_signal_id = gtk_signal_lookup("connection_moved", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(item->parent, connection_moved_signal_id, 0, connection, dx, dy);
}
static void
dia_canvas_item_real_select (DiaCanvasItem *item, gboolean selected)
{
item->selected = selected;
}
/*****************************************************************************
***************************** F O N C T I O N S *****************************
*****************************************************************************/
/**
* dia_canvas_item_request_update:
* @item: a #DiaCanvasItem.
*
* ??
**/
void
dia_canvas_item_request_update(DiaCanvasItem *item)
{
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_ITEM(item));
if (item->canvas == NULL) {
/* an update will be scheduled when the item is actually added to
* the canvas */
return;
}
if (item->canvas->in_update) {
g_warning("recursive update requested. not good");
return;
}
if (item->need_update)
return;
item->need_update = TRUE;
/* propagate update up tree ... */
if (item->parent)
dia_canvas_item_request_update(DIA_CANVAS_ITEM(item->parent));
else /* top of tree ... */
dia_canvas_schedule_update(item->canvas);
}
/**
* dia_canvas_item_sink:
* @item: a #DiaCanvasItem.
*
* ??
**/
void
dia_canvas_item_sink (DiaCanvasItem *item)
{
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_ITEM(item));
if (item->floating) {
g_object_unref(G_OBJECT(item));
}
item->floating = FALSE;
}
/**
* dia_canvas_item_show:
* @item: a #DiaCanvasItem.
*
* Shows the @item.
**/
void
dia_canvas_item_show (DiaCanvasItem *item)
{
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_ITEM(item));
if (item->visible)
return;
item->visible = TRUE;
g_object_notify(G_OBJECT(item), "visible");
if (item->canvas != NULL)
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
/**
* dia_canvas_item_hide:
* @item: a #DiaCanvasItem.
*
* Hide the @item.
**/
void
dia_canvas_item_hide (DiaCanvasItem *item)
{
g_return_if_fail(item != NULL);
g_return_if_fail(DIA_IS_CANVAS_ITEM(item));
if (!item->visible)
return;
item->visible = FALSE;
g_object_notify(G_OBJECT(item), "visible");
if (item->canvas != NULL)
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
/**
* dia_canvas_item_move:
* @item: a #DiaCanvasItem.
* @dx: the x difference.
* @dy: the y difference.
*
* Moves the @item from (@dx,@dy).
* Does the snapping if requiered.
**/
void
dia_canvas_item_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasItem *moved;
static guint event_signal_id = 0;
g_return_if_fail(item != NULL);
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("move", DIA_TYPE_CANVAS_ITEM);
moved = item;
while( !moved->independant_move ) {
moved = DIA_CANVAS_ITEM(moved->parent);
}
g_signal_emit(moved, event_signal_id, 0, dx, dy);
}
/**
* dia_canvas_item_snapmove:
* @item: a #DiaCanvasItem.
* @dx: the x difference.
* @dy: the y difference.
*
* Gets the best (x,y) from the
* snap of the item BUT DO NOT MOVE.
*
* Returns: distance.
**/
gdouble
dia_canvas_item_snapmove (DiaCanvasItem *item,
gdouble *dx, gdouble *dy)
{
gdouble result;
DiaCanvasItem *moved;
static guint event_signal_id = 0;
g_return_val_if_fail( item != NULL, G_MAXDOUBLE );
g_return_val_if_fail( dx != NULL, G_MAXDOUBLE );
g_return_val_if_fail( dy != NULL, G_MAXDOUBLE );
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("snapmove", DIA_TYPE_CANVAS_ITEM);
/*
* Get the topmost item not moving independantly.
*/
moved = item;
while( !moved->independant_move ) {
moved = DIA_CANVAS_ITEM(moved->parent);
}
g_signal_emit(moved, event_signal_id, 0, dx, dy, &result);
return result;
}
/**
* dia_canvas_item_make_connection:
* @item: a #DiaCanvasItem.
*
* Test if connection are possible and do them.
**/
void
dia_canvas_item_make_connection (DiaCanvasItem *item)
{
DiaCanvasItem *connect;
static guint connection_signal_id = 0;
g_return_if_fail( item != NULL );
if (connection_signal_id == 0)
connection_signal_id = gtk_signal_lookup("connection", DIA_TYPE_CANVAS_ITEM);
connect = item;
while( !connect->independant_move ) {
connect = DIA_CANVAS_ITEM(connect->parent);
}
g_signal_emit(connect, connection_signal_id, 0);
}
void
dia_canvas_item_select (DiaCanvasItem *item)
{
static guint item_select_signal_id = 0;
if (item_select_signal_id == 0)
item_select_signal_id = gtk_signal_lookup("select", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(item, item_select_signal_id, 0, TRUE);
}
void
dia_canvas_item_unselect (DiaCanvasItem *item)
{
static guint item_select_signal_id = 0;
if (item_select_signal_id == 0)
item_select_signal_id = gtk_signal_lookup("select", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(item, item_select_signal_id, 0, FALSE);
}
dia-newcanvas-0.6.10/src/dia-canvas-item.h 0100644 0001750 0001750 00000010366 07537446061 020611 0 ustar xordoquy xordoquy /* dia-canvas-item.h
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_ITEM_H__
#define __DIA_CANVAS_ITEM_H__
#include
#include "dia-canvas.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define DIA_TYPE_CANVAS_ITEM (dia_canvas_item_get_type ())
#define DIA_CANVAS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_ITEM, DiaCanvasItem))
#define DIA_CANVAS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_ITEM, DiaCanvasItemClass))
#define DIA_IS_CANVAS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_ITEM))
#define DIA_IS_CANVAS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_ITEM))
#define DIA_CANVAS_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_ITEM, DiaCanvasItemClass))
/* forward declaration of DiaCanvasItem in dia-canvas.h */
/* typedef struct _DiaCanvasItem DiaCanvasItem; */
typedef struct _DiaCanvasItemClass DiaCanvasItemClass;
struct _DiaCanvasItem
{
GObject object;
DiaCanvas *canvas;
DiaCanvasGroup *parent;
/* Bounds in which the item fits */
DiaRectangle bounds;
guint floating : 1;
guint visible : 1;
guint need_update : 1;
/* Does it moves with the group or alone ? */
guint independant_move : 1;
/* is it the source of the attract ? */
guint attract_source : 1;
/* is it the source of the connect ? */
guint connect_source : 1;
/* Does it issue the connection move ? */
guint connection_moved : 1;
/* is the item in the selection ? */
guint selected : 1;
};
struct _DiaCanvasItemClass
{
GObjectClass parent_class;
void (*render) (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
/* Computes the distance */
gdouble (* distance) (DiaCanvasItem *item,
gdouble x,
gdouble y);
void (* update) (DiaCanvasItem *item);
gboolean (* event) (DiaCanvasItem *item,
GdkEvent *event,
DiaCanvasView *view);
/* Signal for simple movement */
void (* move) (DiaCanvasItem *item,
gdouble dx,
gdouble dy);
/* (dx,dy) to add to move to the nearest attraction point */
gdouble (* attract) (DiaCanvasItem *item,
gdouble *x,
gdouble *y);
/* Try a move with snap constraints */
gdouble (* snapmove) (DiaCanvasItem *item,
gdouble *dx,
gdouble *dy);
/* Try to see if connection can be established */
void (* connect) (DiaCanvasItem *item,
DiaCanvasConnection *connection);
/* Ask the item to connect other items */
void (* connection) (DiaCanvasItem *item);
/* Received when a connected object has moved */
void (* connection_moved) (DiaCanvasItem *item,
DiaCanvasConnection *connection,
gdouble dx, gdouble dy);
void (* select) (DiaCanvasItem *item,
gboolean selected);
};
GType dia_canvas_item_get_type (void);
void dia_canvas_item_request_update (DiaCanvasItem *item);
void dia_canvas_item_sink (DiaCanvasItem *item);
void dia_canvas_item_show (DiaCanvasItem *item);
void dia_canvas_item_hide (DiaCanvasItem *item);
void dia_canvas_item_move (DiaCanvasItem *item,
gdouble dx,
gdouble dy);
gdouble dia_canvas_item_snapmove (DiaCanvasItem *item,
gdouble *dx,
gdouble *dy);
void dia_canvas_item_make_connection (DiaCanvasItem *item);
void dia_canvas_item_select (DiaCanvasItem *item);
void dia_canvas_item_unselect (DiaCanvasItem *item);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_CANVAS_ITEM_H__ */
dia-newcanvas-0.6.10/src/dia-canvas-line.c 0100644 0001750 0001750 00000023275 07537446061 020600 0 ustar xordoquy xordoquy /* dia-canvas-line.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-line.h"
#include "dia-canvas-group.h"
#define _(s) (s)
#define sqr(x) ((x)*(x))
/* properties */
enum {
PROP_NONE,
PROP_X1,
PROP_Y1,
PROP_X2,
PROP_Y2,
PROP_LINE_COLOR,
PROP_LINE_WIDTH,
PROP_LAST
};
static void dia_canvas_line_init (DiaCanvasLine *line);
static void dia_canvas_line_class_init (DiaCanvasLineClass *klass);
static void dia_canvas_line_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_line_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_line_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static gdouble dia_canvas_line_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_line_real_update (DiaCanvasItem *item);
static void dia_canvas_line_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_line_get_type (void)
{
static GtkType canvas_line_type = 0;
if (!canvas_line_type)
{
static const GTypeInfo canvas_line_info =
{
sizeof (DiaCanvasLineClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_line_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasLine),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_line_init,
};
canvas_line_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasLine",
&canvas_line_info,
0);
}
return canvas_line_type;
}
static void
dia_canvas_line_class_init (DiaCanvasLineClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_line_set_property;
object_class->get_property = dia_canvas_line_get_property;
item_class->render = dia_canvas_line_real_render;
item_class->update = dia_canvas_line_real_update;
item_class->distance = dia_canvas_line_real_distance;
item_class->move = dia_canvas_line_real_move;
g_object_class_install_property (object_class,
PROP_X1,
g_param_spec_double ("x1", _("First edge"),
_("The position of the first edge of the line"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y1,
g_param_spec_double ("y1", _("First edge"),
_("The position of the first edge of the line"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_X2,
g_param_spec_double ("x2", _("Second edge"),
_("The position of the second edge of the line"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y2,
g_param_spec_double ("y2", _("Second edge"),
_("The position of the second edge of the line"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_COLOR,
g_param_spec_boxed ("line_color", _("Line color"),
_("The line color of the line"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_WIDTH,
g_param_spec_double ("line_width", _("Line width"),
_("The thickness of line"),
0, G_MAXDOUBLE, 0,
G_PARAM_READWRITE));
}
static void
dia_canvas_line_init (DiaCanvasLine *line)
{
GdkColor red = { 0, 0xffff, 0, 0 };
line->line_color = red;
line->line_width = 1;
}
static void
dia_canvas_line_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasLine *line = DIA_CANVAS_LINE(object);
gdouble val;
GdkColor *color;
switch (property_id)
{
case PROP_X1:
val = g_value_get_double(value);
if (val != line->point1.x) {
line->point1.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(line));
}
break;
case PROP_Y1:
val = g_value_get_double(value);
if (val != line->point1.y) {
line->point1.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(line));
}
break;
case PROP_X2:
val = g_value_get_double(value);
if (val != line->point2.x) {
line->point2.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(line));
}
break;
case PROP_Y2:
val = g_value_get_double(value);
if (val != line->point2.y) {
line->point2.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(line));
}
break;
case PROP_LINE_COLOR:
color = g_value_get_boxed(value);
line->line_color = *color;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(line));
break;
case PROP_LINE_WIDTH:
val = g_value_get_double(value);
line->line_width = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(line));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_line_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasLine *line = DIA_CANVAS_LINE(object);
switch (property_id)
{
case PROP_X1:
g_value_set_double(value, line->point1.x);
break;
case PROP_Y1:
g_value_set_double(value, line->point1.y);
break;
case PROP_X2:
g_value_set_double(value, line->point2.x);
break;
case PROP_Y2:
g_value_set_double(value, line->point2.y);
break;
case PROP_LINE_COLOR:
g_value_set_boxed(value, &line->line_color);
break;
case PROP_LINE_WIDTH:
g_value_set_double(value, line->line_width);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_line_real_render (DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rect)
{
DiaCanvasLine *line = DIA_CANVAS_LINE(item);
dia_renderer_set_color(renderer, &line->line_color);
dia_renderer_set_line_width(renderer, line->line_width);
dia_renderer_draw_line(renderer, &line->point1, &line->point2);
}
static void
dia_canvas_line_real_update (DiaCanvasItem *item)
{
DiaCanvasLine *line = DIA_CANVAS_LINE(item);
gdouble half_width, tmp;
/* the line may have been moved, so dirty its former location */
dia_canvas_dirty_region(item->canvas, &item->bounds);
item->bounds.left = line->point1.x;
item->bounds.top = line->point1.y;
item->bounds.right = line->point2.x;
item->bounds.bottom = line->point2.y;
if( item->bounds.left > item->bounds.right ) {
tmp = item->bounds.left;
item->bounds.left = item->bounds.right;
item->bounds.right = tmp;
}
if( item->bounds.top > item->bounds.bottom ) {
tmp = item->bounds.top;
item->bounds.top = item->bounds.bottom;
item->bounds.bottom = tmp;
}
half_width = line->line_width / 2;
item->bounds.left -= half_width;
item->bounds.top -= half_width;
item->bounds.right += half_width;
item->bounds.bottom += half_width;
/* dirty the new location to redraw ... */
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
static gdouble
dia_canvas_line_real_distance (DiaCanvasItem *item, gdouble x,gdouble y)
{
DiaCanvasLine *line = DIA_CANVAS_LINE(item);
gdouble d1,d2,d3;
gdouble scal;
/* not the exact distance, but close enough for our checks */
d1 = sqr(item->bounds.left-x) + sqr(item->bounds.top-y);
d2 = sqr(item->bounds.right-x) + sqr(item->bounds.bottom-y);
scal = ((item->bounds.right - item->bounds.left)*(x - item->bounds.left)) +
((item->bounds.bottom - item->bounds.top)*(y - item->bounds.top));
scal = scal/(sqr(item->bounds.right - item->bounds.left)+sqr(item->bounds.bottom - item->bounds.top));
d3 = sqr(scal*(item->bounds.right - item->bounds.left)+item->bounds.left-x) +
sqr(scal*(item->bounds.bottom - item->bounds.top)+item->bounds.top-y);
scal = sqr((line->line_width)/2.0);
d1 -= scal;
d2 -= scal;
d3 -= scal;
if( d1 < 0 )
d1 = 0;
if( d2 < 0 )
d2 = 0;
if( d3 < 0 )
d3 = 0;
if( d1 < d2 ) {
if( d1 < d3 ) {
return d1;
} else {
return d3;
}
} else {
if( d2 < d3 ) {
return d2;
} else {
return d3;
}
}
}
static void
dia_canvas_line_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasLine *line = DIA_CANVAS_LINE(item);
line->point1.x += dx;
line->point1.y += dy;
line->point2.x += dx;
line->point2.y += dy;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(line));
}
dia-newcanvas-0.6.10/src/dia-canvas-line.h 0100644 0001750 0001750 00000003464 07537446061 020603 0 ustar xordoquy xordoquy /* dia-canvas-line.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_LINE_H__
#define __DIA_CANVAS_LINE_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_LINE (dia_canvas_line_get_type ())
#define DIA_CANVAS_LINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_LINE, DiaCanvasLine))
#define DIA_CANVAS_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_LINE, DiaCanvasLineClass))
#define DIA_IS_CANVAS_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_LINE))
#define DIA_IS_CANVAS_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_LINE))
#define DIA_CANVAS_LINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_LINE, DiaCanvasLineClass))
typedef struct _DiaCanvasLine DiaCanvasLine;
typedef struct _DiaCanvasLineClass DiaCanvasLineClass;
struct _DiaCanvasLine
{
DiaCanvasItem item;
DiaPoint point1, point2;
gdouble line_width;
GdkColor line_color;
};
struct _DiaCanvasLineClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_line_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-point.c 0100644 0001750 0001750 00000015210 07537446061 020770 0 ustar xordoquy xordoquy /* dia-canvas-point.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-point.h"
#include "dia-canvas-group.h"
#include
#define _(s) (s)
#define sqr(x) ((x)*(x))
/* properties */
enum {
PROP_NONE,
PROP_X,
PROP_Y,
PROP_POINT_COLOR,
PROP_LAST
};
static void dia_canvas_point_init (DiaCanvasPoint *point);
static void dia_canvas_point_class_init (DiaCanvasPointClass *klass);
static void dia_canvas_point_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_point_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_point_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static gdouble dia_canvas_point_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_point_real_update (DiaCanvasItem *item);
static void dia_canvas_point_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_point_get_type (void)
{
static GtkType canvas_point_type = 0;
if (!canvas_point_type)
{
static const GTypeInfo canvas_point_info =
{
sizeof (DiaCanvasPointClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_point_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasPoint),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_point_init,
};
canvas_point_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasPoint",
&canvas_point_info,
0);
}
return canvas_point_type;
}
static void
dia_canvas_point_class_init (DiaCanvasPointClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_point_set_property;
object_class->get_property = dia_canvas_point_get_property;
item_class->render = dia_canvas_point_real_render;
item_class->update = dia_canvas_point_real_update;
item_class->distance = dia_canvas_point_real_distance;
item_class->move = dia_canvas_point_real_move;
g_object_class_install_property (object_class,
PROP_X,
g_param_spec_double ("x", _("Position"),
_("The position of the point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y,
g_param_spec_double ("y", _("Position"),
_("The position of the point"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_POINT_COLOR,
g_param_spec_boxed ("point_color", _("Point color"),
_("The point color of the point"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
}
static void
dia_canvas_point_init (DiaCanvasPoint *point)
{
GdkColor red = { 0, 0xffff, 0, 0 };
point->point_color = red;
}
static void
dia_canvas_point_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasPoint *point = DIA_CANVAS_POINT(object);
gdouble val;
GdkColor *color;
switch (property_id)
{
case PROP_X:
val = g_value_get_double(value);
if (val != point->point.x) {
point->point.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(point));
}
break;
case PROP_Y:
val = g_value_get_double(value);
if (val != point->point.y) {
point->point.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(point));
}
break;
case PROP_POINT_COLOR:
color = g_value_get_boxed(value);
point->point_color = *color;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(point));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_point_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasPoint *point = DIA_CANVAS_POINT(object);
switch (property_id)
{
case PROP_X:
g_value_set_double(value, point->point.x);
break;
case PROP_Y:
g_value_set_double(value, point->point.y);
break;
case PROP_POINT_COLOR:
g_value_set_boxed(value, &point->point_color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_point_real_render (DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rect)
{
DiaCanvasPoint *point = DIA_CANVAS_POINT(item);
dia_renderer_set_color(renderer, &point->point_color);
dia_renderer_draw_point(renderer, &point->point);
}
static void
dia_canvas_point_real_update (DiaCanvasItem *item)
{
DiaCanvasPoint *point = DIA_CANVAS_POINT(item);
/* the point may have been moved, so dirty its former location */
dia_canvas_dirty_region(item->canvas, &item->bounds);
item->bounds.left = point->point.x;
item->bounds.top = point->point.y;
item->bounds.right = point->point.x;
item->bounds.bottom = point->point.y;
/* dirty the new location to redraw ... */
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
static gdouble
dia_canvas_point_real_distance (DiaCanvasItem *item, gdouble x,gdouble y)
{
DiaCanvasPoint *point = DIA_CANVAS_POINT(item);
return sqrt(sqr(point->point.x - x) + sqr(point->point.y - y));
}
static void
dia_canvas_point_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasPoint *point = DIA_CANVAS_POINT(item);
point->point.x += dx;
point->point.y += dy;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(point));
}
dia-newcanvas-0.6.10/src/dia-canvas-point.h 0100644 0001750 0001750 00000003457 07537446061 021007 0 ustar xordoquy xordoquy /* dia-canvas-point.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_POINT_H__
#define __DIA_CANVAS_POINT_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_POINT (dia_canvas_point_get_type ())
#define DIA_CANVAS_POINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_POINT, DiaCanvasPoint))
#define DIA_CANVAS_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_POINT, DiaCanvasPointClass))
#define DIA_IS_CANVAS_POINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_POINT))
#define DIA_IS_CANVAS_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_POINT))
#define DIA_CANVAS_POINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_POINT, DiaCanvasPointClass))
typedef struct _DiaCanvasPoint DiaCanvasPoint;
typedef struct _DiaCanvasPointClass DiaCanvasPointClass;
struct _DiaCanvasPoint
{
DiaCanvasItem item;
DiaPoint point;
GdkColor point_color;
};
struct _DiaCanvasPointClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_point_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-polygon.c 0100644 0001750 0001750 00000027631 07537446061 021340 0 ustar xordoquy xordoquy /* dia-canvas-polygon.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-polygon.h"
#include "dia-canvas-group.h"
#include
#define _(s) (s)
#define sqr(x) ((x)*(x))
static guint line_crosses_ray(const DiaPoint *line_start,
const DiaPoint *line_end,
const DiaPoint *rayend);
/* properties */
enum {
PROP_NONE,
PROP_X,
PROP_Y,
PROP_POINT,
PROP_FILL_COLOR,
PROP_LINE_COLOR,
PROP_LINE_WIDTH,
PROP_LAST
};
static void dia_canvas_polygon_init (DiaCanvasPolygon *polygon);
static void dia_canvas_polygon_class_init (DiaCanvasPolygonClass *klass);
static void dia_canvas_polygon_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_polygon_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_polygon_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static gdouble dia_canvas_polygon_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_polygon_real_update (DiaCanvasItem *item);
static void dia_canvas_polygon_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_polygon_get_type (void)
{
static GtkType canvas_polygon_type = 0;
if (!canvas_polygon_type)
{
static const GTypeInfo canvas_polygon_info =
{
sizeof (DiaCanvasPolygonClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_polygon_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasPolygon),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_polygon_init,
};
canvas_polygon_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasPolygon",
&canvas_polygon_info,
0);
}
return canvas_polygon_type;
}
static void
dia_canvas_polygon_class_init (DiaCanvasPolygonClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_polygon_set_property;
object_class->get_property = dia_canvas_polygon_get_property;
item_class->render = dia_canvas_polygon_real_render;
item_class->update = dia_canvas_polygon_real_update;
item_class->distance = dia_canvas_polygon_real_distance;
item_class->move = dia_canvas_polygon_real_move;
g_object_class_install_property (object_class,
PROP_X,
g_param_spec_double ("x", _("Position"),
_("The position of the polygon"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y,
g_param_spec_double ("y", _("Position"),
_("The position of the polygon"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_POINT,
g_param_spec_string ("point", _("Add point"),
_("Add a point to the polygon"),
"(0.0,0.0)",
G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_FILL_COLOR,
g_param_spec_boxed ("fill_color", _("Fill color"),
_("The fill color of the rectangle (or NULL for empty)"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_COLOR,
g_param_spec_boxed ("line_color", _("Polygon line color"),
_("The line color of the polygon"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_WIDTH,
g_param_spec_double ("line_width", _("Line width"),
_("The thickness of line"),
0, G_MAXDOUBLE, 0,
G_PARAM_READWRITE));
}
static void
dia_canvas_polygon_init (DiaCanvasPolygon *polygon)
{
polygon->line_width = 1;
}
static void
dia_canvas_polygon_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasPolygon *polygon = DIA_CANVAS_POLYGON(object);
gdouble val, oldval;
gint i;
DiaPoint *point;
guchar *string;
GdkColor *color;
switch (property_id)
{
case PROP_X:
val = g_value_get_double(value);
if (val != polygon->position.x) {
oldval = polygon->position.x;
polygon->position.x = val;
for( i=0; ilist); i++ ) {
point = g_list_nth_data(polygon->list,i);
point->x += val - oldval;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(polygon));
}
break;
case PROP_Y:
val = g_value_get_double(value);
if (val != polygon->position.y) {
oldval = polygon->position.y;
polygon->position.y = val;
for( i=0; ilist); i++ ) {
point = g_list_nth_data(polygon->list,i);
point->y += val - oldval;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(polygon));
}
break;
case PROP_POINT:
string = g_value_dup_string(value);
point = g_new0(DiaPoint,1);
if( sscanf(string,"(%lf,%lf)",&(point->x),&(point->y)) == 2 ) {
point->x += polygon->position.x;
point->y += polygon->position.y;
polygon->list = g_list_append(polygon->list,point);
dia_canvas_item_request_update(DIA_CANVAS_ITEM(polygon));
} else {
g_free(point);
}
break;
case PROP_FILL_COLOR:
color = g_value_get_boxed(value);
if (color) {
polygon->fill_color = *color;
polygon->fill = TRUE;
} else {
polygon->fill = FALSE;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(polygon));
break;
case PROP_LINE_COLOR:
color = g_value_get_boxed(value);
if (color) {
polygon->line_color = *color;
polygon->line = TRUE;
} else {
polygon->line = FALSE;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(polygon));
break;
case PROP_LINE_WIDTH:
val = g_value_get_double(value);
if (val != polygon->line_width) {
polygon->line_width = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(polygon));
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_polygon_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasPolygon *polygon = DIA_CANVAS_POLYGON(object);
switch (property_id)
{
case PROP_X:
g_value_set_double(value, polygon->position.x);
break;
case PROP_Y:
g_value_set_double(value, polygon->position.y);
break;
case PROP_FILL_COLOR:
if( polygon->fill ) {
g_value_set_boxed(value, &polygon->fill_color);
} else {
g_value_set_boxed(value, NULL);
}
break;
case PROP_LINE_COLOR:
if( polygon->line ) {
g_value_set_boxed(value, &polygon->line_color);
} else {
g_value_set_boxed(value, NULL);
}
break;
case PROP_LINE_WIDTH:
g_value_set_double(value, polygon->line_width);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_polygon_real_render (DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rect)
{
DiaCanvasPolygon *polygon = DIA_CANVAS_POLYGON(item);
if( polygon->fill ) {
dia_renderer_set_color(renderer, &polygon->fill_color);
dia_renderer_draw_polygon(renderer, TRUE, polygon->list);
}
if( polygon->line ) {
dia_renderer_set_color(renderer, &polygon->line_color);
dia_renderer_set_line_width(renderer, polygon->line_width);
dia_renderer_draw_polygon(renderer, FALSE, polygon->list);
}
}
static void
dia_canvas_polygon_real_update (DiaCanvasItem *item)
{
DiaCanvasPolygon *polygon = DIA_CANVAS_POLYGON(item);
gdouble half_width;
DiaPoint *point;
gint i;
/* the polygon may have been moved, so dirty its former location */
dia_canvas_dirty_region(item->canvas, &item->bounds);
item->bounds.left = polygon->position.x;
item->bounds.top = polygon->position.y;
item->bounds.right = polygon->position.x;
item->bounds.bottom = polygon->position.y;
for( i=0; ilist); i++ ) {
point = g_list_nth_data(polygon->list,i);
if( item->bounds.left > point->x ) {
item->bounds.left = point->x;
}
if( item->bounds.top > point->y ) {
item->bounds.top = point->y;
}
if( item->bounds.right < point->x ) {
item->bounds.right = point->x;
}
if( item->bounds.bottom < point->y ) {
item->bounds.bottom = point->y;
}
}
half_width = polygon->line_width / 2;
item->bounds.left -= half_width;
item->bounds.top -= half_width;
item->bounds.right += half_width;
item->bounds.bottom += half_width;
/* dirty the new location to redraw ... */
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
static gdouble
dia_canvas_polygon_real_distance (DiaCanvasItem *item, gdouble x,gdouble y)
{
/*
guint i, last = npoints - 1;
*/
gint i, npoints, crossings;
gdouble line_dist = G_MAXFLOAT;
DiaCanvasPolygon *polygon = DIA_CANVAS_POLYGON(item);
DiaPoint point, *last;
npoints = g_list_length(polygon->list);
point.x = x;
point.y = y;
crossings = 0;
last = g_list_nth_data(polygon->list,npoints-1);
/* calculate ray crossings and line distances */
for (i = 0; i < npoints; i++) {
gdouble dist;
crossings += line_crosses_ray(last, g_list_nth_data(polygon->list,i), &point);
dist = distance_line_point(last, g_list_nth_data(polygon->list,i),
polygon->line_width, &point);
line_dist = MIN(line_dist, dist);
last = g_list_nth_data(polygon->list,i);
}
/* If there is an odd number of ray crossings, we are inside the polygon.
* Otherwise, return the minium distance from a line segment */
if (crossings % 2 == 1)
return 0.0;
else
return line_dist;
}
static void
dia_canvas_polygon_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
gint i;
DiaPoint *point;
DiaCanvasPolygon *polygon = DIA_CANVAS_POLYGON(item);
polygon->position.x += dx;
polygon->position.y += dy;
for( i=0; ilist); i++ ) {
point = g_list_nth_data(polygon->list,i);
point->x += dx;
point->y += dy;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(polygon));
}
static guint
line_crosses_ray(const DiaPoint *line_start,
const DiaPoint *line_end,
const DiaPoint *rayend)
{
gdouble xpos;
/* swap end points if necessary */
if (line_start->y > line_end->y) {
const DiaPoint *tmp;
tmp = line_start;
line_start = line_end;
line_end = tmp;
}
/* if y coords of line do not include rayend.y */
if (line_start->y > rayend->y || line_end->y < rayend->y)
return 0;
/* Avoid division by zero */
if (line_end->y - line_start->y < 0.00000000001) {
return line_end->y - rayend->y < 0.00000000001;
}
xpos = line_start->x + (rayend->y - line_start->y) *
(line_end->x - line_start->x) / (line_end->y - line_start->y);
return xpos <= rayend->x;
}
dia-newcanvas-0.6.10/src/dia-canvas-polygon.h 0100644 0001750 0001750 00000003714 07537446061 021341 0 ustar xordoquy xordoquy /* dia-canvas-polygon.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_POLYGON_H__
#define __DIA_CANVAS_POLYGON_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_POLYGON (dia_canvas_polygon_get_type ())
#define DIA_CANVAS_POLYGON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_POLYGON, DiaCanvasPolygon))
#define DIA_CANVAS_POLYGON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_POLYGON, DiaCanvasPolygonClass))
#define DIA_IS_CANVAS_POLYGON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_POLYGON))
#define DIA_IS_CANVAS_POLYGON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_POLYGON))
#define DIA_CANVAS_POLYGON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_POLYGON, DiaCanvasPolygonClass))
typedef struct _DiaCanvasPolygon DiaCanvasPolygon;
typedef struct _DiaCanvasPolygonClass DiaCanvasPolygonClass;
struct _DiaCanvasPolygon
{
DiaCanvasItem item;
DiaPoint position;
GList *list;
gboolean fill;
gboolean line;
GdkColor fill_color;
GdkColor line_color;
gdouble line_width;
};
struct _DiaCanvasPolygonClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_polygon_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-rectangle.c 0100644 0001750 0001750 00000027233 07537446061 021613 0 ustar xordoquy xordoquy /* dia-canvas-rectangle.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-rectangle.h"
#include "dia-canvas-group.h"
#define _(s) (s)
/* properties */
enum {
PROP_NONE,
PROP_X1,
PROP_Y1,
PROP_X2,
PROP_Y2,
PROP_FILL_COLOR,
PROP_LINE_COLOR,
PROP_LINE_WIDTH,
PROP_TEST_FILL,
PROP_TEST_LINE,
PROP_LAST
};
static void dia_canvas_rectangle_init (DiaCanvasRectangle *rect);
static void dia_canvas_rectangle_class_init (DiaCanvasRectangleClass *klass);
static void dia_canvas_rectangle_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_rectangle_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_rectangle_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rectangle);
static gdouble dia_canvas_rectangle_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_rectangle_real_update (DiaCanvasItem *item);
static void dia_canvas_rectangle_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_rectangle_get_type (void)
{
static GtkType canvas_rectangle_type = 0;
if (!canvas_rectangle_type)
{
static const GTypeInfo canvas_rectangle_info =
{
sizeof (DiaCanvasRectangleClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_rectangle_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasRectangle),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_rectangle_init,
};
canvas_rectangle_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasRectangle",
&canvas_rectangle_info,
0);
}
return canvas_rectangle_type;
}
static void
dia_canvas_rectangle_class_init (DiaCanvasRectangleClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_rectangle_set_property;
object_class->get_property = dia_canvas_rectangle_get_property;
item_class->render = dia_canvas_rectangle_real_render;
item_class->update = dia_canvas_rectangle_real_update;
item_class->distance = dia_canvas_rectangle_real_distance;
item_class->move = dia_canvas_rectangle_real_move;
g_object_class_install_property (object_class,
PROP_X1,
g_param_spec_double ("x1", _("Left edge"),
_("The position of the left edge of the rectangle"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y1,
g_param_spec_double ("y1", _("Top edge"),
_("The position of the top edge of the rectangle"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_X2,
g_param_spec_double ("x2", _("Right edge"),
_("The position of the right edge of the rectangle"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y2,
g_param_spec_double ("y2", _("Bottom edge"),
_("The position of the bottom edge of the rectangle"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FILL_COLOR,
g_param_spec_boxed ("fill_color", _("Fill color"),
_("The fill color of the rectangle (or NULL for empty)"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_COLOR,
g_param_spec_boxed ("line_color", _("Line color"),
_("The line color of the rectangle (or NULL for no outline)"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LINE_WIDTH,
g_param_spec_double ("line_width", _("Line width"),
_("The thickness of rectangle's outline"),
0, G_MAXDOUBLE, 0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TEST_FILL,
g_param_spec_boolean ("test_fill", _("Test fill"),
_("Test if the rectangle is filled or not"),
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_TEST_LINE,
g_param_spec_boolean ("test_line", _("Test line"),
_("Test if the rectangle has border or not"),
FALSE,
G_PARAM_READABLE));
}
static void
dia_canvas_rectangle_init (DiaCanvasRectangle *rect)
{
}
static void
dia_canvas_rectangle_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(object);
gdouble val;
GdkColor *color;
switch (property_id)
{
case PROP_X1:
val = g_value_get_double(value);
if (val != rect->topleft.x) {
rect->topleft.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
}
break;
case PROP_Y1:
val = g_value_get_double(value);
if (val != rect->topleft.y) {
rect->topleft.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
}
break;
case PROP_X2:
val = g_value_get_double(value);
if (val != rect->bottomright.x) {
rect->bottomright.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
}
break;
case PROP_Y2:
val = g_value_get_double(value);
if (val != rect->bottomright.y) {
rect->bottomright.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
}
break;
case PROP_FILL_COLOR:
color = g_value_get_boxed(value);
if (color) {
rect->fill_color = *color;
rect->fill = TRUE;
} else {
rect->fill = FALSE;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
break;
case PROP_LINE_COLOR:
color = g_value_get_boxed(value);
if (color) {
rect->line_color = *color;
rect->line = TRUE;
} else {
rect->line = FALSE;
}
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
break;
case PROP_LINE_WIDTH:
val = g_value_get_double(value);
if (val != rect->line_width) {
rect->line_width = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_rectangle_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(object);
switch (property_id)
{
case PROP_X1:
g_value_set_double(value, rect->topleft.x);
break;
case PROP_Y1:
g_value_set_double(value, rect->topleft.y);
break;
case PROP_X2:
g_value_set_double(value, rect->bottomright.x);
break;
case PROP_Y2:
g_value_set_double(value, rect->bottomright.y);
break;
case PROP_FILL_COLOR:
if (rect->fill)
g_value_set_boxed(value, &rect->fill_color);
else
g_value_set_boxed(value, NULL);
break;
case PROP_LINE_COLOR:
if (rect->line)
g_value_set_boxed(value, &rect->line_color);
else
g_value_set_boxed(value, NULL);
break;
case PROP_LINE_WIDTH:
g_value_set_double(value, rect->line_width);
break;
case PROP_TEST_FILL:
if (rect->fill)
g_value_set_boolean(value, TRUE);
else
g_value_set_boolean(value, FALSE);
break;
case PROP_TEST_LINE:
if (rect->line)
g_value_set_boolean(value, TRUE);
else
g_value_set_boolean(value, FALSE);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/*****************************************************************************
******************************* S I G N A L S *******************************
*****************************************************************************/
static void
dia_canvas_rectangle_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rectangle)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(item);
if (rect->fill) {
dia_renderer_set_color(renderer, &rect->fill_color);
dia_renderer_draw_rectangle(renderer, TRUE,
&rect->topleft, &rect->bottomright);
}
if (rect->line) {
dia_renderer_set_color(renderer, &rect->line_color);
dia_renderer_set_line_width(renderer, rect->line_width);
dia_renderer_draw_rectangle(renderer, FALSE,
&rect->topleft, &rect->bottomright);
}
}
static void
dia_canvas_rectangle_real_update (DiaCanvasItem *item)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(item);
/* the rect may have been moved, so dirty its former location */
dia_canvas_dirty_region(item->canvas, &item->bounds);
item->bounds.left = rect->topleft.x;
item->bounds.top = rect->topleft.y;
item->bounds.right = rect->bottomright.x;
item->bounds.bottom = rect->bottomright.y;
if (rect->line) {
gdouble half_width = rect->line_width / 2;
item->bounds.left -= half_width;
item->bounds.top -= half_width;
item->bounds.right += half_width;
item->bounds.bottom += half_width;
}
/* dirty the new location to redraw ... */
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
static gdouble
dia_canvas_rectangle_real_distance (DiaCanvasItem *item,
gdouble x,gdouble y)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(item);
double dx = 0.0, dy = 0.0;
/* not the exact distance, but close enough for our checks */
if (x < item->bounds.left)
dx = item->bounds.left - x;
else if (x > item->bounds.right)
dx = x - item->bounds.right;
if (y < item->bounds.top)
dy = item->bounds.top - y;
else if (y > item->bounds.bottom)
dy = y - item->bounds.bottom;
/* if we are inside the bounding box, and this isn't a filled rect,
* we need to see how far the point is from the edge */
if (dx == 0 && dy == 0 && !rect->fill) {
gdouble hwidth = rect->line ? rect->line_width/2 : 0.0;
gdouble left = rect->topleft.x + hwidth;
gdouble top = rect->topleft.y + hwidth;
gdouble right = rect->bottomright.x - hwidth;
gdouble bottom = rect->bottomright.x - hwidth;
dx = MIN(0, x - left);
dx = MIN(x, right - x);
dy = MIN(0, y - top);
dy = MIN(y, bottom - y);
}
return dx*dx + dy*dy;
}
static void
dia_canvas_rectangle_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasRectangle *rect = DIA_CANVAS_RECTANGLE(item);
rect->topleft.x += dx;
rect->topleft.y += dy;
rect->bottomright.x += dx;
rect->bottomright.y += dy;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(rect));
}
dia-newcanvas-0.6.10/src/dia-canvas-rectangle.h 0100644 0001750 0001750 00000003751 07537446061 021617 0 ustar xordoquy xordoquy /* dia-canvas-rectangle.h
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_RECTANGLE_H__
#define __DIA_CANVAS_RECTANGLE_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_RECTANGLE (dia_canvas_rectangle_get_type ())
#define DIA_CANVAS_RECTANGLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_RECTANGLE, DiaCanvasRectangle))
#define DIA_CANVAS_RECTANGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_RECTANGLE, DiaCanvasRectangleClass))
#define DIA_IS_CANVAS_RECTANGLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_RECTANGLE))
#define DIA_IS_CANVAS_RECTANGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_RECTANGLE))
#define DIA_CANVAS_RECTANGLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_RECTANGLE, DiaCanvasRectangleClass))
typedef struct _DiaCanvasRectangle DiaCanvasRectangle;
typedef struct _DiaCanvasRectangleClass DiaCanvasRectangleClass;
struct _DiaCanvasRectangle
{
DiaCanvasItem item;
DiaPoint topleft, bottomright;
gdouble line_width;
GdkColor line_color, fill_color;
guint fill : 1;
guint line : 1;
};
struct _DiaCanvasRectangleClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_rectangle_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-text.c 0100644 0001750 0001750 00000021106 07537446061 020624 0 ustar xordoquy xordoquy /* dia-canvas-text.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-canvas-text.h"
#include "dia-canvas-group.h"
#include
#define _(s) (s)
#define sqr(x) ((x)*(x))
/* properties */
enum {
PROP_NONE,
PROP_X,
PROP_Y,
PROP_TEXT,
PROP_TEXT_COLOR,
PROP_TEXT_WIDTH,
PROP_LAST
};
static void dia_canvas_text_init (DiaCanvasText *text);
static void dia_canvas_text_class_init (DiaCanvasTextClass *klass);
static void dia_canvas_text_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dia_canvas_text_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void dia_canvas_text_real_render (DiaCanvasItem *item,
DiaRenderer *renderer,
DiaRectangle *rect);
static gdouble dia_canvas_text_real_distance (DiaCanvasItem *item,
gdouble x, gdouble y);
static void dia_canvas_text_real_update (DiaCanvasItem *item);
static void dia_canvas_text_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy);
static GObjectClass *parent_class = NULL;
GType
dia_canvas_text_get_type (void)
{
static GtkType canvas_text_type = 0;
if (!canvas_text_type)
{
static const GTypeInfo canvas_text_info =
{
sizeof (DiaCanvasTextClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_text_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasText),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_text_init,
};
canvas_text_type = g_type_register_static (DIA_TYPE_CANVAS_ITEM,
"DiaCanvasText",
&canvas_text_info,
0);
}
return canvas_text_type;
}
static void
dia_canvas_text_class_init (DiaCanvasTextClass *klass)
{
GObjectClass *object_class;
DiaCanvasItemClass *item_class;
object_class = G_OBJECT_CLASS(klass);
item_class = DIA_CANVAS_ITEM_CLASS(klass);
parent_class = g_type_class_ref(DIA_TYPE_CANVAS_ITEM);
object_class->set_property = dia_canvas_text_set_property;
object_class->get_property = dia_canvas_text_get_property;
item_class->render = dia_canvas_text_real_render;
item_class->update = dia_canvas_text_real_update;
item_class->distance = dia_canvas_text_real_distance;
item_class->move = dia_canvas_text_real_move;
g_object_class_install_property (object_class,
PROP_X,
g_param_spec_double ("x", _("Position"),
_("The position of the text"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_Y,
g_param_spec_double ("y", _("Position"),
_("The position of the text"),
-G_MAXDOUBLE,
G_MAXDOUBLE,
0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TEXT,
g_param_spec_string ("text", _("The text"),
_("The text"),
"",
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TEXT_COLOR,
g_param_spec_boxed ("text_color", _("Text color"),
_("The text color of the text"),
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TEXT_WIDTH,
g_param_spec_double ("text_width", _("Text width"),
_("The thickness of text"),
0, G_MAXDOUBLE, 0,
G_PARAM_READWRITE));
}
static void
dia_canvas_text_init (DiaCanvasText *text)
{
GdkColor red = { 0, 0xffff, 0, 0 };
text->text_color = red;
text->text_width = 1;
}
static void
dia_canvas_text_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
DiaCanvasText *text = DIA_CANVAS_TEXT(object);
gdouble val;
GdkColor *color;
switch (property_id)
{
case PROP_X:
val = g_value_get_double(value);
if (val != text->point.x) {
text->point.x = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(text));
}
break;
case PROP_Y:
val = g_value_get_double(value);
if (val != text->point.y) {
text->point.y = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(text));
}
break;
case PROP_TEXT:
if( text->text != NULL ) {
g_free(text->text);
}
text->text = strdup(g_value_get_string(value));
dia_canvas_item_request_update(DIA_CANVAS_ITEM(text));
break;
case PROP_TEXT_COLOR:
color = g_value_get_boxed(value);
text->text_color = *color;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(text));
break;
case PROP_TEXT_WIDTH:
val = g_value_get_double(value);
text->text_width = val;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(text));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_text_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
DiaCanvasText *text = DIA_CANVAS_TEXT(object);
switch (property_id)
{
case PROP_X:
g_value_set_double(value, text->point.x);
break;
case PROP_Y:
g_value_set_double(value, text->point.y);
break;
case PROP_TEXT:
g_value_set_string(value, text->text);
break;
case PROP_TEXT_COLOR:
g_value_set_boxed(value, &text->text_color);
break;
case PROP_TEXT_WIDTH:
g_value_set_double(value, text->text_width);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dia_canvas_text_real_render (DiaCanvasItem *item, DiaRenderer *renderer,
DiaRectangle *rect)
{
DiaPoint point;
DiaCanvasText *text = DIA_CANVAS_TEXT(item);
dia_renderer_get_text_size(renderer, &point, text->text);
item->bounds.left = text->point.x;
item->bounds.top = text->point.y;
item->bounds.right = text->point.x + point.x;
item->bounds.bottom = text->point.y + point.y;
dia_renderer_set_color(renderer, &text->text_color);
dia_renderer_set_line_width(renderer, text->text_width);
dia_renderer_draw_text(renderer, &text->point, text->text);
}
static void
dia_canvas_text_real_update (DiaCanvasItem *item)
{
DiaPoint point;
DiaCanvasText *text = DIA_CANVAS_TEXT(item);
/* the text may have been moved, so dirty its former location */
dia_canvas_dirty_region(item->canvas, &item->bounds);
item->bounds.left = text->point.x;
item->bounds.top = text->point.y;
item->bounds.right = text->point.x+1;
item->bounds.bottom = text->point.y+1;
if( (item->canvas->focus_view != NULL) &&
(DIA_IS_RENDERER(item->canvas->focus_view)) ) {
dia_renderer_get_text_size(DIA_RENDERER(item->canvas->focus_view),
&point, text->text);
item->bounds.left = text->point.x;
item->bounds.top = text->point.y;
item->bounds.right = text->point.x + point.x;
item->bounds.bottom = text->point.y + point.y;
}
/* dirty the new location to redraw ... */
dia_canvas_dirty_region(item->canvas, &item->bounds);
}
static gdouble
dia_canvas_text_real_distance (DiaCanvasItem *item, gdouble x,gdouble y)
{
//DiaCanvasText *text = DIA_CANVAS_TEXT(item);
double dx = 0.0, dy = 0.0;
/* not the exact distance, but close enough for our checks */
if (x < item->bounds.left)
dx = item->bounds.left - x;
else if (x > item->bounds.right)
dx = x - item->bounds.right;
if (y < item->bounds.top)
dy = item->bounds.top - y;
else if (y > item->bounds.bottom)
dy = y - item->bounds.bottom;
return dx*dx + dy*dy;
}
static void
dia_canvas_text_real_move (DiaCanvasItem *item,
gdouble dx, gdouble dy)
{
DiaCanvasText *text = DIA_CANVAS_TEXT(item);
text->point.x += dx;
text->point.y += dy;
dia_canvas_item_request_update(DIA_CANVAS_ITEM(text));
}
dia-newcanvas-0.6.10/src/dia-canvas-text.h 0100644 0001750 0001750 00000003475 07537446061 020642 0 ustar xordoquy xordoquy /* dia-canvas-text.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_TEXT_H__
#define __DIA_CANVAS_TEXT_H__
#include
#include "dia-canvas-item.h"
#define DIA_TYPE_CANVAS_TEXT (dia_canvas_text_get_type ())
#define DIA_CANVAS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_TEXT, DiaCanvasText))
#define DIA_CANVAS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_TEXT, DiaCanvasTextClass))
#define DIA_IS_CANVAS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_TEXT))
#define DIA_IS_CANVAS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_TEXT))
#define DIA_CANVAS_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_TEXT, DiaCanvasTextClass))
typedef struct _DiaCanvasText DiaCanvasText;
typedef struct _DiaCanvasTextClass DiaCanvasTextClass;
struct _DiaCanvasText
{
DiaCanvasItem item;
DiaPoint point;
guchar *text;
gdouble text_width;
GdkColor text_color;
};
struct _DiaCanvasTextClass
{
DiaCanvasItemClass parent_class;
};
GType dia_canvas_text_get_type (void);
#endif
dia-newcanvas-0.6.10/src/dia-canvas-view-aa.c 0100644 0001750 0001750 00000003717 07537446061 021201 0 ustar xordoquy xordoquy /* dia-canvas-view-aa.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include "dia-canvas-view-aa.h"
static void dia_canvas_view_aa_init (DiaCanvasViewAA *canvas_view_aa);
static void dia_canvas_view_aa_class_init (DiaCanvasViewAAClass *klass);
static DiaCanvasViewClass *parent_class = NULL;
GtkType
dia_canvas_view_aa_get_type (void)
{
static GtkType canvas_view_aa_type = 0;
if (!canvas_view_aa_type)
{
static const GtkTypeInfo canvas_view_aa_info =
{
"DiaCanvasViewAA",
sizeof (DiaCanvasViewAA),
sizeof (DiaCanvasViewAAClass),
(GtkClassInitFunc) dia_canvas_view_aa_class_init,
(GtkObjectInitFunc) dia_canvas_view_aa_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
canvas_view_aa_type = gtk_type_unique (dia_canvas_view_get_type (), &canvas_view_aa_info);
}
return canvas_view_aa_type;
}
static void
dia_canvas_view_aa_class_init (DiaCanvasViewAAClass *klass)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass*) klass;
parent_class = gtk_type_class (dia_canvas_view_get_type ());
}
static void
dia_canvas_view_aa_init (DiaCanvasViewAA *canvas_view_aa)
{
}
dia-newcanvas-0.6.10/src/dia-canvas-view-aa.h 0100644 0001750 0001750 00000003660 07537446061 021203 0 ustar xordoquy xordoquy /* dia-canvas-view-aa.h
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_VIEW_AA_H__
#define __DIA_CANVAS_VIEW_AA_H__
#include
#include "dia-canvas-view.h"
#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */
#define GTK_TYPE_DIA_CANVAS_VIEW_AA (dia_canvas_view_aa_get_type ())
#define DIA_CANVAS_VIEW_AA(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_DIA_CANVAS_VIEW_AA, DiaCanvasViewAA))
#define DIA_CANVAS_VIEW_AA_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_DIA_CANVAS_VIEW_AA, DiaCanvasViewAAClass))
#define DIA_IS_CANVAS_VIEW_AA(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_DIA_CANVAS_VIEW_AA))
#define DIA_IS_CANVAS_VIEW_AA_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), GTK_TYPE_DIA_CANVAS_VIEW_AA))
typedef struct _DiaCanvasViewAA DiaCanvasViewAA;
typedef struct _DiaCanvasViewAAClass DiaCanvasViewAAClass;
struct _DiaCanvasViewAA
{
DiaCanvasView parent;
/* Put your own, widget-specific fields here */
};
struct _DiaCanvasViewAAClass
{
DiaCanvasViewClass parent_class;
};
GtkType dia_canvas_view_aa_get_type (void);
GtkWidget *dia_canvas_view_aa_new (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_CANVAS_VIEW_AA_H__ */
dia-newcanvas-0.6.10/src/dia-canvas-view-gdk.c 0100644 0001750 0001750 00000043510 07537446061 021360 0 ustar xordoquy xordoquy /* dia-canvas-view-gdk.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include
#include
#include "dia-canvas-view-gdk.h"
static void dia_canvas_view_gdk_init (DiaCanvasViewGdk *canvas_view);
static void dia_canvas_view_gdk_class_init (DiaCanvasViewGdkClass *klass);
static void dia_canvas_view_gdk_renderer_init (DiaRendererClass *vtable);
static void dia_canvas_view_gdk_destroy (GtkObject *object);
static void dia_canvas_view_gdk_realize (GtkWidget *widget);
static void dia_canvas_view_gdk_unrealize (GtkWidget *widget);
static void dia_canvas_view_gdk_render_rect (DiaCanvasView *view,
GdkRectangle *grect,
DiaRectangle *crect);
static void dia_canvas_view_gdk_set_zoom (DiaCanvasView *view,
gdouble zoom);
static DiaCanvasViewClass *parent_class = NULL;
#define TRANS_X(x) (DIA_CANVAS_VIEW(canvas_view)->canvas->extents.left + (x) * DIA_CANVAS_VIEW(canvas_view)->zoom_factor)
#define TRANS_Y(y) (DIA_CANVAS_VIEW(canvas_view)->canvas->extents.top + (y) * DIA_CANVAS_VIEW(canvas_view)->zoom_factor)
#define TRANS_LEN(l) ((l) * DIA_CANVAS_VIEW(canvas_view)->zoom_factor)
GtkType
dia_canvas_view_gdk_get_type (void)
{
static GtkType canvas_view_gdk_type = 0;
if (!canvas_view_gdk_type)
{
static const GTypeInfo canvas_view_gdk_info =
{
sizeof (DiaCanvasViewGdkClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_view_gdk_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasViewGdk),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_view_gdk_init,
};
static const GInterfaceInfo renderer_info =
{
(GInterfaceInitFunc) dia_canvas_view_gdk_renderer_init,
(GInterfaceFinalizeFunc) NULL,
NULL,
};
canvas_view_gdk_type = g_type_register_static (DIA_TYPE_CANVAS_VIEW,
"DiaCanvasViewGdk",
&canvas_view_gdk_info, 0);
g_type_add_interface_static (canvas_view_gdk_type,
DIA_TYPE_RENDERER,
&renderer_info);
}
return canvas_view_gdk_type;
}
static void
dia_canvas_view_gdk_class_init (DiaCanvasViewGdkClass *klass)
{
GObjectClass *object_class;
GtkObjectClass *gtkobject_class;
GtkWidgetClass *widget_class;
DiaCanvasViewClass *view_class;
object_class = G_OBJECT_CLASS(klass);
gtkobject_class = GTK_OBJECT_CLASS(klass);
widget_class = GTK_WIDGET_CLASS(klass);
view_class = DIA_CANVAS_VIEW_CLASS(klass);
parent_class = gtk_type_class (DIA_TYPE_CANVAS_VIEW);
gtkobject_class->destroy = dia_canvas_view_gdk_destroy;
widget_class->realize = dia_canvas_view_gdk_realize;
widget_class->unrealize = dia_canvas_view_gdk_unrealize;
view_class->render_rect = dia_canvas_view_gdk_render_rect;
view_class->set_zoom = dia_canvas_view_gdk_set_zoom;
}
static void
dia_canvas_view_gdk_init (DiaCanvasViewGdk *canvas_view)
{
canvas_view->gc = NULL;
canvas_view->dashes = NULL;
}
/**
* dia_canvas_view_gdk_new:
* @canvas: a #DiaCanvas.
*
* Create a #DiaCanvasViewGdk linked to @canvas.
*
* Return value: a GtkWidget.
**/
GtkWidget *
dia_canvas_view_gdk_new(DiaCanvas *canvas)
{
DiaCanvasViewGdk *view;
g_return_val_if_fail(canvas != NULL, NULL);
g_return_val_if_fail(DIA_IS_CANVAS(canvas), NULL);
view = g_object_new(DIA_TYPE_CANVAS_VIEW_GDK, NULL);
dia_canvas_view_set_canvas(DIA_CANVAS_VIEW(view), canvas);
return GTK_WIDGET(view);
}
static void
dia_canvas_view_gdk_destroy (GtkObject *object)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(object);
if (canvas_view->gc) {
g_object_unref(G_OBJECT(canvas_view->gc));
canvas_view->gc = NULL;
}
if (canvas_view->dashes) {
g_free(canvas_view->dashes);
canvas_view->dashes = NULL;
}
if (GTK_OBJECT_CLASS(parent_class)->destroy)
(* GTK_OBJECT_CLASS(parent_class)->destroy) (object);
}
static void
dia_canvas_view_gdk_realize (GtkWidget *widget)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(widget);
GdkWindowAttr attributes;
gint attributes_mask;
GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual(widget);
attributes.colormap = gtk_widget_get_colormap(widget);
attributes.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (gtk_widget_get_parent_window(widget),
&attributes, attributes_mask);
gdk_window_set_user_data(widget->window, widget);
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
/* now that it is realized, we can create our GC */
canvas_view->gc = gdk_gc_new(widget->window);
canvas_view->fill_rule = GDK_SOLID;
canvas_view->join_style = GDK_JOIN_MITER;
canvas_view->cap_style = GDK_CAP_BUTT;
canvas_view->line_width = 0;
canvas_view->line_style = GDK_LINE_SOLID;
if (canvas_view->dashes) {
g_free(canvas_view->dashes);
canvas_view->dashes = NULL;
}
canvas_view->color.red = 0;
canvas_view->color.green = 0;
canvas_view->color.blue = 0;
gdk_colormap_alloc_color (gtk_widget_get_colormap(widget),
&canvas_view->color, FALSE, TRUE);
gdk_gc_set_foreground (canvas_view->gc, &canvas_view->color);
}
static void
dia_canvas_view_gdk_unrealize (GtkWidget *widget)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(widget);
if (canvas_view->gc) {
g_object_unref(G_OBJECT(canvas_view->gc));
canvas_view->gc = NULL;
}
if (canvas_view->dashes) {
g_free(canvas_view->dashes);
canvas_view->dashes = NULL;
}
if (GTK_WIDGET_CLASS(parent_class)->unrealize)
(* GTK_WIDGET_CLASS(parent_class)->unrealize) (widget);
}
static void
dia_canvas_view_gdk_render_rect(DiaCanvasView *view, GdkRectangle *grect,
DiaRectangle *crect)
{
dia_canvas_render (view->canvas, DIA_RENDERER(view), crect);
}
static void
dia_canvas_view_gdk_set_zoom (DiaCanvasView *view, gdouble zoom)
{
DiaCanvasViewGdk *cvg = DIA_CANVAS_VIEW_GDK(view);
if (DIA_CANVAS_VIEW_CLASS(parent_class)->set_zoom)
(* DIA_CANVAS_VIEW_CLASS(parent_class)->set_zoom) (view, zoom);
if (cvg->gc) {
/* reset the line style with new zoom factor */
gdk_gc_set_line_attributes(cvg->gc,
cvg->line_width * view->zoom_factor,
cvg->line_style, cvg->cap_style, cvg->join_style);
if (cvg->dashes) {
gint8 *dash_list;
gint i;
/* reset dashes with new size */
dash_list = g_new(gint8, cvg->ndashes);
for (i = 0; i < cvg->ndashes; i++) {
int length = (int)floor(cvg->dashes[i] * view->zoom_factor + 0.5);
length = MAX(length, 0);
dash_list[i] = MIN(length, 255);
}
gdk_gc_set_dashes(cvg->gc, 0, dash_list, cvg->ndashes);
g_free(dash_list);
}
}
}
/* -------- the renderer implementation -------- */
static void
set_fill_rule (DiaRenderer *renderer, GdkFillRule rule)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
if (rule != canvas_view->fill_rule) {
canvas_view->fill_rule = rule;
gdk_gc_set_fill(canvas_view->gc, canvas_view->fill_rule);
}
}
static void
set_join_style (DiaRenderer *renderer, GdkJoinStyle style)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
if (style != canvas_view->join_style) {
canvas_view->join_style = style;
gdk_gc_set_line_attributes(canvas_view->gc,
canvas_view->line_width * DIA_CANVAS_VIEW(canvas_view)->zoom_factor,
canvas_view->line_style, canvas_view->cap_style,
canvas_view->join_style);
}
}
static void
set_cap_style (DiaRenderer *renderer, GdkCapStyle style)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
if (style != canvas_view->cap_style) {
canvas_view->cap_style = style;
gdk_gc_set_line_attributes(canvas_view->gc,
canvas_view->line_width * DIA_CANVAS_VIEW(canvas_view)->zoom_factor,
canvas_view->line_style, canvas_view->cap_style,
canvas_view->join_style);
}
}
static void
set_line_width (DiaRenderer *renderer, gdouble width)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
if (width != canvas_view->line_width) {
canvas_view->line_width = width;
gdk_gc_set_line_attributes(canvas_view->gc,
canvas_view->line_width * DIA_CANVAS_VIEW(canvas_view)->zoom_factor,
canvas_view->line_style, canvas_view->cap_style,
canvas_view->join_style);
}
}
static void
set_line_style (DiaRenderer *renderer, GdkLineStyle style)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
if (style != canvas_view->join_style) {
canvas_view->line_style = style;
gdk_gc_set_line_attributes(canvas_view->gc,
canvas_view->line_width * DIA_CANVAS_VIEW(canvas_view)->zoom_factor,
canvas_view->line_style, canvas_view->cap_style,
canvas_view->join_style);
}
}
static void
set_dash_style (DiaRenderer *renderer, gdouble *dash_len, gint nlen)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
gint8 *dash_list;
int i;
g_return_if_fail(canvas_view->gc != NULL);
if (canvas_view->dashes != NULL)
g_free(canvas_view->dashes);
canvas_view->dashes = g_memdup(dash_len, sizeof(gdouble) * nlen);
canvas_view->ndashes = nlen;
dash_list = g_new(gint8, nlen);
for (i = 0; i < nlen; i++) {
int length = (int)floor(dash_len[i] *
DIA_CANVAS_VIEW(renderer)->zoom_factor + 0.5);
length = MAX(length, 0);
dash_list[i] = MIN(length, 255);
}
gdk_gc_set_dashes(canvas_view->gc, 0, dash_list, nlen);
g_free(dash_list);
}
static void
set_color (DiaRenderer *renderer, GdkColor *color)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
if (color->red != canvas_view->color.red ||
color->green != canvas_view->color.green ||
color->blue != canvas_view->color.blue) {
canvas_view->color = *color;
gdk_colormap_alloc_color (gtk_widget_get_colormap(GTK_WIDGET(canvas_view)),
&canvas_view->color, FALSE, TRUE);
gdk_gc_set_foreground(canvas_view->gc, &canvas_view->color);
}
}
static void
set_font (DiaRenderer *renderer, const gchar *font_desc, gdouble size)
{
}
static void
draw_point (DiaRenderer *renderer, DiaPoint *point)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
gdk_draw_point (GTK_WIDGET(canvas_view)->window, canvas_view->gc,
TRANS_X(point->x), TRANS_Y(point->y));
}
static void
draw_line (DiaRenderer *renderer, DiaPoint *start, DiaPoint *end)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
gdk_draw_line (GTK_WIDGET(canvas_view)->window, canvas_view->gc,
TRANS_X(start->x), TRANS_Y(start->y),
TRANS_X(end->x), TRANS_Y(end->y));
}
static void
draw_rectangle (DiaRenderer *renderer, gboolean filled,
DiaPoint *ul_corner, DiaPoint *lr_corner)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
gint top, bottom, left, right;
g_return_if_fail(canvas_view->gc != NULL);
left = TRANS_X(ul_corner->x);
top = TRANS_Y(ul_corner->y);
right = TRANS_X(lr_corner->x);
bottom = TRANS_Y(lr_corner->y);
if (left > right || top > bottom)
return;
gdk_draw_rectangle (GTK_WIDGET(canvas_view)->window,
canvas_view->gc, filled,
left, top, (right - left), (bottom - top));
}
static void
draw_polyline (DiaRenderer *renderer, DiaPoint *points, gint npoints)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
GdkPoint *gdk_points;
gint i;
g_return_if_fail(canvas_view->gc != NULL);
gdk_points = g_new(GdkPoint, npoints);
for (i = 0; i < npoints; i++) {
gdk_points[i].x = TRANS_X(points[i].x);
gdk_points[i].y = TRANS_X(points[i].y);
}
gdk_draw_lines (GTK_WIDGET(canvas_view)->window, canvas_view->gc,
gdk_points, npoints);
g_free(gdk_points);
}
static void
draw_polygon (DiaRenderer *renderer, gboolean filled, GList/*DiaPoint*/ *points)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
GdkPoint *gdk_points;
gint i, npoints;
g_return_if_fail(canvas_view->gc != NULL);
npoints = g_list_length(points);
if( npoints == 0 )
return;
gdk_points = g_new0(GdkPoint, npoints);
for (i = 0; i < npoints; i++) {
DiaPoint *point;
point = g_list_nth_data(points,i);
gdk_points[i].x = TRANS_X(point->x);
gdk_points[i].y = TRANS_X(point->y);
}
gdk_draw_polygon (GTK_WIDGET(canvas_view)->window, canvas_view->gc,
filled, gdk_points, npoints);
g_free(gdk_points);
}
static void
draw_arc (DiaRenderer *renderer, gboolean filled, DiaPoint *centre,
gdouble width, gdouble height, gdouble angle1, gdouble angle2)
{
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
gint top, bottom, left, right;
gdouble dangle;
g_return_if_fail(canvas_view->gc != NULL);
left = TRANS_X(centre->x - width/2);
top = TRANS_Y(centre->y - height/2);
right = TRANS_X(centre->x + width/2);
bottom = TRANS_Y(centre->y + height/2);
if (left > right || top > bottom)
return;
dangle = angle2 - angle1;
if (dangle < 0)
dangle += 360.0;
gdk_draw_arc (GTK_WIDGET(canvas_view)->window, canvas_view->gc,
filled, left, top, (right - left), (bottom - top),
(int) (angle1 * 64), (int) (dangle * 64));
}
static void
draw_ellipse (DiaRenderer *renderer, gboolean filled,
DiaPoint *centre, gdouble width, gdouble height)
{
draw_arc (renderer, filled, centre, width, height, 0.0, 360.0);
}
static void
draw_bezier (DiaRenderer *renderer, gboolean filled,
DiaBezierPath *points, gint npoints)
{
}
static void
draw_pixbuf (DiaRenderer *renderer, DiaPoint *pos, gdouble width,
gdouble height, gdouble angle, GdkPixbuf *src)
{
}
static void
draw_text (DiaRenderer *renderer, DiaPoint *point, const gchar *text)
{
gint fontsize;
PangoContext *pango_context;
PangoLayout *pango_layout;
PangoFontDescription *pango_font_desc;
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
g_return_if_fail(canvas_view->gc != NULL);
pango_context = gtk_widget_get_pango_context (GTK_WIDGET(renderer));
pango_font_desc = pango_font_description_copy(pango_context_get_font_description(pango_context));
fontsize = pango_font_description_get_size(pango_font_desc);
pango_font_description_set_size(pango_font_desc,rint(fontsize*DIA_CANVAS_VIEW(canvas_view)->zoom_factor));
pango_layout = pango_layout_new(pango_context);
pango_layout_set_font_description(pango_layout,pango_font_desc);
pango_layout_set_text(pango_layout,text,strlen(text));
gdk_draw_layout(GTK_WIDGET(renderer)->window,
canvas_view->gc,
TRANS_X(point->x), TRANS_X(point->y),
pango_layout);
g_object_unref(pango_layout);
}
static void
get_text_size (DiaRenderer *renderer, DiaPoint *point, const gchar *text)
{
gint fontsize;
PangoContext *pango_context;
PangoLayout *pango_layout;
PangoFontDescription *pango_font_desc;
PangoRectangle ink, logical;
DiaCanvasViewGdk *canvas_view = DIA_CANVAS_VIEW_GDK(renderer);
pango_context = gtk_widget_get_pango_context (GTK_WIDGET(renderer));
pango_font_desc = pango_font_description_copy(pango_context_get_font_description(pango_context));
fontsize = pango_font_description_get_size(pango_font_desc);
pango_font_description_set_size(pango_font_desc,rint(fontsize*DIA_CANVAS_VIEW(canvas_view)->zoom_factor));
pango_layout = pango_layout_new(pango_context);
pango_layout_set_font_description(pango_layout,pango_font_desc);
pango_layout_set_text(pango_layout,text,strlen(text));
pango_layout_get_pixel_extents(pango_layout,&ink,&logical);
/*
point->x = (ink.width - ink.x)/DIA_CANVAS_VIEW(canvas_view)->zoom_factor;
point->y = (ink.height - ink.y)/DIA_CANVAS_VIEW(canvas_view)->zoom_factor;
*/
point->x = (logical.width - logical.x)/DIA_CANVAS_VIEW(canvas_view)->zoom_factor;
point->y = (logical.height - logical.y)/DIA_CANVAS_VIEW(canvas_view)->zoom_factor;
g_object_unref(pango_layout);
}
static void
dia_canvas_view_gdk_renderer_init (DiaRendererClass *vtable)
{
vtable->set_fill_rule = set_fill_rule;
vtable->set_join_style = set_join_style;
vtable->set_cap_style = set_cap_style;
vtable->set_line_width = set_line_width;
vtable->set_line_style = set_line_style;
vtable->set_dash_style = set_dash_style;
vtable->set_color = set_color;
vtable->set_font = set_font;
vtable->draw_point = draw_point;
vtable->draw_line = draw_line;
vtable->draw_rectangle = draw_rectangle;
vtable->draw_polyline = draw_polyline;
vtable->draw_polygon = draw_polygon;
vtable->draw_ellipse = draw_ellipse;
vtable->draw_arc = draw_arc;
vtable->draw_bezier = draw_bezier;
vtable->draw_pixbuf = draw_pixbuf;
vtable->draw_text = draw_text;
vtable->get_text_size = get_text_size;
}
dia-newcanvas-0.6.10/src/dia-canvas-view-gdk.h 0100644 0001750 0001750 00000004537 07537446061 021373 0 ustar xordoquy xordoquy /* dia-canvas-view-gdk.h
* Copyright (C) 2000 James Henstridge.
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_VIEW_GDK_H__
#define __DIA_CANVAS_VIEW_GDK_H__
#include
#include "dia-canvas-view.h"
#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */
#define DIA_TYPE_CANVAS_VIEW_GDK (dia_canvas_view_gdk_get_type ())
#define DIA_CANVAS_VIEW_GDK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_VIEW_GDK, DiaCanvasViewGdk))
#define DIA_CANVAS_VIEW_GDK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_VIEW_GDK, DiaCanvasViewGdkClass))
#define DIA_IS_CANVAS_VIEW_GDK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_VIEW_GDK))
#define DIA_IS_CANVAS_VIEW_GDK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_VIEW_GDK))
#define DIA_CANVAS_VIEW_GDK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_VIEW_GDK, DiaCanvasViewGdkClass))
typedef struct _DiaCanvasViewGdk DiaCanvasViewGdk;
typedef struct _DiaCanvasViewGdkClass DiaCanvasViewGdkClass;
struct _DiaCanvasViewGdk
{
DiaCanvasView parent;
GdkGC *gc;
/* saved values for the GC -- to convert sets to noops when no
* change is made */
GdkFillRule fill_rule;
GdkJoinStyle join_style;
GdkCapStyle cap_style;
int line_width;
GdkLineStyle line_style;
gdouble *dashes;
int ndashes;
GdkColor color;
/* handle font stuff as well */
};
struct _DiaCanvasViewGdkClass
{
DiaCanvasViewClass parent_class;
};
GType dia_canvas_view_gdk_get_type (void);
GtkWidget *dia_canvas_view_gdk_new (DiaCanvas *canvas);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_CANVAS_VIEW_GDK_H__ */
dia-newcanvas-0.6.10/src/dia-canvas-view.c 0100644 0001750 0001750 00000051310 07537446061 020612 0 ustar xordoquy xordoquy /* dia-canvas-view.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include "dia-canvas-view.h"
#include "dia-canvas-item.h"
#include "dia-marshal.h"
#define REDRAW_PRIORITY (G_PRIORITY_HIGH_IDLE + 40)
#define PICK_PRIORITY (G_PRIORITY_HIGH_IDLE + 35)
#define VIEWPORT_LEFT(v) ((v)->canvas->extents.left + \
(v)->layout.hadjustment->value / (v)->zoom_factor)
#define VIEWPORT_TOP(v) ((v)->canvas->extents.top + \
(v)->layout.vadjustment->value / (v)->zoom_factor)
#define VIEWPORT_WIDTH(v) ((v)->zoom_factor*GTK_WIDGET(v)->allocation.width)
#define VIEWPORT_HEIGHT(v) ((v)->zoom_factor*GTK_WIDGET(v)->allocation.height)
enum {
RENDER_RECT,
SET_ZOOM,
LAST_SIGNAL
};
static void dia_canvas_view_init (DiaCanvasView *canvas_view);
static void dia_canvas_view_class_init (DiaCanvasViewClass *klass);
static void dia_canvas_view_destroy (GtkObject *object);
static void dia_canvas_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void dia_canvas_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gint dia_canvas_view_expose (GtkWidget *widget,
GdkEventExpose *event);
static gint dia_canvas_view_focus_in (GtkWidget *widget,
GdkEventFocus *event);
static gint dia_canvas_view_focus_out (GtkWidget *widget,
GdkEventFocus *event);
static gint dia_canvas_view_key_press (GtkWidget *widget,
GdkEventKey *event);
static gint dia_canvas_view_key_release (GtkWidget *widget,
GdkEventKey *event);
static gint dia_canvas_view_button_press (GtkWidget *widget,
GdkEventButton *event);
static gint dia_canvas_view_button_release (GtkWidget *widget,
GdkEventButton *event);
static gint dia_canvas_view_motion_notify (GtkWidget *widget,
GdkEventMotion *event);
static gint dia_canvas_view_enter_notify (GtkWidget *widget,
GdkEventCrossing *event);
static gint dia_canvas_view_leave_notify (GtkWidget *widget,
GdkEventCrossing *event);
static void dia_canvas_view_real_set_zoom (DiaCanvasView *canvas_view,
gdouble zoom);
static GtkWidgetClass *parent_class = NULL;
static guint canvas_view_signals[LAST_SIGNAL] = { 0 };
GtkType
dia_canvas_view_get_type (void)
{
static GtkType canvas_view_type = 0;
if (!canvas_view_type)
{
static const GTypeInfo canvas_view_info =
{
sizeof (DiaCanvasViewClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_view_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvasView),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_view_init,
};
canvas_view_type = g_type_register_static (GTK_TYPE_WIDGET,
"DiaCanvasView",
&canvas_view_info, 0);
}
return canvas_view_type;
}
static void
dia_canvas_view_class_init (DiaCanvasViewClass *klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = GTK_OBJECT_CLASS(klass);
widget_class = GTK_WIDGET_CLASS(klass);
parent_class = g_type_class_ref (GTK_TYPE_WIDGET);
canvas_view_signals[RENDER_RECT] =
g_signal_new ("render_rect",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (DiaCanvasViewClass, render_rect),NULL,NULL,
dia_marshal_VOID__POINTER_POINTER,
G_TYPE_NONE, 2,
G_TYPE_POINTER /* GdkRectangle */,
G_TYPE_POINTER /* DiaRectangle */);
canvas_view_signals[SET_ZOOM] =
g_signal_new ("set_zoom",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (DiaCanvasViewClass, set_zoom), NULL, NULL,
dia_marshal_VOID__DOUBLE,
G_TYPE_NONE, 1,
G_TYPE_DOUBLE);
klass->image_width = 512;
klass->image_height = 512;
object_class->destroy = dia_canvas_view_destroy;
widget_class->size_request = dia_canvas_view_size_request;
widget_class->size_allocate = dia_canvas_view_size_allocate;
widget_class->expose_event = dia_canvas_view_expose;
widget_class->focus_in_event = dia_canvas_view_focus_in;
widget_class->focus_out_event = dia_canvas_view_focus_out;
widget_class->key_press_event = dia_canvas_view_key_press;
widget_class->key_release_event = dia_canvas_view_key_release;
widget_class->button_press_event = dia_canvas_view_button_press;
widget_class->button_release_event = dia_canvas_view_button_release;
widget_class->motion_notify_event = dia_canvas_view_motion_notify;
widget_class->enter_notify_event = dia_canvas_view_enter_notify;
widget_class->leave_notify_event = dia_canvas_view_leave_notify;
klass->set_zoom = dia_canvas_view_real_set_zoom;
}
static void
dia_canvas_view_init (DiaCanvasView *canvas_view)
{
GTK_WIDGET_SET_FLAGS(canvas_view, GTK_CAN_FOCUS);
gtk_widget_add_events(GTK_WIDGET(canvas_view),
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_MASK |
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_FOCUS_CHANGE_MASK);
canvas_view->zoom_factor = 1.0;
}
#if 0
static void
scroll_to(DiaCanvasView *view, gdouble x, gdouble y)
{
gdouble view_left, view_top, view_width, view_height;
gdouble scroll_width, scroll_height;
gdouble right_limit, bottom_limit;
gboolean changed, changed_x, changed_y;
view_left = VIEWPORT_LEFT(view);
view_top = VIEWPORT_TOP(view);
view_width = VIEWPORT_WIDTH(view);
view_height = VIEWPORT_HEIGHT(view);
scroll_width = view->canvas->extents.right - view->canvas->extents.left;
scroll_height = view->canvas->extents.bottom - view->canvas->extents.top;
right_limit = view->canvas->extents.right - view_width;
bottom_limit = view->canvas->extents.bottom - view_height;
if (x > right_limit)
x = right_limit;
if (y > bottom_limit)
y = bottom_limit;
if (x < view->canvas->extents.left)
x = view->canvas->extents.left;
if (y < view->canvas->extents.top)
y = view->canvas->extents.top;
changed_x = view_left != x;
changed_y = view_top != y;
changed = changed_x || changed_y;
if (changed)
gtk_layout_freeze(GTK_LAYOUT(view));
if (view->layout.width != scroll_width * view->zoom_factor ||
view->layout.height != scroll_height * view->zoom_factor)
gtk_layout_set_size(GTK_LAYOUT(view),
scroll_width * view->zoom_factor,
scroll_height * view->zoom_factor);
if (changed_x) {
view->layout.hadjustment->value = x * view->zoom_factor;
gtk_adjustment_value_changed(view->layout.hadjustment);
}
if (changed_y) {
view->layout.vadjustment->value = y * view->zoom_factor;
gtk_adjustment_value_changed(view->layout.vadjustment);
}
if (changed)
gtk_layout_thaw(GTK_LAYOUT(view));
}
#endif
static gboolean
emit_event(DiaCanvasView *view, GdkEvent *event, DiaCanvasItem *item)
{
GdkEvent ev;
gdouble left = view->canvas->extents.left, top = view->canvas->extents.top;
gdouble zf = view->zoom_factor;
gboolean finished;
DiaCanvasItem *parent;
static guint event_signal_id = 0;
/* do something about handling grabs ... */
/* convert from view to canvas coordinates ... */
ev = *event;
switch(ev.type) {
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
ev.crossing.x = ev.crossing.x / zf + left;
ev.crossing.y = ev.crossing.y / zf + top;
break;
case GDK_MOTION_NOTIFY:
ev.motion.x = ev.motion.x / zf + left;
ev.motion.y = ev.motion.y / zf + top;
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
ev.button.x = ev.button.x / zf + left;
ev.button.y = ev.button.y / zf + top;
break;
default:
break;
}
/* event propagation ... */
finished = FALSE;
if (event_signal_id == 0)
event_signal_id = gtk_signal_lookup("event", DIA_TYPE_CANVAS_ITEM);
while (item && !finished) {
g_object_ref(G_OBJECT(item));
g_signal_emit(item, event_signal_id, 0, &ev, view, &finished);
if (item->parent)
parent = DIA_CANVAS_ITEM(item->parent);
else
parent = NULL;
g_object_unref(G_OBJECT(item));
item = parent;
}
return finished;
}
static void
dia_canvas_view_destroy(GtkObject *object)
{
DiaCanvasView *view;
g_return_if_fail(object != NULL);
g_return_if_fail(DIA_IS_CANVAS_VIEW(object));
view = DIA_CANVAS_VIEW(object);
/* disconnect the dirty_region handler */
if (view->canvas) {
g_signal_handlers_disconnect_matched(view->canvas, G_SIGNAL_MATCH_DATA,
0, 0, NULL, 0, view);
dia_canvas_remove_view(view->canvas, view);
g_object_unref(G_OBJECT(view->canvas));
}
view->canvas = NULL;
if (GTK_OBJECT_CLASS(parent_class)->destroy)
(* GTK_OBJECT_CLASS(parent_class)->destroy)(object);
}
static void
dia_canvas_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
DiaCanvasView *view;
view = DIA_CANVAS_VIEW(widget);
g_return_if_fail(view->canvas != NULL);
requisition->width = (view->canvas->extents.right -
view->canvas->extents.left) * view->zoom_factor;
requisition->height = (view->canvas->extents.bottom -
view->canvas->extents.top) * view->zoom_factor;
}
static void
dia_canvas_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
DiaCanvasView *view;
view = DIA_CANVAS_VIEW(widget);
g_return_if_fail(view->canvas != NULL);
/* do size allocate ... */
if (GTK_WIDGET_CLASS(parent_class)->size_allocate)
(* GTK_WIDGET_CLASS(parent_class)->size_allocate)(widget, allocation);
}
static gint
dia_canvas_view_expose(GtkWidget *widget, GdkEventExpose *event)
{
DiaCanvasView *view;
GdkRectangle grect;
DiaRectangle crect;
g_return_val_if_fail(widget != NULL, FALSE);
g_return_val_if_fail(DIA_IS_CANVAS_VIEW(widget), FALSE);
g_return_val_if_fail(event != NULL, FALSE);
view = DIA_CANVAS_VIEW(widget);
g_return_val_if_fail(view->canvas != NULL, FALSE);
if (!GTK_WIDGET_DRAWABLE (widget) || event->window != widget->window)
return FALSE;
/* change this to use event->region at some point */
grect = event->area;
crect.left = grect.x / view->zoom_factor + view->canvas->extents.left;
crect.right = crect.left + grect.width / view->zoom_factor;
crect.top = grect.y / view->zoom_factor + view->canvas->extents.top;
crect.bottom = crect.top + grect.height / view->zoom_factor;
g_signal_emit(view, canvas_view_signals[RENDER_RECT], 0, &grect, &crect);
return TRUE;
}
static gint
dia_canvas_view_focus_in (GtkWidget *widget, GdkEventFocus *event)
{
DiaCanvasView *canvas_view = DIA_CANVAS_VIEW(widget);
g_return_val_if_fail(canvas_view->canvas != NULL, FALSE);
g_return_val_if_fail(DIA_IS_CANVAS(canvas_view->canvas), FALSE);
/* update focus view */
//canvas_view->canvas->focus_view = canvas_view;
GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS);
if (canvas_view->event_item)
return emit_event(canvas_view, (GdkEvent *)event,
canvas_view->event_item);
else
return FALSE;
}
static gint
dia_canvas_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
{
DiaCanvasView *canvas_view = DIA_CANVAS_VIEW(widget);
g_return_val_if_fail(canvas_view->canvas != NULL, FALSE);
g_return_val_if_fail(DIA_IS_CANVAS(canvas_view->canvas), FALSE);
//canvas_view->canvas->focus_view = NULL;
GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_FOCUS);
if (canvas_view->event_item)
return emit_event(canvas_view, (GdkEvent *)event,
canvas_view->event_item);
else
return FALSE;
}
static gint
dia_canvas_view_key_press (GtkWidget *widget, GdkEventKey *event)
{
DiaCanvasView *canvas_view = DIA_CANVAS_VIEW(widget);
g_return_val_if_fail(canvas_view->canvas != NULL, FALSE);
g_return_val_if_fail(DIA_IS_CANVAS(canvas_view->canvas), FALSE);
if (canvas_view->event_item)
return emit_event(canvas_view, (GdkEvent *)event,
canvas_view->event_item);
else
return (* GTK_WIDGET_CLASS(parent_class)->key_press_event)(widget, event);
}
static gint
dia_canvas_view_key_release (GtkWidget *widget, GdkEventKey *event)
{
DiaCanvasView *canvas_view = DIA_CANVAS_VIEW(widget);
g_return_val_if_fail(canvas_view->canvas != NULL, FALSE);
g_return_val_if_fail(DIA_IS_CANVAS(canvas_view->canvas), FALSE);
if (canvas_view->event_item)
return emit_event(canvas_view, (GdkEvent *)event,
canvas_view->event_item);
else
return (* GTK_WIDGET_CLASS(parent_class)->key_release_event)(widget,event);
}
static gint
dia_canvas_view_button_press (GtkWidget *widget, GdkEventButton *event)
{
DiaCanvasView *view;
DiaCanvas *canvas;
DiaCanvasItem *point_item;
gdouble zf, x, y;
view = DIA_CANVAS_VIEW(widget);
canvas = view->canvas;
g_return_val_if_fail(view->canvas != NULL, FALSE);
g_return_val_if_fail(DIA_IS_CANVAS(view->canvas), FALSE);
canvas = view->canvas;
zf = view->zoom_factor;
x = event->x / zf + canvas->extents.left;
y = event->y / zf + canvas->extents.top;
if (!GTK_WIDGET_HAS_GRAB(view)) {
point_item = dia_canvas_get_item_at(view->canvas, x, y, 0);
if (!point_item)
point_item = canvas->root;
view->event_item = point_item;
}
return emit_event(view, (GdkEvent *)event, view->event_item);
}
static gint
dia_canvas_view_button_release (GtkWidget *widget, GdkEventButton *event)
{
DiaCanvasView *view;
DiaCanvas *canvas;
DiaCanvasItem *point_item;
gdouble zf, x, y;
view = DIA_CANVAS_VIEW(widget);
canvas = view->canvas;
g_return_val_if_fail(view->canvas != NULL, FALSE);
g_return_val_if_fail(DIA_IS_CANVAS(view->canvas), FALSE);
zf = view->zoom_factor;
x = event->x / zf + canvas->extents.left;
y = event->y / zf + canvas->extents.top;
if (!GTK_WIDGET_HAS_GRAB(view)) {
point_item = dia_canvas_get_item_at(view->canvas, x, y, 0);
if (!point_item)
point_item = canvas->root;
view->event_item = point_item;
}
return emit_event(view, (GdkEvent *)event, view->event_item);
}
static gint
dia_canvas_view_motion_notify (GtkWidget *widget, GdkEventMotion *event)
{
DiaCanvasView *view = DIA_CANVAS_VIEW(widget);
DiaCanvas *canvas = view->canvas;
DiaCanvasItem *point_item;
gdouble zf = view->zoom_factor;
gdouble x, y;
gint x2, y2;
GdkModifierType state;
if( event->is_hint ) {
gdk_window_get_pointer (event->window, &x2, &y2, &state);
x = x2 / zf + canvas->extents.left;
y = y2 / zf + canvas->extents.top;
} else {
x = event->x / zf + canvas->extents.left;
y = event->y / zf + canvas->extents.top;
}
/* find the item at the point */
point_item = dia_canvas_get_item_at(view->canvas, x, y, 0);
if (!point_item)
point_item = canvas->root;
if ( (view->event_item != point_item) &&
(!GTK_WIDGET_HAS_GRAB(view)) ) {
GdkEventCrossing ev = { 0 };
ev.type = GDK_LEAVE_NOTIFY;
ev.window = event->window;
ev.send_event = event->send_event;
ev.subwindow = NULL;
if( event->is_hint ) {
ev.x = x2;
ev.y = y2;
} else {
ev.x = event->x;
ev.y = event->y;
}
ev.mode = GDK_CROSSING_NORMAL;
ev.detail = GDK_NOTIFY_NONLINEAR;
ev.focus = FALSE;
ev.state = event->state;
ev.x_root = event->x_root;
ev.y_root = event->y_root;
if (view->event_item != NULL) {
/* create a leave_notify on the old current event */
emit_event(view, (GdkEvent *)&ev, view->event_item);
}
ev.type = GDK_ENTER_NOTIFY;
view->event_item = point_item;
emit_event(view, (GdkEvent *)&ev, view->event_item);
}
/* now emit the motion_notify on the picked item */
return emit_event(view, (GdkEvent *)event, view->event_item);
}
static gint
dia_canvas_view_enter_notify (GtkWidget *widget, GdkEventCrossing *event)
{
DiaCanvasView *view = DIA_CANVAS_VIEW(widget);
DiaCanvas *canvas = view->canvas;
DiaCanvasItem *point_item;
gdouble zf = view->zoom_factor;
gdouble x = event->x / zf + canvas->extents.left;
gdouble y = event->y / zf + canvas->extents.top;
view->canvas->focus_view = view;
gtk_widget_grab_focus(widget);
point_item = dia_canvas_get_item_at(view->canvas, x, y, 0);
if (!point_item)
point_item = canvas->root;
view->event_item = point_item;
return emit_event(view, (GdkEvent *)event, view->event_item);
}
static gint
dia_canvas_view_leave_notify (GtkWidget *widget, GdkEventCrossing *event)
{
DiaCanvasView *view = DIA_CANVAS_VIEW(widget);
gboolean ret = FALSE;
//view->canvas->focus_view = NULL;
if (view->event_item)
ret = emit_event(view, (GdkEvent *)event, view->event_item);
view->event_item = NULL;
return ret;
}
static void
dia_canvas_view_real_set_zoom(DiaCanvasView *view, gdouble zoom)
{
/* default handling of zooms. Extra handling may include updating GCs */
if( GTK_IS_VIEWPORT(GTK_WIDGET(view)->parent) ) {
GtkAdjustment *adjustment;
adjustment = gtk_viewport_get_hadjustment(GTK_VIEWPORT(GTK_WIDGET(view)->parent));
gtk_adjustment_set_value( adjustment, adjustment->value + (1+adjustment->page_size)*(zoom - view->zoom_factor)/2.0);
adjustment = gtk_viewport_get_vadjustment(GTK_VIEWPORT(GTK_WIDGET(view)->parent));
gtk_adjustment_set_value( adjustment, adjustment->value + (1+adjustment->page_size)*(zoom - view->zoom_factor)/2.0);
}
/* dirty whole area and queue a resize */
view->zoom_factor = zoom;
gtk_widget_queue_draw(GTK_WIDGET(view));
gtk_widget_queue_resize(GTK_WIDGET(view));
}
/**
* dia_canvas_view_set_zoom:
* @view: a #DiaCanvasView.
* @zoom: the zoom value.
*
* Sets the @zoom value to a @view.
**/
void
dia_canvas_view_set_zoom(DiaCanvasView *view, gdouble zoom)
{
g_return_if_fail(view != NULL);
g_return_if_fail(DIA_IS_CANVAS_VIEW(view));
g_return_if_fail(view->canvas != NULL);
g_return_if_fail(0.0 < zoom);
if (view->zoom_factor != zoom)
g_signal_emit(view, canvas_view_signals[SET_ZOOM], 0, zoom);
}
static void
dirty_region(DiaCanvas *canvas, DiaRectangle *rect, DiaCanvasView *view)
{
GdkRectangle grect;
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
g_return_if_fail(rect != NULL);
g_return_if_fail(view != NULL);
g_return_if_fail(DIA_IS_CANVAS_VIEW(view));
g_return_if_fail(canvas == view->canvas);
/* if we have no window, then don't redraw */
if (GTK_WIDGET(view)->window == NULL)
return;
grect.x = (rect->left - view->canvas->extents.left) * view->zoom_factor-1;
grect.y = (rect->top - view->canvas->extents.top) * view->zoom_factor-1;
grect.width = (rect->right - rect->left) * view->zoom_factor+2;
grect.height = (rect->bottom - rect->top) * view->zoom_factor+2;
gdk_window_invalidate_rect (GTK_WIDGET(view)->window, &grect, TRUE);
}
/**
* dia_canvas_view_set_canvas:
* @view: a #DiaCanvasView.
* @canvas: a #DiaCanvas.
*
* Sets the @canvas to a @view.
**/
void
dia_canvas_view_set_canvas(DiaCanvasView *view, DiaCanvas *canvas)
{
g_return_if_fail(view != NULL);
g_return_if_fail(DIA_IS_CANVAS_VIEW(view));
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
g_return_if_fail(view->canvas == NULL);
/* view holds a reference to the canvas */
g_object_ref(G_OBJECT(canvas));
view->canvas = canvas;
dia_canvas_add_view(canvas, view);
g_signal_connect(canvas, "dirty_region", G_CALLBACK(dirty_region), view);
/* resize and redraw */
gtk_widget_queue_resize(GTK_WIDGET(view));
gtk_widget_queue_draw(GTK_WIDGET(view));
}
void
dia_canvas_view_grab( DiaCanvasView *view, gboolean exclusive )
{
GdkCursor *fleur;
fleur = gdk_cursor_new (GDK_FLEUR);
if( exclusive == TRUE ) {
gdk_pointer_grab(GTK_WIDGET(view)->window,
TRUE, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK,
GTK_WIDGET(view)->window,
fleur,
GDK_CURRENT_TIME);
} else {
gdk_pointer_grab(GTK_WIDGET(view)->window,
FALSE, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK,
NULL,
fleur,
GDK_CURRENT_TIME);
}
GTK_WIDGET_SET_FLAGS(view,GTK_HAS_GRAB);
gdk_cursor_destroy (fleur);
}
void
dia_canvas_view_ungrab( DiaCanvasView *view )
{
gdk_pointer_ungrab(GDK_CURRENT_TIME);
GTK_WIDGET_UNSET_FLAGS(view,GTK_HAS_GRAB);
}
void
dia_canvas_view_real_to_canvas( DiaCanvasView *view, gdouble *x, gdouble *y )
{
*x = (*x + view->canvas->extents.left) / view->zoom_factor-1;
*y = (*y + view->canvas->extents.top) / view->zoom_factor-1;
}
dia-newcanvas-0.6.10/src/dia-canvas-view.h 0100644 0001750 0001750 00000006003 07537446061 020616 0 ustar xordoquy xordoquy /* dia-canvas-view.h
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_VIEW_H__
#define __DIA_CANVAS_VIEW_H__
#include
#include "dia-canvas.h"
#include "dia-renderer.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define DIA_TYPE_CANVAS_VIEW (dia_canvas_view_get_type ())
#define DIA_CANVAS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_VIEW, DiaCanvasView))
#define DIA_CANVAS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS_VIEW, DiaCanvasViewClass))
#define DIA_IS_CANVAS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS_VIEW))
#define DIA_IS_CANVAS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), DIA_TYPE_CANVAS_VIEW))
#define DIA_CANVAS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS_VIEW, DiaCanvasViewClass))
/* declaration in dia-canvas.h */
/* typedef struct _DiaCanvasView DiaCanvasView; */
typedef struct _DiaCanvasViewClass DiaCanvasViewClass;
struct _DiaCanvasView
{
GtkWidget widget; /* consider changing this to GtkFixed to do widget items */
DiaCanvas *canvas;
gdouble zoom_factor;
/* button/motion event related members */
DiaCanvasItem *event_item;
DiaCanvasItem *point_item;
GdkModifierType button_mask;
};
struct _DiaCanvasViewClass
{
GtkWidgetClass parent_class;
/* max size of update regions for this view type */
guint image_width, image_height;
/* Signals go here */
void (*render_rect) (DiaCanvasView *canvas_view, GdkRectangle *grect,
DiaRectangle *crect);
void (*set_zoom) (DiaCanvasView *canvas_view, gdouble zoom);
};
GType dia_canvas_view_get_type (void);
/* set the zoom factor for canvas (1.0 == 1 pixel/canvas unit) */
void dia_canvas_view_set_zoom(DiaCanvasView *view, gdouble zoom);
/* intended for canvas view subclasses. Users of the canvas shouldn't call
* this */
void dia_canvas_view_set_canvas(DiaCanvasView *view, DiaCanvas *canvas);
/* this grabs the current selection */
void dia_canvas_view_grab(DiaCanvasView *view, gboolean exclusive);
/* this ungrabs the current selection */
void dia_canvas_view_ungrab(DiaCanvasView *view);
void dia_canvas_view_real_to_canvas( DiaCanvasView *view, gdouble *x, gdouble *y );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_CANVAS_VIEW_H__ */
dia-newcanvas-0.6.10/src/dia-canvas.c 0100644 0001750 0001750 00000030455 07537446061 017651 0 ustar xordoquy xordoquy /* dia-canvas.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include
#include "dia-canvas.h"
#include "dia-canvas-item.h"
#include "dia-canvas-view.h"
#include "dia-marshal.h"
#include "dia-marshal.c"
#include "dia-canvas-grid.h"
/* higher than the pick or redraw idles of the canvas view */
#define UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE + 30)
enum {
RENDER,
DIRTY_REGION,
EXTENTS_CHANGED,
LAST_SIGNAL
};
static void dia_canvas_init (DiaCanvas *canvas);
static void dia_canvas_class_init (DiaCanvasClass *klass);
static void dia_canvas_finalize (GObject *object);
static void dia_canvas_real_render (DiaCanvas *canvas,
DiaRenderer *renderer,
DiaRectangle *rect);
static void dia_canvas_real_dirty_region (DiaCanvas *canvas,
DiaRectangle *rect);
static GObjectClass *parent_class = NULL;
static guint canvas_signals[LAST_SIGNAL] = { 0 };
GType
dia_canvas_get_type (void)
{
static GType canvas_type = 0;
if (!canvas_type)
{
static const GTypeInfo canvas_info =
{
sizeof (DiaCanvasClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) dia_canvas_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (DiaCanvas),
0, /* n_preallocs */
(GInstanceInitFunc) dia_canvas_init,
};
canvas_type = g_type_register_static (G_TYPE_OBJECT, "DiaCanvas",
&canvas_info, 0);
}
return canvas_type;
}
static void
dia_canvas_class_init (DiaCanvasClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS(klass);
parent_class = g_type_class_ref (G_TYPE_OBJECT);
canvas_signals[RENDER] =
g_signal_new ("render",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (DiaCanvasClass, render), NULL, NULL,
dia_marshal_VOID__OBJECT_POINTER,
G_TYPE_NONE, 2,
DIA_TYPE_RENDERER, G_TYPE_POINTER /* rectangle */);
canvas_signals[DIRTY_REGION] =
g_signal_new ("dirty_region",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (DiaCanvasClass, dirty_region), NULL, NULL,
gtk_marshal_NONE__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER /* rectangle */);
canvas_signals[EXTENTS_CHANGED] =
g_signal_new ("extents_changed",
G_OBJECT_CLASS_TYPE(klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(DiaCanvasClass, extents_changed), NULL,NULL,
gtk_marshal_NONE__NONE,
G_TYPE_NONE, 0);
object_class->finalize = dia_canvas_finalize;
klass->render = dia_canvas_real_render;
klass->dirty_region = dia_canvas_real_dirty_region;
}
static void
dia_canvas_init (DiaCanvas *canvas)
{
canvas->extents.left = 0.0;
canvas->extents.top = 0.0;
canvas->extents.right = 100.0;
canvas->extents.bottom = 100.0;
canvas->root = DIA_CANVAS_ITEM(g_object_new(DIA_TYPE_CANVAS_GRID, NULL));
canvas->root->canvas = canvas;
canvas->views = NULL;
canvas->selection = NULL;
}
/**
* dia_canvas_new:
*
* Creates a new #DiaCanvas.
*
* Return value: a #DiaCanvas.
**/
DiaCanvas *
dia_canvas_new(void)
{
DiaCanvas *canvas = DIA_CANVAS(g_object_new(DIA_TYPE_CANVAS, NULL));
return canvas;
}
static void
dia_canvas_remove_canvas(DiaCanvasItem *item,gpointer user_data)
{
item->canvas = NULL;
}
static void
dia_canvas_finalize(GObject *object)
{
DiaCanvas *canvas;
g_return_if_fail(object != NULL);
g_return_if_fail(DIA_IS_CANVAS(object));
canvas = DIA_CANVAS(object);
/* to prevent redrawing, set the canvas to null */
if (canvas->root) {
dia_canvas_group_foreach(DIA_CANVAS_GROUP(canvas->root),(GFunc)dia_canvas_remove_canvas,NULL);
g_object_unref(G_OBJECT(canvas->root));
}
if (canvas->update_id)
g_source_remove(canvas->update_id);
g_list_free(canvas->views);
if (parent_class->finalize)
(* parent_class->finalize) (object);
}
static void
dia_canvas_real_render (DiaCanvas *canvas, DiaRenderer *renderer,
DiaRectangle *rect)
{
static guint render_signal_id = 0;
g_return_if_fail (canvas != NULL);
g_return_if_fail (DIA_IS_CANVAS (canvas));
if (!render_signal_id)
render_signal_id = g_signal_lookup("render", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(canvas->root, render_signal_id, 0, renderer, rect);
}
static void
dia_canvas_real_dirty_region (DiaCanvas *canvas, DiaRectangle *rect)
{
g_return_if_fail (canvas != NULL);
g_return_if_fail (DIA_IS_CANVAS (canvas));
}
/**
* dia_canvas_set_extents:
* @canvas: a #DiaCanvas.
* @extents: ??
*
* ??
**/
void
dia_canvas_set_extents(DiaCanvas *canvas, DiaRectangle *extents)
{
g_return_if_fail (canvas != NULL);
g_return_if_fail (DIA_IS_CANVAS (canvas));
g_return_if_fail (extents->top < extents->bottom);
g_return_if_fail (extents->left < extents->right);
if (extents->top != canvas->extents.top ||
extents->left != canvas->extents.left ||
extents->bottom != canvas->extents.bottom ||
extents->right != canvas->extents.right) {
canvas->extents = *extents;
g_signal_emit(canvas, canvas_signals[EXTENTS_CHANGED], 0);
}
}
/**
* dia_canvas_render:
* @canvas: a #DiaCanvas.
* @renderer: the #DiaRenderer used.
* @rect: the area to render.
*
* Renders the @rect area with the @renderer.
**/
void
dia_canvas_render (DiaCanvas *canvas, DiaRenderer *renderer,
DiaRectangle *rect)
{
g_return_if_fail (canvas != NULL);
g_return_if_fail (DIA_IS_CANVAS (canvas));
g_return_if_fail (renderer != NULL);
g_return_if_fail (DIA_IS_RENDERER (renderer));
g_return_if_fail (rect->top < rect->bottom);
g_return_if_fail (rect->left < rect->right);
g_signal_emit (canvas, canvas_signals[RENDER], 0, renderer, rect);
}
/**
* dia_canvas_add_view:
* @canvas: a #DiaCanvas.
* @view: the #DiaCanvasView to add.
*
* Adds the @view to the @canvas.
**/
void
dia_canvas_add_view(DiaCanvas *canvas, DiaCanvasView *view)
{
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
g_return_if_fail(view != NULL);
g_return_if_fail(DIA_IS_CANVAS_VIEW(view));
g_return_if_fail(view->canvas != NULL);
canvas->views = g_list_append(canvas->views, view);
view->canvas = canvas;
}
/**
* dia_canvas_remove_view:
* @canvas: a #DiaCanvas.
* @view: the #DiaCanvasView to remove.
*
* removes the @view to the @canvas.
**/
void
dia_canvas_remove_view(DiaCanvas *canvas, DiaCanvasView *view)
{
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
g_return_if_fail(view != NULL);
g_return_if_fail(DIA_IS_CANVAS_VIEW(view));
g_return_if_fail(view->canvas == canvas);
canvas->views = g_list_remove(canvas->views, view);
}
static DiaCanvasItem *
pick_traverse(DiaCanvasGroup *group, gdouble x, gdouble y,
gdouble close_enough)
{
GList *tmp;
DiaCanvasItem *closest = NULL;
static guint distance_signal_id = 0;
if (!distance_signal_id)
distance_signal_id = g_signal_lookup("distance",
DIA_TYPE_CANVAS_ITEM);
for (tmp = group->children; tmp != NULL; tmp = tmp->next) {
DiaCanvasItem *child = tmp->data;
gdouble dist;
/* if point is far enough outside of bounding box */
if (child->bounds.left - close_enough > x ||
child->bounds.right + close_enough < x ||
child->bounds.top - close_enough > y ||
child->bounds.bottom + close_enough < y)
continue;
if (!child->visible)
continue; /* skip invisible children */
if (DIA_IS_CANVAS_GROUP(child)) {
DiaCanvasItem *possible = pick_traverse(DIA_CANVAS_GROUP(child),
x, y, close_enough);
if (possible) {
closest = possible;
continue;
}
}
g_signal_emit(child, distance_signal_id, 0, x, y, &dist);
if (dist <= close_enough)
closest = child;
}
return closest;
}
/**
* dia_canvas_get_item_at:
* @canvas: a #DiaCanvas.
* @x: the x position.
* @y: the y position.
* @close_enough: ??
*
* Returns the #DiaCanvasItem at (or near) the (@x,@y) position.
*
* Return value: a #DiaCanvasItem.
**/
DiaCanvasItem *
dia_canvas_get_item_at(DiaCanvas *canvas, gdouble x, gdouble y,
gdouble close_enough)
{
dia_canvas_ensure_update(canvas);
return pick_traverse(DIA_CANVAS_GROUP(canvas->root), x, y, close_enough);
}
static gint
start_update(DiaCanvas *canvas)
{
static guint update_signal_id = 0;
GDK_THREADS_ENTER();
canvas->in_update = TRUE;
if (!update_signal_id)
update_signal_id = g_signal_lookup("update", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(canvas->root, update_signal_id, 0);
canvas->root->need_update = FALSE;
canvas->in_update = FALSE;
canvas->update_id = 0;
GDK_THREADS_LEAVE();
return FALSE;
}
/**
* dia_canvas_schedule_update:
* @canvas: a #DiaCanvas.
*
* ??
**/
void
dia_canvas_schedule_update(DiaCanvas *canvas)
{
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
if (!canvas->update_id)
canvas->update_id = g_idle_add_full(UPDATE_PRIORITY,
(GSourceFunc)start_update,
canvas, NULL);
}
/**
* dia_canvas_ensure_update:
* @canvas: a #DiaCanvas.
*
* ??
**/
void
dia_canvas_ensure_update(DiaCanvas *canvas)
{
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
if (canvas->update_id) {
static guint update_signal_id = 0;
gtk_idle_remove(canvas->update_id);
canvas->update_id = 0;
canvas->in_update = TRUE;
if (!update_signal_id)
update_signal_id = g_signal_lookup("update", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(canvas->root, update_signal_id, 0);
canvas->root->need_update = FALSE;
canvas->in_update = FALSE;
}
}
/**
* dia_canvas_dirty_region:
* @canvas: a #DiaCanvas.
* @rect: ??
*
* ??
**/
void
dia_canvas_dirty_region(DiaCanvas *canvas, DiaRectangle *rect)
{
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
g_return_if_fail(rect != NULL);
g_signal_emit(canvas, canvas_signals[DIRTY_REGION], 0, rect);
}
/**
* dia_canvas_snap:
* @canvas: a #DiaCanvas.
* @avoid: the item that asked snapping.
* @x: the x position.
* @y: the y position.
*
* This takes (@x,@y) and snap it to the grid.
*
* Returns: the distance.
**/
gdouble
dia_canvas_snap(DiaCanvas *canvas, gdouble *x, gdouble *y)
{
static guint snap_signal_id = 0;
gdouble result;
g_return_val_if_fail(canvas != NULL,G_MAXDOUBLE);
g_return_val_if_fail(DIA_IS_CANVAS(canvas),G_MAXDOUBLE);
g_return_val_if_fail(x != NULL,G_MAXDOUBLE);
g_return_val_if_fail(y != NULL,G_MAXDOUBLE);
if (!snap_signal_id)
snap_signal_id = g_signal_lookup("attract", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(canvas->root, snap_signal_id, 0, x, y, &result);
return result;
}
void
dia_canvas_connect(DiaCanvas *canvas, DiaCanvasConnection *connection)
{
static guint connect_signal_id = 0;
g_return_if_fail(canvas != NULL);
g_return_if_fail(DIA_IS_CANVAS(canvas));
g_return_if_fail(connection != NULL);
if (!connect_signal_id)
connect_signal_id = g_signal_lookup("connect", DIA_TYPE_CANVAS_ITEM);
g_signal_emit(canvas->root, connect_signal_id, 0, connection);
}
void
dia_canvas_add_selection(DiaCanvas *canvas, DiaCanvasItem *item)
{
if( g_list_find(canvas->selection,item) == NULL ) {
canvas->selection = g_list_append (canvas->selection,item);
dia_canvas_item_select(item);
}
}
void
dia_canvas_remove_from_selection(DiaCanvas *canvas, DiaCanvasItem *item)
{
GList *element;
element = g_list_find(canvas->selection,item);
if( element != NULL ) {
canvas->selection = g_list_delete_link(canvas->selection,element);
dia_canvas_item_unselect(item);
}
}
static void
dia_canvas_unset_selected(DiaCanvasItem *item, gpointer user_data)
{
dia_canvas_item_unselect(item);
}
void
dia_canvas_clear_selection(DiaCanvas *canvas)
{
g_list_foreach(canvas->selection,(GFunc)dia_canvas_unset_selected,NULL);
g_list_free(canvas->selection);
canvas->selection = NULL;
}
dia-newcanvas-0.6.10/src/dia-canvas.h 0100644 0001750 0001750 00000007341 07537446061 017654 0 ustar xordoquy xordoquy /* dia-canvas.h
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_CANVAS_H__
#define __DIA_CANVAS_H__
#include
#include "dia-geometry.h"
#include "dia-renderer.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define DIA_TYPE_CANVAS (dia_canvas_get_type ())
#define DIA_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS, DiaCanvas))
#define DIA_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CANVAS, DiaCanvasClass))
#define DIA_IS_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CANVAS))
#define DIA_IS_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DIA_TYPE_CANVAS))
#define DIA_CANVAS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIA_TYPE_CANVAS, DiaCanvasClass))
typedef struct _DiaCanvas DiaCanvas;
typedef struct _DiaCanvasClass DiaCanvasClass;
/* forward declarations ... */
typedef struct _DiaCanvasItem DiaCanvasItem;
typedef struct _DiaCanvasConnection DiaCanvasConnection;
typedef struct _DiaCanvasGroup DiaCanvasGroup;
typedef struct _DiaCanvasView DiaCanvasView;
struct _DiaCanvas
{
GObject parent;
/* the size of the canvas */
DiaRectangle extents;
/* the root item in the canvas -- is a group */
DiaCanvasItem *root;
/* this is a group of selected items */
GList *selection;
/* views of the canvas */
GList *views;
guint update_id;
gboolean in_update; /* flag used to catch recursive updates */
/* current focused item (where keyboard input goes) */
DiaCanvasItem *focus_item;
/* the current view that holds the focus (if any) */
DiaCanvasView *focus_view;
};
struct _DiaCanvasClass
{
GObjectClass parent_class;
/* Signals go here */
void (*render) (DiaCanvas *canvas, DiaRenderer *renderer,
DiaRectangle *rect);
void (*dirty_region) (DiaCanvas *canvas, DiaRectangle *rect);
void (*extents_changed) (DiaCanvas *canvas);
};
GType dia_canvas_get_type (void);
DiaCanvas *dia_canvas_new (void);
void dia_canvas_set_extents(DiaCanvas *canvas, DiaRectangle *extents);
void dia_canvas_render (DiaCanvas *canvas, DiaRenderer *renderer,
DiaRectangle *rect);
/* for use by canvas views */
void dia_canvas_add_view(DiaCanvas *canvas, DiaCanvasView *view);
void dia_canvas_remove_view(DiaCanvas *canvas, DiaCanvasView *view);
DiaCanvasItem *dia_canvas_get_item_at(DiaCanvas *canvas, gdouble x, gdouble y,
gdouble close_enough);
/* for use by canvas items */
void dia_canvas_schedule_update(DiaCanvas *canvas);
void dia_canvas_ensure_update(DiaCanvas *canvas);
void dia_canvas_dirty_region(DiaCanvas *canvas, DiaRectangle *rect);
gdouble dia_canvas_snap(DiaCanvas *canvas, gdouble *x, gdouble *y);
void dia_canvas_connect(DiaCanvas *canvas, DiaCanvasConnection *connection);
void dia_canvas_add_selection(DiaCanvas *canvas, DiaCanvasItem *item);
void dia_canvas_remove_from_selection(DiaCanvas *canvas, DiaCanvasItem *item);
void dia_canvas_clear_selection(DiaCanvas *canvas);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_CANVAS_H__ */
dia-newcanvas-0.6.10/src/dia-geometry.c 0100644 0001750 0001750 00000006332 07537446061 020226 0 ustar xordoquy xordoquy /* dia-renderer.c
* Copyright (C) 2000 James Henstridge, Alexander Larsson
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-geometry.h"
#define sqr(x) ((x)*(x))
#include
/**
* dia_rectangle_intersect:
* @src1: the first #DiaRectangle.
* @src2: the second #DiaRectangle.
* @dest: the intersection.
*
* Make @dest the intersection between @src1 and @src2. If there's
* no intersection, return FALSE.
*
* Return value: TRUE if there is an intersection.
**/
gboolean
dia_rectangle_intersect (DiaRectangle *src1,
DiaRectangle *src2,
DiaRectangle *dest)
{
DiaRectangle *temp;
gboolean return_val;
g_return_val_if_fail (src1 != NULL, FALSE);
g_return_val_if_fail (src2 != NULL, FALSE);
g_return_val_if_fail (dest != NULL, FALSE);
return_val = FALSE;
if (src2->left < src1->left)
{
temp = src1;
src1 = src2;
src2 = temp;
}
dest->left = src2->left;
if (src2->left < src1->right)
{
if (src1->right < src2->right)
dest->right = src1->right;
else
dest->right = src2->right;
if (src2->top < src1->top)
{
temp = src1;
src1 = src2;
src2 = temp;
}
dest->top = src2->top;
if (src2->top < src1->bottom)
{
return_val = TRUE;
if (src1->bottom < src2->bottom)
dest->bottom = src1->bottom;
else
dest->bottom = src2->bottom;
if (dest->top == dest->bottom)
return_val = FALSE;
if (dest->left == dest->right)
return_val = FALSE;
}
}
return return_val;
}
gdouble
distance_line_point(const DiaPoint *line_start, const DiaPoint *line_end,
gdouble line_width, const DiaPoint *point)
{
DiaPoint v1, v2;
gdouble v1_lensq;
gdouble projlen;
gdouble perp_dist;
v1.x = line_end->x - line_start->x;
v1.y = line_end->y - line_start->y;
v2.x = point->x - line_start->x;
v2.y = point->y - line_start->y;
v1_lensq = sqr(v1.x) + sqr(v1.y);
if (v1_lensq<0.000001) {
return sqrt(sqr(v2.x) + sqr(v2.y));
}
projlen = (v1.x*v2.x + v1.y*v2.y) / v1_lensq;
if (projlen<0.0) {
return sqrt(sqr(v2.x) + sqr(v2.y));
}
if (projlen>1.0) {
v2.x = point->x - line_end->x;
v2.y = point->y - line_end->y;
return sqrt(sqr(v2.x)+sqr(v2.y));
}
v1.x *= projlen;
v1.y *= projlen;
v1.x -= v2.x;
v1.y -= v2.y;
perp_dist = sqrt(sqr(v1.x)+sqr(v1.y));
perp_dist -= line_width / 2.0;
if (perp_dist < 0.0) {
perp_dist = 0.0;
}
return perp_dist;
}
dia-newcanvas-0.6.10/src/dia-geometry.h 0100644 0001750 0001750 00000003061 07537446061 020227 0 ustar xordoquy xordoquy /* dia-renderer.h
* Copyright (C) 2000 James Henstridge, Alexander Larsson
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_GEOMETRY_H__
#define __DIA_GEOMETRY_H__
#include
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _DiaPoint DiaPoint;
typedef struct _DiaRectangle DiaRectangle;
typedef struct _DiaSnapPoint DiaSnapPoint;
struct _DiaRectangle {
gdouble left, top, right, bottom;
};
struct _DiaPoint {
gdouble x, y;
};
struct _DiaSnapPoint {
gdouble x, y;
gint flag;
};
gboolean dia_rectangle_intersect (DiaRectangle *src1,
DiaRectangle *src2,
DiaRectangle *dest);
gdouble distance_line_point(const DiaPoint *line_start,
const DiaPoint *line_end,
gdouble line_width,
const DiaPoint *point);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_GEOMETRY_H__ */
dia-newcanvas-0.6.10/src/dia-marshal.c 0100644 0001750 0001750 00000044257 07537446061 020032 0 ustar xordoquy xordoquy
#include
#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
#define g_marshal_value_peek_char(v) g_value_get_char (v)
#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
#define g_marshal_value_peek_int(v) g_value_get_int (v)
#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
#define g_marshal_value_peek_long(v) g_value_get_long (v)
#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
#define g_marshal_value_peek_float(v) g_value_get_float (v)
#define g_marshal_value_peek_double(v) g_value_get_double (v)
#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
#define g_marshal_value_peek_param(v) g_value_get_param (v)
#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
#define g_marshal_value_peek_object(v) g_value_get_object (v)
#else /* !G_ENABLE_DEBUG */
/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
* Do not access GValues directly in your code. Instead, use the
* g_value_get_*() functions
*/
#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
#define g_marshal_value_peek_char(v) (v)->data[0].v_int
#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
#define g_marshal_value_peek_int(v) (v)->data[0].v_int
#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
#define g_marshal_value_peek_long(v) (v)->data[0].v_long
#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
#define g_marshal_value_peek_enum(v) (v)->data[0].v_int
#define g_marshal_value_peek_flags(v) (v)->data[0].v_uint
#define g_marshal_value_peek_float(v) (v)->data[0].v_float
#define g_marshal_value_peek_double(v) (v)->data[0].v_double
#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
#endif /* !G_ENABLE_DEBUG */
/* VOID:POINTER,POINTER (dia-marshal.list:1) */
void
dia_marshal_VOID__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__POINTER_POINTER) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer data2);
register GMarshalFunc_VOID__POINTER_POINTER callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__POINTER_POINTER) (marshal_data ? marshal_data : cc->callback);
callback (data1,
g_marshal_value_peek_pointer (param_values + 1),
g_marshal_value_peek_pointer (param_values + 2),
data2);
}
/* VOID:DOUBLE (dia-marshal.list:2) */
/* VOID:OBJECT,POINTER (dia-marshal.list:3) */
void
dia_marshal_VOID__OBJECT_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__OBJECT_POINTER) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer data2);
register GMarshalFunc_VOID__OBJECT_POINTER callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__OBJECT_POINTER) (marshal_data ? marshal_data : cc->callback);
callback (data1,
g_marshal_value_peek_object (param_values + 1),
g_marshal_value_peek_pointer (param_values + 2),
data2);
}
/* BOOLEAN:BOXED,OBJECT (dia-marshal.list:4) */
void
dia_marshal_BOOLEAN__BOXED_OBJECT (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_OBJECT) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer data2);
register GMarshalFunc_BOOLEAN__BOXED_OBJECT callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
gboolean v_return;
g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_BOOLEAN__BOXED_OBJECT) (marshal_data ? marshal_data : cc->callback);
v_return = callback (data1,
g_marshal_value_peek_boxed (param_values + 1),
g_marshal_value_peek_object (param_values + 2),
data2);
g_value_set_boolean (return_value, v_return);
}
/* BOOLEAN:BOXED,OBJECT,POINTER (dia-marshal.list:5) */
void
dia_marshal_BOOLEAN__BOXED_OBJECT_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_OBJECT_POINTER) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer arg_3,
gpointer data2);
register GMarshalFunc_BOOLEAN__BOXED_OBJECT_POINTER callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
gboolean v_return;
g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 4);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_BOOLEAN__BOXED_OBJECT_POINTER) (marshal_data ? marshal_data : cc->callback);
v_return = callback (data1,
g_marshal_value_peek_boxed (param_values + 1),
g_marshal_value_peek_object (param_values + 2),
g_marshal_value_peek_pointer (param_values + 3),
data2);
g_value_set_boolean (return_value, v_return);
}
/* DOUBLE:DOUBLE,DOUBLE (dia-marshal.list:6) */
void
dia_marshal_DOUBLE__DOUBLE_DOUBLE (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef gdouble (*GMarshalFunc_DOUBLE__DOUBLE_DOUBLE) (gpointer data1,
gdouble arg_1,
gdouble arg_2,
gpointer data2);
register GMarshalFunc_DOUBLE__DOUBLE_DOUBLE callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
gdouble v_return;
g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_DOUBLE__DOUBLE_DOUBLE) (marshal_data ? marshal_data : cc->callback);
v_return = callback (data1,
g_marshal_value_peek_double (param_values + 1),
g_marshal_value_peek_double (param_values + 2),
data2);
g_value_set_double (return_value, v_return);
}
/* BOOLEAN:POINTER,POINTER (dia-marshal.list:7) */
void
dia_marshal_BOOLEAN__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER_POINTER) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer data2);
register GMarshalFunc_BOOLEAN__POINTER_POINTER callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
gboolean v_return;
g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_BOOLEAN__POINTER_POINTER) (marshal_data ? marshal_data : cc->callback);
v_return = callback (data1,
g_marshal_value_peek_pointer (param_values + 1),
g_marshal_value_peek_pointer (param_values + 2),
data2);
g_value_set_boolean (return_value, v_return);
}
/* DOUBLE:POINTER,POINTER (dia-marshal.list:8) */
void
dia_marshal_DOUBLE__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef gdouble (*GMarshalFunc_DOUBLE__POINTER_POINTER) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer data2);
register GMarshalFunc_DOUBLE__POINTER_POINTER callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
gdouble v_return;
g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_DOUBLE__POINTER_POINTER) (marshal_data ? marshal_data : cc->callback);
v_return = callback (data1,
g_marshal_value_peek_pointer (param_values + 1),
g_marshal_value_peek_pointer (param_values + 2),
data2);
g_value_set_double (return_value, v_return);
}
/* VOID:DOUBLE,DOUBLE (dia-marshal.list:9) */
void
dia_marshal_VOID__DOUBLE_DOUBLE (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__DOUBLE_DOUBLE) (gpointer data1,
gdouble arg_1,
gdouble arg_2,
gpointer data2);
register GMarshalFunc_VOID__DOUBLE_DOUBLE callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__DOUBLE_DOUBLE) (marshal_data ? marshal_data : cc->callback);
callback (data1,
g_marshal_value_peek_double (param_values + 1),
g_marshal_value_peek_double (param_values + 2),
data2);
}
/* DOUBLE:OBJECT,POINTER,POINTER (dia-marshal.list:10) */
void
dia_marshal_DOUBLE__OBJECT_POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef gdouble (*GMarshalFunc_DOUBLE__OBJECT_POINTER_POINTER) (gpointer data1,
gpointer arg_1,
gpointer arg_2,
gpointer arg_3,
gpointer data2);
register GMarshalFunc_DOUBLE__OBJECT_POINTER_POINTER callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
gdouble v_return;
g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 4);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_DOUBLE__OBJECT_POINTER_POINTER) (marshal_data ? marshal_data : cc->callback);
v_return = callback (data1,
g_marshal_value_peek_object (param_values + 1),
g_marshal_value_peek_pointer (param_values + 2),
g_marshal_value_peek_pointer (param_values + 3),
data2);
g_value_set_double (return_value, v_return);
}
/* VOID:OBJECT,DOUBLE,DOUBLE (dia-marshal.list:11) */
void
dia_marshal_VOID__OBJECT_DOUBLE_DOUBLE (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__OBJECT_DOUBLE_DOUBLE) (gpointer data1,
gpointer arg_1,
gdouble arg_2,
gdouble arg_3,
gpointer data2);
register GMarshalFunc_VOID__OBJECT_DOUBLE_DOUBLE callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
g_return_if_fail (n_param_values == 4);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__OBJECT_DOUBLE_DOUBLE) (marshal_data ? marshal_data : cc->callback);
callback (data1,
g_marshal_value_peek_object (param_values + 1),
g_marshal_value_peek_double (param_values + 2),
g_marshal_value_peek_double (param_values + 3),
data2);
}
/* VOID:OBJECT (dia-marshal.list:12) */
/* VOID:VOID (dia-marshal.list:13) */
/* VOID:BOOLEAN (dia-marshal.list:14) */
dia-newcanvas-0.6.10/src/dia-marshal.h 0100644 0001750 0001750 00000013172 07537446061 020027 0 ustar xordoquy xordoquy
#ifndef __dia_marshal_MARSHAL_H__
#define __dia_marshal_MARSHAL_H__
#include
G_BEGIN_DECLS
/* VOID:POINTER,POINTER (dia-marshal.list:1) */
extern void dia_marshal_VOID__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* VOID:DOUBLE (dia-marshal.list:2) */
#define dia_marshal_VOID__DOUBLE g_cclosure_marshal_VOID__DOUBLE
/* VOID:OBJECT,POINTER (dia-marshal.list:3) */
extern void dia_marshal_VOID__OBJECT_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* BOOLEAN:BOXED,OBJECT (dia-marshal.list:4) */
extern void dia_marshal_BOOLEAN__BOXED_OBJECT (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* BOOLEAN:BOXED,OBJECT,POINTER (dia-marshal.list:5) */
extern void dia_marshal_BOOLEAN__BOXED_OBJECT_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* DOUBLE:DOUBLE,DOUBLE (dia-marshal.list:6) */
extern void dia_marshal_DOUBLE__DOUBLE_DOUBLE (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* BOOLEAN:POINTER,POINTER (dia-marshal.list:7) */
extern void dia_marshal_BOOLEAN__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* DOUBLE:POINTER,POINTER (dia-marshal.list:8) */
extern void dia_marshal_DOUBLE__POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* VOID:DOUBLE,DOUBLE (dia-marshal.list:9) */
extern void dia_marshal_VOID__DOUBLE_DOUBLE (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* DOUBLE:OBJECT,POINTER,POINTER (dia-marshal.list:10) */
extern void dia_marshal_DOUBLE__OBJECT_POINTER_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* VOID:OBJECT,DOUBLE,DOUBLE (dia-marshal.list:11) */
extern void dia_marshal_VOID__OBJECT_DOUBLE_DOUBLE (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* VOID:OBJECT (dia-marshal.list:12) */
#define dia_marshal_VOID__OBJECT g_cclosure_marshal_VOID__OBJECT
/* VOID:VOID (dia-marshal.list:13) */
#define dia_marshal_VOID__VOID g_cclosure_marshal_VOID__VOID
/* VOID:BOOLEAN (dia-marshal.list:14) */
#define dia_marshal_VOID__BOOLEAN g_cclosure_marshal_VOID__BOOLEAN
G_END_DECLS
#endif /* __dia_marshal_MARSHAL_H__ */
dia-newcanvas-0.6.10/src/dia-marshal.list 0100644 0001750 0001750 00000000431 07537446061 020545 0 ustar xordoquy xordoquy VOID:POINTER,POINTER
VOID:DOUBLE
VOID:OBJECT,POINTER
BOOLEAN:BOXED,OBJECT
BOOLEAN:BOXED,OBJECT,POINTER
DOUBLE:DOUBLE,DOUBLE
BOOLEAN:POINTER,POINTER
DOUBLE:POINTER,POINTER
VOID:DOUBLE,DOUBLE
DOUBLE:OBJECT,POINTER,POINTER
VOID:OBJECT,DOUBLE,DOUBLE
VOID:OBJECT
VOID:VOID
VOID:BOOLEAN
dia-newcanvas-0.6.10/src/dia-newcanvas.h 0100644 0001750 0001750 00000003224 07537446061 020362 0 ustar xordoquy xordoquy /* dia-newcanvas.h
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
dia-newcanvas-0.6.10/src/dia-renderer.c 0100644 0001750 0001750 00000012715 07537446061 020203 0 ustar xordoquy xordoquy /* dia-renderer.c
* Copyright (C) 2000 James Henstridge
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dia-renderer.h"
GType
dia_renderer_get_type (void)
{
static GType renderer_type = 0;
if (!renderer_type)
{
static const GTypeInfo renderer_info =
{
sizeof (DiaRendererClass), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
};
renderer_type = g_type_register_static (G_TYPE_INTERFACE, "DiaRenderer",
&renderer_info, 0);
g_type_interface_add_prerequisite (renderer_type, G_TYPE_OBJECT);
}
return renderer_type;
}
void
dia_renderer_set_join_style (DiaRenderer *renderer, GdkJoinStyle style)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->set_join_style (renderer, style);
}
void
dia_renderer_set_cap_style (DiaRenderer *renderer, GdkCapStyle style)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->set_cap_style (renderer, style);
}
void
dia_renderer_set_line_width (DiaRenderer *renderer, gdouble width)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->set_line_width (renderer, width);
}
void
dia_renderer_set_line_style (DiaRenderer *renderer, GdkLineStyle style)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->set_line_style (renderer, style);
}
void
dia_renderer_set_dash_style (DiaRenderer *renderer, gdouble *dash_len,
gint nlen)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->set_dash_style (renderer, dash_len, nlen);
}
void
dia_renderer_set_color (DiaRenderer *renderer, GdkColor *color)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->set_color (renderer, color);
}
void
dia_renderer_set_font (DiaRenderer *renderer, const gchar *font_desc,
gdouble size)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->set_font (renderer, font_desc, size);
}
/* Primitives */
void
dia_renderer_draw_point (DiaRenderer *renderer, DiaPoint *point)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_point (renderer, point);
}
void
dia_renderer_draw_line (DiaRenderer *renderer, DiaPoint *start, DiaPoint *end)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_line (renderer, start, end);
}
void
dia_renderer_draw_rectangle (DiaRenderer *renderer, gboolean filled,
DiaPoint *ul_corner, DiaPoint *lr_corner)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_rectangle (renderer, filled,
ul_corner, lr_corner);
}
void
dia_renderer_draw_polyline (DiaRenderer *renderer,
DiaPoint *points, gint npoints)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_polyline (renderer, points, npoints);
}
void
dia_renderer_draw_polygon (DiaRenderer *renderer, gboolean filled,
GList /*DiaPoint*/ *points)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_polygon (renderer, filled, points);
}
void
dia_renderer_draw_ellipse (DiaRenderer *renderer, gboolean filled,
DiaPoint *centre, gdouble width, gdouble height)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_ellipse (renderer, filled, centre,
width, height);
}
void
dia_renderer_draw_arc (DiaRenderer *renderer, gboolean filled,
DiaPoint *centre,
gdouble width, gdouble height,
gdouble angle1, gdouble angle2)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_arc (renderer, filled, centre,
width, height, angle1, angle2);
}
void
dia_renderer_draw_bezier (DiaRenderer *renderer, gboolean filled,
DiaBezierPath *points, gint npoints)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_bezier (renderer, filled,
points, npoints);
}
void
dia_renderer_draw_pixbuf (DiaRenderer *renderer,
DiaPoint *pos, gdouble width, gdouble height,
gdouble angle, GdkPixbuf *src)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_pixbuf (renderer, pos, width,
height, angle, src);
}
void
dia_renderer_draw_text (DiaRenderer *renderer,
DiaPoint *point, const gchar *text)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->draw_text (renderer, point, text);
}
void
dia_renderer_get_text_size (DiaRenderer *renderer,
DiaPoint *point, const gchar *text)
{
g_return_if_fail (DIA_IS_RENDERER(renderer));
DIA_RENDERER_GET_CLASS(renderer)->get_text_size (renderer, point, text);
}
dia-newcanvas-0.6.10/src/dia-renderer.h 0100644 0001750 0001750 00000013733 07537446061 020211 0 ustar xordoquy xordoquy /* dia-renderer.h
* Copyright (C) 2000 James Henstridge, Alexander Larsson
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __DIA_RENDERER_H__
#define __DIA_RENDERER_H__
#include
#include
#include "dia-geometry.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define DIA_TYPE_RENDERER (dia_renderer_get_type ())
#define DIA_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_RENDERER, DiaRenderer))
#define DIA_RENDERER_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), DIA_TYPE_RENDERER, DiaRendererClass)
#define DIA_IS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_RENDERER))
#define DIA_IS_RENDERER_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), DIA_TYPE_RENDERER))
#define DIA_RENDERER_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), DIA_TYPE_RENDERER, DiaRendererClass))
typedef struct _DiaRenderer DiaRenderer;
typedef struct _DiaRendererClass DiaRendererClass;
typedef enum
{
DIA_BEZ_MOVE_TO,
DIA_BEZ_LINE_TO,
DIA_BEZ_CURVE_TO
} DiaBezierType;
typedef struct _DiaBezierPath DiaBezierPath;
struct _DiaBezierPath {
DiaBezierType type;
DiaPoint p1, p2, p3;
};
struct _DiaRendererClass
{
GTypeInterface base_iface;
/* State setting functions */
void (*set_fill_rule) (DiaRenderer *renderer, GdkFillRule rule);
void (*set_join_style) (DiaRenderer *renderer, GdkJoinStyle style);
void (*set_cap_style) (DiaRenderer *renderer, GdkCapStyle style);
void (*set_line_width) (DiaRenderer *renderer, gdouble width);
void (*set_line_style) (DiaRenderer *renderer, GdkLineStyle style);
void (*set_dash_style) (DiaRenderer *renderer, gdouble *dash_len, gint nlen);
void (*set_color) (DiaRenderer *renderer, GdkColor *color);
/* the font size in font_desc is ignored, as we want something scalable */
void (*set_font) (DiaRenderer *renderer, const gchar *font_desc,
gdouble size);
/* Primitives */
void (* draw_point) (DiaRenderer *renderer,
DiaPoint *point);
void (* draw_line) (DiaRenderer *renderer,
DiaPoint *start, DiaPoint *end);
void (* draw_rectangle) (DiaRenderer *renderer, gboolean filled,
DiaPoint *ul_corner, DiaPoint *lr_corner);
void (* draw_polyline) (DiaRenderer *renderer,
DiaPoint *points, gint npoints);
void (* draw_polygon) (DiaRenderer *renderer, gboolean filled,
GList /*DiaPoint*/ *points);
void (* draw_ellipse) (DiaRenderer *renderer, gboolean filled,
DiaPoint *centre, gdouble width, gdouble height);
void (* draw_arc) (DiaRenderer *renderer, gboolean filled,
DiaPoint *centre,
gdouble width, gdouble height,
gdouble angle1, gdouble angle2);
void (* draw_bezier) (DiaRenderer *renderer, gboolean filled,
DiaBezierPath *points, gint npoints);
void (* draw_pixbuf) (DiaRenderer *renderer,
DiaPoint *pos, gdouble width, gdouble height,
gdouble angle, GdkPixbuf *src);
void (* draw_text) (DiaRenderer *renderer,
DiaPoint *point, const gchar *text);
void (* get_text_size) (DiaRenderer *renderer,
DiaPoint *point, const gchar *text);
};
GType dia_renderer_get_type (void);
/* State setting functions */
void dia_renderer_set_fill_rule (DiaRenderer *renderer, GdkFillRule rule);
void dia_renderer_set_join_style (DiaRenderer *renderer, GdkJoinStyle style);
void dia_renderer_set_cap_style (DiaRenderer *renderer, GdkCapStyle style);
void dia_renderer_set_line_width (DiaRenderer *renderer, gdouble width);
void dia_renderer_set_line_style (DiaRenderer *renderer, GdkLineStyle style);
void dia_renderer_set_dash_style (DiaRenderer *renderer, gdouble *dash_len,
gint nlen);
void dia_renderer_set_color (DiaRenderer *renderer, GdkColor *color);
/* the font size in font_desc is ignored, as we want something scalable */
void dia_renderer_set_font (DiaRenderer *renderer,
const gchar *font_desc, gdouble size);
/* Primitives */
void dia_renderer_draw_point (DiaRenderer *renderer,
DiaPoint *point);
void dia_renderer_draw_line (DiaRenderer *renderer,
DiaPoint *start, DiaPoint *end);
void dia_renderer_draw_rectangle (DiaRenderer *renderer, gboolean filled,
DiaPoint *ul_corner, DiaPoint *lr_corner);
void dia_renderer_draw_polyline (DiaRenderer *renderer,
DiaPoint *points, gint npoints);
void dia_renderer_draw_polygon (DiaRenderer *renderer, gboolean filled,
GList /*DiaPoint*/ *points);
void dia_renderer_draw_ellipse (DiaRenderer *renderer, gboolean filled,
DiaPoint *centre, gdouble width,
gdouble height);
void dia_renderer_draw_arc (DiaRenderer *renderer, gboolean filled,
DiaPoint *centre,
gdouble width, gdouble height,
gdouble angle1, gdouble angle2);
void dia_renderer_draw_bezier (DiaRenderer *renderer, gboolean filled,
DiaBezierPath *points, gint npoints);
void dia_renderer_draw_pixbuf (DiaRenderer *renderer,
DiaPoint *pos, gdouble width, gdouble height,
gdouble angle, GdkPixbuf *src);
void dia_renderer_draw_text (DiaRenderer *renderer,
DiaPoint *point, const gchar *text);
/* Text size */
void dia_renderer_get_text_size (DiaRenderer *renderer,
DiaPoint *point, const gchar *text);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __DIA_RENDERER_H__ */
dia-newcanvas-0.6.10/src/libglade.c 0100644 0001750 0001750 00000002274 07537446061 017404 0 ustar xordoquy xordoquy /* libglade.c
* Copyright (C) 2001 Xavier Ordoquy
*
* 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; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include
#include
#include
#include
#include "dia-canvas-view-gdk.h"
/* this macro puts a version check function into the module */
GLADE_MODULE_CHECK_INIT
void
glade_module_register_widgets (void)
{
glade_provide ("libdianewcanvas2");
glade_register_widget (DIA_TYPE_CANVAS_VIEW_GDK,
glade_standard_build_widget,
NULL, NULL);
}
dia-newcanvas-0.6.10/src/test-diacanvas.c 0100644 0001750 0001750 00000014424 07537446061 020547 0 ustar xordoquy xordoquy
#include
#include "dia-canvas.h"
#include "dia-canvas-view.h"
#include "dia-canvas-view-gdk.h"
#include "dia-canvas-rectangle.h"
#include "dia-canvas-ellipse.h"
#include "dia-canvas-arc.h"
#include "dia-canvas-text.h"
#include "dia-canvas-polygon.h"
#include "dia-geometry.h"
static gint
event(DiaCanvasItem *item, GdkEvent *event, DiaCanvasView *view)
{
GdkColor red = { 0, 0xffff, 0, 0 };
GdkColor green = { 0, 0, 0xffff, 0 };
GdkColor blue = { 0, 0, 0, 0xffff };
static gboolean dragging = FALSE;
static DiaPoint DaPoint;
DiaPoint newPoint;
switch (event->type) {
case GDK_BUTTON_PRESS:
g_message("button press %p", item);
if( DIA_IS_CANVAS_TEXT(item) ) {
g_object_set(item,
"text_color", &red,
NULL);
} else {
g_object_set(item,
"line_color", &red,
NULL);
}
DaPoint.x = event->button.x;
DaPoint.y = event->button.y;
dragging = TRUE;
dia_canvas_view_grab(view,TRUE);
return TRUE;
case GDK_BUTTON_RELEASE:
g_message("button release %p", item);
if( DIA_IS_CANVAS_TEXT(item) ) {
g_object_set(item,
"text_color", &green,
NULL);
} else {
g_object_set(item,
"line_color", &green,
NULL);
}
dragging = FALSE;
dia_canvas_view_ungrab(view);
return TRUE;
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
newPoint.x = event->button.x - DaPoint.x;
newPoint.y = event->button.y - DaPoint.y;
dia_canvas_item_snapmove (item, &(newPoint.x), &(newPoint.y));
dia_canvas_item_move (item, newPoint.x, newPoint.y);
DaPoint.x += newPoint.x;
DaPoint.y += newPoint.y;
}
return TRUE;
case GDK_ENTER_NOTIFY:
g_message("enter item %p", item);
if( DIA_IS_CANVAS_TEXT(item) ) {
g_object_set(item,
"text_color", &blue,
NULL);
} else {
g_object_set(item,
"line_color", &blue,
NULL);
}
return TRUE;
case GDK_LEAVE_NOTIFY:
g_message("exit item %p", item);
if( DIA_IS_CANVAS_TEXT(item) ) {
g_object_set(item,
"text_color", &green,
NULL);
} else {
g_object_set(item,
"line_color", &green,
NULL);
}
return TRUE;
default:
return FALSE;
}
return FALSE;
}
static void create_view(DiaCanvas *canvas);
int
main(int argc, char **argv)
{
DiaCanvas *canvas;
DiaCanvasItem *item;
DiaRectangle extents = { 0,0, 200,200 };
//GdkColor red = { 0, 0xffff, 0, 0 };
GdkColor green = { 0, 0, 0xffff, 0 };
GdkColor cyan = { 0, 0, 0xffff, 0xffff };
gtk_init(&argc, &argv);
canvas = dia_canvas_new();
dia_canvas_set_extents(canvas, &extents);
item = g_object_new(DIA_TYPE_CANVAS_RECTANGLE,
"parent", canvas->root,
"x1", 10.0, "y1", 10.0,
"x2", 130.0, "y2", 130.0,
"fill_color", &cyan,
"line_color", &green,
"line_width", 8.0,
NULL);
g_signal_connect(item, "event", G_CALLBACK(event), NULL);
item = g_object_new(DIA_TYPE_CANVAS_ELLIPSE,
"parent", canvas->root,
"x1", 100.0, "y1", 60.0,
"x2", 180.0, "y2", 180.0,
"fill_color", &cyan,
"line_color", &green,
"line_width", 8.0,
NULL);
g_signal_connect(item, "event", G_CALLBACK(event), NULL);
item = g_object_new(DIA_TYPE_CANVAS_ARC,
"parent", canvas->root,
"x", 130.0, "y", 150.0,
"width", 120.0, "height", 100.0,
"angle1", 45.0, "angle2", 170.0,
"fill_color", &cyan,
"line_color", &green,
"line_width", 8.0,
NULL);
g_signal_connect(item, "event", G_CALLBACK(event), NULL);
item = g_object_new(DIA_TYPE_CANVAS_POLYGON,
"parent", canvas->root,
"x", 50.0, "y", 50.0,
"point", "(25.0,25.0)",
"point", "(0.0,50.0)",
"point", "(-25.0,25.0)",
"point", "(-25.0,-25.0)",
"point", "(25.0,-25.0)",
"fill_color", &cyan,
"line_color", &green,
"line_width", 8.0,
NULL);
g_signal_connect(item, "event", G_CALLBACK(event), NULL);
item = g_object_new(DIA_TYPE_CANVAS_TEXT,
"parent", canvas->root,
"x", 50.0, "y", 50.0,
"text_color", &green,
"text_width", 8.0,
"text","TOTO",
NULL);
g_signal_connect(item, "event", G_CALLBACK(event), NULL);
create_view(canvas);
g_object_unref(G_OBJECT(canvas));
gtk_main();
return 0;
}
/* code for creating a new view of the canvas */
static gint view_count = 0;
static void
view_destroy(GtkWidget *widget)
{
view_count--;
if (view_count == 0)
gtk_main_quit();
}
static void
rezoom(GtkAdjustment *adj, DiaCanvasView *view)
{
dia_canvas_view_set_zoom(view, adj->value);
}
static void
new_view_callback(GtkWidget *button, DiaCanvas *canvas)
{
create_view(canvas);
}
static void
create_view(DiaCanvas *canvas)
{
GtkWidget *window;
GtkWidget *vbox, *hbox;
GtkAdjustment *adj;
GtkWidget *label, *zoom, *button;
GtkWidget *swin;
GtkWidget *view;
view_count++;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window), 2);
gtk_window_set_title(GTK_WINDOW(window), "Canvas Test");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 230);
g_signal_connect(window, "destroy", G_CALLBACK(view_destroy), NULL);
vbox = gtk_vbox_new(FALSE, 2);
gtk_container_add(GTK_CONTAINER(window), vbox);
hbox = gtk_hbox_new(FALSE, 2);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
label = gtk_label_new("Zoom:");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
adj = GTK_ADJUSTMENT(gtk_adjustment_new(1.0, 0.0675,256, 0.25,1.0,1.0));
zoom = gtk_spin_button_new(adj, 0.0, 4);
gtk_box_pack_start(GTK_BOX(hbox), zoom, FALSE, FALSE, 0);
button = gtk_button_new_with_label("New view");
g_signal_connect(button, "clicked", G_CALLBACK(new_view_callback), canvas);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
swin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0);
view = dia_canvas_view_gdk_new(canvas);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), view);
g_signal_connect(adj, "value_changed", G_CALLBACK(rezoom), view);
gtk_widget_show_all(window);
}
dia-newcanvas-0.6.10/src/test-diacanvas2.c 0100644 0001750 0001750 00000020604 07537446061 020626 0 ustar xordoquy xordoquy
#include
#include "dia-canvas.h"
#include "dia-canvas-view.h"
#include "dia-canvas-view-gdk.h"
#include "dia-canvas-line.h"
#include "dia-canvas-rectangle.h"
#include "dia-canvas-ellipse.h"
#include "dia-geometry.h"
#include "dia-canvas-group.h"
#include "dia-canvas-connection.h"
#include "dia-canvas-attract.h"
#include "dia-canvas-attracted.h"
static gint
event(DiaCanvasItem *item, GdkEvent *event, DiaCanvasView *view)
{
static gboolean dragging = FALSE;
static DiaPoint DaPoint;
DiaPoint newPoint;
switch (event->type) {
case GDK_BUTTON_PRESS:
g_message("button press %p", item);
DaPoint.x = event->button.x;
DaPoint.y = event->button.y;
dragging = TRUE;
dia_canvas_view_grab(view,TRUE);
return TRUE;
case GDK_BUTTON_RELEASE:
g_message("button release %p", item);
dragging = FALSE;
dia_canvas_view_ungrab(view);
dia_canvas_item_make_connection(item);
return TRUE;
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
newPoint.x = event->button.x - DaPoint.x;
newPoint.y = event->button.y - DaPoint.y;
dia_canvas_item_snapmove (item, &(newPoint.x), &(newPoint.y));
dia_canvas_item_move (item, newPoint.x, newPoint.y);
DaPoint.x += newPoint.x;
DaPoint.y += newPoint.y;
}
return TRUE;
case GDK_ENTER_NOTIFY:
g_message("enter item %p", item);
return TRUE;
case GDK_LEAVE_NOTIFY:
g_message("exit item %p", item);
return TRUE;
default:
return FALSE;
}
return FALSE;
}
static void
component_connection_moved (DiaCanvasItem *item,
DiaCanvasConnection *connection,
gdouble dx, gdouble dy)
{
DiaCanvasConnection *dest = DIA_CANVAS_CONNECTION(item);
dest->connections = g_list_remove(dest->connections,connection);
connection->connections = g_list_remove(connection->connections,dest);
}
static void
line_connection_moved (DiaCanvasItem *item,
DiaCanvasConnection *connection,
gdouble dx, gdouble dy)
{
dia_canvas_item_move(item,dx,dy);
}
static void create_view(DiaCanvas *canvas);
int
main(int argc, char **argv)
{
DiaCanvas *canvas;
DiaCanvasItem *group;
DiaCanvasItem *item;
DiaRectangle extents = { 0,0, 200,200 };
GdkColor line_color = { 0, 0x8000, 0x8000, 0x8000 };
GdkColor fill_color = { 0, 0xffff, 0xffff, 0x99ff };
gtk_init(&argc, &argv);
canvas = dia_canvas_new();
dia_canvas_set_extents(canvas, &extents);
/*
* The rectangle group.
*/
group = g_object_new(DIA_TYPE_CANVAS_GROUP,
"parent", canvas->root,
"move_indep", TRUE,
NULL);
g_signal_connect(group, "event", G_CALLBACK(event), NULL);
g_object_new(DIA_TYPE_CANVAS_RECTANGLE,
"parent", group,
"x1", 10.0, "y1", 10.0,
"x2", 130.0, "y2", 130.0,
"fill_color", &fill_color,
"line_color", &line_color,
"line_width", 5.0,
"move_indep", FALSE,
NULL);
item = g_object_new(DIA_TYPE_CANVAS_CONNECTION,
"parent", group,
"x", 10.0, "y", 10.0,
"move_indep", FALSE,
NULL);
g_signal_connect_after(item, "connection_moved", G_CALLBACK(component_connection_moved), NULL);
item = g_object_new(DIA_TYPE_CANVAS_CONNECTION,
"parent", group,
"x", 130.0, "y", 10.0,
"move_indep", FALSE,
NULL);
g_signal_connect_after(item, "connection_moved", G_CALLBACK(component_connection_moved), NULL);
item = g_object_new(DIA_TYPE_CANVAS_CONNECTION,
"parent", group,
"x", 10.0, "y", 130.0,
"move_indep", FALSE,
NULL);
g_signal_connect(item, "connection_moved", G_CALLBACK(component_connection_moved), NULL);
item = g_object_new(DIA_TYPE_CANVAS_CONNECTION,
"parent", group,
"x", 130.0, "y", 130.0,
"move_indep", FALSE,
NULL);
g_signal_connect(item, "connection_moved", G_CALLBACK(component_connection_moved), NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACT,
"parent", group,
"x", 10.0, "y", 10.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACT,
"parent", group,
"x", 130.0, "y", 10.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACT,
"parent", group,
"x", 10.0, "y", 130.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACT,
"parent", group,
"x", 130.0, "y", 130.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACTED,
"parent", group,
"x", 10.0, "y", 10.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACTED,
"parent", group,
"x", 130.0, "y", 10.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACTED,
"parent", group,
"x", 10.0, "y", 130.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACTED,
"parent", group,
"x", 130.0, "y", 130.0,
"move_indep", FALSE,
NULL);
/*
* The line group.
*/
group = g_object_new(DIA_TYPE_CANVAS_GROUP,
"parent", canvas->root,
"move_indep", TRUE,
NULL);
g_signal_connect(group, "event", G_CALLBACK(event), NULL);
g_signal_connect(group, "connection_moved", G_CALLBACK(line_connection_moved), NULL);
g_object_new(DIA_TYPE_CANVAS_LINE,
"parent", group,
"x1", 130.0, "y1", 130.0,
"x2", 220.0, "y2", 220.0,
"line_color", &line_color,
"line_width", 8.0,
"move_indep", FALSE,
NULL);
item = g_object_new(DIA_TYPE_CANVAS_CONNECTION,
"parent", group,
"x", 130.0, "y", 130.0,
"move_indep", FALSE,
NULL);
item = g_object_new(DIA_TYPE_CANVAS_CONNECTION,
"parent", group,
"x", 220.0, "y", 220.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACT,
"parent", group,
"x", 130.0, "y", 130.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACT,
"parent", group,
"x", 220.0, "y", 220.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACTED,
"parent", group,
"x", 130.0, "y", 130.0,
"move_indep", FALSE,
NULL);
g_object_new(DIA_TYPE_CANVAS_ATTRACTED,
"parent", group,
"x", 220.0, "y", 220.0,
"move_indep", FALSE,
NULL);
create_view(canvas);
g_object_unref(G_OBJECT(canvas));
gtk_main();
return 0;
}
/* code for creating a new view of the canvas */
static gint view_count = 0;
static void
view_destroy(GtkWidget *widget)
{
view_count--;
if (view_count == 0)
gtk_main_quit();
}
static void
rezoom(GtkAdjustment *adj, DiaCanvasView *view)
{
dia_canvas_view_set_zoom(view, adj->value);
}
static void
new_view_callback(GtkWidget *button, DiaCanvas *canvas)
{
create_view(canvas);
}
static void
create_view(DiaCanvas *canvas)
{
GtkWidget *window;
GtkWidget *vbox, *hbox;
GtkAdjustment *adj;
GtkWidget *label, *zoom, *button;
GtkWidget *swin;
GtkWidget *view;
view_count++;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window), 2);
gtk_window_set_title(GTK_WINDOW(window), "Canvas Test");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 230);
g_signal_connect(window, "destroy", G_CALLBACK(view_destroy), NULL);
vbox = gtk_vbox_new(FALSE, 2);
gtk_container_add(GTK_CONTAINER(window), vbox);
hbox = gtk_hbox_new(FALSE, 2);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
label = gtk_label_new("Zoom:");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
adj = GTK_ADJUSTMENT(gtk_adjustment_new(1.0, 0.0675,256, 0.25,1.0,1.0));
zoom = gtk_spin_button_new(adj, 0.0, 4);
gtk_box_pack_start(GTK_BOX(hbox), zoom, FALSE, FALSE, 0);
button = gtk_button_new_with_label("New view");
g_signal_connect(button, "clicked", G_CALLBACK(new_view_callback), canvas);
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
swin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0);
view = dia_canvas_view_gdk_new(canvas);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), view);
g_signal_connect(adj, "value_changed", G_CALLBACK(rezoom), view);
gtk_widget_show_all(window);
}
dia-newcanvas-0.6.10/.cvsignore 0100644 0001750 0001750 00000000333 07346244317 016676 0 ustar xordoquy xordoquy Makefile
Makefile.in
aclocal.m4
config.cache
config.log
config.status
configure
depcomp
install-sh
missing
mkinstalldirs
.deps
.libs
dia-marshal.c
dia-marshal.h
test-diacanvas
test-diacanvas2
dia-newcanvas.pc
*.lo
*.la
dia-newcanvas-0.6.10/AUTHORS 0100644 0001750 0001750 00000000152 07307122545 015740 0 ustar xordoquy xordoquy James Henstridge
Alexander Larsson
Xavier Ordoquy (MCArkan)