From 7ac37a016e3a401e0cfb277cc957e760d209ae3e Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 13 Sep 2006 20:19:58 +0000 Subject: Added a skinned reusable dropdown widget and used it in the server dialog. --- src/gui/widgets/.deps/.dirstamp | 0 src/gui/widgets/.deps/dropdown.Po | 524 ++++++++++++++++++++++++++++++++++++++ src/gui/widgets/.dirstamp | 0 src/gui/widgets/dropdown.cpp | 191 ++++++++++++++ src/gui/widgets/dropdown.h | 85 +++++++ 5 files changed, 800 insertions(+) create mode 100644 src/gui/widgets/.deps/.dirstamp create mode 100644 src/gui/widgets/.deps/dropdown.Po create mode 100644 src/gui/widgets/.dirstamp create mode 100644 src/gui/widgets/dropdown.cpp create mode 100644 src/gui/widgets/dropdown.h (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/.deps/.dirstamp b/src/gui/widgets/.deps/.dirstamp new file mode 100644 index 00000000..e69de29b diff --git a/src/gui/widgets/.deps/dropdown.Po b/src/gui/widgets/.deps/dropdown.Po new file mode 100644 index 00000000..6a0726bb --- /dev/null +++ b/src/gui/widgets/.deps/dropdown.Po @@ -0,0 +1,524 @@ +gui/widgets/dropdown.o gui/widgets/dropdown.o: gui/widgets/dropdown.cpp \ + gui/widgets/dropdown.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++config.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/os_defines.h \ + /usr/include/features.h /usr/include/sys/cdefs.h \ + /usr/include/gnu/stubs.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/cpu_defines.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++locale.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstring \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstddef \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/include/stddef.h \ + /usr/include/string.h /usr/include/xlocale.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdio \ + /usr/include/stdio.h /usr/include/bits/types.h \ + /usr/include/bits/wordsize.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/include/bits/wchar.h /usr/include/gconv.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/bits/stdio.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/clocale \ + /usr/include/locale.h /usr/include/bits/locale.h \ + /usr/include/langinfo.h /usr/include/nl_types.h /usr/include/iconv.h \ + /usr/include/libintl.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++io.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr-default.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/time.h \ + /usr/include/bits/sched.h /usr/include/bits/time.h \ + /usr/include/signal.h /usr/include/bits/sigset.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/initspin.h \ + /usr/include/bits/sigthread.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/environments.h \ + /usr/include/bits/confname.h /usr/include/getopt.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cctype \ + /usr/include/ctype.h /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stringfwd.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/postypes.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cwchar \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ctime \ + /usr/include/stdint.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/functexcept.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception_defines.h \ + /usr/include/guichan/widgets/dropdown.hpp \ + /usr/include/guichan/actionlistener.hpp \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/string \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/char_traits.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/climits \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/include/syslimits.h \ + /usr/include/limits.h /usr/include/bits/posix1_lim.h \ + /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ + /usr/include/bits/posix2_lim.h /usr/include/bits/xopen_lim.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdlib \ + /usr/include/stdlib.h /usr/include/bits/waitflags.h \ + /usr/include/bits/waitstatus.h /usr/include/sys/types.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/sys/sysmacros.h /usr/include/alloca.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_pair.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/cpp_type_traits.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_types.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_funcs.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/concept_check.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/debug/debug.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/memory \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++allocator.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/new \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_construct.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_uninitialized.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_raw_storage_iter.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/limits \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/atomicity.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/atomic_word.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/algorithm \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_heap.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tempbuf.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc \ + /usr/include/guichan/platform.hpp \ + /usr/include/guichan/basiccontainer.hpp \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/list \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/list.tcc \ + /usr/include/guichan/widget.hpp /usr/include/guichan/color.hpp \ + /usr/include/guichan/rectangle.hpp \ + /usr/include/guichan/focushandler.hpp \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/vector \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc \ + /usr/include/guichan/keylistener.hpp /usr/include/guichan/listmodel.hpp \ + /usr/include/guichan/mouselistener.hpp \ + /usr/include/guichan/platform.hpp \ + /usr/include/guichan/widgets/listbox.hpp \ + /usr/include/guichan/widget.hpp \ + /usr/include/guichan/widgets/scrollarea.hpp gui/widgets/../scrollarea.h \ + /usr/include/guichan/widgets/scrollarea.hpp gui/widgets/../listbox.h \ + /usr/include/guichan/widgets/listbox.hpp gui/widgets/../../graphics.h \ + /usr/include/guichan/sdl/sdlgraphics.hpp /usr/include/SDL/SDL.h \ + /usr/include/SDL/SDL_main.h /usr/include/SDL/SDL_stdinc.h \ + /usr/include/SDL/SDL_config.h /usr/include/SDL/SDL_platform.h \ + /usr/include/strings.h /usr/include/inttypes.h \ + /usr/include/SDL/begin_code.h /usr/include/SDL/close_code.h \ + /usr/include/SDL/SDL_audio.h /usr/include/SDL/SDL_error.h \ + /usr/include/SDL/SDL_endian.h /usr/include/SDL/SDL_mutex.h \ + /usr/include/SDL/SDL_thread.h /usr/include/SDL/SDL_rwops.h \ + /usr/include/SDL/SDL_cdrom.h /usr/include/SDL/SDL_cpuinfo.h \ + /usr/include/SDL/SDL_events.h /usr/include/SDL/SDL_active.h \ + /usr/include/SDL/SDL_keyboard.h /usr/include/SDL/SDL_keysym.h \ + /usr/include/SDL/SDL_mouse.h /usr/include/SDL/SDL_video.h \ + /usr/include/SDL/SDL_joystick.h /usr/include/SDL/SDL_quit.h \ + /usr/include/SDL/SDL_loadso.h /usr/include/SDL/SDL_timer.h \ + /usr/include/SDL/SDL_version.h /usr/include/guichan/color.hpp \ + /usr/include/guichan/graphics.hpp \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stack \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/deque \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_deque.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/deque.tcc \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_stack.h \ + /usr/include/guichan/cliprectangle.hpp \ + /usr/include/guichan/platform.hpp gui/widgets/../../graphic/imagerect.h \ + gui/widgets/../../resources/image.h \ + gui/widgets/../../resources/../main.h \ + gui/widgets/../../resources/../../config.h /usr/include/SDL/SDL.h \ + gui/widgets/../../resources/resource.h \ + gui/widgets/../../resources/resourcemanager.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/map \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tree.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_multimap.h \ + gui/widgets/../../utils/dtor.h \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/functional \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/utility \ + /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_relops.h + +gui/widgets/dropdown.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++config.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/os_defines.h: + +/usr/include/features.h: + +/usr/include/sys/cdefs.h: + +/usr/include/gnu/stubs.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/cpu_defines.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++locale.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstring: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstddef: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/include/stddef.h: + +/usr/include/string.h: + +/usr/include/xlocale.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdio: + +/usr/include/stdio.h: + +/usr/include/bits/types.h: + +/usr/include/bits/wordsize.h: + +/usr/include/bits/typesizes.h: + +/usr/include/libio.h: + +/usr/include/_G_config.h: + +/usr/include/wchar.h: + +/usr/include/bits/wchar.h: + +/usr/include/gconv.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/include/stdarg.h: + +/usr/include/bits/stdio_lim.h: + +/usr/include/bits/sys_errlist.h: + +/usr/include/bits/stdio.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/clocale: + +/usr/include/locale.h: + +/usr/include/bits/locale.h: + +/usr/include/langinfo.h: + +/usr/include/nl_types.h: + +/usr/include/iconv.h: + +/usr/include/libintl.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++io.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr-default.h: + +/usr/include/pthread.h: + +/usr/include/sched.h: + +/usr/include/time.h: + +/usr/include/bits/sched.h: + +/usr/include/bits/time.h: + +/usr/include/signal.h: + +/usr/include/bits/sigset.h: + +/usr/include/bits/pthreadtypes.h: + +/usr/include/bits/initspin.h: + +/usr/include/bits/sigthread.h: + +/usr/include/unistd.h: + +/usr/include/bits/posix_opt.h: + +/usr/include/bits/environments.h: + +/usr/include/bits/confname.h: + +/usr/include/getopt.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cctype: + +/usr/include/ctype.h: + +/usr/include/endian.h: + +/usr/include/bits/endian.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stringfwd.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/postypes.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cwchar: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ctime: + +/usr/include/stdint.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/functexcept.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception_defines.h: + +/usr/include/guichan/widgets/dropdown.hpp: + +/usr/include/guichan/actionlistener.hpp: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/string: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/char_traits.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/climits: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/include/syslimits.h: + +/usr/include/limits.h: + +/usr/include/bits/posix1_lim.h: + +/usr/include/bits/local_lim.h: + +/usr/include/linux/limits.h: + +/usr/include/bits/posix2_lim.h: + +/usr/include/bits/xopen_lim.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdlib: + +/usr/include/stdlib.h: + +/usr/include/bits/waitflags.h: + +/usr/include/bits/waitstatus.h: + +/usr/include/sys/types.h: + +/usr/include/sys/select.h: + +/usr/include/bits/select.h: + +/usr/include/sys/sysmacros.h: + +/usr/include/alloca.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_pair.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/cpp_type_traits.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_types.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_funcs.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/concept_check.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/debug/debug.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/memory: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++allocator.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/new: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_construct.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_uninitialized.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_raw_storage_iter.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/limits: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/atomicity.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/atomic_word.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/algorithm: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_heap.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tempbuf.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: + +/usr/include/guichan/platform.hpp: + +/usr/include/guichan/basiccontainer.hpp: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/list: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/list.tcc: + +/usr/include/guichan/widget.hpp: + +/usr/include/guichan/color.hpp: + +/usr/include/guichan/rectangle.hpp: + +/usr/include/guichan/focushandler.hpp: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/vector: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc: + +/usr/include/guichan/keylistener.hpp: + +/usr/include/guichan/listmodel.hpp: + +/usr/include/guichan/mouselistener.hpp: + +/usr/include/guichan/platform.hpp: + +/usr/include/guichan/widgets/listbox.hpp: + +/usr/include/guichan/widget.hpp: + +/usr/include/guichan/widgets/scrollarea.hpp: + +gui/widgets/../scrollarea.h: + +/usr/include/guichan/widgets/scrollarea.hpp: + +gui/widgets/../listbox.h: + +/usr/include/guichan/widgets/listbox.hpp: + +gui/widgets/../../graphics.h: + +/usr/include/guichan/sdl/sdlgraphics.hpp: + +/usr/include/SDL/SDL.h: + +/usr/include/SDL/SDL_main.h: + +/usr/include/SDL/SDL_stdinc.h: + +/usr/include/SDL/SDL_config.h: + +/usr/include/SDL/SDL_platform.h: + +/usr/include/strings.h: + +/usr/include/inttypes.h: + +/usr/include/SDL/begin_code.h: + +/usr/include/SDL/close_code.h: + +/usr/include/SDL/SDL_audio.h: + +/usr/include/SDL/SDL_error.h: + +/usr/include/SDL/SDL_endian.h: + +/usr/include/SDL/SDL_mutex.h: + +/usr/include/SDL/SDL_thread.h: + +/usr/include/SDL/SDL_rwops.h: + +/usr/include/SDL/SDL_cdrom.h: + +/usr/include/SDL/SDL_cpuinfo.h: + +/usr/include/SDL/SDL_events.h: + +/usr/include/SDL/SDL_active.h: + +/usr/include/SDL/SDL_keyboard.h: + +/usr/include/SDL/SDL_keysym.h: + +/usr/include/SDL/SDL_mouse.h: + +/usr/include/SDL/SDL_video.h: + +/usr/include/SDL/SDL_joystick.h: + +/usr/include/SDL/SDL_quit.h: + +/usr/include/SDL/SDL_loadso.h: + +/usr/include/SDL/SDL_timer.h: + +/usr/include/SDL/SDL_version.h: + +/usr/include/guichan/color.hpp: + +/usr/include/guichan/graphics.hpp: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stack: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/deque: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_deque.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/deque.tcc: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_stack.h: + +/usr/include/guichan/cliprectangle.hpp: + +/usr/include/guichan/platform.hpp: + +gui/widgets/../../graphic/imagerect.h: + +gui/widgets/../../resources/image.h: + +gui/widgets/../../resources/../main.h: + +gui/widgets/../../resources/../../config.h: + +/usr/include/SDL/SDL.h: + +gui/widgets/../../resources/resource.h: + +gui/widgets/../../resources/resourcemanager.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/map: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tree.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_multimap.h: + +gui/widgets/../../utils/dtor.h: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/functional: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/utility: + +/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_relops.h: diff --git a/src/gui/widgets/.dirstamp b/src/gui/widgets/.dirstamp new file mode 100644 index 00000000..e69de29b diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp new file mode 100644 index 00000000..34c6b93a --- /dev/null +++ b/src/gui/widgets/dropdown.cpp @@ -0,0 +1,191 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "dropdown.h" + +#include "../../graphics.h" + +#include "../../graphic/imagerect.h" + +#include "../../resources/image.h" +#include "../../resources/resourcemanager.h" + +#include "../../utils/dtor.h" + +int DropDown::instances = 0; +Image *DropDown::buttons[2][2]; +ImageRect DropDown::skin; + +DropDown::DropDown(gcn::ListModel *listModel, + gcn::ScrollArea *scrollArea, + gcn::ListBox *listBox): + gcn::DropDown::DropDown(listModel, + scrollArea, listBox) +{ + setBorderSize(2); + + // Initialize graphics + if (instances == 0) + { + // Load the background skin + ResourceManager *resman = ResourceManager::getInstance(); + + // Get the button skin + buttons[1][0] = + resman->getImage("graphics/gui/vscroll_up_default.png"); + buttons[0][0] = + resman->getImage("graphics/gui/vscroll_down_default.png"); + buttons[1][1] = + resman->getImage("graphics/gui/vscroll_up_pressed.png"); + buttons[0][1] = + resman->getImage("graphics/gui/vscroll_down_pressed.png"); + + // get the border skin + Image *boxBorder = resman->getImage("graphics/gui/deepbox.png"); + int gridx[4] = {0, 3, 28, 31}; + int gridy[4] = {0, 3, 28, 31}; + int a = 0, x, y; + + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + skin.grid[a] = boxBorder->getSubImage( + gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, + gridy[y + 1] - gridy[y] + 1); + a++; + } + } + + boxBorder->decRef(); + } + + instances++; +} + +DropDown::~DropDown() +{ + instances--; + // Free images memory + if (instances == 0) + { + buttons[0][0]->decRef(); + buttons[0][1]->decRef(); + buttons[1][0]->decRef(); + buttons[1][1]->decRef(); + + for_each(skin.grid, skin.grid + 9, dtor()); + } +} + +void DropDown::draw(gcn::Graphics* graphics) +{ + int h; + + if (mDroppedDown) + { + h = mOldH; + } + else + { + h = getHeight(); + } + + int alpha = getBaseColor().a; + gcn::Color faceColor = getBaseColor(); + faceColor.a = alpha; + gcn::Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + gcn::Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + + if (mListBox->getListModel() && mListBox->getSelected() >= 0) + { + graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); + } + + if (isFocused()) + { + graphics->setColor(highlightColor); + graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); + } + + drawButton(graphics); + + if (mDroppedDown) + { + drawChildren(graphics); + + // Draw two lines separating the ListBox with se selected + // element view. + graphics->setColor(highlightColor); + graphics->drawLine(0, h, getWidth(), h); + graphics->setColor(shadowColor); + graphics->drawLine(0, h + 1,getWidth(),h + 1); + } +} + +void DropDown::drawBorder(gcn::Graphics *graphics) +{ + int w, h, bs; + bs = getBorderSize(); + w = getWidth() + bs * 2; + h = getHeight() + bs * 2; + + dynamic_cast(graphics)->drawImageRect(0, 0, w, h, skin); +} + +void DropDown::drawButton(gcn::Graphics *graphics) +{ + + unsigned short state = 0; + unsigned short dir = 0; + gcn::Rectangle dim; + + if (mPushed) + state = 1; + + if (mDroppedDown) + dir = 1; + + int height; + if (mDroppedDown) + { + height = mOldH; + } + else + { + height = getHeight(); + } + int x = getWidth() - height; + int y = 0; + + dynamic_cast(graphics)->drawImage( + buttons[dir][state], x, y + 1); +} diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h new file mode 100644 index 00000000..37e754af --- /dev/null +++ b/src/gui/widgets/dropdown.h @@ -0,0 +1,85 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef DROPDOWN_H +#define DROPDOWN_H + +#include + +#include +#include "../scrollarea.h" +#include "../listbox.h" + +class Image; +class ImageRect; + + /** + * A drop down box from which you can select different values. It is one of + * the most complicated Widgets you will find in Guichan. For drawing the + * DroppedDown box it uses one ScrollArea and one ListBox. It also uses an + * internal FocusHandler to handle the focus of the internal ScollArea and + * ListBox. DropDown uses a ListModel to handle the list. To be able to use + * DropDown you must give DropDown an implemented ListModel which represents + * your list. + */ +class DropDown : public gcn::DropDown +{ + public: + /** + * Contructor. + * + * @param listModel the ListModel to use. + * @param scrollArea the ScrollArea to use. + * @param listBox the listBox to use. + * @see ListModel, ScrollArea, ListBox. + */ + DropDown(gcn::ListModel *listModel = NULL, + gcn::ScrollArea *scrollArea = NULL, + gcn::ListBox *listBox = NULL); + + /** + * Destructor. + */ + ~DropDown(); + + void draw(gcn::Graphics* graphics); + + void drawBorder(gcn::Graphics* graphics); + + + protected: + /** + * Draws the button with the little down arrow. + * + * @param graphics a Graphics object to draw with. + */ + void drawButton(gcn::Graphics *graphics); + + // Add own Images. + static int instances; + static Image *buttons[2][2]; + static ImageRect skin; +}; + +#endif // end DROPDOWN_H + -- cgit v1.2.3-70-g09d2 From 117573e3c4a60d17f56503e5adaae9e300e9b8b1 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 13 Sep 2006 20:21:17 +0000 Subject: --- src/gui/widgets/.deps/.dirstamp | 0 src/gui/widgets/.deps/dropdown.Po | 524 -------------------------------------- src/gui/widgets/.dirstamp | 0 3 files changed, 524 deletions(-) delete mode 100644 src/gui/widgets/.deps/.dirstamp delete mode 100644 src/gui/widgets/.deps/dropdown.Po delete mode 100644 src/gui/widgets/.dirstamp (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/.deps/.dirstamp b/src/gui/widgets/.deps/.dirstamp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/gui/widgets/.deps/dropdown.Po b/src/gui/widgets/.deps/dropdown.Po deleted file mode 100644 index 6a0726bb..00000000 --- a/src/gui/widgets/.deps/dropdown.Po +++ /dev/null @@ -1,524 +0,0 @@ -gui/widgets/dropdown.o gui/widgets/dropdown.o: gui/widgets/dropdown.cpp \ - gui/widgets/dropdown.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++config.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/os_defines.h \ - /usr/include/features.h /usr/include/sys/cdefs.h \ - /usr/include/gnu/stubs.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/cpu_defines.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++locale.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstring \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstddef \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/include/stddef.h \ - /usr/include/string.h /usr/include/xlocale.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdio \ - /usr/include/stdio.h /usr/include/bits/types.h \ - /usr/include/bits/wordsize.h /usr/include/bits/typesizes.h \ - /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ - /usr/include/bits/wchar.h /usr/include/gconv.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/include/stdarg.h \ - /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ - /usr/include/bits/stdio.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/clocale \ - /usr/include/locale.h /usr/include/bits/locale.h \ - /usr/include/langinfo.h /usr/include/nl_types.h /usr/include/iconv.h \ - /usr/include/libintl.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++io.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr-default.h \ - /usr/include/pthread.h /usr/include/sched.h /usr/include/time.h \ - /usr/include/bits/sched.h /usr/include/bits/time.h \ - /usr/include/signal.h /usr/include/bits/sigset.h \ - /usr/include/bits/pthreadtypes.h /usr/include/bits/initspin.h \ - /usr/include/bits/sigthread.h /usr/include/unistd.h \ - /usr/include/bits/posix_opt.h /usr/include/bits/environments.h \ - /usr/include/bits/confname.h /usr/include/getopt.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cctype \ - /usr/include/ctype.h /usr/include/endian.h /usr/include/bits/endian.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stringfwd.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/postypes.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cwchar \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ctime \ - /usr/include/stdint.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/functexcept.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception_defines.h \ - /usr/include/guichan/widgets/dropdown.hpp \ - /usr/include/guichan/actionlistener.hpp \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/string \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/char_traits.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/climits \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/include/syslimits.h \ - /usr/include/limits.h /usr/include/bits/posix1_lim.h \ - /usr/include/bits/local_lim.h /usr/include/linux/limits.h \ - /usr/include/bits/posix2_lim.h /usr/include/bits/xopen_lim.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdlib \ - /usr/include/stdlib.h /usr/include/bits/waitflags.h \ - /usr/include/bits/waitstatus.h /usr/include/sys/types.h \ - /usr/include/sys/select.h /usr/include/bits/select.h \ - /usr/include/sys/sysmacros.h /usr/include/alloca.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_pair.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/cpp_type_traits.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_types.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_funcs.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/concept_check.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/debug/debug.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/memory \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++allocator.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/new \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_construct.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_uninitialized.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_raw_storage_iter.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/limits \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/atomicity.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/atomic_word.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/algorithm \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_heap.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tempbuf.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc \ - /usr/include/guichan/platform.hpp \ - /usr/include/guichan/basiccontainer.hpp \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/list \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/list.tcc \ - /usr/include/guichan/widget.hpp /usr/include/guichan/color.hpp \ - /usr/include/guichan/rectangle.hpp \ - /usr/include/guichan/focushandler.hpp \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/vector \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc \ - /usr/include/guichan/keylistener.hpp /usr/include/guichan/listmodel.hpp \ - /usr/include/guichan/mouselistener.hpp \ - /usr/include/guichan/platform.hpp \ - /usr/include/guichan/widgets/listbox.hpp \ - /usr/include/guichan/widget.hpp \ - /usr/include/guichan/widgets/scrollarea.hpp gui/widgets/../scrollarea.h \ - /usr/include/guichan/widgets/scrollarea.hpp gui/widgets/../listbox.h \ - /usr/include/guichan/widgets/listbox.hpp gui/widgets/../../graphics.h \ - /usr/include/guichan/sdl/sdlgraphics.hpp /usr/include/SDL/SDL.h \ - /usr/include/SDL/SDL_main.h /usr/include/SDL/SDL_stdinc.h \ - /usr/include/SDL/SDL_config.h /usr/include/SDL/SDL_platform.h \ - /usr/include/strings.h /usr/include/inttypes.h \ - /usr/include/SDL/begin_code.h /usr/include/SDL/close_code.h \ - /usr/include/SDL/SDL_audio.h /usr/include/SDL/SDL_error.h \ - /usr/include/SDL/SDL_endian.h /usr/include/SDL/SDL_mutex.h \ - /usr/include/SDL/SDL_thread.h /usr/include/SDL/SDL_rwops.h \ - /usr/include/SDL/SDL_cdrom.h /usr/include/SDL/SDL_cpuinfo.h \ - /usr/include/SDL/SDL_events.h /usr/include/SDL/SDL_active.h \ - /usr/include/SDL/SDL_keyboard.h /usr/include/SDL/SDL_keysym.h \ - /usr/include/SDL/SDL_mouse.h /usr/include/SDL/SDL_video.h \ - /usr/include/SDL/SDL_joystick.h /usr/include/SDL/SDL_quit.h \ - /usr/include/SDL/SDL_loadso.h /usr/include/SDL/SDL_timer.h \ - /usr/include/SDL/SDL_version.h /usr/include/guichan/color.hpp \ - /usr/include/guichan/graphics.hpp \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stack \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/deque \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_deque.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/deque.tcc \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_stack.h \ - /usr/include/guichan/cliprectangle.hpp \ - /usr/include/guichan/platform.hpp gui/widgets/../../graphic/imagerect.h \ - gui/widgets/../../resources/image.h \ - gui/widgets/../../resources/../main.h \ - gui/widgets/../../resources/../../config.h /usr/include/SDL/SDL.h \ - gui/widgets/../../resources/resource.h \ - gui/widgets/../../resources/resourcemanager.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/map \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tree.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_multimap.h \ - gui/widgets/../../utils/dtor.h \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/functional \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/utility \ - /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_relops.h - -gui/widgets/dropdown.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++config.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/os_defines.h: - -/usr/include/features.h: - -/usr/include/sys/cdefs.h: - -/usr/include/gnu/stubs.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/cpu_defines.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++locale.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstring: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstddef: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/include/stddef.h: - -/usr/include/string.h: - -/usr/include/xlocale.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdio: - -/usr/include/stdio.h: - -/usr/include/bits/types.h: - -/usr/include/bits/wordsize.h: - -/usr/include/bits/typesizes.h: - -/usr/include/libio.h: - -/usr/include/_G_config.h: - -/usr/include/wchar.h: - -/usr/include/bits/wchar.h: - -/usr/include/gconv.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/include/stdarg.h: - -/usr/include/bits/stdio_lim.h: - -/usr/include/bits/sys_errlist.h: - -/usr/include/bits/stdio.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/clocale: - -/usr/include/locale.h: - -/usr/include/bits/locale.h: - -/usr/include/langinfo.h: - -/usr/include/nl_types.h: - -/usr/include/iconv.h: - -/usr/include/libintl.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++io.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/gthr-default.h: - -/usr/include/pthread.h: - -/usr/include/sched.h: - -/usr/include/time.h: - -/usr/include/bits/sched.h: - -/usr/include/bits/time.h: - -/usr/include/signal.h: - -/usr/include/bits/sigset.h: - -/usr/include/bits/pthreadtypes.h: - -/usr/include/bits/initspin.h: - -/usr/include/bits/sigthread.h: - -/usr/include/unistd.h: - -/usr/include/bits/posix_opt.h: - -/usr/include/bits/environments.h: - -/usr/include/bits/confname.h: - -/usr/include/getopt.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cctype: - -/usr/include/ctype.h: - -/usr/include/endian.h: - -/usr/include/bits/endian.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stringfwd.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/postypes.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cwchar: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ctime: - -/usr/include/stdint.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/functexcept.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception_defines.h: - -/usr/include/guichan/widgets/dropdown.hpp: - -/usr/include/guichan/actionlistener.hpp: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/string: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/char_traits.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/climits: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/include/syslimits.h: - -/usr/include/limits.h: - -/usr/include/bits/posix1_lim.h: - -/usr/include/bits/local_lim.h: - -/usr/include/linux/limits.h: - -/usr/include/bits/posix2_lim.h: - -/usr/include/bits/xopen_lim.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/cstdlib: - -/usr/include/stdlib.h: - -/usr/include/bits/waitflags.h: - -/usr/include/bits/waitstatus.h: - -/usr/include/sys/types.h: - -/usr/include/sys/select.h: - -/usr/include/bits/select.h: - -/usr/include/sys/sysmacros.h: - -/usr/include/alloca.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_pair.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/cpp_type_traits.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_types.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator_base_funcs.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/concept_check.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/debug/debug.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/memory: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/c++allocator.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/new: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/exception: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_construct.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_uninitialized.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_raw_storage_iter.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/limits: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/atomicity.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu/bits/atomic_word.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/algorithm: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_heap.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tempbuf.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.tcc: - -/usr/include/guichan/platform.hpp: - -/usr/include/guichan/basiccontainer.hpp: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/list: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/list.tcc: - -/usr/include/guichan/widget.hpp: - -/usr/include/guichan/color.hpp: - -/usr/include/guichan/rectangle.hpp: - -/usr/include/guichan/focushandler.hpp: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/vector: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc: - -/usr/include/guichan/keylistener.hpp: - -/usr/include/guichan/listmodel.hpp: - -/usr/include/guichan/mouselistener.hpp: - -/usr/include/guichan/platform.hpp: - -/usr/include/guichan/widgets/listbox.hpp: - -/usr/include/guichan/widget.hpp: - -/usr/include/guichan/widgets/scrollarea.hpp: - -gui/widgets/../scrollarea.h: - -/usr/include/guichan/widgets/scrollarea.hpp: - -gui/widgets/../listbox.h: - -/usr/include/guichan/widgets/listbox.hpp: - -gui/widgets/../../graphics.h: - -/usr/include/guichan/sdl/sdlgraphics.hpp: - -/usr/include/SDL/SDL.h: - -/usr/include/SDL/SDL_main.h: - -/usr/include/SDL/SDL_stdinc.h: - -/usr/include/SDL/SDL_config.h: - -/usr/include/SDL/SDL_platform.h: - -/usr/include/strings.h: - -/usr/include/inttypes.h: - -/usr/include/SDL/begin_code.h: - -/usr/include/SDL/close_code.h: - -/usr/include/SDL/SDL_audio.h: - -/usr/include/SDL/SDL_error.h: - -/usr/include/SDL/SDL_endian.h: - -/usr/include/SDL/SDL_mutex.h: - -/usr/include/SDL/SDL_thread.h: - -/usr/include/SDL/SDL_rwops.h: - -/usr/include/SDL/SDL_cdrom.h: - -/usr/include/SDL/SDL_cpuinfo.h: - -/usr/include/SDL/SDL_events.h: - -/usr/include/SDL/SDL_active.h: - -/usr/include/SDL/SDL_keyboard.h: - -/usr/include/SDL/SDL_keysym.h: - -/usr/include/SDL/SDL_mouse.h: - -/usr/include/SDL/SDL_video.h: - -/usr/include/SDL/SDL_joystick.h: - -/usr/include/SDL/SDL_quit.h: - -/usr/include/SDL/SDL_loadso.h: - -/usr/include/SDL/SDL_timer.h: - -/usr/include/SDL/SDL_version.h: - -/usr/include/guichan/color.hpp: - -/usr/include/guichan/graphics.hpp: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/stack: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/deque: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_deque.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/deque.tcc: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_stack.h: - -/usr/include/guichan/cliprectangle.hpp: - -/usr/include/guichan/platform.hpp: - -gui/widgets/../../graphic/imagerect.h: - -gui/widgets/../../resources/image.h: - -gui/widgets/../../resources/../main.h: - -gui/widgets/../../resources/../../config.h: - -/usr/include/SDL/SDL.h: - -gui/widgets/../../resources/resource.h: - -gui/widgets/../../resources/resourcemanager.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/map: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_tree.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_multimap.h: - -gui/widgets/../../utils/dtor.h: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/functional: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/utility: - -/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_relops.h: diff --git a/src/gui/widgets/.dirstamp b/src/gui/widgets/.dirstamp deleted file mode 100644 index e69de29b..00000000 -- cgit v1.2.3-70-g09d2 From dd96213cdf64c5481c8d07dbd39ce1247f42d04e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 5 Nov 2006 18:41:34 +0000 Subject: Merged the definition of ImageRect into graphics.h. --- ChangeLog | 6 ++++++ src/CMakeLists.txt | 1 - src/Makefile.am | 3 +-- src/graphic/imagerect.h | 50 -------------------------------------------- src/graphics.cpp | 2 -- src/graphics.h | 21 +++++++++++++++++++ src/gui/button.cpp | 2 -- src/gui/playerbox.cpp | 2 -- src/gui/progressbar.cpp | 2 -- src/gui/scrollarea.cpp | 2 -- src/gui/textfield.cpp | 2 -- src/gui/widgets/dropdown.cpp | 24 ++++++++++----------- src/gui/window.cpp | 2 -- 13 files changed, 39 insertions(+), 80 deletions(-) delete mode 100644 src/graphic/imagerect.h (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 16171bd1..531a8c25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,12 @@ wallpaper. * src/resources/resourcemanager.cpp: More useful logging about resources that are being loaded (including source). + * src/graphics.cpp, src/gui/window.cpp, src/gui/button.cpp, + src/gui/widgets/dropdown.cpp, src/gui/textfield.cpp, + src/gui/playerbox.cpp, src/gui/progressbar.cpp, + src/gui/scrollarea.cpp, src/graphics.h, src/CMakeLists.txt, + src/Makefile.am, src/graphic, src/graphic/imagerect.h: Merged the + definition of ImageRect into graphics.h. 2006-11-05 Yohann Ferreira diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8523b066..4fd8d880 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,7 +36,6 @@ INCLUDE_DIRECTORIES( ) SET(SRCS - graphic/imagerect.h gui/box.cpp gui/box.h gui/browserbox.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 5c8d77a0..09348700 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,8 +1,7 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = tmw -tmw_SOURCES = graphic/imagerect.h \ - gui/widgets/dropdown.cpp \ +tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/dropdown.h \ gui/browserbox.cpp \ gui/browserbox.h \ diff --git a/src/graphic/imagerect.h b/src/graphic/imagerect.h deleted file mode 100644 index be63d4ac..00000000 --- a/src/graphic/imagerect.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_IMAGERECT_H -#define _TMW_IMAGERECT_H - -class Image; - -/** - * 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The - * topology is as follows: - * - *
- *  !-----!-----------------!-----!
- *  !  0  !        1        !  2  !
- *  !-----!-----------------!-----!
- *  !  3  !        4        !  5  !
- *  !-----!-----------------!-----!
- *  !  6  !        7        !  8  !
- *  !-----!-----------------!-----!
- * 
- * - * Sections 0, 2, 6 and 8 will remain as is. 1, 3, 4, 5 and 7 will be - * repeated to fit the size of the widget. - */ -struct ImageRect { - Image *grid[9]; -}; - -#endif diff --git a/src/graphics.cpp b/src/graphics.cpp index 2757214a..065c0a46 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -25,8 +25,6 @@ #include "log.h" -#include "graphic/imagerect.h" - #include "resources/image.h" Graphics::Graphics(): diff --git a/src/graphics.h b/src/graphics.h index 3c060e97..b3d36653 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -31,6 +31,27 @@ class ImageRect; class SDL_Surface; +/** + * 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The + * topology is as follows: + * + *
+ *  !-----!-----------------!-----!
+ *  !  0  !        1        !  2  !
+ *  !-----!-----------------!-----!
+ *  !  3  !        4        !  5  !
+ *  !-----!-----------------!-----!
+ *  !  6  !        7        !  8  !
+ *  !-----!-----------------!-----!
+ * 
+ * + * Sections 0, 2, 6 and 8 will remain as is. 1, 3, 4, 5 and 7 will be + * repeated to fit the size of the widget. + */ +struct ImageRect { + Image *grid[9]; +}; + /** * A central point of control for graphics. */ diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 9d01095b..31f38593 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -29,8 +29,6 @@ #include "../graphics.h" -#include "../graphic/imagerect.h" - #include "../resources/image.h" #include "../resources/resourcemanager.h" diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index 46cd7e85..568c3350 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -26,8 +26,6 @@ #include "../being.h" #include "../graphics.h" -#include "../graphic/imagerect.h" - #include "../resources/image.h" #include "../resources/resourcemanager.h" #include "../resources/spriteset.h" diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 5f047c6a..2bdfc856 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -25,8 +25,6 @@ #include "../graphics.h" -#include "../graphic/imagerect.h" - #include "../resources/image.h" #include "../resources/resourcemanager.h" diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 18a1dfb4..903ec95d 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -25,8 +25,6 @@ #include "../graphics.h" -#include "../graphic/imagerect.h" - #include "../resources/image.h" #include "../resources/resourcemanager.h" diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 2e083d5a..adf41a9a 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -27,8 +27,6 @@ #include "../graphics.h" -#include "../graphic/imagerect.h" - #include "../resources/image.h" #include "../resources/resourcemanager.h" diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 34c6b93a..0bf0e673 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -25,8 +25,6 @@ #include "../../graphics.h" -#include "../../graphic/imagerect.h" - #include "../../resources/image.h" #include "../../resources/resourcemanager.h" @@ -138,17 +136,17 @@ void DropDown::draw(gcn::Graphics* graphics) drawButton(graphics); - if (mDroppedDown) - { - drawChildren(graphics); - - // Draw two lines separating the ListBox with se selected - // element view. - graphics->setColor(highlightColor); - graphics->drawLine(0, h, getWidth(), h); - graphics->setColor(shadowColor); - graphics->drawLine(0, h + 1,getWidth(),h + 1); - } + if (mDroppedDown) + { + drawChildren(graphics); + + // Draw two lines separating the ListBox with se selected + // element view. + graphics->setColor(highlightColor); + graphics->drawLine(0, h, getWidth(), h); + graphics->setColor(shadowColor); + graphics->drawLine(0, h + 1,getWidth(),h + 1); + } } void DropDown::drawBorder(gcn::Graphics *graphics) diff --git a/src/gui/window.cpp b/src/gui/window.cpp index c7860021..13d42c78 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -33,8 +33,6 @@ #include "../graphics.h" #include "../log.h" -#include "../graphic/imagerect.h" - #include "../resources/image.h" #include "../resources/resourcemanager.h" -- cgit v1.2.3-70-g09d2 From a353543dd4da3c489a84f6f17125fdd0e1be2349 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 4 Jun 2007 21:48:47 +0000 Subject: Merged 0.0 changes from revision 3234 to 3317 to trunk. --- ChangeLog | 465 ++++++++++++++++++++++++++++- NEWS | 16 + README | 3 +- data/graphics/gui/CMakeLists.txt | 8 +- data/graphics/gui/Makefile.am | 6 + data/graphics/gui/target-cursor-blue-l.png | Bin 0 -> 23803 bytes data/graphics/gui/target-cursor-blue-m.png | Bin 0 -> 18439 bytes data/graphics/gui/target-cursor-blue-s.png | Bin 0 -> 8353 bytes data/graphics/gui/target-cursor-blue.png | Bin 8353 -> 0 bytes data/graphics/gui/target-cursor-red-l.png | Bin 0 -> 25586 bytes data/graphics/gui/target-cursor-red-m.png | Bin 0 -> 17950 bytes data/graphics/gui/target-cursor-red-s.png | Bin 0 -> 8361 bytes data/graphics/gui/target-cursor-red.png | Bin 8361 -> 0 bytes data/help/changes.txt | 147 ++++----- data/help/header.txt | 2 +- docs/Makefile.am | 3 +- src/CMakeLists.txt | 14 + src/Makefile.am | 16 +- src/animatedsprite.cpp | 24 ++ src/animatedsprite.h | 12 + src/animationparticle.cpp | 51 ++++ src/animationparticle.h | 49 +++ src/being.cpp | 122 +++++--- src/being.h | 36 ++- src/engine.cpp | 7 + src/game.cpp | 24 +- src/graphics.cpp | 2 - src/gui/buy.cpp | 117 +++----- src/gui/buy.h | 6 + src/gui/chat.cpp | 4 +- src/gui/chat.h | 4 +- src/gui/debugwindow.cpp | 10 + src/gui/debugwindow.h | 1 + src/gui/inventorywindow.cpp | 7 +- src/gui/sell.cpp | 159 +++++----- src/gui/sell.h | 6 + src/gui/updatewindow.cpp | 7 +- src/gui/viewport.cpp | 108 ++++--- src/gui/viewport.h | 20 +- src/gui/widgets/resizegrip.cpp | 65 ++++ src/gui/widgets/resizegrip.h | 61 ++++ src/gui/window.cpp | 185 ++++++++---- src/gui/window.h | 66 ++-- src/imageparticle.cpp | 69 +++++ src/imageparticle.h | 61 ++++ src/main.cpp | 26 +- src/map.cpp | 23 ++ src/map.h | 25 +- src/monster.cpp | 6 + src/monster.h | 3 + src/net/beinghandler.cpp | 17 +- src/openglgraphics.cpp | 24 +- src/particle.cpp | 370 +++++++++++++++++++++++ src/particle.h | 288 ++++++++++++++++++ src/particleemitter.cpp | 327 ++++++++++++++++++++ src/particleemitter.h | 120 ++++++++ src/resources/animation.h | 2 +- src/resources/image.cpp | 25 +- src/resources/mapreader.cpp | 24 ++ src/resources/monsterdb.cpp | 21 ++ src/resources/monsterinfo.h | 14 +- src/simpleanimation.cpp | 85 ++++++ src/simpleanimation.h | 15 +- src/sprite.h | 16 + src/textparticle.cpp | 64 ++++ src/textparticle.h | 53 ++++ src/utils/fastsqrt.h | 24 ++ src/utils/minmax.h | 47 +++ src/utils/wingettimeofday.h | 226 +++++++------- src/utils/xml.cpp | 23 ++ src/utils/xml.h | 11 + 71 files changed, 3240 insertions(+), 602 deletions(-) create mode 100644 data/graphics/gui/target-cursor-blue-l.png create mode 100644 data/graphics/gui/target-cursor-blue-m.png create mode 100644 data/graphics/gui/target-cursor-blue-s.png delete mode 100644 data/graphics/gui/target-cursor-blue.png create mode 100644 data/graphics/gui/target-cursor-red-l.png create mode 100644 data/graphics/gui/target-cursor-red-m.png create mode 100644 data/graphics/gui/target-cursor-red-s.png delete mode 100644 data/graphics/gui/target-cursor-red.png create mode 100644 src/animationparticle.cpp create mode 100644 src/animationparticle.h create mode 100644 src/gui/widgets/resizegrip.cpp create mode 100644 src/gui/widgets/resizegrip.h create mode 100644 src/imageparticle.cpp create mode 100644 src/imageparticle.h create mode 100644 src/particle.cpp create mode 100644 src/particle.h create mode 100644 src/particleemitter.cpp create mode 100644 src/particleemitter.h create mode 100644 src/textparticle.cpp create mode 100644 src/textparticle.h create mode 100644 src/utils/fastsqrt.h create mode 100644 src/utils/minmax.h (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 61aef963..63aaa1eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,162 @@ +2007-06-03 David Athay + + * src/main.cpp, src/game.cpp: Fixed screenshot taking on OSX. + +2007-06-03 Bjørn Lindeijer + + * src/CMakeLists.txt, src/Makefile.am, docs/Makefile.am: Added some + files to be included with the release. + * src/utils/fastsqrt.h: Fixed warning about strict-aliasing rules. + * src/Makefile.am: Don't die on warnings by default. + * src/resources/image.cpp: Fixed image loading in software mode to not + check for alpha layer when images aren't 32-bit. + * src/graphics.cpp, src/graphics.h, src/imageparticle.cpp: Removed + drawImageTransparent from Graphics class, should be set on image. + * src/imageparticle.h, src/particleemitter.h, src/particle.h, + src/particleemitter.cpp, src/particle.cpp, src/imageparticle.cpp: Have + ParticleEmitter load a possible particle image early on and don't + cause a crash when the image can't be found. + +2007-06-02 Bjørn Lindeijer + + * src/winver.h, README, NEWS, CMakeLists.txt, configure.ac, + data/help/changes.txt, data/help/header.txt: Updated version and + release date and summarized changes. + * src/gui/chat.h, src/gui/chat.cpp: Changed color of chat messages in + OpenGL mode from orange to black. + * src/gui/sell.cpp, src/gui/buy.h, src/gui/buy.cpp, src/gui/sell.h: + Some cleanup of buy/sell dialog code. + +2007-06-01 Bjørn Lindeijer + + * data/graphics/gui/CMakeLists.txt, data/graphics/gui/Makefile.am: + Added target cursors to installed files. + +2007-05-31 Philipp Sehmisch + + * data/maps/new_16-1.tmx.gz: Fixed an inconsistency with the neighbor + map (no new walkmap required). + +2007-05-23 Bjørn Lindeijer + + * src/gui/sell.cpp, src/gui/buy.cpp, src/being.cpp: A bunch of + lingering syntactical changes. + * src/gui/viewport.cpp: Added a missing include and fixed a bug with + cleaning up target cursor animations. + +2007-05-23 Philipp Sehmisch + + * src/gui/viewport.cpp, + data/graphics/gui/target-cursor-blue-s.png, + data/graphics/gui/target-cursor-blue-m.png, + data/graphics/gui/target-cursor-blue-l.png, + data/graphics/gui/target-cursor-red-s.png, + data/graphics/gui/target-cursor-red-m.png, + data/graphics/gui/target-cursor-red-l.png: Replaced target cursor + graphics with higher quality ones by Pauan. + * src/particle.cpp: Made bouncing particles immune against death by + ground contact and removed a nonsensical debugging log message. Made + text splash effects fade out. + * src/textparticle.cpp: Implemented fading in and out for text + particles. + * src/being.cpp, src/particle.cpp, src/particle.h, + src/textparticle.cpp, src/textparticle.h: The color values of text + particles are now stored in 3 integers instead of a Guichan color + structure. + +2007-05-20 Eugenio Favalli + + * tmw.cbp: Updated Code::Blocks project file. + +2007-05-20 Philipp Sehmisch + + * src/gui/buy.cpp, src/gui/sell.cpp: Unified some differences between + buy and sell dialog. Money label now shows money after transaction + instead of current money. + * src/gui/sell.cpp: Fixed the amount-not-reset-when-using-scrollwheel + bug. + * src/being.h, src/gui/viewport.cpp, src/gui/viewport.h: Added 3 + different target cursor sizes. + * src/monster.h, src/monster.cpp, src/resources/monsterdb.cpp, + scr/resources/monsterinfo.h, data/monsters.xml: Target cursor size for + monster is read from the monsters.xml. + * data/graphics/gui/target-cursor-blue-s.png, + data/graphics/gui/target-cursor-blue-m.png, + data/graphics/gui/target-cursor-blue-l.png, + data/graphics/gui/target-cursor-red-s.png, + data/graphics/gui/target-cursor-red-m.png, + data/graphics/gui/target-cursor-red-l.png: Added temporary + placeholders for small and large target cursors until better versions + based on the original SVG are available. + +2007-05-08 Philipp Sehmisch + + * data/graphics/sprites/monster-bat.png, + data/graphics/sprites/monster-bat.xml, + data/graphics/sprites/monster-flower.xml, + data/graphics/sprites/monster-fluffy.xml, + data/graphics/sprites/monster-fluffy.png, + data/graphics/sprites/monster-goblin-fire.xml, + data/graphics/sprites/monster-maggot-giant.xml, + data/graphics/sprites/monster-maggot.xml, + data/graphics/sprites/monster-mountsnake.xml, + data/graphics/sprites/monster-mushroom-red.xml, + data/graphics/sprites/monster-mushroom-spiky.xml, + data/graphics/sprites/monster-pinkie.xml, + data/graphics/sprites/monster-scorpion-black.xml, + data/graphics/sprites/monster-scorpion-red.png, + data/graphics/sprites/monster-scorpion-red.xml, + data/graphics/sprites/monster-skull-poison.xml, + data/graphics/sprites/monster-slime-green.xml, + data/graphics/sprites/monster-slime-red.xml, + data/graphics/sprites/monster-slime-rudolph.xml, + data/graphics/sprites/monster-slime-santa.png, + data/graphics/sprites/monster-slime-santa.xml, + data/graphics/sprites/monster-slime-yellow.xml, + data/graphics/sprites/monster-snake-cave.png, + data/graphics/sprites/monster-snake-cave.xml, + data/graphics/sprites/monster-snake.xml, + data/graphics/sprites/monster-spider.xml: + Adjusted offsets of monster sprites (thanks to Pauan for finding out + the correct offsets - I just subtracted 6 of all x offsets to take the + new position of the target circle in account) and committed some + modifications at some monster graphics by Pauan. + +2007-05-02 Philipp Sehmisch + + * src/sprite.h, src/being.cpp, src/being.h, src/animatedsprite.cpp, + src/animatedsprite.h: Added methods to get the width and height of the + graphical representation of a sprite. + * src/gui/viewport.cpp: Fixed positioning of monster names and target + circles. + +2007-05-02 Philipp Sehmisch + + * src/particle.cpp: Fixed a compiler warning. + +2007-05-02 Björn Steinbrink + + * src/Makefile.am: Add the new particle subclasses to the automake + configuration. + * src/imageparticle.h, src/textparticle.h, src/particle.h, + src/animationparticle.h, src/CMakeLists.txt, src/particleemitter.cpp, + src/animationparticle.cpp, src/particle.cpp, src/imageparticle.cpp, + src/textparticle.cpp, src/utils/xml.cpp, src/utils/xml.h: Split the + particle class into subclasses based on their appearance. + +2007-04-24 Philipp Sehmisch + + * src/particle.cpp, src/particle.h: Some minor code cleanups, speed + optimizations and a bit of documentation. + +2007-04-23 Philipp Sehmisch + + * data/graphics/particles/flame.particle.xml, + data/graphics/particles/blaze.png: Added two files I forgot with the + last commit. + * src/resources/mapreader.cpp, src/particle.cpp, + src/particleemitter.cpp: Using XML child node iteration macro. + 2007-04-22 Björn Steinbrink * CMake/Modules/FindENet.cmake: Fixed ENet status always being set to @@ -10,11 +169,74 @@ * src/resources/itemdb.cpp: Made the parameter checks more terse and manageable. +2007-04-19 Philipp Sehmisch + + * src/resources/mapreader.cpp: Emitter positions are now read from map + files. + * src/engine.cpp: Removed the player follow effect used for testing. + * data/maps/new_4-1.tmx.gz, data/maps/new_5-1.tmx.gz: Added flame + effect to all lamps on the cave maps + * data/maps/new_9-1.tmx.gz: Added waterfall effect to the upper right + corner of NW woodland map. + +2007-04-15 Bjørn Lindeijer + + * src/openglgraphics.cpp: Rely on default 0 value for z axis. + * src/CMakeLists.txt, src/gui/window.cpp, src/gui/widgets, + src/gui/widgets/resizegrip.cpp, src/gui/widgets/resizegrip.h, + src/gui/inventorywindow.cpp, src/gui/window.h, src/Makefile.am: + Reimplemented window resizing. It is now once again possible to resize + windows using their borders (except for the top one, since that's the + title bar for Guichan) and the resize grip in the bottom right is much + easier to grab. + * src/gui/window.cpp: Increased minimum window height and fixed a + problem with setting window content size which was introduced with the + new resize grip. + 2007-04-13 Björn Steinbrink * data/graphics/gui/CMakeLists.txt: Added target cursor graphics to the set of files to be installed. +2007-04-05 Eugenio Favalli + + * src/main.cpp: Unified storage of configuration, updates and + screenshots in home directory. + +2007-04-03 Philipp Sehmisch + + * data/graphics/items/generic-easteregg-blue.png, + data/graphics/items/generic-easteregg-green.png, + data/graphics/items/generic-easteregg-pink.png, + data/graphics/items/generic-easteregg-red.png, + data/graphics/items/generic-easteregg-teal.png, + data/graphics/items/generic-easteregg-yellow.png, + data/items.xml: Added six different easter egg item graphics for the + easter event. Item IDs are 1208 - 1213. + * data/graphics/sprites/npcs.png: Added bunny girl npc for the easter + event. + +2007-04-01 Philipp Sehmisch + + * src/game.cpp: Screenshots are no longer saved directly in the users + home directory on UNIX systems but in the sub folder /.tmw/. A chatlog + message about the success of the screenshot saving does appear now. + Based on a patch by Patrick "the-me" Matthäi. + +2007-03-27 Bjørn Lindeijer + + * src/main.cpp: Icon loading doesn't necessarily succeed, so better + not crash when it doesn't. + +2007-03-25 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Improved programming style and documentation + and added some small tweaks. + * src/engine.cpp, src/map.cpp, src/map.h, src/resources/mapreader.cpp: + Prepared getting the emitter positions from the map file by storing + them in the Map class and setting them up from the MapReader. + 2007-03-24 Bjørn Lindeijer * src/main.cpp: Changed the order of network message handling and @@ -49,6 +271,16 @@ src/net/charserverhandler.h, src/net/charserverhandler.cpp: Made sure the character creation dialog doesn't close when creation failed. +2007-03-22 Philipp Sehmisch + + * src/simpleanimation.cpp, src/simpleanimation.h: Added new + constructor for simple animation that allows to build the animation + based on an xmlNodePtr pointing to an node. + * src/particle.cpp, src/particle.h: Added support for and + childtags for effect root particles. + * data/graphics/particles/playerglow.particle.xml: New player follow + effect that demonstrates an animated root particle with an emitter. + 2007-03-22 Bjørn Lindeijer * src/gui/login.cpp, src/gui/login.h, src/gui/register.h, @@ -84,6 +316,11 @@ src/resources/resourcemanager.cpp, src/resources/spriteset.cpp, src/resources/spritedef.h: Renamed Spriteset to ImageSet. +2007-03-20 Philipp Sehmisch + + * src/gui/updatewindow.cpp: Cancel button is now disabled after + downloading is finished. + 2007-03-20 David Athay * src/gui/viewport.cpp: Fixed target cursor animation, and changed @@ -160,6 +397,8 @@ * src/simpleanimation.cpp, src/simpleanimation.h, src/CmakeLists.txt, src/Makefile.am: Added a simple animation class that hosts a looping animation without the action and direction stuff from AnimatedSprite. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp: Used said + simple animation class for animated particles. 2007-03-12 Bjørn Lindeijer @@ -171,6 +410,14 @@ * src/map.cpp, src/gui/viewport.cpp: Fixed a bug that made the engine not draw the last row and column of the map. +2007-03-09 Philipp Sehmisch + + * src/particle.cpp: Reimplemented physics mode that uses the default + square root function as fallback for systems where the fastInvSqrt + function doesn't work properly. + * src/particle.cpp, src/particle.h: Some performance optimizations + suggested by Rogier "Avaniel" Polak. + 2007-03-09 Bjørn Lindeijer * data/graphics/gui/target-cursor-blue.png, @@ -221,6 +468,10 @@ data/sfx/pinkie-hit1.ogg, data/sfx/pinkie-miss1.ogg, data/monsters.xml: New sound effects by Cosmostrator. +2007-02-25 Philipp Sehmisch + + * src/particle.h, src/particleemitter.h: Just some documentation work. + 2007-02-25 Bjørn Lindeijer * src/CMakeLists.txt: Updated CMake file. @@ -247,6 +498,12 @@ size and data type. * src/logindata.h: Added a clear function. +2007-02-22 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added new particle property "bounce" that makes + particles bounce off the ground and use it with the damage numbers. + 2007-02-21 Philipp Sehmisch * src/gui/char-server.cpp, src/gui/updatewindow.cpp, src/gui/main.cpp, @@ -286,6 +543,16 @@ * src/winver.h, README, configure.ac, data/help/header.txt, NEWS, CMakeLists.txt: Changed version to 0.0.22.2. +2007-02-15 Philipp Sehmisch + + * src/engine.cpp: The name conflict problem with Guichan seems to be + solved with version 0.6.1. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added support for animated particles. + * data/graphics/particles/playerglow.particle.xml: Created a new + player follow particle that spawns a swarm of animated bats that + follow the player. + 2007-02-13 Philipp Sehmisch * src/gui/register.cpp, src/logindata.h, src/main.cpp: Fixed the _M/_F @@ -306,8 +573,36 @@ 2007-02-10 Philipp Sehmisch - * src/gui/viewport.cpp: Fixed the bug in the scrolling limitation that made - it possible to scroll outside of the map in the south and east. + * src/gui/viewport.cpp: Fixed the bug in the scrolling limitation that + made it possible to scroll outside of the map in the south and east. + +2007-02-09 Philipp Sehmisch + + * src/particle.cpp: Fixed a misspelled include and another + optimisation at the vector calculation. + +2007-02-08 Philipp Sehmisch + + * src/particle.cpp, src/utils/fastsqrt.h: Added a faster function to + calculate square roots and using it for hypotenuse calculations. + Thanks to Rogier aka Avaniel for finding the function. + +2007-02-07 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp: Renamed + Particle::MAX_PARTICLES to Particle::maxCount and read the value from + config ("particleMaxCount") + * src/particle.cpp: Added fast physics mode that replaces the + trigonometric calculations made for calculating the acceleration by + much less cpu intense but also less accurate formulas. To enable it + set the config option "particleFastPhysics" to "1". + * src/particle.cpp: Added the config option "particleEmitterSkip" that + allows to reduces the output of the emitters by making them spawn + particles only every n-th game tick. + * src/graphics.cpp, src/graphics.h: Added a new method + "drawImageTransparent" to the graphic engine that blits an image with + an alpha factor. + * src/particle.cpp: Using new drawImageTransparent method. 2007-02-04 Bjørn Lindeijer @@ -357,6 +652,35 @@ Defence: 12, Weight: 120. * data/graphics/sprites/chest-cotton-female.png: Huh? Shouldn't this be on svn for ages? + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Implemented die-distance (particles are deleted + when they reached a certain proximity to their target) + * src/particle.cpp: Fixed a bug in the acceleration vector calculation. + * src/particle.cpp, src/particle.h: Fixed a problem with particles with + unlimited lifetime and fade-in. + * data/graphics/particles/playerglow.particle.xml: And again a new + player follow particle. This time it demonstrates die-distance and the + fixed acceleration vector calculation. + * src/engine.cpp, data/graphics/particles/snow.particle.xml, + data/graphics/particles/snowflake.png: I can't stand the begging + anymore. Now it snows in the snow area... and the forest... and the + desert... and under the earth... and indoors... Are you happy now, + Rotonen and Elven? ;-) + * src/particle.cpp: Removed some debug log messages. + * src/being.cpp: Avoided crash when attempting to control an invalid + particle. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Cleaned the includes up. + +2007-01-31 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Changed some variable names. + * data/graphics/particles/waterfall.particle.xml, + data/graphics/particles/waterfall-a.png: New waterfall with Modanungs + waterfall particle. + * src/particle.cpp: forgot to remove a svn conflict marker and changed + the order of initialisations to fix some compiler warnings. 2007-01-30 Eugenio Favalli @@ -373,6 +697,54 @@ src/resources/mapreader.h, src/resources/music.h: Some trivial documentation work. Fixes all Doxygen warnings. +2007-01-30 Philipp Sehmisch + + * src/net/beinghandler.cpp, + data/graphics/particles/skillup.particle.xml: Added different particle + effect for job levelup. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Renamed "alphafade" to "fade-out", added new + property "fade-in". + * data/graphics/particles/playerglow.particle.xml: Added a new player + effect (a fire) demonstrating how to use fade-in and fade-out to fade + one color into another. + +2007-01-29 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added a new particle property "alphafade" that + makes the particles fade into alpha before their lifetime ends. + * src/particle.cpp, src/particle.h: fixed an issue with particles that + have a lifetime of 0 and an issue with the momentum property. + * data/graphics/particles/waterfall.particle.xml, + data/graphics/particles/fog-medium-white-a.png, + data/graphics/particles/fog-medium-white-b.png, + data/graphics/particles/fog-medium-white-c.png: Added fog to the + waterfall effect demonstrating the new alphafade feature. + +2007-01-28 Philipp Sehmisch + + * src/utils/xml.cpp, src/utils/xml.h, src/particleemitter.cpp: Most + values are now read as floating point values from the emitter files. + * data/graphics/particles/fountain.particle.xml, + data/graphics/particles/hit.particle.xml, + data/graphics/particles/playerglow.particle.xml: Changed some values + as floating point values. Made the player follow effect magenta to + improve the visibility of the hit effects. + * src/engine.cpp, data/graphics/particles/waterfall.particle.xml: + Removed the fountain and added a waterfall instead. + * src/particle.h: Corrected the drawing order of the particles in + relation to the other sprites. + * src/gui/debugwindow.cpp, src/gui/debugwindow.h: Added particle count + to debug window. + * src/particle.cpp: Allowed momentum without acceleration and + implement the acceleration properly. + * src/utils/minmax.h, src/particleemitter.cpp, src/particleemitter.h: + Added a structure to hold a pair of numeric minimum and maximum values + and used it to store all numeric emitter properties. + * src/utils/randbetween.h: Removed (the functionality is now in struct + MinMax) + 2007-01-28 Bjørn Lindeijer * src/gui/char_select.h, src/net/messagein.h, @@ -383,6 +755,39 @@ * data/maps/new_8-1.tmx.gz, data/maps/new_11-1.tmx.gz: Map fixes by Pauan. +2007-01-27 Bjørn Lindeijer + + * src/gui/shoplistbox.cpp: Fixed compilation against Guichan 0.6.1. + * src/utils/randbetween.h: Fixed integer overflow causing the + randBetween function not to work properly on Linux. + +2007-01-27 Philipp Sehmisch + + * src/net/beinghandler.cpp: Fixed a compiler issue. + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h, src/engine.cpp: Emitter data is read from + external xml files. Reimplemented target-based particles with the + difference that they don't target beings or locations but other + particles (at the moment the host particle of the effect). + * src/being.cpp: Beings now move controlled particles to their center + instead of their upper left corner. + * data/graphics/particles/orb*: Added a bunch of new particles. + * data/graphics/particles/fountain.particle.xml: Reimplementation of + the fountain effect in XML. + * data/graphics/particles/playerglow.particle.xml: New effect that + spawns orbs that orbit around the origin. + * src/being.cpp, data/graphics/particles/hit.particle.xml: Added + particle effect on hit. + * src/net/beinghandler.cpp, + data/graphics/particles/levelup.particle.xml: Added particle effect on + levelup (own or other player). + +2007-01-24 Philipp Sehmisch + + * src/particle.cpp: Initialized all variables of the particles in the + constructor. + * src/particleemitter.cpp, src/particleemitter.h: minor cleanups. + 2007-01-23 Bjørn Lindeijer * src/gui/shoplistbox.cpp, docs/INSTALL/win32.txt, INSTALL, NEWS: @@ -393,6 +798,39 @@ * src/gui/updatewindow.cpp: Identify ourselves when requesting files from the update server. +2007-01-22 Philipp Sehmisch + + * src/being.cpp, src/being.h, src/particle.cpp, src/particle.h + src/particleemitter.cpp, src/particleemitter.h, src/engine.cpp: + Particle effects are now created in child particles of the root + particle. Particle emitters have no longer a being they check every + frame. Instead beings have the ability to take control of particles. + +2007-01-19 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Implemented emitters that follow a being. + * src/engine.cpp: Added an emitter that follows the local player. + * src/particle.cpp: Fixed the crash on exit (reason was that the + mSpriteIterator wasn't initialized in every case) + +2007-01-18 Bjørn Lindeijer + + * src/properties.h, src/being.cpp, src/beingmanager.h, src/sound.h, + src/gui/window.h, src/sound.cpp, src/main.h, src/being.h, + src/resources/soundeffect.h, src/resources/image.h, + src/resources/mapreader.h, src/resources/music.h: Some trivial + documentation work. Fixes all Doxygen warnings. + * src/particle.h, src/particle.cpp, src/CMakeLists.txt, + src/Makefile.am: Fixed compilation issues on Linux. + * src/gui/char_select.h, src/net/messagein.h, + src/net/messagehandler.h, src/net/network.h, src/net/connection.h, + src/net/messageout.h, src/utils/xml.h, src/main.h, + src/resources/monsterdb.h, src/resources/itemdb.h, + src/resources/equipmentdb.h: Some work on documentation. + * data/maps/new_8-1.tmx.gz, data/maps/new_11-1.tmx.gz: Map fixes by + Pauan. + 2007-01-17 Eugenio Favalli * docs/win32-release.txt, src/gui/register.cpp, src/main.cpp: Changed @@ -408,6 +846,12 @@ * data/help/header.txt, NEWS, README: Updated release date. +2007-01-15 Philipp Sehmisch + + * src/game.cpp, src/particle.cpp, src/particle.h, + src/particleemitter.h: Made the particle count global and more + performant. + 2007-01-14 Eugenio Favalli * src/gui/updatewindow.cpp, src/main.cpp, tmw.cbp: Fixed windows @@ -448,6 +892,17 @@ * src/winver.h, configure.ac, data/help/header.txt, NEWS, README, CMakeLists.txt: Updated version to 0.0.22.1. +2007-01-14 Philipp Sehmisch + + * src/particle.cpp, src/particle.h; src/particleemitter.cpp, + src/particleemitter.h, src/utils/randbetween.h: + Implemented particle engine. + * src/engine.cpp, src/game.cpp: added calls to the particle engine + * data/graphics/particles/*: added a bunch of particle graphics for + testing purpose. + * particleengine-todo.txt: Added particle engine todo list (please + omit when merging) + 2007-01-13 Bjørn Lindeijer * data/graphics/sprites/Makefile.am, @@ -1298,7 +1753,7 @@ 2006-10-12 Yohann Ferreira * debian/rules, debian/tmw-data.install, debian/tmw-data.dirs, - debian/tmw-music.install, debian/changelog: Updating debian files for + debian/tmw-music.install, debian/changelog: Updating Debian files for bug fixing. 2006-10-12 Frode Lindeijer @@ -1473,7 +1928,7 @@ * src/animation.h, src/animatedsprite.h, data/graphics/sprites/weapon.xml: Some modifications at the animation system. No more "undefined action foo" warnings in the tmw.log. Not - visible actions must now be declared explicitely. + visible actions must now be declared explicitly. * data/graphics/images/ambient/sandstorm.png, data/graphics/images/ambient/clouds.png: Improved quality of the overlay graphics. @@ -1892,7 +2347,7 @@ with more distinctive names. (no, i won't list all 114) * src/itemmanager.cpp, data/items.xml: Replaced indices on the item spriteset with filenames. added names and descriptions for all missing - items. Changed names and dascriptions of some items. + items. Changed names and descriptions of some items. * src/engine.cpp: Removed global item spriteset. * src/floor_item.cpp, src/floor_item.h, src/iteminfo.cpp, src/iteminfo.h, src/equipmentwindow.cpp, src/equipmentwindow.h, diff --git a/NEWS b/NEWS index 5281cf78..9529ae1b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,19 @@ +0.0.23 (3 June 2007) +- Added a particle engine along with some particle effects +- Added a cursor to indicate targeted enemy +- Added new program icon +- Added a man page for UNIX like systems +- Added the --version command line parameter +- Improved MacOS X release +- Screenshots are now saved in the .tmw directory on UNIX like systems +- Magic pink is no longer used for transparency (fixes issues with that on Mac) +- Fixed difficulties with resizing windows +- Fixed misleading error message when connecting fails +- Fixed wrong error message when account name already exists +- Fixed crash when deleting a character +- Fixed error message when creating a new character fails +- Fixed updating problem when using scrollwheel to change shop selection + 0.0.22.2 (17 February 2007) - Updated to work with Guichan 0.6.1 - Changed to new default server (server.themanaworld.org) diff --git a/README b/README index 2d6f07b1..39677e1e 100644 --- a/README +++ b/README @@ -1,8 +1,7 @@ THE MANA WORLD ============== - Version: 0.0.22.2 Date: 17/02/2007 - + Version: 0.1.0 Date: XX/XX/2007 Development team: - See AUTHORS file for a list diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 1549b2b4..5a02d7f1 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -30,8 +30,12 @@ SET (FILES sansserif8.png selection.png slider.png - target-cursor-blue.png - target-cursor-red.png + target-cursor-blue-l.png + target-cursor-blue-m.png + target-cursor-blue-s.png + target-cursor-red-l.png + target-cursor-red-m.png + target-cursor-red-s.png thickborder.png vscroll_blue.png vscroll_down_default.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index c0e0655b..a37e1196 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -33,6 +33,12 @@ gui_DATA = \ sansserif8.png \ selection.png \ slider.png \ + target-cursor-blue-l.png \ + target-cursor-blue-m.png \ + target-cursor-blue-s.png \ + target-cursor-red-l.png \ + target-cursor-red-m.png \ + target-cursor-red-s.png \ thickborder.png \ vscroll_blue.png \ vscroll_down_default.png \ diff --git a/data/graphics/gui/target-cursor-blue-l.png b/data/graphics/gui/target-cursor-blue-l.png new file mode 100644 index 00000000..77cdf4b6 Binary files /dev/null and b/data/graphics/gui/target-cursor-blue-l.png differ diff --git a/data/graphics/gui/target-cursor-blue-m.png b/data/graphics/gui/target-cursor-blue-m.png new file mode 100644 index 00000000..c0107357 Binary files /dev/null and b/data/graphics/gui/target-cursor-blue-m.png differ diff --git a/data/graphics/gui/target-cursor-blue-s.png b/data/graphics/gui/target-cursor-blue-s.png new file mode 100644 index 00000000..3e81c75d Binary files /dev/null and b/data/graphics/gui/target-cursor-blue-s.png differ diff --git a/data/graphics/gui/target-cursor-blue.png b/data/graphics/gui/target-cursor-blue.png deleted file mode 100644 index 3e81c75d..00000000 Binary files a/data/graphics/gui/target-cursor-blue.png and /dev/null differ diff --git a/data/graphics/gui/target-cursor-red-l.png b/data/graphics/gui/target-cursor-red-l.png new file mode 100644 index 00000000..76d2101b Binary files /dev/null and b/data/graphics/gui/target-cursor-red-l.png differ diff --git a/data/graphics/gui/target-cursor-red-m.png b/data/graphics/gui/target-cursor-red-m.png new file mode 100644 index 00000000..e2ab79c2 Binary files /dev/null and b/data/graphics/gui/target-cursor-red-m.png differ diff --git a/data/graphics/gui/target-cursor-red-s.png b/data/graphics/gui/target-cursor-red-s.png new file mode 100644 index 00000000..09195f44 Binary files /dev/null and b/data/graphics/gui/target-cursor-red-s.png differ diff --git a/data/graphics/gui/target-cursor-red.png b/data/graphics/gui/target-cursor-red.png deleted file mode 100644 index 09195f44..00000000 Binary files a/data/graphics/gui/target-cursor-red.png and /dev/null differ diff --git a/data/help/changes.txt b/data/help/changes.txt index f8a3eb67..dd062e49 100644 --- a/data/help/changes.txt +++ b/data/help/changes.txt @@ -3,99 +3,56 @@ ##3 === RECENT CHANGES === - 0.0.21 (17 September 2006) - - Added item pickup messages to the chat dialog - - Added XP bar to ministatus in the top left - - Added configurable smooth and lazy scrolling - - Added option to turn off the joystick - - Added --playername option for automatic character picking - - Added --configfile option for specifying which configuration file to use - - Added shortcut and middle mouse button for targetting nearest monster - - Added support for map effect overlays - - Fixed FPS limiter - - Fixed updating system on Windows - - Fixed player animations going out of sync on changing equipment or hairstyle - - Fixed SDL_image configure check on some systems by first checking for libpng - - Fixed big memory leak when using OpenGL - - Updated to work with Guichan 0.5.0 (older versions no longer supported) - - 0.0.20 (24 July 2006) - - Added new hairstyle, and some fixes to the old ones - - Added slider to set FPS limit - - Added visible equipments - - Added new maps and monsters - - Added female characters - - Implemented a new animation system - - Updated the updating system - - Reduced size of textures to stay within the limits of some OpenGL drivers - - Fixed connection not being shut down completely in case of an error - - Fixed min size of a window when resizing - - Fixed some maps issues - - Some fixes to monsters and player graphics - - Minor bug fixes and lots of code cleanups - - 0.0.19 (6 March 2006) - - - Added --username, --password and --defaults command line options - - Improved login sequence - - Enabled 3 slots to create players - - Improved setup window and added a joystick calibration tool - - Some maps fixes - - Reorganized and improved network code - - Fixed some bugs - - Made the player walk to items prior to picking them up - - Added new playerset - - Lots of cleanups and code re-roganization - - 0.0.18.1 (30 December 2005) - - - Fixed a drawing glitch with high tiles at the bottom of the screen - - Fixed glitches caused by fading out the damage display - - 0.0.18 (20 December 2005) - - - Added new items, npcs, tilesets, maps and monsters - - Non blocking connection at startup - - Enabled monster emotions - - Client version is now displayed during login - - Fixed setup window behaviour - - Fixed a Windows crash issue - - Fixed ScrollArea and BrowserBox behaviour - - Code cleanups - - 0.0.17 (10 October 2005) - - - Added remembering of window position and sizes - - Added taking screenshot with Alt+P - - Added notice about the player being overweight - - Added time to chat messages - - Added messagebox on error for MacOS X - - Added new network layer based on SDL_net - - Added proper error message for when the map server goes offline - - Added more international characters to fixed and rpg fonts - - Improved damage text font, shadow is now translucent - - Improved GUI layout, new profile window - - Improved support for building on FreeBSD and MacOS X - - Improved tile engine to fix graphics glitches and make mapping easier - - Rearranged keyboard shortcuts - - Fixed items on map to be removed on map switch - - Fixed OpenGL checkbox in the setup window to be usable - - Cleaned up a lot of code - - 0.0.16 (04 September 2005) - - - Added inn and casino - - Improved status window - - Improved OpenGL support - - Removed lot of bugs - - Code cleanups - - 0.0.15 (31 July 2005) - - - Added dynamic updating of client data - - Added much better font for chat and names - - Added option not to use the custom mouse cursor - - Added joystick support - - Improved mouse attack by not walking while pressing shift - - Fixed items being shown as equipped in inventory although they are not + 0.0.23 (3 June 2007) + - Added a particle engine along with some particle effects + - Added a cursor to indicate targeted enemy + - Added new program icon + - Added a man page for UNIX like systems + - Added the --version command line parameter + - Improved MacOS X release + - Screenshots are now saved in the .tmw directory on UNIX like systems + - Magic pink is no longer used for transparency (fixes issues with that on Mac) + - Fixed difficulties with resizing windows + - Fixed misleading error message when connecting fails + - Fixed wrong error message when account name already exists + - Fixed crash when deleting a character + - Fixed error message when creating a new character fails + - Fixed updating problem when using scrollwheel to change shop selection + + 0.0.22.2 (17 February 2007) + - Updated to work with Guichan 0.6.1 + - Changed to new default server (server.themanaworld.org) + - Changed custom mouse cursor + - Fixed the issue where _M or _F is appended to the username + - Fixed problem with Cancel button in update dialog + + 0.0.22.1 (15 January 2007) + - Updated to work with Guichan 0.6.0 (older versions no longer supported) + - Fixed mouse coordinates in debug window + - Fixed clicking on GUI to cause the player to start walking sometimes + + 0.0.22 (24 December 2006) + - Added support for female-specific equipment graphics + - Added support for monster sounds + - Added item icons to buy/sell dialogs + - Enhanced character select dialog to show equipment + - Changed to new update host (http://updates.themanaworld.org) + - Worked around a Guichan exception thrown for mice with many buttons + - Changed mouse walk to keep following mouse while button is held down + - Extended font support for Ã¥ and Ã… + - Disabled RLE compression on all surfaces in software mode + - Fixed joystick setting not to show disabled when it's actually enabled + - Fixed money field to no longer hide below the bottom of the window + - Fixed pathfinding to allow walking through beings when they block your path + - Fixed an issue with NPC dialogs staying open after player respawn + + 0.0.21.1 (30 October 2006) + - Reload wallpaper after loading updates + - Added support for gzip compressed map layer data + - Added support for building with CMake + - Added slider to setup dialog for configuring overlay effect + - Fixed excessive unnecessary reloading of sprites + - Fixed problem with OpenGL related redefinition + - Fixed problems with hiding windows using h + - Fixed trade window positioning diff --git a/data/help/header.txt b/data/help/header.txt index 7311c111..b10ed991 100644 --- a/data/help/header.txt +++ b/data/help/header.txt @@ -2,7 +2,7 @@ ##1 T H E M A N A W O R L D ##1 ========================================== - ##2Version:##6 0.0.22.2 ##2Date:##317 February 2007 + ##2Version:##6 0.0.23 ##2Date:##33 June 2007 ##2 Website: http://themanaworld.org diff --git a/docs/Makefile.am b/docs/Makefile.am index 8b57d5bb..1ee9a9a6 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,6 +1,7 @@ man6_MANS = tmw.6 -EXTRA_DIST = packages.txt \ +EXTRA_DIST = $(man6_MANS) \ + packages.txt \ FAQ.txt \ HACKING.txt \ SOURCE/tmwdox.sh \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e28e235e..7a4da70d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,8 @@ MARK_AS_ADVANCED(SDL_INCLUDE_DIR) MARK_AS_ADVANCED(SDL_LIBRARY) SET(SRCS + gui/widgets/resizegrip.cpp + gui/widgets/resizegrip.h gui/box.cpp gui/box.h gui/browserbox.cpp @@ -275,11 +277,15 @@ SET(SRCS utils/base64.cpp utils/base64.h utils/dtor.h + utils/fastsqrt.h + utils/minmax.h utils/tostring.h utils/xml.cpp utils/xml.h animatedsprite.cpp animatedsprite.h + animationparticle.cpp + animationparticle.h being.cpp being.h beingmanager.cpp @@ -304,6 +310,8 @@ SET(SRCS graphics.cpp graphics.h guichanfwd.h + imageparticle.cpp + imageparticle.h inventory.cpp inventory.h item.cpp @@ -326,6 +334,10 @@ SET(SRCS npc.h openglgraphics.cpp openglgraphics.h + particle.cpp + particle.h + particleemitter.cpp + particleemitter.h player.cpp player.h properties.h @@ -335,6 +347,8 @@ SET(SRCS sound.cpp sound.h sprite.h + textparticle.cpp + textparticle.h tileset.h ) diff --git a/src/Makefile.am b/src/Makefile.am index f1f51b79..92c1b1b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,8 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = tmw tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/dropdown.h \ + gui/widgets/resizegrip.cpp \ + gui/widgets/resizegrip.h \ gui/browserbox.cpp \ gui/browserbox.h \ gui/buddywindow.cpp \ @@ -229,11 +231,15 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ utils/base64.cpp \ utils/base64.h \ utils/dtor.h \ + utils/fastsqrt.h \ + utils/minmax.h \ utils/tostring.h \ utils/xml.cpp \ utils/xml.h \ animatedsprite.cpp \ animatedsprite.h \ + animationparticle.cpp \ + animationparticle.h \ being.cpp \ being.h \ beingmanager.cpp \ @@ -258,6 +264,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ graphics.cpp \ graphics.h \ guichanfwd.h \ + imageparticle.cpp \ + imageparticle.h \ inventory.cpp \ inventory.h \ item.cpp \ @@ -280,15 +288,21 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ npc.h \ openglgraphics.cpp\ openglgraphics.h \ + particle.cpp \ + particle.h \ + particleemitter.cpp \ + particleemitter.h \ player.cpp \ player.h \ properties.h \ serverinfo.h \ simpleanimation.cpp \ - simpleanimation.h \ + simpleanimation.h \ sound.cpp \ sound.h \ sprite.h \ + textparticle.cpp \ + textparticle.h \ tileset.h # set the include path found by configure diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 7260a512..c1e89ff0 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -197,3 +197,27 @@ AnimatedSprite::setDirection(SpriteDirection direction) } } } + +int +AnimatedSprite::getWidth() const +{ + if (mFrame) + { + return mFrame->image->getWidth(); + } + else { + return 0; + } +} + +int +AnimatedSprite::getHeight() const +{ + if (mFrame) + { + return mFrame->image->getHeight(); + } + else { + return 0; + } +} diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 2257c0f0..42c0a743 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -85,6 +85,18 @@ class AnimatedSprite bool draw(Graphics* graphics, int posX, int posY) const; + /** + * gets the width in pixels of the image of the current frame + */ + int + getWidth() const; + + /** + * gets the height in pixels of the image of the current frame + */ + int + getHeight() const; + /** * Sets the direction. */ diff --git a/src/animationparticle.cpp b/src/animationparticle.cpp new file mode 100644 index 00000000..30c33da7 --- /dev/null +++ b/src/animationparticle.cpp @@ -0,0 +1,51 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "animationparticle.h" + +#include "graphics.h" +#include "simpleanimation.h" + +AnimationParticle::AnimationParticle(Map *map, Animation *animation): + ImageParticle(map, 0), + mAnimation(new SimpleAnimation(animation)) +{ +} + +AnimationParticle::AnimationParticle(Map *map, xmlNodePtr animationNode): + ImageParticle(map, 0), + mAnimation(new SimpleAnimation(animationNode)) +{ +} + +AnimationParticle::~AnimationParticle() +{ + delete mAnimation; +} + +bool AnimationParticle::update() +{ + mAnimation->update(10); // particle engine is updated every 10ms + mImage = mAnimation->getCurrentImage(); + + return Particle::update(); +} diff --git a/src/animationparticle.h b/src/animationparticle.h new file mode 100644 index 00000000..054b1b73 --- /dev/null +++ b/src/animationparticle.h @@ -0,0 +1,49 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _ANIMATION_PARTICLE +#define _ANIMATION_PARTICLE + +#include + +#include "imageparticle.h" + +class Animation; +class Map; +class SimpleAnimation; + +class AnimationParticle : public ImageParticle +{ + public: + AnimationParticle(Map *map, Animation *animation); + + AnimationParticle(Map *map, xmlNodePtr animationNode); + + ~AnimationParticle(); + + virtual bool update(); + + private: + SimpleAnimation *mAnimation; /**< Used animation for this particle */ +}; + +#endif diff --git a/src/being.cpp b/src/being.cpp index 682daddb..7ba9ddb9 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -32,12 +32,16 @@ #include "graphics.h" #include "log.h" #include "map.h" +#include "particle.h" #include "resources/resourcemanager.h" #include "resources/imageset.h" #include "gui/gui.h" +#include "resources/resourcemanager.h" +#include "resources/imageset.h" + #include "utils/dtor.h" #include "utils/tostring.h" @@ -61,7 +65,6 @@ Being::Being(Uint16 id, Uint16 job, Map *map): mMap(NULL), mHairStyle(0), mHairColor(0), mSpeechTime(0), - mDamageTime(0), mPx(0), mPy(0), mSprites(VECTOREND_SPRITE, NULL), mEquipmentSpriteIDs(VECTOREND_SPRITE, 0) @@ -85,6 +88,13 @@ Being::~Being() clearPath(); setMap(NULL); + for ( std::list::iterator i = mChildParticleEffects.begin(); + i != mChildParticleEffects.end(); + i++) + { + (*i)->kill(); + } + instances--; if (instances == 0) @@ -292,8 +302,32 @@ Being::setSpeech(const std::string &text, Uint32 time) void Being::takeDamage(int amount) { - mDamage = amount ? toString(amount) : "miss"; - mDamageTime = 300; + gcn::Font* font; + std::string damage = amount ? toString(amount) : "miss"; + + // Selecting the right color + if (damage == "miss") + { + font = hitYellowFont; + } + else + { + // hit particle effect + controlParticle(particleEngine->addEffect("graphics/particles/hit.particle.xml", 0, 0)); + + if (getType() == MONSTER) + { + font = hitBlueFont; + } + else + { + font = hitRedFont; + } + } + + // show damage number + particleEngine->addTextSplashEffect(damage, 255, 255, 255, font, + mPx + 16, mPy + 16); } void @@ -318,6 +352,19 @@ Being::setMap(Map *map) { mSpriteIterator = mMap->addSprite(this); } + + //clear particle effect list because child particles became invalid + mChildParticleEffects.clear(); +} + +void +Being::controlParticle(Particle *particle) +{ + if (particle) + { + particle->disableAutoDelete(); //the effect may not die without the beings permission or we segvault + mChildParticleEffects.push_back(particle); + } } void @@ -465,10 +512,6 @@ Being::logic() if (mSpeechTime > 0) mSpeechTime--; - // Reduce the time that damage is still displayed - if (mDamageTime > 0) - mDamageTime--; - // Update pixel coordinates mPx = mX - 16 + getXOffset(); mPy = mY - 16 + getYOffset(); @@ -489,6 +532,14 @@ Being::logic() mSprites[i]->update(tick_time * 10); } } + + //Update particle effects + for ( std::list::iterator i = mChildParticleEffects.begin(); + i != mChildParticleEffects.end(); + i++) + { + (*i)->setPosition((float)mPx + 16.0f, (float)mPy + 32.0f); + } } void @@ -531,37 +582,6 @@ Being::drawSpeech(Graphics *graphics, int offsetX, int offsetY) graphics->setColor(gcn::Color(255, 255, 255)); graphics->drawText(mSpeech, px + 18, py - 60, gcn::Graphics::CENTER); } - - // Draw damage above this being - if (mDamageTime > 0 && mDamageTime < 275) - { - // Selecting the right color - if (mDamage == "miss") - { - graphics->setFont(hitYellowFont); - } - else if (getType() == MONSTER) - { - graphics->setFont(hitBlueFont); - } - else - { - graphics->setFont(hitRedFont); - } - - int textY = (getType() == MONSTER) ? 32 : 70; - int ft = 150 - mDamageTime; - float a = (ft > 0) ? 1.0 - ft / 150.0 : 1.0; - - graphics->setColor(gcn::Color(255, 255, 255, (int)(255 * a))); - graphics->drawText(mDamage, - px + 16, - py - textY - (300 - mDamageTime) / 10, - gcn::Graphics::CENTER); - - // Reset alpha value - graphics->setColor(gcn::Color(255, 255, 255)); - } } Being::Type @@ -632,3 +652,29 @@ int Being::getOffset(int step) const return offset; } + + +int +Being::getWidth() const +{ + if (mSprites[BASE_SPRITE]) + { + return mSprites[BASE_SPRITE]->getWidth(); + } + else { + return 0; + } +} + + +int +Being::getHeight() const +{ + if (mSprites[BASE_SPRITE]) + { + return mSprites[BASE_SPRITE]->getHeight(); + } + else { + return 0; + } +} diff --git a/src/being.h b/src/being.h index 332f1b4a..8820c30a 100644 --- a/src/being.h +++ b/src/being.h @@ -42,6 +42,7 @@ class Item; class Map; class Graphics; class ImageSet; +class Particle; /** * A position along a being's path. @@ -97,6 +98,13 @@ class Being : public Sprite VECTOREND_SPRITE }; + enum TargetCursorSize { + TC_SMALL = 0, + TC_MEDIUM, + TC_LARGE, + NUM_TC + }; + /** * Directions, to be used as bitmask values @@ -359,8 +367,33 @@ class Being : public Sprite int getYOffset() const { return getOffset(mStepY); } + /** + * Returns the horizontal size of the current base sprite of the being + */ + virtual int + getWidth() const; + + /** + * Returns the vertical size of the current base sprite of the being + */ + virtual int + getHeight() const; + + /** + * Returns the required size of a target cursor for this being + */ + virtual Being::TargetCursorSize + getTargetCursorSize() const + { return TC_MEDIUM; } + std::auto_ptr mEquipment; + /** + * Take control of a particle + */ + void + controlParticle(Particle *particle); + protected: /** * Sets the new path for this being. @@ -380,14 +413,13 @@ class Being : public Sprite Path mPath; std::string mSpeech; - std::string mDamage; Uint16 mHairStyle, mHairColor; Uint32 mSpeechTime; - Uint32 mDamageTime; Sint32 mPx, mPy; /**< Pixel coordinates */ std::vector mSprites; std::vector mEquipmentSpriteIDs; + std::list mChildParticleEffects; private: int diff --git a/src/engine.cpp b/src/engine.cpp index 31bec9ff..3b5fb403 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -35,6 +35,7 @@ #include "localplayer.h" #include "log.h" #include "map.h" +#include "particle.h" #include "sound.h" #include "gui/gui.h" @@ -63,6 +64,7 @@ void Engine::changeMap(const std::string &mapPath) floorItemManager->clear(); beingManager->clear(); + particleEngine->clear(); // Store full map path in global var map_path = "maps/" + mapPath; @@ -83,8 +85,12 @@ void Engine::changeMap(const std::string &mapPath) } minimap->setMapImage(mapImage); beingManager->setMap(newMap); + particleEngine->setMap(newMap); viewport->setMap(newMap); + // Initialize map-based particle effects + newMap->initializeParticleEffects(particleEngine); + // Start playing new music file when necessary std::string oldMusic = ""; @@ -106,5 +112,6 @@ void Engine::changeMap(const std::string &mapPath) void Engine::logic() { beingManager->logic(); + particleEngine->update(); gui->logic(); } diff --git a/src/game.cpp b/src/game.cpp index ba4e2b9d..1afc530b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -41,6 +41,7 @@ #include "localplayer.h" #include "log.h" #include "npc.h" +#include "particle.h" #include "gui/buy.h" #include "gui/buysell.h" @@ -121,6 +122,8 @@ BeingManager *beingManager = NULL; FloorItemManager *floorItemManager = NULL; ChannelManager *channelManager = NULL; +Particle *particleEngine = NULL; + const int MAX_TIME = 10000; /** @@ -242,6 +245,9 @@ Game::Game(): floorItemManager = new FloorItemManager(); channelManager = new ChannelManager(); + particleEngine = new Particle(NULL); + particleEngine->setupEngine(); + // Initialize timers tick_time = 0; mLogicCounterId = SDL_AddTimer(10, nextTick, NULL); //Logic counter @@ -286,6 +292,7 @@ Game::~Game() delete floorItemManager; delete channelManager; delete joystick; + delete particleEngine; beingManager = NULL; floorItemManager = NULL; @@ -308,7 +315,9 @@ bool saveScreenshot(SDL_Surface *screenshot) screenshotCount++; filename.str(""); #if (defined __USE_UNIX98 || defined __FreeBSD__ || defined __APPLE__) - filename << PHYSFS_getUserDir() << "/"; + filename << PHYSFS_getUserDir() << ".tmw/"; +#elif defined __APPLE__ + filename << PHYSFS_getUserDir() << "Desktop/"; #endif filename << "TMW_Screenshot_" << screenshotCount << ".png"; testExists.open(filename.str().c_str(), std::ios::in); @@ -316,7 +325,18 @@ bool saveScreenshot(SDL_Surface *screenshot) testExists.close(); } while (!found); - return ImageWriter::writePNG(screenshot, filename.str()); + if (ImageWriter::writePNG(screenshot, filename.str())) + { + std::stringstream chatlogentry; + chatlogentry << "Screenshot saved to " << filename.str().c_str(); + chatWindow->chatLog(chatlogentry.str(), BY_SERVER); + return true; + } + else + { + chatWindow->chatLog("Saving screenshot failed!", BY_SERVER); + return false; + } } void Game::optionChanged(const std::string &name) diff --git a/src/graphics.cpp b/src/graphics.cpp index f007470a..1e31f903 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -136,8 +136,6 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, srcX += image->mBounds.x; srcY += image->mBounds.y; - - SDL_Rect dstRect; SDL_Rect srcRect; dstRect.x = dstX; dstRect.y = dstY; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index cb07da22..2a8616f8 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -111,27 +111,21 @@ void BuyDialog::setMoney(int amount) { mMoney = amount; mShopItemList->setPlayersMoney(amount); - mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); + + updateButtonsAndLabels(); } void BuyDialog::reset() { mShopItems->clear(); + mShopItemList->adjustSize(); mMoney = 0; mSlider->setValue(0.0); - mAmountItems = 0; // Reset Previous Selected Items to prevent failing asserts mShopItemList->setSelected(-1); - mIncreaseButton->setEnabled(false); - mDecreaseButton->setEnabled(false); - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); - mItemDescLabel->setCaption(""); - mItemEffectLabel->setCaption(""); + + updateButtonsAndLabels(); } void BuyDialog::addItem(short id, int price) @@ -151,45 +145,36 @@ void BuyDialog::action(const gcn::ActionEvent &event) } // The following actions require a valid selection - if (selectedItem < 0 || selectedItem >= int(mShopItems->getNumberOfElements())) + if (selectedItem < 0 || + selectedItem >= (int) mShopItems->getNumberOfElements()) { return; } - bool updateButtonsAndLabels = false; - if (event.getId() == "slider") { mAmountItems = (int)(mSlider->getValue() * mMaxItems); - updateButtonsAndLabels = true; + updateButtonsAndLabels(); } - else if (event.getId() == "+") + else if (event.getId() == "+" && mAmountItems < mMaxItems) { - if (mAmountItems < mMaxItems) { - mAmountItems++; - } else { - mAmountItems = mMaxItems; - } + mAmountItems++; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems / (double) mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "-") + else if (event.getId() == "-" && mAmountItems > 0) { - if (mAmountItems > 0) { - mAmountItems--; - } else { - mAmountItems = 0; - } + mAmountItems--; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems / (double) mMaxItems); + updateButtonsAndLabels(); } // TODO: Actually we'd have a bug elsewhere if this check for the number // of items to be bought ever fails, Bertram removed the assertions, is // there a better way to ensure this fails in an _obivous_ way in C++? - else if (event.getId() == "buy" && (mAmountItems > 0 && - mAmountItems <= mMaxItems)) + else if (event.getId() == "buy" && mAmountItems > 0 && + mAmountItems <= mMaxItems) { // XXX Convert for new server /* @@ -199,38 +184,15 @@ void BuyDialog::action(const gcn::ActionEvent &event) outMsg.writeShort(mShopItems->at(selectedItem).id); */ - // update money ! + // Update money and adjust the max number of items that can be bought mMoney -= mAmountItems * mShopItems->at(selectedItem).price; - // Update number of items that can be bought at max mMaxItems -= mAmountItems; - if (!mMaxItems) { - mSlider->setEnabled(false); - } - // Reset selection mAmountItems = 0; - mSlider->setValue(0); - - updateButtonsAndLabels = true; - } + mSlider->setValue(0.0); - // If anything has changed, we have to update the buttons and labels - if (updateButtonsAndLabels) - { - // Update buttons - mIncreaseButton->setEnabled(mAmountItems < mMaxItems); - mDecreaseButton->setEnabled(mAmountItems > 0); - mBuyButton->setEnabled(mAmountItems > 0); - - // Update labels - mQuantityLabel->setCaption(toString(mAmountItems)); - mQuantityLabel->adjustSize(); - - int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " - + toString(mMoney) + " GP" ); - mMoneyLabel->adjustSize(); + updateButtonsAndLabels(); } } @@ -238,17 +200,16 @@ void BuyDialog::selectionChanged(const SelectionEvent &event) { // Reset amount of items and update labels mAmountItems = 0; - mSlider->setValue(0); - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); + mSlider->setValue(0.0); - // Disable buttons for buying and decreasing - mBuyButton->setEnabled(false); - mDecreaseButton->setEnabled(false); + updateButtonsAndLabels(); +} +void +BuyDialog::updateButtonsAndLabels() +{ int selectedItem = mShopItemList->getSelected(); + int price = 0; if (selectedItem > -1) { @@ -259,16 +220,32 @@ void BuyDialog::selectionChanged(const SelectionEvent &event) // Calculate how many the player can afford mMaxItems = mMoney / mShopItems->at(selectedItem).price; + if (mAmountItems > mMaxItems) + { + mAmountItems = mMaxItems; + } + + // Calculate price of pending purchase + price = mAmountItems * mShopItems->at(selectedItem).price; } else { mItemDescLabel->setCaption("Description:"); mItemEffectLabel->setCaption("Effect:"); mMaxItems = 0; + mAmountItems = 0; } - // When at least one item can be bought, enable the slider and the - // increase button - mIncreaseButton->setEnabled(mMaxItems > 0); + // Enable or disable buttons and slider + mIncreaseButton->setEnabled(mAmountItems < mMaxItems); + mDecreaseButton->setEnabled(mAmountItems > 0); + mBuyButton->setEnabled(mAmountItems > 0); mSlider->setEnabled(mMaxItems > 0); + + // Update quantity and money labels + mQuantityLabel->setCaption(toString(mAmountItems)); + mQuantityLabel->adjustSize(); + mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " + + toString(mMoney - price) + " GP" ); + mMoneyLabel->adjustSize(); } diff --git a/src/gui/buy.h b/src/gui/buy.h index 13116b6e..7834a434 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -92,6 +92,12 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener */ std::string getElementAt(int i); + /** + * Updates the state of buttons and labels. + */ + void + updateButtonsAndLabels(); + private: gcn::Button *mBuyButton; gcn::Button *mQuitButton; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index eb6b7612..48df9efe 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -160,7 +160,7 @@ ChatWindow::chatLog(std::string line, int own, std::string channelName) break; case BY_OTHER: tmp.nick += CAT_NORMAL; - lineColor = "##4"; // Equiv. to BrowserBox::ORANGE + lineColor = "##0"; // Equiv. to BrowserBox::BLACK break; case BY_SERVER: tmp.nick += std::string("Server: "); @@ -195,7 +195,7 @@ ChatWindow::chatLog(std::string line, int own, std::string channelName) // We look if the Vertical Scroll Bar is set at the max before // adding a row, otherwise the max will always be a row higher // at comparison. - if (mScrollArea->getVerticalScrollAmount() == mScrollArea->getVerticalMaxScroll() ) + if (mScrollArea->getVerticalScrollAmount() == mScrollArea->getVerticalMaxScroll()) { mTextOutput->addRow(line); mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); diff --git a/src/gui/chat.h b/src/gui/chat.h index c7e51ebf..6f9b91fe 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -168,13 +168,13 @@ class ChatWindow : public Window, public gcn::ActionListener, /* * Determines whether to send a command or an ordinary message, then - * contructs packets & sends them + * contructs packets & sends them. * * @param nick The character's name to display in front. * @param msg The message text which is to be send. * * NOTE: - * the nickname is required by the server, if not specified + * The nickname is required by the server, if not specified * the message may not be sent unless a command was intended * which requires another packet to be constructed! you can * achieve this by putting a slash ("/") infront of the diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 563f380f..ebf7d974 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -33,6 +33,7 @@ #include "../game.h" #include "../engine.h" +#include "../particle.h" #include "../map.h" #include "../utils/tostring.h" @@ -58,6 +59,9 @@ DebugWindow::DebugWindow(): mTileMouseLabel = new gcn::Label("[Mouse: 0, 0]"); mTileMouseLabel->setPosition(100, 0); + mParticleCountLabel = new gcn::Label("[Particle count: 0]"); + mParticleCountLabel->setPosition(100, 60); + Button *closeButton = new Button("Close", "close", this); closeButton->setPosition(5, 60); @@ -65,6 +69,7 @@ DebugWindow::DebugWindow(): add(mMusicFileLabel); add(mMapFileLabel); add(mTileMouseLabel); + add(mParticleCountLabel); add(closeButton); } @@ -97,6 +102,11 @@ DebugWindow::logic() mMapFileLabel->setCaption(minimap); mMapFileLabel->adjustSize(); } + + mParticleCountLabel->setCaption("[Particle count: " + + toString(Particle::particleCount) + +"]"); + mParticleCountLabel->adjustSize(); } void diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 4fd33d83..d082b2ca 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -58,6 +58,7 @@ class DebugWindow : public Window, public gcn::ActionListener private: gcn::Label *mMusicFileLabel, *mMapFileLabel; gcn::Label *mTileMouseLabel, *mFPSLabel; + gcn::Label *mParticleCountLabel; }; #endif diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 44d042a6..2018c75a 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -165,8 +165,8 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) if (!item) return; - /* Convert relative to the window coordinates to - * absolute screen coordinates. + /* Convert relative to the window coordinates to absolute screen + * coordinates. */ int mx = event.getX() + getX(); int my = event.getY() + getY(); @@ -178,7 +178,8 @@ void InventoryWindow::mouseDragged(gcn::MouseEvent &event) { int tmpWidth = getWidth(), tmpHeight = getHeight(); Window::mouseDragged(event); - if (getWidth() != tmpWidth || getHeight() != tmpHeight) { + if (getWidth() != tmpWidth || getHeight() != tmpHeight) + { updateWidgets(); } } diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index c9878c84..478371b1 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -88,7 +88,7 @@ SellDialog::SellDialog(): quitButton->setPosition(208, 186); mShopItemList->setActionEventId("item"); - mSlider->setActionEventId("mSlider"); + mSlider->setActionEventId("slider"); mShopItemList->setPriceCheck(false); @@ -119,20 +119,11 @@ void SellDialog::reset() { mShopItems->clear(); mSlider->setValue(0.0); - mAmountItems = 0; - - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Money: 0 GP / Total: " - + toString(mPlayerMoney) + " GP"); - mMoneyLabel->adjustSize(); - mItemDescLabel->setCaption(""); - mItemEffectLabel->setCaption(""); - // Reset Previous Selected Items to prevent failing asserts + // Reset previous selected item to prevent failing asserts mShopItemList->setSelected(-1); - mIncreaseButton->setEnabled(false); - mDecreaseButton->setEnabled(false); + + updateButtonsAndLabels(); } void SellDialog::addItem(Item *item, int price) @@ -162,25 +153,7 @@ void SellDialog::action(const gcn::ActionEvent &event) { mAmountItems = 0; mSlider->setValue(0); - mDecreaseButton->setEnabled(false); - mSellButton->setEnabled(false); - - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Money: 0 GP / Total: " - + toString(mPlayerMoney) + " GP"); - mMoneyLabel->adjustSize(); - - if (selectedItem > -1) { - mSlider->setEnabled(true); - mIncreaseButton->setEnabled(true); - mMaxItems = mShopItems->at(selectedItem).quantity; - mQuantityLabel->setCaption("0 / " + toString(mMaxItems)); - } else { - mSlider->setEnabled(false); - mIncreaseButton->setEnabled(false); - mQuantityLabel->setCaption("0"); - } - mQuantityLabel->adjustSize(); + updateButtonsAndLabels(); } else if (event.getId() == "quit") { @@ -189,40 +162,35 @@ void SellDialog::action(const gcn::ActionEvent &event) } // The following actions require a valid item selection - if (selectedItem == -1 || selectedItem >= int(mShopItems->getNumberOfElements())) { + if (selectedItem == -1 || + selectedItem >= (int) mShopItems->getNumberOfElements()) + { return; } - bool updateButtonsAndLabels = false; - - if (event.getId() == "mSlider") + if (event.getId() == "slider") { - mAmountItems = (int)(mSlider->getValue() * mMaxItems); - - updateButtonsAndLabels = true; + mAmountItems = (int) (mSlider->getValue() * mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "+") + else if (event.getId() == "+" && mAmountItems < mMaxItems) { - assert(mAmountItems < mMaxItems); mAmountItems++; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems /(double) mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "-") + else if (event.getId() == "-" && mAmountItems > 0) { - assert(mAmountItems > 0); mAmountItems--; - mSlider->setValue(double(mAmountItems)/double(mMaxItems)); - - updateButtonsAndLabels = true; + mSlider->setValue((double) mAmountItems / (double) mMaxItems); + updateButtonsAndLabels(); } - else if (event.getId() == "sell") + else if (event.getId() == "sell" && mAmountItems > 0 + && mAmountItems <= mMaxItems) { // Attempt sell - assert(mAmountItems > 0 && mAmountItems <= mMaxItems); - // XXX Convert for new server /* MessageOut outMsg(CMSG_NPC_SELL_REQUEST); @@ -236,60 +204,77 @@ void SellDialog::action(const gcn::ActionEvent &event) mPlayerMoney += (mAmountItems * mShopItems->at(selectedItem).price); mAmountItems = 0; mSlider->setValue(0); - mSlider->setEnabled(mMaxItems != 0); - - // All were sold - if (!mMaxItems) { + if (!mMaxItems) + { + // All were sold mShopItemList->setSelected(-1); - mShopItems->getShop()->erase(mShopItems->getShop()->begin() + selectedItem); + mShopItems->getShop()->erase( + mShopItems->getShop()->begin() + selectedItem); + } + else + { + // Update only when there are items left, the entry doesn't exist + // otherwise and can't be updated + updateButtonsAndLabels(); } - - // Update only when there are items left, the entry doesn't exist - // otherwise and can't be updated - updateButtonsAndLabels = bool(mMaxItems); - } - - // If anything changed, we need to update the buttons and labels - if (updateButtonsAndLabels) - { - // Update labels - mQuantityLabel->setCaption(toString(mAmountItems) + " / " + toString(mMaxItems)); - mQuantityLabel->adjustSize(); - - int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Money: " + toString(price) + " GP / Total: " - + toString(price + mPlayerMoney) + " GP"); - mMoneyLabel->adjustSize(); - - // Update Buttons - mSellButton->setEnabled(mAmountItems > 0); - mDecreaseButton->setEnabled(mAmountItems > 0); - mIncreaseButton->setEnabled(mAmountItems < mMaxItems); } } void SellDialog::selectionChanged(const SelectionEvent &event) +{ + // Reset amount of items and update labels + mAmountItems = 0; + mSlider->setValue(0); + + updateButtonsAndLabels(); +} + +void SellDialog::setMoney(int amount) +{ + mPlayerMoney = amount; + mShopItemList->setPlayersMoney(amount); +} + +void +SellDialog::updateButtonsAndLabels() { int selectedItem = mShopItemList->getSelected(); + int income = 0; if (selectedItem > -1) { - const ItemInfo &info = - ItemDB::get(mShopItems->at(selectedItem).id); + mMaxItems = mShopItems->at(selectedItem).quantity; + if (mAmountItems > mMaxItems) + { + mAmountItems = mMaxItems; + } + income = mAmountItems * mShopItems->at(selectedItem).price; + + const ItemInfo &info = ItemDB::get(mShopItems->at(selectedItem).id); mItemDescLabel->setCaption("Description: " + info.getDescription()); mItemEffectLabel->setCaption("Effect: " + info.getEffect()); } else { - mItemDescLabel->setCaption("Description"); - mItemEffectLabel->setCaption("Effect"); + mMaxItems = 0; + mAmountItems = 0; + mItemDescLabel->setCaption("Description:"); + mItemEffectLabel->setCaption("Effect:"); } -} -void SellDialog::setMoney(int amount) -{ - mPlayerMoney = amount; - mShopItemList->setPlayersMoney(amount); + // Update Buttons and slider + mSellButton->setEnabled(mAmountItems > 0); + mDecreaseButton->setEnabled(mAmountItems > 0); + mIncreaseButton->setEnabled(mAmountItems < mMaxItems); + mSlider->setEnabled(selectedItem > -1); + + // Update the quantity and money labels + mQuantityLabel->setCaption( + toString(mAmountItems) + " / " + toString(mMaxItems)); + mQuantityLabel->adjustSize(); + mMoneyLabel->setCaption("Money: " + toString(income) + " GP / Total: " + + toString(mPlayerMoney + income) + " GP"); + mMoneyLabel->adjustSize(); } diff --git a/src/gui/sell.h b/src/gui/sell.h index 68bd7b8b..b8385a6f 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,6 +82,12 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener */ void setMoney(int amount); + /** + * Updates the state of buttons and labels. + */ + void + updateButtonsAndLabels(); + private: gcn::Button *mSellButton; gcn::Button *mIncreaseButton; diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index d8130cd3..ed75e5b3 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -157,6 +157,7 @@ void UpdaterWindow::setLabel(const std::string &str) void UpdaterWindow::enable() { + mCancelButton->setEnabled(false); mPlayButton->setEnabled(true); mPlayButton->requestFocus(); } @@ -168,11 +169,7 @@ void UpdaterWindow::action(const gcn::ActionEvent &event) // Register the user cancel mUserCancel = true; // Skip the updating process - if (mDownloadStatus == UPDATE_COMPLETE) - { - state = STATE_EXIT; - } - else + if (mDownloadStatus != UPDATE_COMPLETE) { mDownloadStatus = UPDATE_ERROR; } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index f3e9031c..2af1d960 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -41,10 +41,13 @@ #include "../resources/animation.h" #include "../resources/monsterinfo.h" #include "../resources/resourcemanager.h" +#include "../resources/image.h" #include "../resources/imageset.h" #include "../utils/tostring.h" +#include + Viewport::Viewport(): mMap(0), mViewX(0.0f), @@ -67,37 +70,62 @@ Viewport::Viewport(): mPopupMenu = new PopupMenu(); // Load target cursors + loadTargetCursor("graphics/gui/target-cursor-blue-s.png", 44, 35, + false, Being::TC_SMALL); + loadTargetCursor("graphics/gui/target-cursor-red-s.png", 44, 35, + true, Being::TC_SMALL); + loadTargetCursor("graphics/gui/target-cursor-blue-m.png", 62, 44, + false, Being::TC_MEDIUM); + loadTargetCursor("graphics/gui/target-cursor-red-m.png", 62, 44, + true, Being::TC_MEDIUM); + loadTargetCursor("graphics/gui/target-cursor-blue-l.png", 82, 60, + false, Being::TC_LARGE); + loadTargetCursor("graphics/gui/target-cursor-red-l.png", 82, 60, + true, Being::TC_LARGE); +} + +void +Viewport::loadTargetCursor(std::string filename, int width, int height, + bool outRange, Being::TargetCursorSize size) +{ + assert(size > -1); + assert(size < 3); + + ImageSet* currentImageSet; + SimpleAnimation* currentCursor; + ResourceManager *resman = ResourceManager::getInstance(); - mInRangeImages = resman->getImageSet( - "graphics/gui/target-cursor-blue.png", 44, 35); - mOutRangeImages = resman->getImageSet( - "graphics/gui/target-cursor-red.png", 44, 35); - Animation *animInRange = new Animation(); - Animation *animOutRange = new Animation(); - - for (unsigned int i = 0; i < mInRangeImages->size(); ++i) + + currentImageSet = resman->getImageSet(filename, width, height); + Animation *anim = new Animation(); + for (unsigned int i = 0; i < currentImageSet->size(); ++i) { - animInRange->addFrame(mInRangeImages->get(i), 75, 0, 0); + anim->addFrame(currentImageSet->get(i), 75, 0, 0); } + currentCursor = new SimpleAnimation(anim); - for (unsigned int j = 0; j < mOutRangeImages->size(); ++j) + if (outRange) { - animOutRange->addFrame(mOutRangeImages->get(j), 75, 0, 0); + mOutRangeImages[size] = currentImageSet; + mTargetCursorOutRange[size] = currentCursor; + } + else { + mInRangeImages[size] = currentImageSet; + mTargetCursorInRange[size] = currentCursor; } - - mTargetCursorInRange = new SimpleAnimation(animInRange); - mTargetCursorOutRange = new SimpleAnimation(animOutRange); } Viewport::~Viewport() { delete mPopupMenu; - delete mTargetCursorInRange; - delete mTargetCursorOutRange; - - mInRangeImages->decRef(); - mOutRangeImages->decRef(); + for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++) + { + delete mTargetCursorInRange[i]; + delete mTargetCursorOutRange[i]; + mInRangeImages[i]->decRef(); + mOutRangeImages[i]->decRef(); + } } void @@ -259,8 +287,11 @@ Viewport::logic() mWalkTime = player_node->mWalkTime; } - mTargetCursorInRange->update(10); - mTargetCursorOutRange->update(10); + for (int i = 0; i < 3; i++) + { + mTargetCursorInRange[i]->update(10); + mTargetCursorOutRange[i]->update(10); + } } void @@ -270,26 +301,31 @@ Viewport::drawTargetCursor(Graphics *graphics) Being *target = player_node->getTarget(); if (target) { + // Calculate target circle position + // Find whether target is in range int rangeX = abs(target->mX - player_node->mX); int rangeY = abs(target->mY - player_node->mY); int attackRange = player_node->getAttackRange(); - // Draw the target cursor, which one depends if the target is in range + // Get the correct target cursors graphic + Being::TargetCursorSize cursorSize = target->getTargetCursorSize(); + Image* targetCursor; if (rangeX > attackRange || rangeY > attackRange) { - // Draw the out of range cursor - graphics->drawImage(mTargetCursorOutRange->getCurrentImage(), - target->getPixelX() - mCameraX, - target->getPixelY() - mCameraY); + targetCursor = mTargetCursorOutRange[cursorSize]->getCurrentImage(); } - else - { - // Draw the in range cursor - graphics->drawImage(mTargetCursorInRange->getCurrentImage(), - target->getPixelX() - mCameraX, - target->getPixelY() - mCameraY); + else { + targetCursor = mTargetCursorInRange[cursorSize]->getCurrentImage(); } + + // Draw the target cursor at the correct position + int posX = target->getPixelX() + 16 - + targetCursor->getWidth() / 2 - mCameraX; + int posY = target->getPixelY() + 16 - + targetCursor->getHeight() / 2 - mCameraY; + + graphics->drawImage(targetCursor, posX, posY); } } @@ -304,10 +340,10 @@ Viewport::drawTargetName(Graphics *graphics) graphics->setColor(gcn::Color(255, 32, 32)); const MonsterInfo &mi = static_cast(target)->getInfo(); - graphics->drawText(mi.getName(), - target->getPixelX() - mCameraX + 15, - target->getPixelY() - mCameraY - 42, - gcn::Graphics::CENTER); + int posX = target->getPixelX() + 16 - mCameraX; + int posY = target->getPixelY() + 16 - target->getHeight() - mCameraY; + + graphics->drawText(mi.getName(), posX, posY, gcn::Graphics::CENTER); } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 84efeff3..22d0f249 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -29,9 +29,9 @@ #include "windowcontainer.h" #include "../configlistener.h" +#include "../being.h" class Map; -class Being; class FloorItem; class ImageSet; class Item; @@ -141,6 +141,13 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void showPopup(int x, int y, Being *being); + /** + * Helper function for loading target cursors + */ + void + loadTargetCursor(std::string filename, int width, int height, + bool outRange, Being::TargetCursorSize size); + /** * Draws range based target cursor */ @@ -164,14 +171,17 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mCameraY; /**< Current viewpoint in tiles. */ bool mShowDebugPath; /**< Show a path from player to pointer. */ - ImageSet *mInRangeImages; /**< Images of in range target cursor. */ - ImageSet *mOutRangeImages; /**< Images of out of range target cursor.*/ + /** Images of in range target cursor. */ + ImageSet *mInRangeImages[Being::NUM_TC]; + + /** Images of out of range target cursor. */ + ImageSet *mOutRangeImages[Being::NUM_TC]; /** Animated in range target cursor. */ - SimpleAnimation *mTargetCursorInRange; + SimpleAnimation *mTargetCursorInRange[Being::NUM_TC]; /** Animated out of range target cursor. */ - SimpleAnimation *mTargetCursorOutRange; + SimpleAnimation *mTargetCursorOutRange[Being::NUM_TC]; bool mPlayerFollowMouse; int mWalkTime; diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp new file mode 100644 index 00000000..50a6fce4 --- /dev/null +++ b/src/gui/widgets/resizegrip.cpp @@ -0,0 +1,65 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "resizegrip.h" + +#include + +#include "../../graphics.h" + +#include "../../resources/image.h" +#include "../../resources/resourcemanager.h" + +Image *ResizeGrip::gripImage = 0; +int ResizeGrip::mInstances = 0; + +ResizeGrip::ResizeGrip() +{ + if (mInstances == 0) + { + // Load the grip image + ResourceManager *resman = ResourceManager::getInstance(); + gripImage = resman->getImage("graphics/gui/resize.png"); + } + + mInstances++; + + setWidth(gripImage->getWidth() + 2); + setHeight(gripImage->getHeight() + 2); +} + +ResizeGrip::~ResizeGrip() +{ + mInstances--; + + if (mInstances == 0) + { + gripImage->decRef(); + } +} + +void +ResizeGrip::draw(gcn::Graphics *graphics) +{ + dynamic_cast(graphics)->drawImage(gripImage, 0, 0); +} diff --git a/src/gui/widgets/resizegrip.h b/src/gui/widgets/resizegrip.h new file mode 100644 index 00000000..04be3db3 --- /dev/null +++ b/src/gui/widgets/resizegrip.h @@ -0,0 +1,61 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_RESIZEGRIP_H +#define _TMW_RESIZEGRIP_H + +#include + +class Image; + +/** + * Resize grip. The resize grip is part of a resizable Window. It relies on the + * fact that uncaught mouse events are automatically routed to the parent + * window. + * + * \ingroup GUI + */ +class ResizeGrip : public gcn::Widget +{ + public: + /** + * Constructor. + */ + ResizeGrip(); + + /** + * Destructor. + */ + ~ResizeGrip(); + + /** + * Draws the resize grip. + */ + void draw(gcn::Graphics *graphics); + + private: + static Image *gripImage; /**< Resize grip image */ + static int mInstances; /**< Number of resize grip instances */ +}; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bb60c6ff..8a052bba 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -24,10 +24,13 @@ #include "window.h" #include +#include #include "gccontainer.h" #include "windowcontainer.h" +#include "widgets/resizegrip.h" + #include "../configlistener.h" #include "../configuration.h" #include "../graphics.h" @@ -36,11 +39,10 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" -ConfigListener *Window::windowConfigListener = NULL; -WindowContainer *Window::windowContainer = NULL; +ConfigListener *Window::windowConfigListener = 0; +WindowContainer *Window::windowContainer = 0; int Window::instances = 0; ImageRect Window::border; -Image *Window::resizeGrip; class WindowConfigListener : public ConfigListener { @@ -54,16 +56,16 @@ class WindowConfigListener : public ConfigListener Window::Window(const std::string& caption, bool modal, Window *parent): gcn::Window(caption), + mGrip(0), mParent(parent), mWindowName("window"), - mSnapSize(8), mShowTitle(true), mModal(modal), mResizable(false), - mMouseResize(false), + mMouseResize(0), mSticky(false), mMinWinWidth(100), - mMinWinHeight(28), + mMinWinHeight(40), mMaxWinWidth(INT_MAX), mMaxWinHeight(INT_MAX) { @@ -87,7 +89,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent): border.grid[6] = dBorders->getSubImage(0, 15, 4, 4); border.grid[7] = dBorders->getSubImage(4, 15, 3, 4); border.grid[8] = dBorders->getSubImage(7, 15, 4, 4); - resizeGrip = resman->getImage("graphics/gui/resize.png"); dBorders->decRef(); windowConfigListener = new WindowConfigListener(); // Send GUI alpha changed for initialization @@ -151,10 +152,10 @@ Window::~Window() delete border.grid[6]; delete border.grid[7]; delete border.grid[8]; - resizeGrip->decRef(); } delete mChrome; + delete mGrip; } void Window::setWindowContainer(WindowContainer *wc) @@ -162,22 +163,15 @@ void Window::setWindowContainer(WindowContainer *wc) windowContainer = wc; } -void Window::draw(gcn::Graphics* graphics) +void Window::draw(gcn::Graphics *graphics) { - Graphics *g = (Graphics*)graphics; + Graphics *g = static_cast(graphics); g->drawImageRect(0, 0, getWidth(), getHeight(), border); - // Draw grip - if (mResizable) - { - g->drawImage(Window::resizeGrip, - getWidth() - resizeGrip->getWidth(), - getHeight() - resizeGrip->getHeight()); - } - // Draw title - if (mShowTitle) { + if (mShowTitle) + { graphics->setFont(getFont()); graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } @@ -188,13 +182,13 @@ void Window::draw(gcn::Graphics* graphics) void Window::setContentWidth(int width) { mChrome->setWidth(width); - resizeToContent(); + setWidth(width + 2 * getPadding()); } void Window::setContentHeight(int height) { mChrome->setHeight(height); - resizeToContent(); + setHeight(height + getPadding() + getTitleBarHeight()); } void Window::setContentSize(int width, int height) @@ -203,6 +197,37 @@ void Window::setContentSize(int width, int height) setContentHeight(height); } +void Window::setWidth(int width) +{ + gcn::Window::setWidth(width); + + if (mGrip) + { + mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); + } +} + +void Window::setHeight(int height) +{ + gcn::Window::setHeight(height); + + if (mGrip) + { + mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); + } +} + +void Window::setDimension(const gcn::Rectangle &dimension) +{ + gcn::Window::setDimension(dimension); + + if (mGrip) + { + mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); + mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); + } +} + void Window::setLocationRelativeTo(gcn::Widget *widget) { int wx, wy; @@ -238,6 +263,19 @@ void Window::setMaxHeight(unsigned int height) void Window::setResizable(bool r) { mResizable = r; + + if (mResizable) + { + mGrip = new ResizeGrip(); + mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); + mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); + gcn::Window::add(mGrip); + } + else + { + delete mGrip; + mGrip = 0; + } } bool Window::isResizable() @@ -287,15 +325,27 @@ void Window::mousePressed(gcn::MouseEvent &event) // Let Guichan move window to top and figure out title bar drag gcn::Window::mousePressed(event); - int x = event.getX(); - int y = event.getY(); + const int x = event.getX(); + const int y = event.getY(); + mMouseResize = 0; - // Activate resizing if the left mouse button was pressed on the grip - mMouseResize = - isResizable() && - event.getButton() == gcn::MouseEvent::LEFT && - getGripDimension().isPointInRect(x, y) && - !getChildrenArea().isPointInRect(x, y); + // Activate resizing handles as appropriate + if (event.getSource() == this && isResizable() && + event.getButton() == gcn::MouseEvent::LEFT && + !getChildrenArea().isPointInRect(x, y)) + { + mMouseResize |= (x > getWidth() - resizeBorderWidth) ? RIGHT : + (x < resizeBorderWidth) ? LEFT : 0; + mMouseResize |= (y > getHeight() - resizeBorderWidth) ? BOTTOM : + (y < resizeBorderWidth) ? TOP : 0; + } + else if (event.getSource() == mGrip) + { + mDragOffsetX = x + mGrip->getX(); + mDragOffsetY = y + mGrip->getY(); + mMouseResize |= BOTTOM | RIGHT; + mIsMoving = false; + } } void Window::mouseDragged(gcn::MouseEvent &event) @@ -303,20 +353,47 @@ void Window::mouseDragged(gcn::MouseEvent &event) // Let Guichan handle title bar drag gcn::Window::mouseDragged(event); - // Keep guichan window inside screen - int newX = std::max(0, getX()); - int newY = std::max(0, getY()); - newX = std::min(windowContainer->getWidth() - getWidth(), newX); - newY = std::min(windowContainer->getHeight() - getHeight(), newY); - setPosition(newX, newY); + // Keep guichan window inside screen when it may be moved + if (isMovable() && mIsMoving) + { + int newX = std::max(0, getX()); + int newY = std::max(0, getY()); + newX = std::min(windowContainer->getWidth() - getWidth(), newX); + newY = std::min(windowContainer->getHeight() - getHeight(), newY); + setPosition(newX, newY); + } if (mMouseResize && !mIsMoving) { + const int dx = event.getX() - mDragOffsetX + + ((event.getSource() == mGrip) ? mGrip->getX() : 0); + const int dy = event.getY() - mDragOffsetY + + ((event.getSource() == mGrip) ? mGrip->getY() : 0); gcn::Rectangle newDim = getDimension(); - // We're dragging bottom right - newDim.width += event.getX() - mDragOffsetX; - newDim.height += event.getY() - mDragOffsetY; + if (mMouseResize & (TOP | BOTTOM)) + { + int newHeight = newDim.height + ((mMouseResize & TOP) ? -dy : dy); + newDim.height = std::min(mMaxWinHeight, + std::max(mMinWinHeight, newHeight)); + + if (mMouseResize & TOP) + { + newDim.y -= newDim.height - getHeight(); + } + } + + if (mMouseResize & (LEFT | RIGHT)) + { + int newWidth = newDim.width + ((mMouseResize & LEFT) ? -dx : dx); + newDim.width = std::min(mMaxWinWidth, + std::max(mMinWinWidth, newWidth)); + + if (mMouseResize & LEFT) + { + newDim.x -= newDim.width - getWidth(); + } + } // Keep guichan window inside screen (supports resizing any side) if (newDim.x < 0) @@ -338,29 +415,16 @@ void Window::mouseDragged(gcn::MouseEvent &event) newDim.height = windowContainer->getHeight() - newDim.y; } - // Keep the window at least its minimum size - if (newDim.width < mMinWinWidth) - { - newDim.width = mMinWinWidth; - } - else if (newDim.width > mMaxWinWidth) - { - newDim.width = mMaxWinWidth; - } - - if (newDim.height < mMinWinHeight) + // Update mouse offset when dragging bottom or right border + if (mMouseResize & BOTTOM) { - newDim.height = mMinWinHeight; + mDragOffsetY += newDim.height - getHeight(); } - else if (newDim.height > mMaxWinHeight) + if (mMouseResize & RIGHT) { - newDim.height = mMaxWinHeight; + mDragOffsetX += newDim.width - getWidth(); } - // Update mouse offset when dragging bottom or right border - mDragOffsetX += newDim.width - getWidth(); - mDragOffsetY += newDim.height - getHeight(); - // Set the new window and content dimensions setDimension(newDim); const gcn::Rectangle area = getChildrenArea(); @@ -368,15 +432,6 @@ void Window::mouseDragged(gcn::MouseEvent &event) } } -gcn::Rectangle -Window::getGripDimension() -{ - return gcn::Rectangle(getWidth() - resizeGrip->getWidth(), - getHeight() - resizeGrip->getHeight(), - getWidth(), - getHeight()); -} - void Window::loadWindowState() { diff --git a/src/gui/window.h b/src/gui/window.h index 31c260cf..03248908 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -30,11 +30,10 @@ class ConfigListener; class GCContainer; -class Image; class ImageRect; +class ResizeGrip; class WindowContainer; - /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -99,6 +98,21 @@ class Window : public gcn::Window */ void setContentSize(int width, int height); + /** + * Sets the width of this window. + */ + void setWidth(int width); + + /** + * Sets the height of this window. + */ + void setHeight(int height); + + /** + * Sets the position and size of this window. + */ + void setDimension(const gcn::Rectangle &dimension); + /** * Sets the location relative to the given widget. */ @@ -168,16 +182,15 @@ class Window : public gcn::Window void scheduleDelete(); /** - * Window dragging and resizing mouse related. These methods also makes - * sure the window is not dragged/resized outside of the screen. + * Starts window resizing when appropriate. */ void mousePressed(gcn::MouseEvent &event); - void mouseDragged(gcn::MouseEvent &event); /** - * Gets the position of the resize grip. + * Implements window resizing and makes sure the window is not + * dragged/resized outside of the screen. */ - gcn::Rectangle getGripDimension(); + void mouseDragged(gcn::MouseEvent &event); /** * Sets the name of the window. This is not the window title. @@ -214,37 +227,50 @@ class Window : public gcn::Window */ virtual void resetToDefaultSize(); + enum ResizeHandles + { + TOP = 0x01, + RIGHT = 0x02, + BOTTOM = 0x04, + LEFT = 0x08 + }; + protected: - GCContainer *mChrome; /**< Contained container */ + GCContainer *mChrome; /**< Contained container */ + ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ std::string mWindowName; /**< Name of the window */ - int mSnapSize; /**< Snap distance to window edge */ bool mShowTitle; /**< Window has a title bar */ bool mModal; /**< Window is modal */ - bool mResizable; /**< Window can be resized */ - bool mMouseResize; /**< Window is being resized */ - bool mSticky; /**< Window resists minimzation */ - int mMinWinWidth; /**< Minimum window width */ - int mMinWinHeight; /**< Minimum window height */ - int mMaxWinWidth; /**< Maximum window width */ - int mMaxWinHeight; /**< Maximum window height */ + bool mResizable; /**< Window can be resized */ + int mMouseResize; /**< Window is being resized */ + bool mSticky; /**< Window resists minimization */ + int mMinWinWidth; /**< Minimum window width */ + int mMinWinHeight; /**< Minimum window height */ + int mMaxWinWidth; /**< Maximum window width */ + int mMaxWinHeight; /**< Maximum window height */ int mDefaultX; /**< Default window X position */ int mDefaultY; /**< Default window Y position */ int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ /** The window container windows add themselves to. */ - static WindowContainer* windowContainer; + static WindowContainer *windowContainer; /** - * The config listener that listens to changes relevant to all - * windows + * The config listener that listens to changes relevant to all windows. */ static ConfigListener *windowConfigListener; static int instances; /**< Number of Window instances */ static ImageRect border; /**< The window border and background */ - static Image *resizeGrip; /**< The grip to resize window */ + + /** + * The width of the resize border. Is independent of the actual window + * border width, and determines mostly the size of the corner area + * where two borders are moved at the same time. + */ + static const int resizeBorderWidth = 10; }; #endif diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp new file mode 100644 index 00000000..35cc21ad --- /dev/null +++ b/src/imageparticle.cpp @@ -0,0 +1,69 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "imageparticle.h" + +#include "graphics.h" + +#include "resources/image.h" + +ImageParticle::ImageParticle(Map *map, Image *image): + Particle(map), + mImage(image) +{ + mImage->incRef(); +} + +ImageParticle::~ImageParticle() +{ + mImage->decRef(); +} + +void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const +{ + if (!mAlive) + return; + + int screenX = (int) mPosX + offsetX - mImage->getWidth() / 2; + int screenY = (int) mPosY - (int) mPosZ + offsetY - mImage->getHeight()/2; + + // Check if on screen + if (screenX + mImage->getWidth() < 0 || + screenX > graphics->getWidth() || + screenY + mImage->getHeight() < 0 || + screenY > graphics->getHeight()) + { + return; + } + + float alphafactor = 1.0f; + + if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) + alphafactor *= (float) mLifetimeLeft / (float) mFadeOut; + + if (mLifetimePast < mFadeIn) + alphafactor *= (float) mLifetimePast / (float) mFadeIn; + + mImage->setAlpha(alphafactor); + graphics->drawImage(mImage, screenX, screenY); +} diff --git a/src/imageparticle.h b/src/imageparticle.h new file mode 100644 index 00000000..0ad515cc --- /dev/null +++ b/src/imageparticle.h @@ -0,0 +1,61 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _IMAGEPARTICLE_H +#define _IMAGEPARTICLE_H + +#include "particle.h" + +class Image; +class Map; + +/** + * A particle that uses an image for its visualization. + */ +class ImageParticle : public Particle +{ + public: + /** + * Constructor. The image is reference counted by this particle. + * + * @param map the map this particle appears on + * @param image an Image instance, may not be NULL + */ + ImageParticle(Map *map, Image *image); + + /** + * Destructor. + */ + ~ImageParticle(); + + /** + * Draws the particle image + */ + virtual void + draw(Graphics *graphics, int offsetX, int offsetY) const; + + protected: + Image *mImage; /**< The image used for this particle. */ +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp index bbbf0fd1..58c563ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,7 @@ #include -#if (defined __USE_UNIX98 || defined __FreeBSD__ || defined __APPLE__) +#ifndef WIN32 #include #include #endif @@ -148,21 +148,21 @@ struct Options */ void initHomeDir() { -#if !(defined __USE_UNIX98 || defined __FreeBSD__ || defined __APPLE__) - homeDir = "."; -#else homeDir = std::string(PHYSFS_getUserDir()) + "/.tmw"; - +#if defined WIN32 + if (!CreateDirectory(homeDir.c_str(), 0) && + GetLastError() != ERROR_ALREADY_EXISTS) +#else // Checking if /home/user/.tmw folder exists. if ((mkdir(homeDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST)) +#endif { std::cout << homeDir - << " can't be made, but it doesn't exist! Exiting." + << " can't be created, but it doesn't exist! Exiting." << std::endl; exit(1); } -#endif } /** @@ -236,11 +236,17 @@ void initEngine() static SDL_SysWMinfo pInfo; SDL_GetWMInfo(&pInfo); HICON icon = LoadIcon(GetModuleHandle(NULL), "A"); - SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); + if (icon) + { + SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); + } #else SDL_Surface *icon = IMG_Load(TMW_DATADIR "data/icons/tmw.png"); - SDL_SetAlpha(icon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); - SDL_WM_SetIcon(icon, NULL); + if (icon) + { + SDL_SetAlpha(icon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); + SDL_WM_SetIcon(icon, NULL); + } #endif ResourceManager *resman = ResourceManager::getInstance(); diff --git a/src/map.cpp b/src/map.cpp index a6beb951..ac570627 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -29,6 +29,7 @@ #include "beingmanager.h" #include "game.h" #include "graphics.h" +#include "particle.h" #include "sprite.h" #include "tileset.h" @@ -530,3 +531,25 @@ Map::findPath(int startX, int startY, int destX, int destY) return path; } + +void +Map::addParticleEffect (std::string effectFile, int x, int y) +{ + ParticleEffectData newEffect; + newEffect.file = effectFile; + newEffect.x = x; + newEffect.y = y; + particleEffects.push_back(newEffect); +} + +void +Map::initializeParticleEffects(Particle* particleEngine) +{ + for (std::list::iterator i = particleEffects.begin(); + i != particleEffects.end(); + i++ + ) + { + particleEngine->addEffect(i->file, i->x, i->y); + } +} diff --git a/src/map.h b/src/map.h index c8a6fdb3..17772847 100644 --- a/src/map.h +++ b/src/map.h @@ -32,8 +32,9 @@ class AmbientOverlay; class Graphics; class Image; -class Tileset; +class Particle; class Sprite; +class Tileset; struct PATH_NODE; @@ -185,6 +186,17 @@ class Map : public Properties void removeSprite(SpriteIterator iterator); + /** + * Adds a particle effect + */ + void addParticleEffect (std::string effectFile, int x, int y); + + /** + * Initializes all added particle effects + */ + void + initializeParticleEffects(Particle* particleEngine); + private: /** * Converts a global tile id to the Image* pointing to the associated @@ -220,10 +232,19 @@ class Map : public Properties // Pathfinding members int mOnClosedList, mOnOpenList; - //overlay Data + // Overlay Data std::list mOverlays; float mLastScrollX; float mLastScrollY; + + // Particle effect data + struct ParticleEffectData + { + std::string file; + int x; + int y; + }; + std::list particleEffects; }; #endif diff --git a/src/monster.cpp b/src/monster.cpp index bea5b7a5..768bf16a 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -93,6 +93,12 @@ Monster::handleAttack() sound.playSfx(mi.getSound(EVENT_HIT)); } +Being::TargetCursorSize +Monster::getTargetCursorSize() const +{ + return getInfo().getTargetCursorSize(); +} + const MonsterInfo& Monster::getInfo() const { diff --git a/src/monster.h b/src/monster.h index 39bbf3d7..4915520d 100644 --- a/src/monster.h +++ b/src/monster.h @@ -37,6 +37,9 @@ class Monster : public Being virtual Type getType() const; + virtual TargetCursorSize + getTargetCursorSize() const; + /** * Handles an attack of another being by this monster. Plays a hit or * miss sound when appropriate. diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 53746671..f82a0fa8 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -34,6 +34,7 @@ #include "../localplayer.h" #include "../log.h" #include "../main.h" +#include "../particle.h" #include "../sound.h" const int EMOTION_TIME = 150; /**< Duration of emotion icon */ @@ -240,13 +241,23 @@ void BeingHandler::handleMessage(MessageIn &msg) break; case SMSG_BEING_LEVELUP: - if ((Uint32) msg.readLong() == player_node->getId()) { + id = (Uint32) msg->readLong(); + + if (id == player_node->getId()) { logger->log("Level up"); sound.playSfx("sfx/levelup.ogg"); - } else { + } + else { logger->log("Someone else went level up"); } - msg.readLong(); // type + Particle *levelupFX; + if (msg->readLong() == 0) { // type + levelupFX = particleEngine->addEffect("graphics/particles/levelup.particle.xml", 0, 0); + } + else { + levelupFX = particleEngine->addEffect("graphics/particles/skillup.particle.xml", 0, 0); + } + beingManager->findBeing(id)->controlParticle(levelupFX); break; case SMSG_BEING_EMOTION: diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index ec6c1ee3..f4cda0b9 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -261,7 +261,7 @@ void OpenGLGraphics::drawPoint(int x, int y) setTexturingAndBlending(false); glBegin(GL_POINTS); - glVertex3i(x, y, 0); + glVertex2i(x, y); glEnd(); } @@ -270,12 +270,12 @@ void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) setTexturingAndBlending(false); glBegin(GL_LINES); - glVertex3f(x1 + 0.5f, y1 + 0.5f, 0); - glVertex3f(x2 + 0.5f, y2 + 0.5f, 0); + glVertex2f(x1 + 0.5f, y1 + 0.5f); + glVertex2f(x2 + 0.5f, y2 + 0.5f); glEnd(); glBegin(GL_POINTS); - glVertex3f(x2 + 0.5f, y2 + 0.5f, 0); + glVertex2f(x2 + 0.5f, y2 + 0.5f); glEnd(); } @@ -329,10 +329,10 @@ void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) setTexturingAndBlending(false); glBegin(filled ? GL_QUADS : GL_LINE_LOOP); - glVertex3f(rect.x + offset, rect.y + offset, 0); - glVertex3f(rect.x + rect.width - offset, rect.y + offset, 0); - glVertex3f(rect.x + rect.width - offset, rect.y + rect.height - offset, 0); - glVertex3f(rect.x + offset, rect.y + rect.height - offset, 0); + glVertex2f(rect.x + offset, rect.y + offset); + glVertex2f(rect.x + rect.width - offset, rect.y + offset); + glVertex2f(rect.x + rect.width - offset, rect.y + rect.height - offset); + glVertex2f(rect.x + offset, rect.y + rect.height - offset); glEnd(); } @@ -344,16 +344,16 @@ void OpenGLGraphics::drawTexedQuad(int x, int y, int w, int h, // Draw a textured quad glBegin(GL_QUADS); glTexCoord2f(texX1, texY1); - glVertex3i(x, y, 0); + glVertex2i(x, y); glTexCoord2f(texX2, texY1); - glVertex3i(x + w, y, 0); + glVertex2i(x + w, y); glTexCoord2f(texX2, texY2); - glVertex3i(x + w, y + h, 0); + glVertex2i(x + w, y + h); glTexCoord2f(texX1, texY2); - glVertex3i(x, y + h, 0); + glVertex2i(x, y + h); glEnd(); } diff --git a/src/particle.cpp b/src/particle.cpp new file mode 100644 index 00000000..509c20ee --- /dev/null +++ b/src/particle.cpp @@ -0,0 +1,370 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "particle.h" + +#include + +#include "animationparticle.h" +#include "configuration.h" +#include "imageparticle.h" +#include "log.h" +#include "map.h" +#include "particleemitter.h" +#include "textparticle.h" + +#include "resources/resourcemanager.h" + +#include "utils/dtor.h" +#include "utils/fastsqrt.h" +#include "utils/xml.h" + +class Graphics; +class Image; + +int Particle::particleCount = 0; +int Particle::maxCount = 0; +int Particle::fastPhysics = 0; +int Particle::emitterSkip = 1; +const float Particle::PARTICLE_SKY = 800.0f; + +Particle::Particle(Map *map): + mAlive(true), + mPosX(0.0f), mPosY(0.0f), mPosZ(0.0f), + mLifetimeLeft(-1), + mLifetimePast(0), + mFadeOut(0), + mFadeIn(0), + mAutoDelete(true), + mMap(map), + mVectorX(0.0f), mVectorY(0.0f), mVectorZ(0.0f), + mGravity(0.0f), + mRandomnes(0), + mBounce(0.0f), + mTarget(NULL), + mAcceleration(0.0f), + mInvDieDistance(-1.0f), + mMomentum(1.0f) +{ + Particle::particleCount++; + if (mMap) setSpriteIterator(mMap->addSprite(this)); +} + + +void +Particle::setupEngine() +{ + Particle::maxCount = (int)config.getValue("particleMaxCount", 3000); + Particle::fastPhysics = (int)config.getValue("particleFastPhysics", 0); + Particle::emitterSkip = (int)config.getValue("particleEmitterSkip", 0) + 1; + disableAutoDelete(); + logger->log("Particle engine set up"); +} + +bool +Particle::update() +{ + if (!mMap) return false; + + if (mLifetimeLeft == 0) + { + mAlive = false; + } + + if (mAlive) + { + // Update child emitters + if (mLifetimePast%Particle::emitterSkip == 0) + { + for ( EmitterIterator e = mChildEmitters.begin(); + e != mChildEmitters.end(); + e++ + ) + { + Particles newParticles = (*e)->createParticles(); + for ( ParticleIterator p = newParticles.begin(); + p != newParticles.end(); + p++ + ) + { + (*p)->moveBy(mPosX, mPosY, mPosZ); + mChildParticles.push_back (*p); + } + } + } + + if (mMomentum != 1.0f) + { + mVectorX *= mMomentum; + mVectorY *= mMomentum; + mVectorZ *= mMomentum; + } + + if (mTarget && mAcceleration != 0.0f) + { + float distX = mPosX - mTarget->getPosX(); + float distY = mPosY - mTarget->getPosY(); + float distZ = mPosZ - mTarget->getPosZ(); + float invHypotenuse; + + switch(Particle::fastPhysics) + { + case 1: + invHypotenuse = fastInvSqrt( + distX * distX + distY * distY + distZ * distZ); + break; + case 2: + invHypotenuse = 2.0f / + fabs(distX) + fabs(distY) + fabs(distZ); + break; + default: + invHypotenuse = 1.0f / sqrt( + distX * distX + distY * distY + distZ * distZ); + break; + } + + if (invHypotenuse) + { + if (mInvDieDistance > 0.0f && invHypotenuse > mInvDieDistance) + { + mAlive = false; + } + float accFactor = invHypotenuse * mAcceleration; + mVectorX -= distX * accFactor; + mVectorY -= distY * accFactor; + mVectorZ -= distZ * accFactor; + } + } + + if (mRandomnes > 0) + { + mVectorX += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVectorY += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVectorZ += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + } + + mVectorZ -= mGravity; + + // Update position + mPosX += mVectorX; + mPosY += mVectorY; + mPosZ += mVectorZ; + + // Update other stuff + if (mLifetimeLeft > 0) + { + mLifetimeLeft--; + } + mLifetimePast++; + + if (mPosZ > PARTICLE_SKY || mPosZ < 0.0f) + { + if (mBounce > 0.0f) + { + mPosZ *= -mBounce; + mVectorX *= mBounce; + mVectorY *= mBounce; + mVectorZ *= -mBounce; + } + else { + mAlive = false; + } + } + } + + // Update child particles + for ( ParticleIterator p = mChildParticles.begin(); + p != mChildParticles.end(); + + ) + { + if ((*p)->update()) + { + p++; + } else { + delete (*p); + p = mChildParticles.erase(p); + } + } + + if (!mAlive && mChildParticles.empty() && mAutoDelete) + { + return false; + } + + return true; +} + + +void Particle::draw(Graphics *graphics, int offsetX, int offsetY) const +{ +} + + +Particle* +Particle::addEffect(std::string particleEffectFile, int pixelX, int pixelY) +{ + Particle *newParticle = NULL; + + // XML parser initialisation stuff + int size; + ResourceManager *resman = ResourceManager::getInstance(); + char *data = (char*) resman->loadFile(particleEffectFile.c_str(), size); + + if (!data) { + logger->log("Warning: Particle engine could not find %s !", + particleEffectFile.c_str()); + return NULL; + } + + xmlDocPtr doc = xmlParseMemory(data, size); + free(data); + + if (!doc) { + logger->log("Warning: Particle engine found syntax error in %s!", + particleEffectFile.c_str()); + return NULL; + } + + xmlNodePtr rootNode = xmlDocGetRootElement(doc); + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect")) + { + logger->log("Warning: %s is not a valid particle effect definition file!", + particleEffectFile.c_str()); + return NULL; + } + + // Parse particles + for_each_xml_child_node(effectChildNode, rootNode) + { + // We're only interested in particles + if (!xmlStrEqual(effectChildNode->name, BAD_CAST "particle")) + continue; + + // Determine the exact particle type + xmlNodePtr node; + + // Animation + if ((node = XML::findFirstChildByName( + effectChildNode, "animation"))) { + newParticle = new AnimationParticle(mMap, node); + } + // Image + else if ((node = XML::findFirstChildByName( + effectChildNode, "image"))) { + Image *img= resman->getImage((const char*) + node->xmlChildrenNode->content); + + newParticle = new ImageParticle(mMap, img); + } + // Other + else { + newParticle = new Particle(mMap); + } + + // Read and set the basic properties of the particle + int offsetX = XML::getProperty(effectChildNode, "position-x", 0); + int offsetY = XML::getProperty(effectChildNode, "position-y", 0); + int offsetZ = XML::getProperty(effectChildNode, "position-z", 0); + + int particleX = (int)mPosX + pixelX + offsetX; + int particleY = (int)mPosY + pixelY + offsetY; + int particleZ = (int)mPosZ + offsetZ; + + int lifetime = XML::getProperty(effectChildNode, "lifetime", -1); + + newParticle->setPosition(particleX, particleY, particleZ); + newParticle->setLifetime(lifetime); + + // Look for additional emitters for this particle + for_each_xml_child_node(emitterNode, effectChildNode) + { + if (!xmlStrEqual(emitterNode->name, BAD_CAST "emitter")) + continue; + + ParticleEmitter *newEmitter; + newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap); + newParticle->addEmitter(newEmitter); + } + + mChildParticles.push_back(newParticle); + } + + return newParticle; +} + + +Particle* +Particle::addTextSplashEffect(std::string text, + int colorR, int colorG, int colorB, + gcn::Font *font, int x, int y) +{ + Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, + font); + newParticle->setPosition(x, y, 0); + newParticle->setVector ( ((rand()%100) - 50) / 200.0f, // X vector + ((rand()%100) - 50) / 200.0f, // Y vector + ((rand()%100) / 200.0f) + 4.0f // Z vector + ); + newParticle->setGravity(0.1f); + newParticle->setBounce(0.5f); + newParticle->setLifetime(200); + newParticle->setFadeOut(100); + + mChildParticles.push_back(newParticle); + + return newParticle; +} + + +void +Particle::setMap(Map *map) +{ + mMap = map; + if (mMap) setSpriteIterator(mMap->addSprite(this)); + + // TODO: Create map emitters based on emitter data in map data +} + + +Particle::~Particle() +{ + // Remove from map sprite list + if (mMap) mMap->removeSprite(mSpriteIterator); + // Delete child emitters and child particles + clear(); + Particle::particleCount--; +} + + +void +Particle::clear() +{ + std::for_each(mChildEmitters.begin(), mChildEmitters.end(), + make_dtor(mChildEmitters)); + mChildEmitters.clear(); + + std::for_each(mChildParticles.begin(), mChildParticles.end(), + make_dtor(mChildParticles)); + mChildParticles.clear(); +} diff --git a/src/particle.h b/src/particle.h new file mode 100644 index 00000000..7a747a5f --- /dev/null +++ b/src/particle.h @@ -0,0 +1,288 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _PARTICLE_H +#define _PARTICLE_H + +#include +#include + +#include + +#include "guichanfwd.h" +#include "sprite.h" + + +class Map; +class Particle; +class ParticleEmitter; + +typedef std::list Particles; +typedef Particles::iterator ParticleIterator; +typedef std::list Emitters; +typedef Emitters::iterator EmitterIterator; + +/** + * A particle spawned by a ParticleEmitter. + */ +class Particle : public Sprite +{ + public: + static const float PARTICLE_SKY; /**< Maximum Z position of particles */ + static int fastPhysics; /**< Mode of squareroot calculation */ + static int particleCount; /**< Current number of particles */ + static int maxCount; /**< Maximum number of particles */ + static int emitterSkip; /**< Duration of pause between two emitter updates in ticks */ + + /** + * Constructor. + * + * @param map the map this particle will add itself to, may be NULL + */ + Particle(Map *map); + + /** + * Destructor. + */ + ~Particle(); + + /** + * Deletes all child particles and emitters + */ + void + clear(); + + /** + * Gives a particle the properties of an engine root particle and loads + * the particle-related config settings + */ + void + setupEngine(); + + /** + * Updates particle position, returns false when the particle should + * be deleted + */ + virtual bool + update(); + + /** + * Draws the particle image + */ + virtual void + draw(Graphics *graphics, int offsetX, int offsetY) const; + + /** + * Necessary for sorting with the other sprites + */ + virtual int + getPixelY() const + { + return (int)(mPosY + mPosZ) - 64; + }; + + /* + Basic Particle properties: + */ + + /** + * Sets the map the particle is on. + */ + void setMap(Map *map); + + /** + * Creates a child particle that hosts some emitters described in the + * particleEffectFile. + */ + Particle* + addEffect(std::string particleEffectFile, int pixelX, int pixelY); + + /** + * Creates a standalone text particle. + */ + Particle* + addTextSplashEffect(std::string text, int colorR, int colorG, int colorB, + gcn::Font *font, int x, int y); + + /** + * Adds an emitter to the particle. + */ + void + addEmitter (ParticleEmitter* emitter) + { mChildEmitters.push_back(emitter); } + + /** + * Sets the position in 3 dimensional space in pixels relative to map + */ + void + setPosition(float x, float y, float z) + { mPosX = x; mPosY = y; mPosZ = z; } + + /** + * Sets the position in 2 dimensional space in pixels relative to map + */ + void + setPosition(float x, float y) + { mPosX = x; mPosY = y; } + + float getPosX() const + { return mPosX; } + + float getPosY() const + { return mPosY; } + + float getPosZ() const + { return mPosZ; } + + /** + * Changes the particle position relative + */ + void + moveBy(float x, float y, float z) + { mPosX += x; mPosY += y; mPosZ += z; } + + /** + * Sets the time in game ticks until the particle is destroyed. + */ + void + setLifetime(int lifetime) + { mLifetimeLeft = lifetime; mLifetimePast = 0; } + + /** + * Sets the age of the pixel in game ticks where the particle has + * faded in completely + */ + void + setFadeOut (int fadeOut) + { mFadeOut = fadeOut; } + + /** + * Sets the remaining particle lifetime where the particle starts to + * fade out + */ + void + setFadeIn (int fadeIn) + { mFadeIn = fadeIn; } + + /** + * Sets the sprite iterator of the particle on the current map to make + * it easier to remove the particle from the map when it is destroyed + */ + void + setSpriteIterator(std::list::iterator spriteIterator) + { mSpriteIterator = spriteIterator; } + + /** + * Gets the sprite iterator of the particle on the current map + */ + std::list::iterator + getSpriteIterator() const + { return mSpriteIterator; } + + /** + * Sets the current velocity in 3 dimensional space + */ + void + setVector(float x, float y, float z) + { mVectorX = x; mVectorY = y; mVectorZ = z; } + + /** + * Sets the downward acceleration + */ + void + setGravity(float g) + { mGravity = g; } + + /** + * Sets the ammount of random vector changes + */ + void + setRandomnes(int r) + { mRandomnes = r; } + + /** + * Sets the ammount of velocity particles retain after + * hitting the ground. + */ + void + setBounce(float bouncieness) + { mBounce = bouncieness; } + + /** + * Makes the particle move toward another particle with a + * given acceleration and momentum + */ + void setDestination(Particle *target, float accel, float moment) + { mTarget = target; mAcceleration = accel; mMomentum = moment; } + + /** + * Sets the distance in pixel the particle can come near the target + * particle before it is destroyed. Does only make sense after a + * target particle has been set using setDestination. + */ + void setDieDistance(float dist) + { mInvDieDistance = 1.0f / dist; } + + /** + * Manually marks the particle for deletion + */ + void kill() + { mAlive = false; mAutoDelete = true; } + + /** + * After calling this function the particle will only request + * deletion when kill() is called + */ + void disableAutoDelete() + { mAutoDelete = false; } + + protected: + bool mAlive; /**< Is the particle supposed to be drawn and updated?*/ + float mPosX, mPosY, mPosZ; /**< Position in 3 dimensonal space - pixel based relative to map */ + int mLifetimeLeft; /**< Lifetime left in game ticks*/ + int mLifetimePast; /**< Age of the particle in game ticks*/ + int mFadeOut; /**< Lifetime in game ticks left where fading out begins*/ + int mFadeIn; /**< Age in game ticks where fading in is finished*/ + + private: + // generic properties + bool mAutoDelete; /**< May the particle request its deletion by the parent particle?*/ + Map *mMap; /**< Map the particle is on*/ + std::list::iterator mSpriteIterator; /**< iterator of the particle on the current map */ + Emitters mChildEmitters; /**< List of child emitters*/ + Particles mChildParticles; /**< List of particles controlled by this particle*/ + //dynamic particle + float mVectorX, mVectorY, mVectorZ; /**< Speed in 3 dimensional space in pixels per game-tick */ + float mGravity; /**< Downward acceleration in pixels per game-tick²*/ + int mRandomnes; /**< Ammount of random vector change*/ + float mBounce; /**< How much the particle bounces off when hitting the ground*/ + //follow-point particles + Particle *mTarget; /**< The particle that attracts this particle*/ + float mAcceleration; /**< Acceleration towards the target particle in pixels per game-tick²*/ + float mInvDieDistance; /**< Distance in pixels from the target particle that causes the destruction of the particle*/ + float mMomentum; /**< How much speed the particle retains after each game tick*/ +}; + +extern Particle *particleEngine; + +#endif diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp new file mode 100644 index 00000000..2387c652 --- /dev/null +++ b/src/particleemitter.cpp @@ -0,0 +1,327 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "particleemitter.h" + +#include "animationparticle.h" +#include "imageparticle.h" +#include "log.h" +#include "particle.h" + +#include "resources/animation.h" +#include "resources/image.h" +#include "resources/resourcemanager.h" +#include "resources/imageset.h" + +#include + +#define SIN45 0.707106781f +#define DEG_RAD_FACTOR 0.017453293f + +ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map): + mParticleImage(0) +{ + mMap = map; + mParticleTarget = target; + + //initializing default values + mParticlePosX.set(0.0f); + mParticlePosY.set(0.0f); + mParticlePosZ.set(0.0f); + mParticleAngleHorizontal.set(0.0f); + mParticleAngleVertical.set(0.0f); + mParticlePower.set(0.0f); + mParticleGravity.set(0.0f); + mParticleRandomnes.set(0); + mParticleBounce.set(0.0f); + mParticleAcceleration.set(0.0f); + mParticleDieDistance.set(-1.0f); + mParticleMomentum.set(1.0f); + mParticleLifetime.set(-1); + mParticleFadeOut.set(0); + mParticleFadeIn.set(0); + mOutput.set(1); + + for_each_xml_child_node(propertyNode, emitterNode) + { + if (xmlStrEqual(propertyNode->name, BAD_CAST "property")) + { + std::string name = XML::getProperty(propertyNode, "name", ""); + + if (name == "position-x") + { + mParticlePosX = readMinMax(propertyNode, 0.0f); + } + else if (name == "position-y") + { + + mParticlePosY = readMinMax(propertyNode, 0.0f); + } + else if (name == "position-z") + { + mParticlePosZ = readMinMax(propertyNode, 0.0f); + } + else if (name == "image") + { + std::string image = XML::getProperty(propertyNode, "value", ""); + // Don't leak when multiple images are defined + if (image != "" && !mParticleImage) + { + ResourceManager *resman = ResourceManager::getInstance(); + mParticleImage = resman->getImage(image); + } + } + else if (name == "horizontal-angle") + { + mParticleAngleHorizontal = readMinMax(propertyNode, 0.0f); + mParticleAngleHorizontal.minVal *= DEG_RAD_FACTOR; + mParticleAngleHorizontal.maxVal *= DEG_RAD_FACTOR; + } + else if (name == "vertical-angle") + { + mParticleAngleVertical = readMinMax(propertyNode, 0.0f); + mParticleAngleVertical.minVal *= DEG_RAD_FACTOR; + mParticleAngleVertical.maxVal *= DEG_RAD_FACTOR; + } + else if (name == "power") + { + mParticlePower = readMinMax(propertyNode, 0.0f); + } + else if (name == "gravity") + { + mParticleGravity = readMinMax(propertyNode, 0.0f); + } + else if (name == "randomnes") + { + mParticleRandomnes = readMinMax(propertyNode, 0); + } + else if (name == "bounce") + { + mParticleBounce = readMinMax(propertyNode, 0.0f); + } + else if (name == "lifetime") + { + mParticleLifetime = readMinMax(propertyNode, 0); + mParticleLifetime.minVal += 1; + } + else if (name == "output") + { + mOutput = readMinMax(propertyNode, 0); + mOutput.maxVal +=1; + } + else if (name == "acceleration") + { + mParticleAcceleration = readMinMax(propertyNode, 0.0f); + } + else if (name == "die-distance") + { + mParticleDieDistance = readMinMax(propertyNode, 0.0f); + } + else if (name == "momentum") + { + mParticleMomentum = readMinMax(propertyNode, 1.0f); + } + else if (name == "fade-out") + { + mParticleFadeOut = readMinMax(propertyNode, 0); + } + else if (name == "fade-in") + { + mParticleFadeIn = readMinMax(propertyNode, 0); + } + else + { + logger->log("Particle Engine: Warning, unknown emitter property \"%s\"", + name.c_str() + ); + } + } + else if (xmlStrEqual(propertyNode->name, BAD_CAST "emitter")) + { + ParticleEmitter newEmitter(propertyNode, mParticleTarget, map); + mParticleChildEmitters.push_back(newEmitter); + } + else if (xmlStrEqual(propertyNode->name, BAD_CAST "animation")) + { + ImageSet *imageset = ResourceManager::getInstance()->getImageSet( + XML::getProperty(propertyNode, "imageset", ""), + XML::getProperty(propertyNode, "width", 0), + XML::getProperty(propertyNode, "height", 0) + ); + + // Get animation frames + for_each_xml_child_node(frameNode, propertyNode) + { + int delay = XML::getProperty(frameNode, "delay", 0); + int offsetX = XML::getProperty(frameNode, "offsetX", 0); + int offsetY = XML::getProperty(frameNode, "offsetY", 0); + offsetY -= imageset->getHeight() - 32; + offsetX -= imageset->getWidth() / 2 - 16; + + if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) + { + int index = XML::getProperty(frameNode, "index", -1); + + if (index < 0) + { + logger->log("No valid value for 'index'"); + continue; + } + + Image *img = imageset->get(index); + + if (!img) + { + logger->log("No image at index " + (index)); + continue; + } + + mParticleAnimation.addFrame(img, delay, offsetX, offsetY); + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) + { + int start = XML::getProperty(frameNode, "start", -1); + int end = XML::getProperty(frameNode, "end", -1); + + if (start < 0 || end < 0) + { + logger->log("No valid value for 'start' or 'end'"); + continue; + } + + while (end >= start) + { + Image *img = imageset->get(start); + + if (!img) + { + logger->log("No image at index " + + (start)); + continue; + } + + mParticleAnimation.addFrame(img, delay, offsetX, offsetY); + start++; + } + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) + { + mParticleAnimation.addTerminator(); + } + } // for frameNode + } + } +} + + +ParticleEmitter::~ParticleEmitter() +{ + if (mParticleImage) + { + mParticleImage->decRef(); + } +} + + +template MinMax +ParticleEmitter::readMinMax(xmlNodePtr propertyNode, T def) +{ + MinMax retval; + + def = (T)XML::getFloatProperty(propertyNode, "value", (double)def); + retval.set ( (T)XML::getFloatProperty(propertyNode, "min", (double)def), + (T)XML::getFloatProperty(propertyNode, "max", (double)def) + ); + + return retval; +} + + +std::list +ParticleEmitter::createParticles() +{ + std::list newParticles; + + for (int i = mOutput.value(); i > 0; i--) + { + // Limit maximum particles + if (Particle::particleCount > Particle::maxCount) break; + + Particle *newParticle; + if (mParticleImage) + { + newParticle = new ImageParticle(mMap, mParticleImage); + } + else if (mParticleAnimation.getLength() > 0) + { + Animation *newAnimation = new Animation(mParticleAnimation); + newParticle = new AnimationParticle(mMap, newAnimation); + } + else + { + newParticle = new Particle(mMap); + } + + + newParticle->setPosition( + mParticlePosX.value(), + mParticlePosY.value(), + mParticlePosZ.value() + ); + + float angleH = mParticleAngleHorizontal.value(); + float angleV = mParticleAngleVertical.value(); + float power = mParticlePower.value(); + newParticle->setVector( + cos(angleH) * cos(angleV) * power, + sin(angleH) * cos(angleV) * SIN45 * power, + sin(angleV) * SIN45 * power + ); + + newParticle->setRandomnes(mParticleRandomnes.value()); + newParticle->setGravity(mParticleGravity.value()); + newParticle->setBounce(mParticleBounce.value()); + + newParticle->setDestination(mParticleTarget, + mParticleAcceleration.value(), + mParticleMomentum.value() + ); + newParticle->setDieDistance(mParticleDieDistance.value()); + + newParticle->setLifetime(mParticleLifetime.value()); + newParticle->setFadeOut(mParticleFadeOut.value()); + newParticle->setFadeIn(mParticleFadeIn.value()); + + for ( std::list::iterator i = mParticleChildEmitters.begin(); + i != mParticleChildEmitters.end(); + i++ + ) + { + newParticle->addEmitter(new ParticleEmitter(*i)); + } + + newParticles.push_back(newParticle); + } + + return newParticles; +} diff --git a/src/particleemitter.h b/src/particleemitter.h new file mode 100644 index 00000000..ca6d8622 --- /dev/null +++ b/src/particleemitter.h @@ -0,0 +1,120 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _PARTICLEEMITTER_H +#define _PARTICLEEMITTER_H + +#include + +#include "utils/xml.h" +#include "utils/minmax.h" + +#include "resources/animation.h" + +class Image; +class Map; +class Particle; + +/** + * Every Particle can have one or more particle emitters that create new + * particles when they are updated + */ +class ParticleEmitter +{ + public: + /** + * Constructor. + */ + ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map); + + /** + * Destructor. + */ + ~ParticleEmitter(); + + /** + * Spawns new particles + * @return: a list of created particles + */ + std::list createParticles(); + + /** + * Sets the target of the particles that are created + */ + void + setTarget(Particle *target) + { mParticleTarget = target; }; + + private: + template MinMax readMinMax(xmlNodePtr propertyNode, T def); + + /** + * initial position of particles: + */ + MinMax mParticlePosX, mParticlePosY, mParticlePosZ; + + /** + * initial vector of particles: + */ + MinMax mParticleAngleHorizontal, mParticleAngleVertical; + + /** + * Initial velocity of particles + */ + MinMax mParticlePower; + + /* + * Vector changing of particles: + */ + MinMax mParticleGravity; + MinMax mParticleRandomnes; + MinMax mParticleBounce; + + /* + * Properties of targeting particles: + */ + Particle *mParticleTarget; + MinMax mParticleAcceleration; + MinMax mParticleDieDistance; + MinMax mParticleMomentum; + + /* + * Behavior over time of the particles: + */ + MinMax mParticleLifetime; + MinMax mParticleFadeOut; + MinMax mParticleFadeIn; + + Map *mMap; /**< Map the particles are spawned on */ + + MinMax mOutput; /**< Number of particles spawned per update */ + + Image *mParticleImage; /**< Particle image, if used */ + + /** Filename of particle animation file */ + Animation mParticleAnimation; + + /** List of emitters the spawned particles are equipped with */ + std::list mParticleChildEmitters; +}; +#endif diff --git a/src/resources/animation.h b/src/resources/animation.h index d0d11c69..aad93cda 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -54,7 +54,7 @@ class Animation Animation(); /** - * Appends a new animation at the end of the sequence + * Appends a new animation at the end of the sequence. */ void addFrame(Image *image, unsigned int delay, int offsetX, int offsetY); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index a27783d4..d7d4e64b 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -187,19 +187,22 @@ Image* Image::load(void *buffer, unsigned int bufferSize, bool hasAlpha = false; - // Figure out whether the image uses its alpha layer - for (int i = 0; i < tmpImage->w * tmpImage->h; ++i) + if (tmpImage->format->BitsPerPixel == 32) { - Uint8 r, g, b, a; - SDL_GetRGBA( - ((Uint32*) tmpImage->pixels)[i], - tmpImage->format, - &r, &g, &b, &a); - - if (a != 255) + // Figure out whether the image uses its alpha layer + for (int i = 0; i < tmpImage->w * tmpImage->h; ++i) { - hasAlpha = true; - break; + Uint8 r, g, b, a; + SDL_GetRGBA( + ((Uint32*) tmpImage->pixels)[i], + tmpImage->format, + &r, &g, &b, &a); + + if (a != 255) + { + hasAlpha = true; + break; + } } } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index fda8916d..2230cb6a 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -231,6 +231,30 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) { readProperties(childNode, map); } + else if (xmlStrEqual(childNode->name, BAD_CAST "objectgroup")) + { + for_each_xml_child_node(objectNode, childNode) + { + if (xmlStrEqual(objectNode->name, BAD_CAST "object")) + { + std::string objName = XML::getProperty(objectNode, "name", ""); + std::string objType = XML::getProperty(objectNode, "type", ""); + int objX = XML::getProperty(objectNode, "x", 0); + int objY = XML::getProperty(objectNode, "y", 0); + + logger->log("- Loading object name: %s type: %s at %d:%d", + objName.c_str(), objType.c_str(), objX, objY); + if (objType == "PARTICLE_EFFECT") + { + map->addParticleEffect(objName, objX, objY); + } + else + { + logger->log(" Warning: Unknown object type"); + } + } + } + } } map->initializeOverlays(); diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index ac3ac3bc..89afc549 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -83,6 +83,27 @@ MonsterDB::load() currentInfo->setName (XML::getProperty(monsterNode, "name", "unnamed")); + std::string targetCursor; + targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium"); + if (targetCursor == "small") + { + currentInfo->setTargetCursorSize(Being::TC_SMALL); + } + else if (targetCursor == "medium") + { + currentInfo->setTargetCursorSize(Being::TC_MEDIUM); + } + else if (targetCursor == "large") + { + currentInfo->setTargetCursorSize(Being::TC_LARGE); + } + else + { + logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one", + targetCursor.c_str(), currentInfo->getName().c_str()); + currentInfo->setTargetCursorSize(Being::TC_MEDIUM); + } + //iterate s and s for_each_xml_child_node(spriteNode, monsterNode) { diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index 05d4c014..d2a0a2c8 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -28,6 +28,9 @@ #include #include +#include "../being.h" + + enum SoundEvent { EVENT_HIT, @@ -62,7 +65,11 @@ class MonsterInfo setSprite(std::string filename) { mSprite = filename; } void - addSound (SoundEvent event, std::string filename); + setTargetCursorSize(Being::TargetCursorSize targetCursorSize) + { mTargetCursorSize = targetCursorSize; } + + void + addSound(SoundEvent event, std::string filename); const std::string& getName () const { return mName; }; @@ -70,13 +77,16 @@ class MonsterInfo const std::string& getSprite () const { return mSprite; }; + const Being::TargetCursorSize + getTargetCursorSize() const { return mTargetCursorSize; } + std::string getSound (SoundEvent event) const; private: std::string mName; std::string mSprite; - + Being::TargetCursorSize mTargetCursorSize; std::map* > mSounds; }; diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index 5fc35bcd..18e732ef 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -23,6 +23,91 @@ #include "simpleanimation.h" +#include "graphics.h" +#include "log.h" + +#include "resources/image.h" +#include "resources/resourcemanager.h" +#include "resources/imageset.h" + + +SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): + mAnimationTime(0), + mAnimationPhase(0) +{ + mAnimation = new Animation(); + + ImageSet *imageset = ResourceManager::getInstance()->getImageSet( + XML::getProperty(animationNode, "imageset", ""), + XML::getProperty(animationNode, "width", 0), + XML::getProperty(animationNode, "height", 0) + ); + + // Get animation frames + for ( xmlNodePtr frameNode = animationNode->xmlChildrenNode; + frameNode != NULL; + frameNode = frameNode->next) + { + int delay = XML::getProperty(frameNode, "delay", 0); + int offsetX = XML::getProperty(frameNode, "offsetX", 0); + int offsetY = XML::getProperty(frameNode, "offsetY", 0); + offsetY -= imageset->getHeight() - 32; + offsetX -= imageset->getWidth() / 2 - 16; + + if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) + { + int index = XML::getProperty(frameNode, "index", -1); + + if (index < 0) + { + logger->log("No valid value for 'index'"); + continue; + } + + Image *img = imageset->get(index); + + if (!img) + { + logger->log("No image at index " + (index)); + continue; + } + + mAnimation->addFrame(img, delay, offsetX, offsetY); + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) + { + int start = XML::getProperty(frameNode, "start", -1); + int end = XML::getProperty(frameNode, "end", -1); + + if (start < 0 || end < 0) + { + logger->log("No valid value for 'start' or 'end'"); + continue; + } + + while (end >= start) + { + Image *img = imageset->get(start); + + if (!img) + { + logger->log("No image at index " + + (start)); + continue; + } + + mAnimation->addFrame(img, delay, offsetX, offsetY); + start++; + } + } + else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) + { + mAnimation->addTerminator(); + } + } + + mCurrentFrame = mAnimation->getFrame(0); +} void SimpleAnimation::update(unsigned int timePassed) { diff --git a/src/simpleanimation.h b/src/simpleanimation.h index a56c31da..561c540d 100644 --- a/src/simpleanimation.h +++ b/src/simpleanimation.h @@ -26,7 +26,10 @@ #include "resources/animation.h" +#include "utils/xml.h" + class Frame; +class Graphics; /** * This class is a leightweight alternative to the AnimatedSprite class. @@ -35,6 +38,9 @@ class Frame; class SimpleAnimation { public: + /** + * Creates a simple animation with an already created animation. + */ SimpleAnimation(Animation *animation): mAnimation(animation), mAnimationTime(0), @@ -42,6 +48,11 @@ class SimpleAnimation mCurrentFrame(mAnimation->getFrame(0)) {}; + /** + * Creates a simple animation that creates its animation from XML Data. + */ + SimpleAnimation(xmlNodePtr animationNode); + ~SimpleAnimation(); void update(unsigned int timePassed); @@ -55,10 +66,10 @@ class SimpleAnimation /** Time in game ticks the current frame is shown. */ unsigned int mAnimationTime; - /** Index of current animation frame. */ + /** Index of current animation phase. */ unsigned int mAnimationPhase; - /** Current animation frame. */ + /** Current animation phase. */ Frame *mCurrentFrame; }; diff --git a/src/sprite.h b/src/sprite.h index 51811149..89780519 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -49,6 +49,22 @@ class Sprite virtual void draw(Graphics *graphics, int offsetX, int offsetY) const = 0; + /** + * Returns the horizontal size of the sprites graphical representation + * in pixels or 0 when it is undefined. + */ + virtual int + getWidth() const + { return 0; } + + /** + * Returns the vertical size of the sprites graphical representation + * in pixels or 0 when it is undefined. + */ + virtual int + getHeight() const + { return 0; } + /** * Returns the pixel Y coordinate of the sprite. */ diff --git a/src/textparticle.cpp b/src/textparticle.cpp new file mode 100644 index 00000000..dd01d2fe --- /dev/null +++ b/src/textparticle.cpp @@ -0,0 +1,64 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "textparticle.h" + +#include "graphics.h" + +TextParticle::TextParticle(Map *map, const std::string &text, + int colorR, int colorG, int colorB, gcn::Font *font): + Particle(map), + mText(text), + mTextFont(font), + mColorR(colorR), + mColorG(colorG), + mColorB(colorB) +{ +} + +void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const +{ + if (!mAlive) + return; + + int screenX = (int)mPosX + offsetX; + int screenY = (int)mPosY - int(mPosZ) + offsetY; + + int alpha = 255; + + if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) + { + alpha *= mLifetimeLeft; + alpha /= mFadeOut; + }; + + if (mLifetimePast < mFadeIn) + { + alpha *= mLifetimePast; + alpha /= mFadeIn; + } + + graphics->setFont(mTextFont); + graphics->setColor(gcn::Color (mColorR, mColorG, mColorB, alpha)); + graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); +} diff --git a/src/textparticle.h b/src/textparticle.h new file mode 100644 index 00000000..b365c885 --- /dev/null +++ b/src/textparticle.h @@ -0,0 +1,53 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TEXTPARTICLE_H +#define _TEXTPARTICLE_H + +#include "particle.h" + +#include + +#include "guichanfwd.h" + +class TextParticle : public Particle +{ + public: + TextParticle(Map *map, const std::string &text, + int colorR, int colorG, int colorB, gcn::Font *font); + /** + * Draws the particle image + */ + virtual void + draw(Graphics *graphics, int offsetX, int offsetY) const; + + // hack to improve text visibility + virtual int getPixelY() const { return (int)(mPosY + mPosZ); } + + private: + std::string mText; /**< Text of the particle */ + gcn::Font *mTextFont; /**< Font used for drawing the text */ + int mColorR, mColorG, mColorB; /**< Color used for drawing the text */ +}; + +#endif diff --git a/src/utils/fastsqrt.h b/src/utils/fastsqrt.h new file mode 100644 index 00000000..8da1d354 --- /dev/null +++ b/src/utils/fastsqrt.h @@ -0,0 +1,24 @@ +/* A very fast function to calculate the approximate inverse square root of a + * floating point value and a helper function that uses it for getting the + * normal squareroot. For an explanation of the inverse squareroot function + * read: + * http://www.math.purdue.edu/~clomont/Math/Papers/2003/InvSqrt.pdf + * + * Unfortunately the original creator of this function seems to be unknown. + */ + +float fastInvSqrt(float x) +{ + union { int i; float x; } tmp; + float xhalf = 0.5f * x; + tmp.x = x; + tmp.i = 0x5f375a86 - (tmp.i >> 1); + x = tmp.x; + x = x * (1.5f - xhalf * x * x); + return x; +} + +float fastSqrt(float x) +{ + return 1.0f / fastInvSqrt(x); +} diff --git a/src/utils/minmax.h b/src/utils/minmax.h new file mode 100644 index 00000000..1add2b7e --- /dev/null +++ b/src/utils/minmax.h @@ -0,0 +1,47 @@ +/* + * The Mana World + * Copyright 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/** + * Returns a random numeric value that is larger than or equal min and smaller + * than max + */ + +template struct MinMax +{ + void set(T min, T max) + { + minVal=min; maxVal=max; + } + + void set(T val) + { + set(val, val); + } + + T value() + { + return (T)(minVal + (maxVal - minVal) * (rand() / ((double) RAND_MAX + 1))); + } + + T minVal; + T maxVal; +}; diff --git a/src/utils/wingettimeofday.h b/src/utils/wingettimeofday.h index a5537f39..28afb7e5 100644 --- a/src/utils/wingettimeofday.h +++ b/src/utils/wingettimeofday.h @@ -1,113 +1,113 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_WINGETTIMEOFDAY_H_ -#define _TMW_WINGETTIMEOFDAY_H_ - -#ifdef WIN32 - -#include - -/* - * the function gettimeofday() is available on UNIX but not on windows. - * this header defines a windows implementation as a - * GetSystemTimeAsFileTime() wrapper. - */ - -int gettimeofday(struct timeval* tv, void *tz) -/*--------------------------------------------------------------- - * Copyright (c) 1999,2000,2001,2002,2003 - * The Board of Trustees of the University of Illinois - * All Rights Reserved. - *--------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software (Iperf) and associated - * documentation files (the "Software"), to deal in the Software - * without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do - * so, subject to the following conditions: - * - * - * Redistributions of source code must retain the above - * copyright notice, this list of conditions and - * the following disclaimers. - * - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimers in the documentation and/or other materials - * provided with the distribution. - * - * - * Neither the names of the University of Illinois, NCSA, - * nor the names of its contributors may be used to endorse - * or promote products derived from this Software without - * specific prior written permission. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * ________________________________________________________________ - * National Laboratory for Applied Network Research - * National Center for Supercomputing Applications - * University of Illinois at Urbana-Champaign - * http://www.ncsa.uiuc.edu - * ________________________________________________________________ - * - * gettimeofday.c - * by Mark Gates - * ------------------------------------------------------------------- - * A (hack) implementation of gettimeofday for Windows. - * Since I send sec/usec in UDP packets, this made the most sense. - * ------------------------------------------------------------------- */ -{ - FILETIME time; - double timed; - - GetSystemTimeAsFileTime( &time ); - - // Apparently Win32 has units of 1e-7 sec (tenths of microsecs) - // 4294967296 is 2^32, to shift high word over - // 11644473600 is the number of seconds between - // the Win32 epoch 1601-Jan-01 and the Unix epoch 1970-Jan-01 - // Tests found floating point to be 10x faster than 64bit int math. - - timed = ((time.dwHighDateTime * 4294967296e-7) - 11644473600.0) + - (time.dwLowDateTime * 1e-7); - - tv->tv_sec = (long) timed; - tv->tv_usec = (long) ((timed - tv->tv_sec) * 1e6); - - return 0; -} - - -#endif // WIN32 -#endif +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_WINGETTIMEOFDAY_H_ +#define _TMW_WINGETTIMEOFDAY_H_ + +#ifdef WIN32 + +#include + +/* + * the function gettimeofday() is available on UNIX but not on windows. + * this header defines a windows implementation as a + * GetSystemTimeAsFileTime() wrapper. + */ + +int gettimeofday(struct timeval* tv, void *tz) +/*--------------------------------------------------------------- + * Copyright (c) 1999,2000,2001,2002,2003 + * The Board of Trustees of the University of Illinois + * All Rights Reserved. + *--------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software (Iperf) and associated + * documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and + * the following disclaimers. + * + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimers in the documentation and/or other materials + * provided with the distribution. + * + * + * Neither the names of the University of Illinois, NCSA, + * nor the names of its contributors may be used to endorse + * or promote products derived from this Software without + * specific prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * ________________________________________________________________ + * National Laboratory for Applied Network Research + * National Center for Supercomputing Applications + * University of Illinois at Urbana-Champaign + * http://www.ncsa.uiuc.edu + * ________________________________________________________________ + * + * gettimeofday.c + * by Mark Gates + * ------------------------------------------------------------------- + * A (hack) implementation of gettimeofday for Windows. + * Since I send sec/usec in UDP packets, this made the most sense. + * ------------------------------------------------------------------- */ +{ + FILETIME time; + double timed; + + GetSystemTimeAsFileTime( &time ); + + // Apparently Win32 has units of 1e-7 sec (tenths of microsecs) + // 4294967296 is 2^32, to shift high word over + // 11644473600 is the number of seconds between + // the Win32 epoch 1601-Jan-01 and the Unix epoch 1970-Jan-01 + // Tests found floating point to be 10x faster than 64bit int math. + + timed = ((time.dwHighDateTime * 4294967296e-7) - 11644473600.0) + + (time.dwLowDateTime * 1e-7); + + tv->tv_sec = (long) timed; + tv->tv_usec = (long) ((timed - tv->tv_sec) * 1e6); + + return 0; +} + + +#endif // WIN32 +#endif diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 7c917dc0..e30450f0 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -39,6 +39,20 @@ namespace XML return ret; } + double + getFloatProperty(xmlNodePtr node, const char* name, double def) + { + double &ret = def; + + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + if (prop) { + ret = atof((char*)prop); + xmlFree(prop); + } + + return ret; + } + std::string getProperty(xmlNodePtr node, const char *name, const std::string &def) { @@ -51,4 +65,13 @@ namespace XML return def; } + + xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name) + { + for_each_xml_child_node(child, parent) + if (xmlStrEqual(child->name, BAD_CAST name)) + return child; + + return NULL; + } } diff --git a/src/utils/xml.h b/src/utils/xml.h index db4c264a..ef3bad3d 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -39,11 +39,22 @@ namespace XML int getProperty(xmlNodePtr node, const char *name, int def); + /** + * Gets an floating point property from an xmlNodePtr. + */ + double + getFloatProperty(xmlNodePtr node, const char *name, double def); + /** * Gets a string property from an xmlNodePtr. */ std::string getProperty(xmlNodePtr node, const char *name, const std::string &def); + + /** + * Finds the first child node with the given name + */ + xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name); } #define for_each_xml_child_node(var, parent) \ -- cgit v1.2.3-70-g09d2 From d61fdaf1932724f86a68484c4a05195ca270646e Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Fri, 27 Jul 2007 22:30:19 +0000 Subject: Removed useless yet costly dynamic casts. --- ChangeLog | 11 +++++++++++ src/gui/browserbox.cpp | 4 ++-- src/gui/button.cpp | 5 ++--- src/gui/checkbox.cpp | 6 ++---- src/gui/equipmentwindow.cpp | 6 +++--- src/gui/gui.cpp | 5 ++--- src/gui/itemcontainer.cpp | 9 +++------ src/gui/minimap.cpp | 4 ++-- src/gui/playerbox.cpp | 4 ++-- src/gui/popupmenu.cpp | 2 +- src/gui/progressbar.cpp | 5 ++--- src/gui/radiobutton.cpp | 2 +- src/gui/scrollarea.cpp | 16 ++++++++-------- src/gui/slider.cpp | 12 ++++++------ src/gui/textfield.cpp | 2 +- src/gui/widgets/dropdown.cpp | 31 +++++-------------------------- src/gui/widgets/resizegrip.cpp | 2 +- src/resources/image.cpp | 2 +- 18 files changed, 55 insertions(+), 73 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index b27becc3..3e617d90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-07-25 Guillaume Melquiond + + * src/resources/image.cpp: Added support for subimages of subimages. + * src/gui/equipmentwindow.cpp, src/gui/button.cpp, src/gui/slider.cpp, + src/gui/widgets/resizegrip.cpp, src/gui/widgets/dropdown.cpp, + src/gui/progressbar.cpp, src/gui/browserbox.cpp, src/gui/gui.cpp, + src/gui/radiobutton.cpp, src/gui/textfield.cpp, src/gui/playerbox.cpp, + src/gui/itemcontainer.cpp, src/gui/checkbox.cpp, src/gui/minimap.cpp, + src/gui/scrollarea.cpp, src/gui/popupmenu.cpp: Removed useless yet + costly dynamic casts. + 2007-07-25 Guillaume Melquiond * src/net/beinghandler.cpp, src/net/protocol.h: Added being speed to diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 65fdde64..4a3f2f64 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -104,7 +104,7 @@ void BrowserBox::addRow(const std::string &row) std::string newRow; BROWSER_LINK bLink; int idx1, idx2, idx3; - gcn::ImageFont *font = dynamic_cast(getFont()); + gcn::ImageFont *font = static_cast(getFont()); // Use links and user defined colors if (mUseLinksAndUserColors) @@ -294,7 +294,7 @@ BrowserBox::draw(gcn::Graphics *graphics) unsigned int i, j; int x = 0, y = 0; int wrappedLines = 0; - gcn::ImageFont *font = dynamic_cast(getFont()); + gcn::ImageFont *font = static_cast(getFont()); graphics->setColor(BLACK); for (i = 0; i < mTextRows.size(); i++) diff --git a/src/gui/button.cpp b/src/gui/button.cpp index e607b66a..83d4657c 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -111,9 +111,8 @@ Button::draw(gcn::Graphics *graphics) mode = 0; } - dynamic_cast(graphics)->drawImageRect(0, 0, - getWidth(), getHeight(), - button[mode]); + static_cast(graphics)-> + drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); graphics->setColor(getForegroundColor()); diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index ec7eb578..fab4780c 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -66,7 +66,7 @@ CheckBox::~CheckBox() void CheckBox::drawBox(gcn::Graphics* graphics) { - Image *box = NULL; + Image *box; if (mMarked) { if (isEnabled()) { @@ -80,7 +80,5 @@ void CheckBox::drawBox(gcn::Graphics* graphics) box = checkBoxDisabled; } - if (box != NULL) { - dynamic_cast(graphics)->drawImage(box, 2, 2); - } + static_cast(graphics)->drawImage(box, 2, 2); } diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index ec84491e..1ae887bc 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -65,8 +65,8 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) } image = item->getInfo().getImage(); - dynamic_cast(graphics)->drawImage( - image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); + static_cast(graphics)-> + drawImage(image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32)); @@ -77,7 +77,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) image = item->getInfo().getImage(); - dynamic_cast(graphics)->drawImage(image, 160, 25); + static_cast(graphics)->drawImage(image, 160, 25); graphics->drawText(toString(item->getQuantity()), 170, 62, gcn::Graphics::CENTER); } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index b9b15429..8f1cc7f4 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -213,9 +213,8 @@ Gui::draw() if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) && mCustomCursor) { - dynamic_cast(mGraphics)->drawImage(mMouseCursor, - mouseX - 5, - mouseY - 2); + static_cast(mGraphics)-> + drawImage(mMouseCursor, mouseX - 5, mouseY - 2); } mGraphics->popClipArea(); diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index a176f226..0e5bcce9 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -105,16 +105,13 @@ ItemContainer::draw(gcn::Graphics *graphics) // Draw selection image below selected item if (mSelectedItem == item) { - dynamic_cast(graphics)->drawImage( - mSelImg, itemX, itemY); + static_cast(graphics)->drawImage(mSelImg, itemX, itemY); } // Draw item icon - Image* image; - if ((image = item->getInfo().getImage()) != NULL) + if (Image *image = item->getInfo().getImage()) { - dynamic_cast(graphics)->drawImage( - image, itemX, itemY); + static_cast(graphics)->drawImage(image, itemX, itemY); } // Draw item caption diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 69c5eb6e..2720225d 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -72,8 +72,8 @@ void Minimap::draw(gcn::Graphics *graphics) if (mMapImage != NULL) { - dynamic_cast(graphics)->drawImage( - mMapImage, getPadding(), getTitleBarHeight()); + static_cast(graphics)-> + drawImage(mMapImage, getPadding(), getTitleBarHeight()); } Beings &beings = beingManager->getAll(); diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index fad156f1..95366bee 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -80,7 +80,7 @@ PlayerBox::draw(gcn::Graphics *graphics) if (mPlayer) { // Draw character - mPlayer->draw(dynamic_cast(graphics), 40, 42); + mPlayer->draw(static_cast(graphics), 40, 42); } } @@ -92,5 +92,5 @@ PlayerBox::drawBorder(gcn::Graphics *graphics) w = getWidth() + bs * 2; h = getHeight() + bs * 2; - dynamic_cast(graphics)->drawImageRect(0, 0, w, h, background); + static_cast(graphics)->drawImageRect(0, 0, w, h, background); } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index c7c77ef4..cc764d35 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -124,7 +124,7 @@ void PopupMenu::handleLink(const std::string& link) mBeing->getType() == Being::NPC && current_npc == 0) { - dynamic_cast(mBeing)->talk(); + static_cast(mBeing)->talk(); } // Trade action diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 2bdfc856..6d18b2f7 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -93,9 +93,8 @@ void ProgressBar::logic() void ProgressBar::draw(gcn::Graphics *graphics) { - dynamic_cast(graphics)->drawImageRect(0, 0, - getWidth(), getHeight(), - mBorder); + static_cast(graphics)-> + drawImageRect(0, 0, getWidth(), getHeight(), mBorder); // The bar if (mProgress > 0) diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index bbebe48f..e318116a 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -80,6 +80,6 @@ void RadioButton::drawBox(gcn::Graphics* graphics) } if (box != NULL) { - dynamic_cast(graphics)->drawImage(box, 2, 2); + static_cast(graphics)->drawImage(box, 2, 2); } } diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 903ec95d..816f94a8 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -228,8 +228,8 @@ void ScrollArea::drawBorder(gcn::Graphics *graphics) int h = getHeight() + bs * 2; if (mOpaque) { - dynamic_cast(graphics)->drawImageRect(0, 0, w, h, - background); + static_cast(graphics)-> + drawImageRect(0, 0, w, h, background); } } @@ -269,8 +269,8 @@ void ScrollArea::drawButton(gcn::Graphics *graphics, BUTTON_DIR dir) break; } - dynamic_cast(graphics)->drawImage( - buttons[dir][state], dim.x, dim.y); + static_cast(graphics)-> + drawImage(buttons[dir][state], dim.x, dim.y); } void ScrollArea::drawUpButton(gcn::Graphics *graphics) @@ -313,14 +313,14 @@ void ScrollArea::drawVMarker(gcn::Graphics *graphics) { gcn::Rectangle dim = getVerticalMarkerDimension(); - dynamic_cast(graphics)->drawImageRect( - dim.x, dim.y, dim.width, dim.height, vMarker); + static_cast(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker); } void ScrollArea::drawHMarker(gcn::Graphics *graphics) { gcn::Rectangle dim = getHorizontalMarkerDimension(); - dynamic_cast(graphics)->drawImageRect( - dim.x, dim.y, dim.width, dim.height, vMarker); + static_cast(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker); } diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index 98efc409..f0170a1b 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -109,22 +109,22 @@ void Slider::draw(gcn::Graphics *graphics) int x = 0; int y = (h - hStart->getHeight()) / 2; - dynamic_cast(graphics)->drawImage(hStart, x, y); + static_cast(graphics)->drawImage(hStart, x, y); w -= hStart->getWidth() + hEnd->getWidth(); x += hStart->getWidth(); - dynamic_cast(graphics)->drawImagePattern( - hMid, x, y, w, hMid->getHeight()); + static_cast(graphics)-> + drawImagePattern(hMid, x, y, w, hMid->getHeight()); x += w; - dynamic_cast(graphics)->drawImage(hEnd, x, y); + static_cast(graphics)->drawImage(hEnd, x, y); drawMarker(graphics); } void Slider::drawMarker(gcn::Graphics *graphics) { - dynamic_cast(graphics)->drawImage(hGrip, - getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2); + static_cast(graphics)-> + drawImage(hGrip, getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2); } diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index adf41a9a..ce7f6d5f 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -98,5 +98,5 @@ void TextField::drawBorder(gcn::Graphics *graphics) w = getWidth() + bs * 2; h = getHeight() + bs * 2; - dynamic_cast(graphics)->drawImageRect(0, 0, w, h, skin); + static_cast(graphics)->drawImageRect(0, 0, w, h, skin); } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 0bf0e673..1176ef2a 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -145,7 +145,7 @@ void DropDown::draw(gcn::Graphics* graphics) graphics->setColor(highlightColor); graphics->drawLine(0, h, getWidth(), h); graphics->setColor(shadowColor); - graphics->drawLine(0, h + 1,getWidth(),h + 1); + graphics->drawLine(0, h + 1, getWidth(), h + 1); } } @@ -156,34 +156,13 @@ void DropDown::drawBorder(gcn::Graphics *graphics) w = getWidth() + bs * 2; h = getHeight() + bs * 2; - dynamic_cast(graphics)->drawImageRect(0, 0, w, h, skin); + static_cast(graphics)->drawImageRect(0, 0, w, h, skin); } void DropDown::drawButton(gcn::Graphics *graphics) { + int height = mDroppedDown ? mOldH : getHeight(); - unsigned short state = 0; - unsigned short dir = 0; - gcn::Rectangle dim; - - if (mPushed) - state = 1; - - if (mDroppedDown) - dir = 1; - - int height; - if (mDroppedDown) - { - height = mOldH; - } - else - { - height = getHeight(); - } - int x = getWidth() - height; - int y = 0; - - dynamic_cast(graphics)->drawImage( - buttons[dir][state], x, y + 1); + static_cast(graphics)-> + drawImage(buttons[mDroppedDown][mPushed], getWidth() - height, 1); } diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp index 50a6fce4..6be50f2c 100644 --- a/src/gui/widgets/resizegrip.cpp +++ b/src/gui/widgets/resizegrip.cpp @@ -61,5 +61,5 @@ ResizeGrip::~ResizeGrip() void ResizeGrip::draw(gcn::Graphics *graphics) { - dynamic_cast(graphics)->drawImage(gripImage, 0, 0); + static_cast(graphics)->drawImage(gripImage, 0, 0); } diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 993b0a2b..ad280eeb 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -343,5 +343,5 @@ SubImage::~SubImage() Image *SubImage::getSubImage(int x, int y, int w, int h) { - return NULL; + return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h); } -- cgit v1.2.3-70-g09d2 From 59472ef68fdef3f7e8858a81a46e28c127119c58 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 20 Oct 2007 11:29:18 +0000 Subject: Added a layout handler for automatically positioning widgets in a window. Fixed layout of login dialog box when native language is not English. --- ChangeLog | 10 +++ src/Makefile.am | 2 + src/gui/login.cpp | 44 ++++--------- src/gui/widgets/layout.cpp | 159 +++++++++++++++++++++++++++++++++++++++++++++ src/gui/widgets/layout.h | 116 +++++++++++++++++++++++++++++++++ src/gui/window.cpp | 65 ++++++++++-------- src/gui/window.h | 39 +++++++---- 7 files changed, 365 insertions(+), 70 deletions(-) create mode 100644 src/gui/widgets/layout.cpp create mode 100644 src/gui/widgets/layout.h (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 88dfff79..7d93294f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-10-20 Guillaume Melquiond + + * src/gui/widgets/layout.h, src/gui/widgets/layout.cpp, + src/Makefile.am: Added a layout handler for automatically positioning + widgets in a window. + * src/gui/window.h, src/gui/window.cpp: Removed garbage-collected + container. Fixed dangling resize widget. Added layout handler. + * src/gui/login.cpp: Fixed layout of login dialog box when native + language is not English. + 2007-10-19 Guillaume Melquiond * data/equipment.xml: Removed obsolete file. diff --git a/src/Makefile.am b/src/Makefile.am index e0a5a41b..6e6cdfa4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,8 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = tmw tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/dropdown.h \ + gui/widgets/layout.cpp \ + gui/widgets/layout.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ gui/box.h \ diff --git a/src/gui/login.cpp b/src/gui/login.cpp index fccfc05a..9a7d1e5b 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -36,6 +36,8 @@ #include "passwordfield.h" #include "textfield.h" +#include "widgets/layout.h" + #include "../utils/gettext.h" LoginDialog::LoginDialog(LoginData *loginData): @@ -50,28 +52,6 @@ LoginDialog::LoginDialog(LoginData *loginData): mCancelButton = new Button(_("Cancel"), "cancel", this); mRegisterButton = new Button(_("Register"), "register", this); - const int width = 220; - const int height = 100; - - setContentSize(width, height); - - userLabel->setPosition(5, 5); - passLabel->setPosition(5, 14 + userLabel->getHeight()); - mUserField->setPosition(65, 5); - mPassField->setPosition(65, 14 + userLabel->getHeight()); - mUserField->setWidth(width - 70); - mPassField->setWidth(width - 70); - mKeepCheck->setPosition(4, 68); - mCancelButton->setPosition( - width - mCancelButton->getWidth() - 5, - height - mCancelButton->getHeight() - 5); - mOkButton->setPosition( - mCancelButton->getX() - mOkButton->getWidth() - 5, - height - mOkButton->getHeight() - 5); - mRegisterButton->setPosition( - mKeepCheck->getX() + mKeepCheck->getWidth() + 10, - height - mRegisterButton->getHeight() - 5); - mUserField->setActionEventId("ok"); mPassField->setActionEventId("ok"); @@ -81,14 +61,18 @@ LoginDialog::LoginDialog(LoginData *loginData): mPassField->addActionListener(this); mKeepCheck->addActionListener(this); - add(userLabel); - add(passLabel); - add(mUserField); - add(mPassField); - add(mKeepCheck); - add(mOkButton); - add(mCancelButton); - add(mRegisterButton); + setPadding(8); + place(0, 0, userLabel); + place(0, 1, passLabel); + place(1, 0, mUserField, 3).setPadding(2); + place(1, 1, mPassField, 3).setPadding(2); + place(0, 2, mKeepCheck, 4); + place(0, 3, mRegisterButton).setHAlign(Cell::LEFT); + place(2, 3, mOkButton); + place(3, 3, mCancelButton); + getLayout().setColWidth(1, 20); + reflowLayout(); + forgetLayout(); setLocationRelativeTo(getParent()); setVisible(true); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp new file mode 100644 index 00000000..8a64acc0 --- /dev/null +++ b/src/gui/widgets/layout.cpp @@ -0,0 +1,159 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "layout.h" + +void Layout::resizeGrid(int w, int h) +{ + bool extW = w && w > (int)mColWidths.size(), + extH = h && h > (int)mRowHeights.size(); + if (!extW && !extH) return; + + if (extH) + { + mRowHeights.resize(h, -1); + mCells.resize(h); + if (!extW) w = (int)mColWidths.size(); + } + + mColWidths.resize(w, -1); + for (std::vector< std::vector< Cell > >::iterator + i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) + { + i->resize(w); + } +} + +void Layout::setColWidth(int n, int w) +{ + resizeGrid(n + 1, 0); + mColWidths[n] = w; +} + +void Layout::setRowHeight(int n, int h) +{ + resizeGrid(0, n + 1); + mRowHeights[n] = h; +} + +Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h) +{ + resizeGrid(x + w, y + h); + Cell &cell = mCells[y][x]; + cell.mWidget = widget; + cell.mColExtent = w; + cell.mRowExtent = h; + cell.mPadding = 0; + cell.mHAlign = Cell::FILL; + cell.mVAlign = Cell::FILL; + return cell; +} + +static void align(int &pos, int &cur, int upp, Cell::Alignment a) +{ + cur = std::min(cur, upp); + switch (a) + { + case Cell::LEFT: + return; + case Cell::RIGHT: + pos += upp - cur; + return; + case Cell::CENTER: + pos += (upp - cur) / 2; + return; + case Cell::FILL: + cur = upp; + return; + } +} + +void Layout::reflow() +{ + int gridW = mColWidths.size(), gridH = mRowHeights.size(); + + std::vector< int > widths(gridW, 0); + std::vector< int > heights(gridH, 0); + + for (int gridY = 0; gridY < gridH; ++gridY) + { + for (int gridX = 0; gridX < gridW; ++gridX) + { + Cell &cell = mCells[gridY][gridX]; + if (!cell.mWidget) continue; + + if (cell.mColExtent == 1) + { + int w = cell.mWidget->getWidth() + cell.mPadding * 2; + if (w > widths[gridX]) widths[gridX] = w; + } + + if (cell.mRowExtent == 1) + { + int h = cell.mWidget->getHeight() + cell.mPadding * 2; + if (h > heights[gridY]) heights[gridY] = h; + } + } + } + + for (int gridX = 0; gridX < gridW; ++gridX) + { + int w = mColWidths[gridX]; + if (w != -1) widths[gridX] = w; + } + + for (int gridY = 0; gridY < gridH; ++gridY) + { + int h = mRowHeights[gridY]; + if (h != -1) heights[gridY] = h; + } + + int y = 0; + for (int gridY = 0; gridY < gridH; ++gridY) + { + int h = heights[gridY]; + int x = 0; + for (int gridX = 0; gridX < gridW; ++gridX) + { + int w = widths[gridX]; + Cell &cell = mCells[gridY][gridX]; + if (cell.mWidget) + { + int ew = w - cell.mPadding * 2, + eh = h - cell.mPadding * 2; + for (int i = 1; i < cell.mColExtent; ++i) + ew += widths[gridX + i] + mPadding; + for (int i = 1; i < cell.mRowExtent; ++i) + eh += heights[gridY + i] + mPadding; + int dw = cell.mWidget->getWidth(), + dh = cell.mWidget->getHeight(); + int dx = x + cell.mPadding, dy = y + cell.mPadding; + align(dx, dw, ew, cell.mHAlign); + align(dy, dh, eh, cell.mVAlign); + cell.mWidget->setDimension(gcn::Rectangle(dx, dy, dw, dh)); + } + x += w + mPadding; + } + y += h + mPadding; + } +} diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h new file mode 100644 index 00000000..1c4df490 --- /dev/null +++ b/src/gui/widgets/layout.h @@ -0,0 +1,116 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_WIDGET_LAYOUT_H__ +#define _TMW_WIDGET_LAYOUT_H__ + +#include + +#include + +class Cell +{ + friend class Layout; + + public: + + enum Alignment + { + LEFT, RIGHT, CENTER, FILL + }; + + Cell(): mWidget(0) {} + + /** + * Sets padding. + */ + Cell &setPadding(int p) + { mPadding = p; return *this; } + + /** + * Sets horizontal alignment of cell content. + */ + Cell &setHAlign(Alignment a) + { mHAlign = a; return *this; } + + /** + * Sets vertical alignment of cell content. + */ + Cell &setVAlign(Alignment a) + { mVAlign = a; return *this; } + + private: + + gcn::Widget *mWidget; + int mColExtent, mRowExtent; + int mPadding; + Alignment mHAlign, mVAlign; +}; + +class Layout +{ + public: + + Layout(): mPadding(4) {} + + /** + * Sets the width of a column. + */ + void setColWidth(int n, int w); + + /** + * Sets the height of a row. + */ + void setRowHeight(int n, int h); + + /** + * Sets padding between cells. + */ + void setPadding(int p) + { mPadding = p; } + + /** + * Places a widget in given cell. + */ + Cell &place(gcn::Widget *, int x, int y, int w, int h); + + /** + * Computes position of all the widgets. + */ + void reflow(); + + private: + + /** + * Ensures the private vectors are large enough. + */ + void resizeGrid(int w, int h); + + std::vector< int > mColWidths; + std::vector< int > mRowHeights; + std::vector< std::vector < Cell > > mCells; + + int mPadding; +}; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 17447009..b5ac79b5 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -30,6 +30,7 @@ #include "gccontainer.h" #include "windowcontainer.h" +#include "widgets/layout.h" #include "widgets/resizegrip.h" #include "../configlistener.h" @@ -61,6 +62,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): gcn::Window(caption), mGrip(0), mParent(parent), + mLayout(NULL), mModal(modal), mResizable(false), mCloseButton(false), @@ -105,11 +107,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent): setPadding(3); setTitleBarHeight(20); - // Add chrome - mChrome = new GCContainer(); - mChrome->setOpaque(false); - gcn::Window::add(mChrome); - // Add this window to the window container windowContainer->add(this); @@ -141,6 +138,15 @@ Window::~Window() } } + delete mLayout; + + while (!mWidgets.empty()) + { + gcn::Widget *w = mWidgets.front(); + remove(w); + delete(w); + } + instances--; if (instances == 0) @@ -161,9 +167,6 @@ Window::~Window() delete border.grid[8]; closeImage->decRef(); } - - delete mChrome; - delete mGrip; } void Window::setWindowContainer(WindowContainer *wc) @@ -198,13 +201,11 @@ void Window::draw(gcn::Graphics *graphics) void Window::setContentWidth(int width) { - mChrome->setWidth(width); setWidth(width + 2 * getPadding()); } void Window::setContentHeight(int height) { - mChrome->setHeight(height); setHeight(height + getPadding() + getTitleBarHeight()); } @@ -304,6 +305,7 @@ void Window::setMaxHeight(unsigned int height) void Window::setResizable(bool r) { + if (mResizable == r) return; mResizable = r; if (mResizable) @@ -311,10 +313,11 @@ void Window::setResizable(bool r) mGrip = new ResizeGrip(); mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); - gcn::Window::add(mGrip); + add(mGrip); } else { + remove(mGrip); delete mGrip; mGrip = 0; } @@ -357,16 +360,6 @@ void Window::scheduleDelete() windowContainer->scheduleDelete(this); } -void Window::add(gcn::Widget *w, bool delChild) -{ - mChrome->add(w, delChild); -} - -void Window::add(gcn::Widget *w, int x, int y, bool delChild) -{ - mChrome->add(w, x, y, delChild); -} - void Window::mousePressed(gcn::MouseEvent &event) { // Let Guichan move window to top and figure out title bar drag @@ -519,8 +512,6 @@ void Window::mouseDragged(gcn::MouseEvent &event) // Set the new window and content dimensions setDimension(newDim); - const gcn::Rectangle area = getChildrenArea(); - mChrome->setSize(area.width, area.height); updateContentSize(); } } @@ -536,9 +527,6 @@ void Window::loadWindowState(std::string const &name) { setSize((int) config.getValue(name + "WinWidth", getWidth()), (int) config.getValue(name + "WinHeight", getHeight())); - - const gcn::Rectangle area = getChildrenArea(); - mChrome->setSize(area.width, area.height); } } @@ -607,3 +595,28 @@ void Window::fireWindowEvent(const WindowEvent &event) break; } } + +Layout &Window::getLayout() +{ + if (!mLayout) mLayout = new Layout; + return *mLayout; +} + +void Window::forgetLayout() +{ + delete mLayout; + mLayout = 0; +} + +Cell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) +{ + add(wg); + return getLayout().place(wg, x, y, w, h); +} + +void Window::reflowLayout() +{ + if (!mLayout) return; + mLayout->reflow(); + resizeToContent(); +} diff --git a/src/gui/window.h b/src/gui/window.h index ab266422..034c99da 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -30,12 +30,13 @@ #include "windowlistener.h" +class Cell; class ConfigListener; -class GCContainer; +class Image; class ImageRect; +class Layout; class ResizeGrip; class WindowContainer; -class Image; /** * A window. This window can be dragged around and has a title bar. Windows are @@ -62,7 +63,7 @@ class Window : public gcn::Window Window *parent = NULL); /** - * Destructor. + * Destructor. Deletes all the added widgets. */ ~Window(); @@ -76,16 +77,6 @@ class Window : public gcn::Window */ void draw(gcn::Graphics *graphics); - /** - * Adds a widget to the window. - */ - void add(gcn::Widget *wi, bool delChild = true); - - /** - * Adds a widget to the window and also specifices its position. - */ - void add(gcn::Widget *w, int x, int y, bool delChild = true); - /** * Sets the width of the window contents. */ @@ -291,6 +282,26 @@ class Window : public gcn::Window /** The window container windows add themselves to. */ static WindowContainer *windowContainer; + /** + * Gets the layout handler for this window. + */ + Layout &getLayout(); + + /** + * Deletes the layout handler. + */ + void forgetLayout(); + + /** + * Resizes the window after computing the position of the widgets. + */ + void reflowLayout(); + + /** + * Adds a widget to the window and sets it at given cell. + */ + Cell &place(int x, int y, gcn::Widget *, int w = 1, int h = 1); + private: /** * Determines if the mouse is in a resize area and returns appropriate @@ -301,9 +312,9 @@ class Window : public gcn::Window */ int getResizeHandles(gcn::MouseEvent &event); - GCContainer *mChrome; /**< Contained container */ ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ + Layout *mLayout; /**< Layout handler */ std::string mConfigName; /**< Name used for saving window-related data */ bool mShowTitle; /**< Window has a title bar */ bool mModal; /**< Window is modal */ -- cgit v1.2.3-70-g09d2 From 30165a4d80ffcfd22f9977fa52ce87d4e87249a2 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 20 Oct 2007 13:33:39 +0000 Subject: Added a few comments. --- src/gui/widgets/layout.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 1c4df490..5be8e84c 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -28,6 +28,13 @@ #include +/** + * This class describes the formatting of a widget in the cell of a layout + * table. Horizontally, a widget can either fill the width of the cell (minus + * the cell padding), or it can retain its size and be flushed left, or flush + * right, or centered in the cell. The process is similar for the vertical + * alignment, except that top is represented by LEFT and bottom by RIGHT. + */ class Cell { friend class Layout; @@ -42,19 +49,19 @@ class Cell Cell(): mWidget(0) {} /** - * Sets padding. + * Sets the padding around the cell content. */ Cell &setPadding(int p) { mPadding = p; return *this; } /** - * Sets horizontal alignment of cell content. + * Sets the horizontal alignment of the cell content. */ Cell &setHAlign(Alignment a) { mHAlign = a; return *this; } /** - * Sets vertical alignment of cell content. + * Sets the vertical alignment of the cell content. */ Cell &setVAlign(Alignment a) { mVAlign = a; return *this; } @@ -67,6 +74,13 @@ class Cell Alignment mHAlign, mVAlign; }; +/** + * This class is an helper for setting the position of widgets. They are + * positioned along the cells of a rectangular table. The size of a given + * table column can either be set manually or be chosen from the widest widget + * of the column. The process is similar for table rows. By default, there is a + * padding of 4 pixels between rows and between columns. + */ class Layout { public: @@ -84,18 +98,18 @@ class Layout void setRowHeight(int n, int h); /** - * Sets padding between cells. + * Sets the padding between cells. */ void setPadding(int p) { mPadding = p; } /** - * Places a widget in given cell. + * Places a widget in a given cell. */ Cell &place(gcn::Widget *, int x, int y, int w, int h); /** - * Computes position of all the widgets. + * Computes the positions of all the widgets. */ void reflow(); -- cgit v1.2.3-70-g09d2 From aab0b1724897e186d2d4056da7f0cd34ccc12fcb Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 20 Oct 2007 16:50:41 +0000 Subject: Improved layout manager. Reworked layout of character selection dialog box. --- ChangeLog | 1 + src/gui/char_select.cpp | 58 ++++++++---------- src/gui/widgets/layout.cpp | 145 ++++++++++++++++++++++++++++----------------- src/gui/widgets/layout.h | 56 ++++++++++++++--- 4 files changed, 163 insertions(+), 97 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index a6d41da7..7590d646 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ * src/gui/login.cpp: Fixed layout of login dialog box when native language is not English. * src/gui/playerbox.cpp: Centered sprite inside selection box. + * src/gui/char_select.cpp: Reworked layout of dialog box. 2007-10-19 Guillaume Melquiond diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index e8381bef..ea04b6bc 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -36,6 +36,8 @@ #include "unregisterdialog.h" +#include "widgets/layout.h" + #include "../game.h" #include "../localplayer.h" #include "../main.h" @@ -100,40 +102,28 @@ CharSelectDialog::CharSelectDialog(LockedArray *charInfo, mMoneyLabel = new gcn::Label(strprintf(_("Money: %d"), 0)); mPlayerBox = new PlayerBox(); - int w = 195; - int h = 220; - setContentSize(w, h); - mPlayerBox->setDimension(gcn::Rectangle(5, 5, w - 10, 90)); - mNameLabel->setDimension(gcn::Rectangle(10, 100, 128, 16)); - mLevelLabel->setDimension(gcn::Rectangle(10, 116, 128, 16)); - mMoneyLabel->setDimension(gcn::Rectangle(10, 148, 128, 16)); - mPreviousButton->setPosition(5, 170); - mNextButton->setPosition(mPreviousButton->getWidth() + 10, 170); - mNewCharButton->setPosition(5, h - 5 - mNewCharButton->getHeight()); - mDelCharButton->setPosition( - 5 + mNewCharButton->getWidth() + 5, - mNewCharButton->getY()); - mCancelButton->setPosition( - w - 5 - mCancelButton->getWidth(), - mNewCharButton->getY()); - mSelectButton->setPosition( - mCancelButton->getX() - 5 - mSelectButton->getWidth(), - mNewCharButton->getY()); - mUnRegisterButton->setPosition( - w - 5 - mUnRegisterButton->getWidth(), - mCancelButton->getY() - 5 - mUnRegisterButton->getHeight()); - - add(mPlayerBox); - add(mSelectButton); - add(mCancelButton); - add(mUnRegisterButton); - add(mNewCharButton); - add(mDelCharButton); - add(mPreviousButton); - add(mNextButton); - add(mNameLabel); - add(mLevelLabel); - add(mMoneyLabel); + setPadding(8); + Layout &layout = getLayout(); + place(0, 0, mPlayerBox, 1, 5).setPadding(3); + place(1, 0, mNameLabel, 3); + place(1, 1, mLevelLabel, 3); + place(1, 2, mMoneyLabel, 3); + place(1, 3, mPreviousButton); + place(2, 3, mNextButton); + place(1, 4, mNewCharButton); + place(2, 4, mDelCharButton); + layout.setWidth(230); + layout.setColWidth(0, 80); + layout.setColWidth(3, Layout::FILL); + layout.matchColWidth(1, 2); + layout.setRowHeight(5, 5); + layout.flush(); + place(0, 0, mUnRegisterButton); + place(2, 0, mSelectButton); + place(3, 0, mCancelButton); + layout.setColWidth(1, Layout::FILL); + reflowLayout(); + forgetLayout(); setLocationRelativeTo(getParent()); setVisible(true); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 8a64acc0..2133b077 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -25,18 +25,22 @@ void Layout::resizeGrid(int w, int h) { - bool extW = w && w > (int)mColWidths.size(), - extH = h && h > (int)mRowHeights.size(); + bool extW = w && w > (int)mSizes[0].size(), + extH = h && h > (int)mSizes[1].size(); if (!extW && !extH) return; if (extH) { - mRowHeights.resize(h, -1); + mSizes[1].resize(h, 0); mCells.resize(h); - if (!extW) w = (int)mColWidths.size(); + if (!extW) w = mSizes[0].size(); + } + + if (extW) + { + mSizes[0].resize(w, 0); } - mColWidths.resize(w, -1); for (std::vector< std::vector< Cell > >::iterator i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) { @@ -47,13 +51,22 @@ void Layout::resizeGrid(int w, int h) void Layout::setColWidth(int n, int w) { resizeGrid(n + 1, 0); - mColWidths[n] = w; + mSizes[0][n] = w; } void Layout::setRowHeight(int n, int h) { resizeGrid(0, n + 1); - mRowHeights[n] = h; + mSizes[1][n] = h; +} + +void Layout::matchColWidth(int n1, int n2) +{ + resizeGrid(std::max(n1, n2) + 1, 0); + std::vector< int > widths = compute(0, mW); + int s = std::max(widths[n1], widths[n2]); + mSizes[0][n1] = s; + mSizes[0][n2] = s; } Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h) @@ -61,40 +74,45 @@ Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h) resizeGrid(x + w, y + h); Cell &cell = mCells[y][x]; cell.mWidget = widget; - cell.mColExtent = w; - cell.mRowExtent = h; + cell.mExtent[0] = w; + cell.mExtent[1] = h; cell.mPadding = 0; - cell.mHAlign = Cell::FILL; - cell.mVAlign = Cell::FILL; + cell.mAlign[0] = Cell::FILL; + cell.mAlign[1] = Cell::FILL; return cell; } -static void align(int &pos, int &cur, int upp, Cell::Alignment a) +void Layout::align(int &pos, int &size, int dim, Cell &cell, int *sizes) { - cur = std::min(cur, upp); - switch (a) + int size_max = sizes[0] - cell.mPadding * 2; + for (int i = 1; i < cell.mExtent[dim]; ++i) + size_max += sizes[i] + mPadding; + size = std::min(dim == 0 ? cell.mWidget->getWidth() + : cell.mWidget->getHeight(), size_max); + pos += cell.mPadding; + + switch (cell.mAlign[dim]) { case Cell::LEFT: return; case Cell::RIGHT: - pos += upp - cur; + pos += size_max - size; return; case Cell::CENTER: - pos += (upp - cur) / 2; + pos += (size_max - size) / 2; return; case Cell::FILL: - cur = upp; + size = size_max; return; } } -void Layout::reflow() +std::vector< int > Layout::compute(int dim, int upp) { - int gridW = mColWidths.size(), gridH = mRowHeights.size(); - - std::vector< int > widths(gridW, 0); - std::vector< int > heights(gridH, 0); + int gridW = mSizes[0].size(), gridH = mSizes[1].size(); + std::vector< int > sizes = mSizes[dim]; + // Compute minimum sizes. for (int gridY = 0; gridY < gridH; ++gridY) { for (int gridX = 0; gridX < gridW; ++gridX) @@ -102,58 +120,77 @@ void Layout::reflow() Cell &cell = mCells[gridY][gridX]; if (!cell.mWidget) continue; - if (cell.mColExtent == 1) - { - int w = cell.mWidget->getWidth() + cell.mPadding * 2; - if (w > widths[gridX]) widths[gridX] = w; - } - - if (cell.mRowExtent == 1) + if (cell.mExtent[dim] == 1) { - int h = cell.mWidget->getHeight() + cell.mPadding * 2; - if (h > heights[gridY]) heights[gridY] = h; + int s = dim == 0 ? cell.mWidget->getWidth() + : cell.mWidget->getHeight(); + int n = dim == 0 ? gridX : gridY; + s += cell.mPadding * 2; + if (s > sizes[n]) sizes[n] = s; } } } - for (int gridX = 0; gridX < gridW; ++gridX) + // Compute the FILL sizes. + int nb = sizes.size(); + int nbFill = 0; + for (int i = 0; i < nb; ++i) { - int w = mColWidths[gridX]; - if (w != -1) widths[gridX] = w; + if (mSizes[dim][i] == FILL) ++nbFill; + if (sizes[i] > 0) upp -= sizes[i]; + upp -= mPadding; } + upp += mPadding; - for (int gridY = 0; gridY < gridH; ++gridY) + if (upp <= 0 || nbFill == 0) return sizes; + + for (int i = 0; i < nb; ++i) { - int h = mRowHeights[gridY]; - if (h != -1) heights[gridY] = h; + if (mSizes[dim][i] != FILL) continue; + int s = (upp + nbFill / 2) / nbFill; + sizes[i] += s; + upp -= s; + --nbFill; } - int y = 0; + return sizes; +} + +void Layout::reflow() +{ + int gridW = mSizes[0].size(), gridH = mSizes[1].size(); + + std::vector< int > widths = compute(0, mW); + std::vector< int > heights = compute(1, mH); + + int y = mY; for (int gridY = 0; gridY < gridH; ++gridY) { - int h = heights[gridY]; - int x = 0; + int x = mX; for (int gridX = 0; gridX < gridW; ++gridX) { - int w = widths[gridX]; Cell &cell = mCells[gridY][gridX]; if (cell.mWidget) { - int ew = w - cell.mPadding * 2, - eh = h - cell.mPadding * 2; - for (int i = 1; i < cell.mColExtent; ++i) - ew += widths[gridX + i] + mPadding; - for (int i = 1; i < cell.mRowExtent; ++i) - eh += heights[gridY + i] + mPadding; - int dw = cell.mWidget->getWidth(), - dh = cell.mWidget->getHeight(); - int dx = x + cell.mPadding, dy = y + cell.mPadding; - align(dx, dw, ew, cell.mHAlign); - align(dy, dh, eh, cell.mVAlign); + int dx = x, dy = y, dw, dh; + align(dx, dw, 0, cell, &widths[gridX]); + align(dy, dh, 1, cell, &heights[gridY]); cell.mWidget->setDimension(gcn::Rectangle(dx, dy, dw, dh)); } - x += w + mPadding; + x += widths[gridX] + mPadding; + mNW = x - mX; } - y += h + mPadding; + y += heights[gridY] + mPadding; + mNH = y - mY; } } + +void Layout::flush() +{ + reflow(); + mY += mNH; + mW = mNW - mPadding; + mSizes[0].clear(); + mSizes[1].clear(); + mCells.clear(); +} diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 5be8e84c..09b511f6 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -58,20 +58,20 @@ class Cell * Sets the horizontal alignment of the cell content. */ Cell &setHAlign(Alignment a) - { mHAlign = a; return *this; } + { mAlign[0] = a; return *this; } /** * Sets the vertical alignment of the cell content. */ Cell &setVAlign(Alignment a) - { mVAlign = a; return *this; } + { mAlign[1] = a; return *this; } private: gcn::Widget *mWidget; - int mColExtent, mRowExtent; int mPadding; - Alignment mHAlign, mVAlign; + int mExtent[2]; + Alignment mAlign[2]; }; /** @@ -85,18 +85,35 @@ class Layout { public: - Layout(): mPadding(4) {} + Layout(): mPadding(4), mX(0), mY(0), mW(0), mH(0) {} /** - * Sets the width of a column. + * Sets the minimum width of a column. */ void setColWidth(int n, int w); /** - * Sets the height of a row. + * Sets the minimum height of a row. */ void setRowHeight(int n, int h); + /** + * Matchs widths of two columns. + */ + void matchColWidth(int n1, int n2); + + /** + * Sets the minimum width of the layout. + */ + void setWidth(int w) + { mW = w; } + + /** + * Sets the minimum height of the layout. + */ + void setHeight(int h) + { mH = h; } + /** * Sets the padding between cells. */ @@ -113,18 +130,39 @@ class Layout */ void reflow(); + /** + * Reflows the current layout. Then starts a new layout just below with + * the same width. + */ + void flush(); + + enum + { + FILL = -1, /**< Expand until the layout as the expected size. */ + }; + private: + /** + * Gets the position and size of a widget along a given axis + */ + void align(int &pos, int &size, int dim, Cell &cell, int *sizes); + /** * Ensures the private vectors are large enough. */ void resizeGrid(int w, int h); - std::vector< int > mColWidths; - std::vector< int > mRowHeights; + /** + * Gets the column/row sizes along a given axis. + */ + std::vector< int > compute(int dim, int upp); + + std::vector< int > mSizes[2]; std::vector< std::vector < Cell > > mCells; int mPadding; + int mX, mY, mW, mH, mNW, mNH; }; #endif -- cgit v1.2.3-70-g09d2 From 94ab3f3afa12f9f73d7f832e95aa0af2d9efdf16 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 20 Oct 2007 17:38:23 +0000 Subject: Set FILL as default size in layout. Converted server selection dialog to layout handler. --- ChangeLog | 1 + src/gui/serverdialog.cpp | 43 +++++++++++++++---------------------------- src/gui/widgets/layout.cpp | 11 +++++++---- src/gui/widgets/layout.h | 18 +++++++++++++----- 4 files changed, 36 insertions(+), 37 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 7590d646..8ab87921 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ language is not English. * src/gui/playerbox.cpp: Centered sprite inside selection box. * src/gui/char_select.cpp: Reworked layout of dialog box. + * src/gui/serverdialog.cpp: Converted to layout handler. 2007-10-19 Guillaume Melquiond diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 292e8fca..aaaa5eca 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -34,6 +34,8 @@ #include "scrollarea.h" #include "textfield.h" +#include "widgets/layout.h" + #include "../configuration.h" #include "../log.h" #include "../logindata.h" @@ -138,27 +140,6 @@ ServerDialog::ServerDialog(LoginData *loginData): mOkButton = new Button(_("Ok"), "ok", this); mCancelButton = new Button(_("Cancel"), "cancel", this); - setContentSize(200, 100); - - serverLabel->setPosition(10, 5); - portLabel->setPosition(10, 14 + serverLabel->getHeight()); - - mServerNameField->setPosition(60, 5); - mPortField->setPosition(60, 14 + serverLabel->getHeight()); - mServerNameField->setWidth(130); - mPortField->setWidth(130); - - mMostUsedServersDropDown->setPosition(10, 10 + - portLabel->getY() + portLabel->getHeight()); - mMostUsedServersDropDown->setWidth(180); - - mCancelButton->setPosition( - 200 - mCancelButton->getWidth() - 5, - 100 - mCancelButton->getHeight() - 5); - mOkButton->setPosition( - mCancelButton->getX() - mOkButton->getWidth() - 5, - 100 - mOkButton->getHeight() - 5); - mServerNameField->setActionEventId("ok"); mPortField->setActionEventId("ok"); mMostUsedServersDropDown->setActionEventId("changeSelection"); @@ -167,13 +148,19 @@ ServerDialog::ServerDialog(LoginData *loginData): mPortField->addActionListener(this); mMostUsedServersDropDown->addActionListener(mDropDownListener); - add(serverLabel); - add(portLabel); - add(mServerNameField); - add(mPortField); - add(mMostUsedServersDropDown); - add(mOkButton); - add(mCancelButton); + setPadding(8); + place(0, 0, serverLabel); + place(0, 1, portLabel); + place(1, 0, mServerNameField, 3).setPadding(3); + place(1, 1, mPortField, 3).setPadding(3); + place(0, 2, mMostUsedServersDropDown, 4).setPadding(3); + place(2, 3, mOkButton); + place(3, 3, mCancelButton); + Layout &layout = getLayout(); + layout.setWidth(250); + layout.setColWidth(1, Layout::FILL); + reflowLayout(); + forgetLayout(); setLocationRelativeTo(getParent()); setVisible(true); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 2133b077..9d0b4791 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -31,14 +31,14 @@ void Layout::resizeGrid(int w, int h) if (extH) { - mSizes[1].resize(h, 0); + mSizes[1].resize(h, FILL); mCells.resize(h); if (!extW) w = mSizes[0].size(); } if (extW) { - mSizes[0].resize(w, 0); + mSizes[0].resize(w, FILL); } for (std::vector< std::vector< Cell > >::iterator @@ -79,6 +79,9 @@ Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h) cell.mPadding = 0; cell.mAlign[0] = Cell::FILL; cell.mAlign[1] = Cell::FILL; + int &cs = mSizes[0][x], &rs = mSizes[1][y]; + if (cs == FILL) cs = 0; + if (rs == FILL) rs = 0; return cell; } @@ -137,8 +140,8 @@ std::vector< int > Layout::compute(int dim, int upp) for (int i = 0; i < nb; ++i) { if (mSizes[dim][i] == FILL) ++nbFill; - if (sizes[i] > 0) upp -= sizes[i]; - upp -= mPadding; + if (sizes[i] == FILL) sizes[i] = 0; + else upp -= sizes[i]; } upp += mPadding; diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 09b511f6..05a84d53 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -76,10 +76,14 @@ class Cell /** * This class is an helper for setting the position of widgets. They are - * positioned along the cells of a rectangular table. The size of a given - * table column can either be set manually or be chosen from the widest widget - * of the column. The process is similar for table rows. By default, there is a - * padding of 4 pixels between rows and between columns. + * positioned along the cells of a rectangular table. + * + * The size of a given table column can either be set manually or be chosen + * from the widest widget of the column. An empty column has a FILL width, + * which means it will be extended so that the layout fits its minimum width. + * + * The process is similar for table rows. By default, there is a padding of 4 + * pixels between rows and between columns. */ class Layout { @@ -89,11 +93,15 @@ class Layout /** * Sets the minimum width of a column. + * @note Setting the width to FILL and then placing a widget in the + * column will reset the width to zero. */ void setColWidth(int n, int w); /** * Sets the minimum height of a row. + * @note Setting the height to FILL and then placing a widget in the + * row will reset the height to zero. */ void setRowHeight(int n, int h); @@ -138,7 +146,7 @@ class Layout enum { - FILL = -1, /**< Expand until the layout as the expected size. */ + FILL = -42, /**< Expand until the layout as the expected size. */ }; private: -- cgit v1.2.3-70-g09d2 From 1f6ef95ca6bc8972d16b5b3c97e4fe4797fdf97d Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sun, 21 Oct 2007 10:37:44 +0000 Subject: Allowed for decreasing sizes in layout. --- ChangeLog | 1 + src/gui/widgets/layout.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 8a62cac7..477995bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * src/gui/window.cpp, src/gui/window.h: Removed redundant resizable flag. Factored moving/resizing code, so that events are fired only once per size change. + * src/gui/widgets/layout.cpp: Allowed for decreasing sizes in layout. 2007-10-20 Guillaume Melquiond diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 9d0b4791..228eac74 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -142,15 +142,16 @@ std::vector< int > Layout::compute(int dim, int upp) if (mSizes[dim][i] == FILL) ++nbFill; if (sizes[i] == FILL) sizes[i] = 0; else upp -= sizes[i]; + upp -= mPadding; } upp += mPadding; - if (upp <= 0 || nbFill == 0) return sizes; + if (nbFill == 0) return sizes; for (int i = 0; i < nb; ++i) { if (mSizes[dim][i] != FILL) continue; - int s = (upp + nbFill / 2) / nbFill; + int s = upp / nbFill; sizes[i] += s; upp -= s; --nbFill; -- cgit v1.2.3-70-g09d2 From 59c3b69103bf9bc346f6a4337c2ede0f43bfb6bf Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sun, 21 Oct 2007 11:20:55 +0000 Subject: Made visible the resizable grip on inventory window. --- ChangeLog | 6 ++++++ src/gui/char_select.cpp | 3 +-- src/gui/inventorywindow.cpp | 1 - src/gui/login.cpp | 1 - src/gui/serverdialog.cpp | 1 - src/gui/widgets/layout.cpp | 35 +++++++++++++++++++---------------- src/gui/widgets/layout.h | 43 ++++++++++++++++++++++++++++++++----------- src/gui/window.cpp | 10 +++++++--- 8 files changed, 65 insertions(+), 35 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index dc14d2ad..2db18c8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,12 @@ * src/gui/widgets/layout.cpp: Allowed for decreasing sizes in layout. * src/gui/inventorywindow.cpp, src/gui/inventorywindow.cpp: Delegated resizing events to layout handler. + * src/gui/widgets/layout.cpp, src/gui/widgets/layout.h: Renamed padding + to spacing. Added margin around layout. Constified code. + * src/gui/window.cpp, src/gui/login.cpp, src/gui/char_select.cpp, + src/gui/serverdialog.cpp, src/gui/inventorywindow.cpp: Removed window + padding and replaced it by layout margin, so that the grip on resizable + window is not outside the inner clip area. 2007-10-20 Guillaume Melquiond diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index ea04b6bc..f7042c70 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -102,7 +102,6 @@ CharSelectDialog::CharSelectDialog(LockedArray *charInfo, mMoneyLabel = new gcn::Label(strprintf(_("Money: %d"), 0)); mPlayerBox = new PlayerBox(); - setPadding(8); Layout &layout = getLayout(); place(0, 0, mPlayerBox, 1, 5).setPadding(3); place(1, 0, mNameLabel, 3); @@ -112,7 +111,7 @@ CharSelectDialog::CharSelectDialog(LockedArray *charInfo, place(2, 3, mNextButton); place(1, 4, mNewCharButton); place(2, 4, mDelCharButton); - layout.setWidth(230); + layout.setWidth(250); layout.setColWidth(0, 80); layout.setColWidth(3, Layout::FILL); layout.matchColWidth(1, 2); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 9aaba37a..fabbf541 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -81,7 +81,6 @@ InventoryWindow::InventoryWindow(): mWeightLabel = new gcn::Label( strprintf(_("Total Weight: %d - Maximum Weight: %d"), 0, 0)); - setPadding(8); place(0, 0, mWeightLabel, 4); place(0, 1, mInvenScroll, 4).setPadding(3); place(0, 2, mItemNameLabel, 4); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 9a7d1e5b..f35f427a 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -61,7 +61,6 @@ LoginDialog::LoginDialog(LoginData *loginData): mPassField->addActionListener(this); mKeepCheck->addActionListener(this); - setPadding(8); place(0, 0, userLabel); place(0, 1, passLabel); place(1, 0, mUserField, 3).setPadding(2); diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index aaaa5eca..2051518d 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -148,7 +148,6 @@ ServerDialog::ServerDialog(LoginData *loginData): mPortField->addActionListener(this); mMostUsedServersDropDown->addActionListener(mDropDownListener); - setPadding(8); place(0, 0, serverLabel); place(0, 1, portLabel); place(1, 0, mServerNameField, 3).setPadding(3); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 228eac74..252cf198 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -85,11 +85,12 @@ Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h) return cell; } -void Layout::align(int &pos, int &size, int dim, Cell &cell, int *sizes) +void Layout::align(int &pos, int &size, int dim, + Cell const &cell, int *sizes) const { int size_max = sizes[0] - cell.mPadding * 2; for (int i = 1; i < cell.mExtent[dim]; ++i) - size_max += sizes[i] + mPadding; + size_max += sizes[i] + mSpacing; size = std::min(dim == 0 ? cell.mWidget->getWidth() : cell.mWidget->getHeight(), size_max); pos += cell.mPadding; @@ -110,7 +111,7 @@ void Layout::align(int &pos, int &size, int dim, Cell &cell, int *sizes) } } -std::vector< int > Layout::compute(int dim, int upp) +std::vector< int > Layout::compute(int dim, int upp) const { int gridW = mSizes[0].size(), gridH = mSizes[1].size(); std::vector< int > sizes = mSizes[dim]; @@ -120,7 +121,7 @@ std::vector< int > Layout::compute(int dim, int upp) { for (int gridX = 0; gridX < gridW; ++gridX) { - Cell &cell = mCells[gridY][gridX]; + Cell const &cell = mCells[gridY][gridX]; if (!cell.mWidget) continue; if (cell.mExtent[dim] == 1) @@ -142,9 +143,9 @@ std::vector< int > Layout::compute(int dim, int upp) if (mSizes[dim][i] == FILL) ++nbFill; if (sizes[i] == FILL) sizes[i] = 0; else upp -= sizes[i]; - upp -= mPadding; + upp -= mSpacing; } - upp += mPadding; + upp = upp + mSpacing - mMargin * 2; if (nbFill == 0) return sizes; @@ -160,17 +161,17 @@ std::vector< int > Layout::compute(int dim, int upp) return sizes; } -void Layout::reflow() +void Layout::reflow(int &nw, int &nh) { int gridW = mSizes[0].size(), gridH = mSizes[1].size(); std::vector< int > widths = compute(0, mW); std::vector< int > heights = compute(1, mH); - int y = mY; + int x, y = mY + mMargin; for (int gridY = 0; gridY < gridH; ++gridY) { - int x = mX; + x = mX + mMargin; for (int gridX = 0; gridX < gridW; ++gridX) { Cell &cell = mCells[gridY][gridX]; @@ -181,19 +182,21 @@ void Layout::reflow() align(dy, dh, 1, cell, &heights[gridY]); cell.mWidget->setDimension(gcn::Rectangle(dx, dy, dw, dh)); } - x += widths[gridX] + mPadding; - mNW = x - mX; + x += widths[gridX] + mSpacing; } - y += heights[gridY] + mPadding; - mNH = y - mY; + y += heights[gridY] + mSpacing; } + + nw = x - mX - mSpacing + mMargin; + nh = y - mY - mSpacing + mMargin; } void Layout::flush() { - reflow(); - mY += mNH; - mW = mNW - mPadding; + int w, h; + reflow(w, h); + mY += h; + mW = w; mSizes[0].clear(); mSizes[1].clear(); mCells.clear(); diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 05a84d53..ae03ed9d 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -82,14 +82,27 @@ class Cell * from the widest widget of the column. An empty column has a FILL width, * which means it will be extended so that the layout fits its minimum width. * - * The process is similar for table rows. By default, there is a padding of 4 - * pixels between rows and between columns. + * The process is similar for table rows. By default, there is a spacing of 4 + * pixels between rows and between columns, and a margin of 6 pixels around the + * whole layout. */ class Layout { public: - Layout(): mPadding(4), mX(0), mY(0), mW(0), mH(0) {} + Layout(): mSpacing(4), mMargin(6), mX(0), mY(0), mW(0), mH(0) {} + + /** + * Gets the x-coordinate of the top left point of the layout. + */ + int getX() const + { return mX; } + + /** + * Gets the y-coordinate of the top left point of the layout. + */ + int getY() const + { return mY; } /** * Sets the minimum width of a column. @@ -123,10 +136,16 @@ class Layout { mH = h; } /** - * Sets the padding between cells. + * Sets the spacing between cells. */ - void setPadding(int p) - { mPadding = p; } + void setSpacing(int p) + { mSpacing = p; } + + /** + * Sets the margin around the layout. + */ + void setMargin(int m) + { mMargin = m; } /** * Places a widget in a given cell. @@ -134,9 +153,10 @@ class Layout Cell &place(gcn::Widget *, int x, int y, int w, int h); /** - * Computes the positions of all the widgets. + * Computes the positions of all the widgets. Returns the size of the + * layout. */ - void reflow(); + void reflow(int &nW, int &nH); /** * Reflows the current layout. Then starts a new layout just below with @@ -154,7 +174,8 @@ class Layout /** * Gets the position and size of a widget along a given axis */ - void align(int &pos, int &size, int dim, Cell &cell, int *sizes); + void align(int &pos, int &size, int dim, + Cell const &cell, int *sizes) const; /** * Ensures the private vectors are large enough. @@ -164,12 +185,12 @@ class Layout /** * Gets the column/row sizes along a given axis. */ - std::vector< int > compute(int dim, int upp); + std::vector< int > compute(int dim, int upp) const; std::vector< int > mSizes[2]; std::vector< std::vector < Cell > > mCells; - int mPadding; + int mSpacing, mMargin; int mX, mY, mW, mH, mNW, mNH; }; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf5f03db..f8d4a503 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -233,7 +233,8 @@ void Window::setSize(int width, int height) { mLayout->setWidth(width - 2 * getPadding()); mLayout->setHeight(height - getPadding() - getTitleBarHeight()); - mLayout->reflow(); + int w, h; + mLayout->reflow(w, h); } fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); @@ -621,10 +622,13 @@ Cell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) void Window::reflowLayout() { if (!mLayout) return; - mLayout->reflow(); + int w, h; + mLayout->reflow(w, h); + w += mLayout->getX(); + h += mLayout->getY(); Layout *tmp = mLayout; // Hide it so that the incoming resize does not reflow the layout again. mLayout = NULL; - resizeToContent(); + setContentSize(w, h); mLayout = tmp; } -- cgit v1.2.3-70-g09d2 From ee15a808a1e0d36167f80d9f96147103ba5583de Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 27 Oct 2007 09:03:13 +0000 Subject: Made it compile with GCC 4.3 --- ChangeLog | 17 +++++++++++++++++ src/beingmanager.cpp | 1 + src/channel.cpp | 7 +------ src/channel.h | 4 ++-- src/channelmanager.cpp | 1 + src/flooritemmanager.cpp | 2 ++ src/game.cpp | 16 ++++++++-------- src/gui/button.cpp | 4 +++- src/gui/chat.cpp | 5 +++-- src/gui/chat.h | 2 +- src/gui/playerbox.cpp | 2 ++ src/gui/scrollarea.cpp | 2 ++ src/gui/serverdialog.cpp | 5 +++-- src/gui/setup.cpp | 2 ++ src/gui/skill.cpp | 4 +++- src/gui/tabbedcontainer.cpp | 2 ++ src/gui/textfield.cpp | 4 +++- src/gui/widgets/dropdown.cpp | 2 ++ src/gui/window.cpp | 5 ++++- src/gui/windowcontainer.cpp | 2 ++ src/localplayer.h | 2 +- src/log.cpp | 9 +++++---- src/main.cpp | 2 ++ src/net/messageout.cpp | 5 +++-- src/particle.cpp | 5 +++-- src/properties.h | 3 +-- src/resources/buddylist.cpp | 8 ++++++-- src/resources/imageset.cpp | 2 ++ src/resources/itemdb.cpp | 4 ++-- src/resources/iteminfo.h | 2 +- src/resources/monsterdb.cpp | 2 ++ src/resources/monsterinfo.cpp | 2 ++ src/resources/monsterinfo.h | 2 +- 33 files changed, 95 insertions(+), 42 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 6d3dae7b..d382dd8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-10-27 Guillaume Melquiond + + * src/properties.h, src/game.cpp, src/channel.h, src/log.cpp, + src/gui/window.cpp, src/gui/setup.cpp, src/gui/button.cpp, + src/gui/chat.h, src/gui/widgets/dropdown.cpp, src/gui/chat.cpp, + src/gui/tabbedcontainer.cpp, src/gui/windowcontainer.cpp, + src/gui/skill.cpp, src/gui/serverdialog.cpp, src/gui/textfield.cpp, + src/gui/playerbox.cpp, src/gui/scrollarea.cpp, src/beingmanager.cpp, + src/flooritemmanager.cpp, src/channelmanager.cpp, src/main.cpp, + src/particle.cpp, src/net/messageout.cpp, src/channel.cpp, + src/localplayer.h, src/resources/imageset.cpp, + src/resources/buddylist.cpp, src/resources/monsterinfo.h, + src/resources/iteminfo.h, src/resources/monsterdb.cpp, + src/resources/monsterinfo.cpp, src/resources/itemdb.cpp: Fixed missing + dependencies, spurious const qualifiers, and weak brackets, so that it + compiles with GCC 4.3. + 2007-10-24 Bjørn Lindeijer * po/nl.po: Completed Dutch translation. diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 56865841..8ef3de1e 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -21,6 +21,7 @@ * $Id$ */ +#include #include #include "beingmanager.h" diff --git a/src/channel.cpp b/src/channel.cpp index 170dbf5e..3204b3b2 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -40,12 +40,7 @@ void Channel::setName(const std::string &channelName) mName = channelName; } -const short Channel::getId() const -{ - return mID; -} - -const int Channel::getUserListSize() const +int Channel::getUserListSize() const { return userList.size(); } diff --git a/src/channel.h b/src/channel.h index 0a62e073..ea6789ee 100644 --- a/src/channel.h +++ b/src/channel.h @@ -30,8 +30,8 @@ class Channel Channel(short id); std::string getName() const; void setName(const std::string &channelName); - const short getId() const; - const int getUserListSize() const; + int getId() const { return mID; } + int getUserListSize() const; std::string getUser(unsigned int i) const; private: typedef std::vector Users; diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp index 082581a1..91c20e98 100644 --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -21,6 +21,7 @@ * $Id$ */ +#include #include #include "channelmanager.h" diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp index 680616a8..8a00cc51 100644 --- a/src/flooritemmanager.cpp +++ b/src/flooritemmanager.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "flooritemmanager.h" #include "floor_item.h" diff --git a/src/game.cpp b/src/game.cpp index 53874f4d..b4887f5b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -684,24 +684,24 @@ void Game::handleInput() unsigned char direction = 0; // Translate pressed keys to movement and direction - if ( keyboard.isKeyActive(keyboard.KEY_MOVE_UP) || - joystick && joystick->isUp()) + if (keyboard.isKeyActive(keyboard.KEY_MOVE_UP) || + (joystick && joystick->isUp())) { direction |= Being::UP; } - else if ( keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN) || - joystick && joystick->isDown()) + else if (keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN) || + (joystick && joystick->isDown())) { direction |= Being::DOWN; } - if ( keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT) || - joystick && joystick->isLeft()) + if (keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT) || + (joystick && joystick->isLeft())) { direction |= Being::LEFT; } - else if ( keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT) || - joystick && joystick->isRight()) + else if (keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT) || + (joystick && joystick->isRight())) { direction |= Being::RIGHT; } diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 0379ebc0..e47f90f8 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -21,12 +21,14 @@ * $Id$ */ -#include "button.h" +#include #include #include #include +#include "button.h" + #include "../graphics.h" #include "../resources/image.h" diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index da60ef42..de47c8a9 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -21,13 +21,14 @@ * $Id$ */ -#include "chat.h" - +#include #include #include #include +#include "chat.h" + #include "browserbox.h" #include "../channelmanager.h" #include "../channel.h" diff --git a/src/gui/chat.h b/src/gui/chat.h index 2227e87d..ee699cf2 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -218,7 +218,7 @@ class ChatWindow : public Window, public gcn::ActionListener, int mItems; int mItemsKeep; - typedef struct CHATLOG + struct CHATLOG { std::string nick; std::string text; diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index e3f5b540..8e5f1827 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "playerbox.h" #include "../player.h" diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 816f94a8..cf555ef4 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "scrollarea.h" #include "../graphics.h" diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index c05e7aa9..70ed7fe8 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -21,13 +21,14 @@ * $Id$ */ -#include "serverdialog.h" - +#include #include #include #include +#include "serverdialog.h" + #include "button.h" #include "listbox.h" #include "ok_dialog.h" diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 6a13232a..821e9da6 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "setup.h" #include "button.h" diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index d5cfe76a..c553863f 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -21,10 +21,12 @@ * $Id$ */ -#include "skill.h" +#include #include +#include "skill.h" + #include "button.h" #include "listbox.h" #include "scrollarea.h" diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp index 5d6d21d1..8fb2f598 100644 --- a/src/gui/tabbedcontainer.cpp +++ b/src/gui/tabbedcontainer.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "tabbedcontainer.h" #include "button.h" diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 88d8fff9..81b1a0ab 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -21,10 +21,12 @@ * $Id$ */ -#include "textfield.h" +#include #include +#include "textfield.h" + #include "sdlinput.h" #include "../graphics.h" diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 1176ef2a..6863aa01 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "dropdown.h" #include "../../graphics.h" diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 1509ac92..68b79367 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -21,11 +21,14 @@ * $Id$ */ -#include "window.h" +#include +#include #include #include +#include "window.h" + #include "gui.h" #include "gccontainer.h" #include "windowcontainer.h" diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index 14aaaf68..d10c519c 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "windowcontainer.h" #include "../utils/dtor.h" diff --git a/src/localplayer.h b/src/localplayer.h index 6349f7ed..d6cb11ba 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -24,7 +24,7 @@ #ifndef _TMW_LOCALPLAYER_H #define _TMW_LOCALPLAYER_H -#include +#include #include "player.h" diff --git a/src/log.cpp b/src/log.cpp index 224736bd..6f69c671 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -19,7 +19,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "log.h" +#include +#include +#include +#include #ifdef WIN32 #include "utils/wingettimeofday.h" @@ -31,9 +34,7 @@ #include #endif -#include -#include -#include +#include "log.h" Logger::Logger(): mLogToStandardOut(false) diff --git a/src/main.cpp b/src/main.cpp index e8fe26cb..74a2fe13 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -770,6 +770,7 @@ int main(int argc, char *argv[]) case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) + { if (!quitDialog) { quitDialog = new QuitDialog(NULL, &quitDialog); @@ -778,6 +779,7 @@ int main(int argc, char *argv[]) { quitDialog->requestMoveToTop(); } + } break; } diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 4d68c14f..208196e2 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -21,12 +21,13 @@ * $Id$ */ -#include "messageout.h" - +#include #include #include +#include "messageout.h" + MessageOut::MessageOut(short id): mData(0), mDataSize(0), diff --git a/src/particle.cpp b/src/particle.cpp index 0f116b15..93fc7893 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -21,10 +21,11 @@ * $Id$ */ -#include "particle.h" - +#include #include +#include "particle.h" + #include "animationparticle.h" #include "configuration.h" #include "imageparticle.h" diff --git a/src/properties.h b/src/properties.h index bcd114c1..69950d56 100644 --- a/src/properties.h +++ b/src/properties.h @@ -63,8 +63,7 @@ class Properties * @return the value of the given property, or 0.0f when it doesn't * exist. */ - const float - getFloatProperty(const std::string &name, float def = 0.0f) + float getFloatProperty(std::string const &name, float def = 0.0f) { PropertyMap::const_iterator i = mProperties.find(name); float ret = def; diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp index 9327ef60..2f85825a 100644 --- a/src/resources/buddylist.cpp +++ b/src/resources/buddylist.cpp @@ -21,11 +21,15 @@ * $Id$ */ +#include +#include +#include +#include + #include "buddylist.h" + #include "../main.h" #include "../configuration.h" -#include -#include BuddyList::BuddyList() { diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 565e8860..08a6a110 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "imageset.h" #include "../log.h" diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 49632279..a83da342 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -21,12 +21,12 @@ * $Id$ */ +#include #include +#include #include "itemdb.h" -#include - #include "iteminfo.h" #include "resourcemanager.h" diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index b6fc922c..2726a012 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -107,7 +107,7 @@ class ItemInfo void setWeaponType(int); - const SpriteAction getAttackType() const + SpriteAction getAttackType() const { return mAttackType; } void addSound(EquipmentSoundEvent event, const std::string &filename); diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 7bdafdc2..84e3a219 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "monsterdb.h" #include "resourcemanager.h" diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index 2e896237..0a7e18dc 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include + #include "monsterinfo.h" #include "../utils/dtor.h" diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index b068056d..3034f10e 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -77,7 +77,7 @@ class MonsterInfo const std::string& getSprite() const { return mSprite; } - const Being::TargetCursorSize + Being::TargetCursorSize getTargetCursorSize() const { return mTargetCursorSize; } std::string -- cgit v1.2.3-70-g09d2 From 97bbe57e21a28544646da087e2a522390bf2ce5c Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 27 Oct 2007 20:23:48 +0000 Subject: Improved layout handler to support trees of nested arrays. Needed for converting and fixing the trade window. --- ChangeLog | 6 + src/gui/buy.cpp | 1 - src/gui/char_select.cpp | 18 ++- src/gui/login.cpp | 6 +- src/gui/serverdialog.cpp | 12 +- src/gui/widgets/layout.cpp | 231 +++++++++++++++++++++++++++---------- src/gui/widgets/layout.h | 276 +++++++++++++++++++++++++++++++-------------- src/gui/window.cpp | 30 ++--- src/gui/window.h | 26 ++--- 9 files changed, 407 insertions(+), 199 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index d382dd8b..5d2d6221 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,12 @@ src/resources/monsterinfo.cpp, src/resources/itemdb.cpp: Fixed missing dependencies, spurious const qualifiers, and weak brackets, so that it compiles with GCC 4.3. + * src/gui/widgets/layout.h, src/gui/widgets/layout.cpp: Improved layout + handler to support trees of nested arrays. + * src/gui/window.cpp, src/gui/window.h: Removed unused function + updateContentSize. Simplified layout accessors. + * src/gui/char_select.cpp: Replaced flushed-layout hack with a tree. + * src/gui/serverdialog.cpp, src/gui/buy.cpp: Simplified layouts. 2007-10-24 Bjørn Lindeijer diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index b95a8b25..bf449b2f 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -87,7 +87,6 @@ BuyDialog::BuyDialog(): place(4, 5, mQuitButton); Layout &layout = getLayout(); layout.setRowHeight(0, Layout::FILL); - layout.setColWidth(2, Layout::FILL); loadWindowState("Buy"); setLocationRelativeTo(getParent()); diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index f7042c70..c2306880 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -100,9 +100,11 @@ CharSelectDialog::CharSelectDialog(LockedArray *charInfo, mNameLabel = new gcn::Label(strprintf(_("Name: %s"), "")); mLevelLabel = new gcn::Label(strprintf(_("Level: %d"), 0)); mMoneyLabel = new gcn::Label(strprintf(_("Money: %d"), 0)); - mPlayerBox = new PlayerBox(); + mPlayerBox = new PlayerBox; + mPlayerBox->setWidth(74); - Layout &layout = getLayout(); + ContainerPlacer place; + place = getPlacer(0, 0); place(0, 0, mPlayerBox, 1, 5).setPadding(3); place(1, 0, mNameLabel, 3); place(1, 1, mLevelLabel, 3); @@ -111,18 +113,12 @@ CharSelectDialog::CharSelectDialog(LockedArray *charInfo, place(2, 3, mNextButton); place(1, 4, mNewCharButton); place(2, 4, mDelCharButton); - layout.setWidth(250); - layout.setColWidth(0, 80); - layout.setColWidth(3, Layout::FILL); - layout.matchColWidth(1, 2); - layout.setRowHeight(5, 5); - layout.flush(); + place.getCell().matchColWidth(1, 2); + place = getPlacer(0, 1); place(0, 0, mUnRegisterButton); place(2, 0, mSelectButton); place(3, 0, mCancelButton); - layout.setColWidth(1, Layout::FILL); - reflowLayout(); - forgetLayout(); + reflowLayout(250, 0); setLocationRelativeTo(getParent()); setVisible(true); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index f35f427a..565277a0 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -66,12 +66,10 @@ LoginDialog::LoginDialog(LoginData *loginData): place(1, 0, mUserField, 3).setPadding(2); place(1, 1, mPassField, 3).setPadding(2); place(0, 2, mKeepCheck, 4); - place(0, 3, mRegisterButton).setHAlign(Cell::LEFT); + place(0, 3, mRegisterButton).setHAlign(LayoutCell::LEFT); place(2, 3, mOkButton); place(3, 3, mCancelButton); - getLayout().setColWidth(1, 20); - reflowLayout(); - forgetLayout(); + reflowLayout(250, 0); setLocationRelativeTo(getParent()); setVisible(true); diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 70ed7fe8..00490d31 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -120,16 +120,12 @@ ServerDialog::ServerDialog(LoginData *loginData): place(0, 0, serverLabel); place(0, 1, portLabel); - place(1, 0, mServerNameField, 3).setPadding(3); - place(1, 1, mPortField, 3).setPadding(3); - place(0, 2, mMostUsedServersDropDown, 4).setPadding(3); + place(1, 0, mServerNameField, 3).setPadding(2); + place(1, 1, mPortField, 3).setPadding(2); + place(0, 2, mMostUsedServersDropDown, 4).setPadding(2); place(2, 3, mOkButton); place(3, 3, mCancelButton); - Layout &layout = getLayout(); - layout.setWidth(250); - layout.setColWidth(1, Layout::FILL); - reflowLayout(); - forgetLayout(); + reflowLayout(250, 0); setLocationRelativeTo(getParent()); setVisible(true); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 252cf198..2bcc558d 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -21,9 +21,103 @@ * $Id$ */ +#include + #include "layout.h" -void Layout::resizeGrid(int w, int h) +ContainerPlacer ContainerPlacer::at(int x, int y) +{ + return ContainerPlacer(mContainer, &mCell->at(x, y)); +} + +LayoutCell &ContainerPlacer::operator() + (int x, int y, gcn::Widget *wg, int w, int h) +{ + mContainer->add(wg); + return mCell->place(wg, x, y, w, h); +} + +LayoutCell::~LayoutCell() +{ + if (mType == ARRAY) delete mArray; +} + +LayoutArray &LayoutCell::getArray() +{ + assert(mType != WIDGET); + if (mType == ARRAY) return *mArray; + mArray = new LayoutArray; + mType = ARRAY; + mExtent[0] = 1; + mExtent[1] = 1; + mPadding = 0; + mAlign[0] = FILL; + mAlign[1] = FILL; + return *mArray; +} + +void LayoutCell::reflow(int nx, int ny, int nw, int nh) +{ + assert(mType != NONE); + nx += mPadding; + ny += mPadding; + nw -= 2 * mPadding; + nh -= 2 * mPadding; + if (mType == ARRAY) + mArray->reflow(nx, ny, nw, nh); + else + mWidget->setDimension(gcn::Rectangle(nx, ny, nw, nh)); +} + +void LayoutCell::computeSizes() +{ + assert(mType == ARRAY); + + for (std::vector< std::vector< LayoutCell * > >::iterator + i = mArray->mCells.begin(), i_end = mArray->mCells.end(); + i != i_end; ++i) + { + for (std::vector< LayoutCell * >::iterator + j = i->begin(), j_end = i->end(); j != j_end; ++j) + { + LayoutCell *cell = *j; + if (cell && cell->mType == ARRAY) cell->computeSizes(); + } + } + + mSize[0] = mArray->getSize(0); + mSize[1] = mArray->getSize(1); +} + +LayoutArray::LayoutArray(): mSpacing(4) +{ +} + +LayoutArray::~LayoutArray() +{ + for (std::vector< std::vector< LayoutCell * > >::iterator + i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) + { + for (std::vector< LayoutCell * >::iterator + j = i->begin(), j_end = i->end(); j != j_end; ++j) + { + delete *j; + } + } +} + +LayoutCell &LayoutArray::at(int x, int y, int w, int h) +{ + resizeGrid(x + w, y + h); + LayoutCell *&cell = mCells[y][x]; + if (!cell) + { + cell = new LayoutCell; + } + return *cell; +} + +void LayoutArray::resizeGrid(int w, int h) { bool extW = w && w > (int)mSizes[0].size(), extH = h && h > (int)mSizes[1].size(); @@ -31,127 +125,128 @@ void Layout::resizeGrid(int w, int h) if (extH) { - mSizes[1].resize(h, FILL); + mSizes[1].resize(h, Layout::FILL); mCells.resize(h); if (!extW) w = mSizes[0].size(); } if (extW) { - mSizes[0].resize(w, FILL); + mSizes[0].resize(w, Layout::FILL); } - for (std::vector< std::vector< Cell > >::iterator + for (std::vector< std::vector< LayoutCell * > >::iterator i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) { - i->resize(w); + i->resize(w, NULL); } } -void Layout::setColWidth(int n, int w) +void LayoutArray::setColWidth(int n, int w) { resizeGrid(n + 1, 0); mSizes[0][n] = w; } -void Layout::setRowHeight(int n, int h) +void LayoutArray::setRowHeight(int n, int h) { resizeGrid(0, n + 1); mSizes[1][n] = h; } -void Layout::matchColWidth(int n1, int n2) +void LayoutArray::matchColWidth(int n1, int n2) { resizeGrid(std::max(n1, n2) + 1, 0); - std::vector< int > widths = compute(0, mW); + std::vector< short > widths = getSizes(0, Layout::FILL); int s = std::max(widths[n1], widths[n2]); mSizes[0][n1] = s; mSizes[0][n2] = s; } -Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h) +LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) { - resizeGrid(x + w, y + h); - Cell &cell = mCells[y][x]; + LayoutCell &cell = at(x, y, w, h); + assert(cell.mType == LayoutCell::NONE); + cell.mType = LayoutCell::WIDGET; cell.mWidget = widget; + cell.mSize[0] = w == 1 ? widget->getWidth() : 0; + cell.mSize[1] = h == 1 ? widget->getHeight() : 0; cell.mExtent[0] = w; cell.mExtent[1] = h; cell.mPadding = 0; - cell.mAlign[0] = Cell::FILL; - cell.mAlign[1] = Cell::FILL; - int &cs = mSizes[0][x], &rs = mSizes[1][y]; - if (cs == FILL) cs = 0; - if (rs == FILL) rs = 0; + cell.mAlign[0] = LayoutCell::FILL; + cell.mAlign[1] = LayoutCell::FILL; + short &cs = mSizes[0][x], &rs = mSizes[1][y]; + if (cs == Layout::FILL && w == 1) cs = 0; + if (rs == Layout::FILL && h == 1) rs = 0; return cell; } -void Layout::align(int &pos, int &size, int dim, - Cell const &cell, int *sizes) const +void LayoutArray::align(int &pos, int &size, int dim, + LayoutCell const &cell, short *sizes) const { - int size_max = sizes[0] - cell.mPadding * 2; + int size_max = sizes[0]; for (int i = 1; i < cell.mExtent[dim]; ++i) size_max += sizes[i] + mSpacing; - size = std::min(dim == 0 ? cell.mWidget->getWidth() - : cell.mWidget->getHeight(), size_max); - pos += cell.mPadding; + size = std::min(cell.mSize[dim], size_max); switch (cell.mAlign[dim]) { - case Cell::LEFT: + case LayoutCell::LEFT: return; - case Cell::RIGHT: + case LayoutCell::RIGHT: pos += size_max - size; return; - case Cell::CENTER: + case LayoutCell::CENTER: pos += (size_max - size) / 2; return; - case Cell::FILL: + case LayoutCell::FILL: size = size_max; return; } } -std::vector< int > Layout::compute(int dim, int upp) const +std::vector< short > LayoutArray::getSizes(int dim, int upp) const { int gridW = mSizes[0].size(), gridH = mSizes[1].size(); - std::vector< int > sizes = mSizes[dim]; + std::vector< short > sizes = mSizes[dim]; // Compute minimum sizes. for (int gridY = 0; gridY < gridH; ++gridY) { for (int gridX = 0; gridX < gridW; ++gridX) { - Cell const &cell = mCells[gridY][gridX]; - if (!cell.mWidget) continue; + LayoutCell const *cell = mCells[gridY][gridX]; + if (!cell || cell->mType == LayoutCell::NONE) continue; - if (cell.mExtent[dim] == 1) + if (cell->mExtent[dim] == 1) { - int s = dim == 0 ? cell.mWidget->getWidth() - : cell.mWidget->getHeight(); int n = dim == 0 ? gridX : gridY; - s += cell.mPadding * 2; + int s = cell->mSize[dim] + cell->mPadding * 2; if (s > sizes[n]) sizes[n] = s; } } } + if (upp == Layout::FILL) return sizes; + // Compute the FILL sizes. int nb = sizes.size(); int nbFill = 0; for (int i = 0; i < nb; ++i) { - if (mSizes[dim][i] == FILL) ++nbFill; - if (sizes[i] == FILL) sizes[i] = 0; + if (mSizes[dim][i] == Layout::FILL) ++nbFill; + if (sizes[i] == Layout::FILL) sizes[i] = 0; else upp -= sizes[i]; upp -= mSpacing; } - upp = upp + mSpacing - mMargin * 2; + upp = upp + mSpacing; if (nbFill == 0) return sizes; for (int i = 0; i < nb; ++i) { - if (mSizes[dim][i] != FILL) continue; + if (mSizes[dim][i] != Layout::FILL) continue; int s = upp / nbFill; sizes[i] += s; upp -= s; @@ -161,43 +256,61 @@ std::vector< int > Layout::compute(int dim, int upp) const return sizes; } -void Layout::reflow(int &nw, int &nh) +int LayoutArray::getSize(int dim) const +{ + std::vector< short > sizes = getSizes(dim, Layout::FILL); + int size = 0; + int nb = sizes.size(); + for (int i = 0; i < nb; ++i) + { + if (sizes[i] != Layout::FILL) size += sizes[i]; + size += mSpacing; + } + return size - mSpacing; +} + +void LayoutArray::reflow(int nx, int ny, int nw, int nh) { int gridW = mSizes[0].size(), gridH = mSizes[1].size(); - std::vector< int > widths = compute(0, mW); - std::vector< int > heights = compute(1, mH); + std::vector< short > widths = getSizes(0, nw); + std::vector< short > heights = getSizes(1, nh); - int x, y = mY + mMargin; + int y = ny; for (int gridY = 0; gridY < gridH; ++gridY) { - x = mX + mMargin; + int x = nx; for (int gridX = 0; gridX < gridW; ++gridX) { - Cell &cell = mCells[gridY][gridX]; - if (cell.mWidget) + LayoutCell *cell = mCells[gridY][gridX]; + if (cell && cell->mType != LayoutCell::NONE) { int dx = x, dy = y, dw, dh; - align(dx, dw, 0, cell, &widths[gridX]); - align(dy, dh, 1, cell, &heights[gridY]); - cell.mWidget->setDimension(gcn::Rectangle(dx, dy, dw, dh)); + align(dx, dw, 0, *cell, &widths[gridX]); + align(dy, dh, 1, *cell, &heights[gridY]); + cell->reflow(dx, dy, dw, dh); } x += widths[gridX] + mSpacing; } y += heights[gridY] + mSpacing; } +} - nw = x - mX - mSpacing + mMargin; - nh = y - mY - mSpacing + mMargin; +Layout::Layout(): mComputed(false) +{ + getArray(); + setPadding(6); } -void Layout::flush() +void Layout::reflow(int &nw, int &nh) { - int w, h; - reflow(w, h); - mY += h; - mW = w; - mSizes[0].clear(); - mSizes[1].clear(); - mCells.clear(); + if (!mComputed) + { + computeSizes(); + mComputed = true; + } + + nw = nw == 0 ? mSize[0] + 2 * mPadding : nw; + nh = nh == 0 ? mSize[1] + 2 * mPadding : nh; + LayoutCell::reflow(0, 0, nw, nh); } diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index ae03ed9d..a6e630c2 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -26,172 +26,280 @@ #include -#include +#include + +class LayoutCell; /** - * This class describes the formatting of a widget in the cell of a layout - * table. Horizontally, a widget can either fill the width of the cell (minus - * the cell padding), or it can retain its size and be flushed left, or flush - * right, or centered in the cell. The process is similar for the vertical - * alignment, except that top is represented by LEFT and bottom by RIGHT. + * This class is a helper for adding widgets to nested tables in a window. */ -class Cell +class ContainerPlacer { - friend class Layout; - public: - enum Alignment - { - LEFT, RIGHT, CENTER, FILL - }; - - Cell(): mWidget(0) {} + ContainerPlacer(gcn::Container *c = NULL, LayoutCell *l = NULL): + mContainer(c), mCell(l) + {} /** - * Sets the padding around the cell content. + * Gets the pointed cell. */ - Cell &setPadding(int p) - { mPadding = p; return *this; } + LayoutCell &getCell() + { return *mCell; } /** - * Sets the horizontal alignment of the cell content. + * Returns a placer for the same container but to an inner cell. */ - Cell &setHAlign(Alignment a) - { mAlign[0] = a; return *this; } + ContainerPlacer at(int x, int y); /** - * Sets the vertical alignment of the cell content. + * Adds the given widget to the container and places it in the layout. + * @see LayoutArray::place */ - Cell &setVAlign(Alignment a) - { mAlign[1] = a; return *this; } + LayoutCell &operator() + (int x, int y, gcn::Widget *, int w = 1, int h = 1); private: - gcn::Widget *mWidget; - int mPadding; - int mExtent[2]; - Alignment mAlign[2]; + gcn::Container *mContainer; + LayoutCell *mCell; }; /** - * This class is an helper for setting the position of widgets. They are - * positioned along the cells of a rectangular table. - * - * The size of a given table column can either be set manually or be chosen - * from the widest widget of the column. An empty column has a FILL width, - * which means it will be extended so that the layout fits its minimum width. - * - * The process is similar for table rows. By default, there is a spacing of 4 - * pixels between rows and between columns, and a margin of 6 pixels around the - * whole layout. + * This class contains a rectangular array of cells. */ -class Layout +class LayoutArray { + friend class LayoutCell; + public: - Layout(): mSpacing(4), mMargin(6), mX(0), mY(0), mW(0), mH(0) {} + LayoutArray(); + + ~LayoutArray(); /** - * Gets the x-coordinate of the top left point of the layout. + * Returns a reference on the cell at given position. */ - int getX() const - { return mX; } + LayoutCell &at(int x, int y, int w = 1, int h = 1); /** - * Gets the y-coordinate of the top left point of the layout. + * Places a widget in a given cell. + * @param w number of columns the widget spawns. + * @param h number of rows the widget spawns. + * @note When @a w is 1, the width of column @a x is reset to zero if + * it was FILL. */ - int getY() const - { return mY; } + LayoutCell &place(gcn::Widget *, int x, int y, int w = 1, int h = 1); /** * Sets the minimum width of a column. - * @note Setting the width to FILL and then placing a widget in the - * column will reset the width to zero. */ void setColWidth(int n, int w); /** * Sets the minimum height of a row. - * @note Setting the height to FILL and then placing a widget in the - * row will reset the height to zero. */ void setRowHeight(int n, int h); /** - * Matchs widths of two columns. + * Sets the widths of two columns to the maximum of their widths. */ void matchColWidth(int n1, int n2); /** - * Sets the minimum width of the layout. + * Computes and sets the positions of all the widgets. + * @param nW width of the array, used to resize the FILL columns. + * @param nH height of the array, used to resize the FILL rows. */ - void setWidth(int w) - { mW = w; } + void reflow(int nX, int nY, int nW, int nH); + + private: + + // Copy not allowed, as the array owns all its cells. + LayoutArray(LayoutArray const &); + LayoutArray &operator=(LayoutArray const &); /** - * Sets the minimum height of the layout. + * Gets the position and size of a widget along a given axis */ - void setHeight(int h) - { mH = h; } + void align(int &pos, int &size, int dim, + LayoutCell const &cell, short *sizes) const; /** - * Sets the spacing between cells. + * Ensures the private vectors are large enough. */ - void setSpacing(int p) - { mSpacing = p; } + void resizeGrid(int w, int h); /** - * Sets the margin around the layout. + * Gets the column/row sizes along a given axis. + * @param upp target size for the array. Ignored if FILL. */ - void setMargin(int m) - { mMargin = m; } + std::vector< short > getSizes(int dim, int upp) const; /** - * Places a widget in a given cell. + * Gets the total size along a given axis. */ - Cell &place(gcn::Widget *, int x, int y, int w, int h); + int getSize(int dim) const; + + std::vector< short > mSizes[2]; + std::vector< std::vector < LayoutCell * > > mCells; + + char mSpacing; +}; + +/** + * This class describes the formatting of a widget in the cell of a layout + * table. Horizontally, a widget can either fill the width of the cell (minus + * the cell padding), or it can retain its size and be flushed left, or flush + * right, or centered in the cell. The process is similar for the vertical + * alignment, except that top is represented by LEFT and bottom by RIGHT. + */ +class LayoutCell +{ + friend class Layout; + friend class LayoutArray; + + public: + + enum Alignment + { + LEFT, RIGHT, CENTER, FILL + }; + + LayoutCell(): mType(NONE) {} + + ~LayoutCell(); /** - * Computes the positions of all the widgets. Returns the size of the - * layout. + * Sets the padding around the cell content. */ - void reflow(int &nW, int &nH); + LayoutCell &setPadding(int p) + { mPadding = p; return *this; } + + /** + * Sets the horizontal alignment of the cell content. + */ + LayoutCell &setHAlign(Alignment a) + { mAlign[0] = a; return *this; } + + /** + * Sets the vertical alignment of the cell content. + */ + LayoutCell &setVAlign(Alignment a) + { mAlign[1] = a; return *this; } + + /** + * @see LayoutArray::at + */ + LayoutCell &at(int x, int y) + { return getArray().at(x, y); } + + /** + * @see LayoutArray::place + */ + LayoutCell &place(gcn::Widget *wg, int x, int y, int w = 1, int h = 1) + { return getArray().place(wg, x, y, w, h); } /** - * Reflows the current layout. Then starts a new layout just below with - * the same width. + * @see LayoutArray::matchColWidth */ - void flush(); + void matchColWidth(int n1, int n2) + { getArray().matchColWidth(n1, n2); } + + /** + * @see LayoutArray::setColWidth + */ + void setColWidth(int n, int w) + { getArray().setColWidth(n, w); } + + /** + * @see LayoutArray::setRowHeight + */ + void setRowHeight(int n, int h) + { getArray().setRowHeight(n, h); } + + /** + * Sets the minimum widths and heights of this cell and of all the + * inner cells. + */ + void computeSizes(); + + private: + + // Copy not allowed, as the cell may own an array. + LayoutCell(LayoutCell const &); + LayoutCell &operator=(LayoutCell const &); + + union + { + gcn::Widget *mWidget; + LayoutArray *mArray; + }; enum { - FILL = -42, /**< Expand until the layout as the expected size. */ + NONE, WIDGET, ARRAY }; - private: + /** + * Returns the embedded array. Creates it if the cell does not contain + * anything yet. Aborts if it contains a widget. + */ + LayoutArray &getArray(); /** - * Gets the position and size of a widget along a given axis + * @see LayoutArray::reflow */ - void align(int &pos, int &size, int dim, - Cell const &cell, int *sizes) const; + void reflow(int nx, int ny, int nw, int nh); + + short mSize[2]; + char mPadding; + char mExtent[2]; + char mAlign[2]; + char mNbFill[2]; + char mType; +}; + +/** + * This class is an helper for setting the position of widgets. They are + * positioned along the cells of some rectangular tables. The layout may either + * be a single table or a tree of nested tables. + * + * The size of a given table column can either be set manually or be chosen + * from the widest widget of the column. An empty column has a FILL width, + * which means it will be extended so that the layout fits its minimum width. + * + * The process is similar for table rows. By default, there is a spacing of 4 + * pixels between rows and between columns, and a margin of 6 pixels around the + * whole layout. + */ +class Layout: public LayoutCell +{ + public: + + Layout(); /** - * Ensures the private vectors are large enough. + * Sets the margin around the layout. */ - void resizeGrid(int w, int h); + void setMargin(int m) + { setPadding(m); } /** - * Gets the column/row sizes along a given axis. + * Sets the positions of all the widgets. + * @see LayoutArray::reflow */ - std::vector< int > compute(int dim, int upp) const; + void reflow(int &nW, int &nH); + + enum + { + FILL = -42, /**< Expand until the layout as the expected size. */ + }; - std::vector< int > mSizes[2]; - std::vector< std::vector < Cell > > mCells; + private: - int mSpacing, mMargin; - int mX, mY, mW, mH, mNW, mNH; + bool mComputed; }; #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 68b79367..7629e2e7 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include @@ -234,9 +235,8 @@ void Window::setSize(int width, int height) if (mLayout) { - mLayout->setWidth(width - 2 * getPadding()); - mLayout->setHeight(height - getPadding() - getTitleBarHeight()); - int w, h; + int w = width - 2 * getPadding(), + h = height - getPadding() - getTitleBarHeight(); mLayout->reflow(w, h); } @@ -520,7 +520,6 @@ void Window::mouseDragged(gcn::MouseEvent &event) // Set the new window and content dimensions setDimension(newDim); - updateContentSize(); } } @@ -555,7 +554,6 @@ void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); setContentSize(mDefaultWidth, mDefaultHeight); - updateContentSize(); } int Window::getResizeHandles(gcn::MouseEvent &event) @@ -611,28 +609,22 @@ Layout &Window::getLayout() return *mLayout; } -void Window::forgetLayout() +LayoutCell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) { - delete mLayout; - mLayout = 0; + add(wg); + return getLayout().place(wg, x, y, w, h); } -Cell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) +ContainerPlacer Window::getPlacer(int x, int y) { - add(wg); - return getLayout().place(wg, x, y, w, h); + return ContainerPlacer(this, &getLayout().at(x, y)); } -void Window::reflowLayout() +void Window::reflowLayout(int w, int h) { - if (!mLayout) return; - int w, h; + assert(mLayout); mLayout->reflow(w, h); - w += mLayout->getX(); - h += mLayout->getY(); - Layout *tmp = mLayout; - // Hide it so that the incoming resize does not reflow the layout again. + delete mLayout; mLayout = NULL; setContentSize(w, h); - mLayout = tmp; } diff --git a/src/gui/window.h b/src/gui/window.h index a09a9bbc..df756be3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -30,11 +30,12 @@ #include "windowlistener.h" -class Cell; class ConfigListener; +class ContainerPlacer; class Image; class ImageRect; class Layout; +class LayoutCell; class ResizeGrip; class WindowContainer; @@ -92,12 +93,6 @@ class Window : public gcn::Window */ void setContentSize(int width, int height); - /** - * Called when either the user or resetToDefaultSize resizes the - * windows, so that the windows can manage its widgets. - */ - virtual void updateContentSize() {} - /** * Sets the size of this window. */ @@ -292,19 +287,24 @@ class Window : public gcn::Window Layout &getLayout(); /** - * Deletes the layout handler. + * Computes the position of the widgets according to the current + * layout. Resizes the window so that the layout fits. Deletes the + * layout. + * @param w if non-zero, force the window to this width. + * @param h if non-zero, force the window to this height. + * @note This function is meant to be called with fixed-size windows. */ - void forgetLayout(); + void reflowLayout(int w = 0, int h = 0); /** - * Resizes the window after computing the position of the widgets. + * Adds a widget to the window and sets it at given cell. */ - void reflowLayout(); + LayoutCell &place(int x, int y, gcn::Widget *, int w = 1, int h = 1); /** - * Adds a widget to the window and sets it at given cell. + * Returns a proxy for adding widgets in an inner table of the layout. */ - Cell &place(int x, int y, gcn::Widget *, int w = 1, int h = 1); + ContainerPlacer getPlacer(int x, int y); private: /** -- cgit v1.2.3-70-g09d2 From aea08a9368265c6afd6741fa84c97491552bfb84 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sun, 28 Oct 2007 14:59:38 +0000 Subject: Separated auto-resizing into two categories: "set" and "add". Removed useless code. --- ChangeLog | 7 +++++++ src/gui/buy.cpp | 2 +- src/gui/inventorywindow.cpp | 10 +--------- src/gui/sell.cpp | 3 +-- src/gui/widgets/layout.cpp | 39 ++++++++++++++++++++++++++------------- src/gui/widgets/layout.h | 29 +++++++++++++++++++++++------ 6 files changed, 59 insertions(+), 31 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 4c5b865a..8cc10b0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-10-28 Guillaume Melquiond + + * src/gui/widgets/layout.h, src/gui/widgets/layout.cpp: Separated + auto-resizing into two categories: "set" and "add". + * src/gui/sell.cpp, src/gui/inventorywindow.cpp, src/gui/buy.cpp: + Removed useless code. Updated constant names. + 2007-10-28 Eugenio Favalli * src/gui/debugwindow.cpp, tmw.cbp: Fixed coordinates in the debug diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index bf449b2f..a21435f8 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -86,7 +86,7 @@ BuyDialog::BuyDialog(): place(3, 5, mBuyButton); place(4, 5, mQuitButton); Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::FILL); + layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState("Buy"); setLocationRelativeTo(getParent()); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 4621e59a..bf23a419 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -65,10 +65,6 @@ InventoryWindow::InventoryWindow(): mDropButton = new Button(_("Drop"), "drop", this); mSplitButton = new Button(_("Split"), "split", this); - mUseButton->adjustSize(); - mDropButton->adjustSize(); - mSplitButton->adjustSize(); - mItems = new ItemContainer(player_node->mInventory.get(), 10, 5); mItems->addSelectionListener(this); @@ -93,7 +89,7 @@ InventoryWindow::InventoryWindow(): layout.setColWidth(0, 48); layout.setColWidth(1, 48); layout.setColWidth(2, 48); - layout.setRowHeight(1, Layout::FILL); + layout.setRowHeight(1, Layout::AUTO_SET); loadWindowState("Inventory"); } @@ -160,10 +156,6 @@ void InventoryWindow::selectionChanged(const SelectionEvent &event) mItemDescriptionLabel->setCaption(strprintf(_("Description: %s"), info ? info->getDescription().c_str() : "")); - mItemNameLabel->adjustSize(); - mItemEffectLabel->adjustSize(); - mItemDescriptionLabel->adjustSize(); - if (mSplit) { if (item && !item->isEquipment() && item->getQuantity() > 1) { diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 8c442aad..08565654 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -91,8 +91,7 @@ SellDialog::SellDialog(): place(3, 5, mSellButton); place(4, 5, mQuitButton); Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::FILL); - layout.setColWidth(2, Layout::FILL); + layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState("Sell"); setLocationRelativeTo(getParent()); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 2bcc558d..02ed42a1 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -125,14 +125,14 @@ void LayoutArray::resizeGrid(int w, int h) if (extH) { - mSizes[1].resize(h, Layout::FILL); + mSizes[1].resize(h, Layout::AUTO_DEF); mCells.resize(h); if (!extW) w = mSizes[0].size(); } if (extW) { - mSizes[0].resize(w, Layout::FILL); + mSizes[0].resize(w, Layout::AUTO_DEF); } for (std::vector< std::vector< LayoutCell * > >::iterator @@ -157,12 +157,19 @@ void LayoutArray::setRowHeight(int n, int h) void LayoutArray::matchColWidth(int n1, int n2) { resizeGrid(std::max(n1, n2) + 1, 0); - std::vector< short > widths = getSizes(0, Layout::FILL); + std::vector< short > widths = getSizes(0, Layout::AUTO_DEF); int s = std::max(widths[n1], widths[n2]); mSizes[0][n1] = s; mSizes[0][n2] = s; } +void LayoutArray::extend(int x, int y, int w, int h) +{ + LayoutCell &cell = at(x, y, w, h); + cell.mExtent[0] = w; + cell.mExtent[1] = h; +} + LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) { LayoutCell &cell = at(x, y, w, h); @@ -177,8 +184,8 @@ LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) cell.mAlign[0] = LayoutCell::FILL; cell.mAlign[1] = LayoutCell::FILL; short &cs = mSizes[0][x], &rs = mSizes[1][y]; - if (cs == Layout::FILL && w == 1) cs = 0; - if (rs == Layout::FILL && h == 1) rs = 0; + if (cs == Layout::AUTO_DEF && w == 1) cs = 0; + if (rs == Layout::AUTO_DEF && h == 1) rs = 0; return cell; } @@ -228,17 +235,23 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const } } - if (upp == Layout::FILL) return sizes; + if (upp == Layout::AUTO_DEF) return sizes; // Compute the FILL sizes. int nb = sizes.size(); int nbFill = 0; for (int i = 0; i < nb; ++i) { - if (mSizes[dim][i] == Layout::FILL) ++nbFill; - if (sizes[i] == Layout::FILL) sizes[i] = 0; - else upp -= sizes[i]; - upp -= mSpacing; + if (mSizes[dim][i] <= Layout::AUTO_DEF) + { + ++nbFill; + if (mSizes[dim][i] == Layout::AUTO_SET || + sizes[i] <= Layout::AUTO_DEF) + { + sizes[i] = 0; + } + } + upp -= sizes[i] + mSpacing; } upp = upp + mSpacing; @@ -246,7 +259,7 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const for (int i = 0; i < nb; ++i) { - if (mSizes[dim][i] != Layout::FILL) continue; + if (mSizes[dim][i] > Layout::AUTO_DEF) continue; int s = upp / nbFill; sizes[i] += s; upp -= s; @@ -258,12 +271,12 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const int LayoutArray::getSize(int dim) const { - std::vector< short > sizes = getSizes(dim, Layout::FILL); + std::vector< short > sizes = getSizes(dim, Layout::AUTO_DEF); int size = 0; int nb = sizes.size(); for (int i = 0; i < nb; ++i) { - if (sizes[i] != Layout::FILL) size += sizes[i]; + if (sizes[i] > Layout::AUTO_DEF) size += sizes[i]; size += mSpacing; } return size - mSpacing; diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index a6e630c2..2d81ad81 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -88,7 +88,7 @@ class LayoutArray * @param w number of columns the widget spawns. * @param h number of rows the widget spawns. * @note When @a w is 1, the width of column @a x is reset to zero if - * it was FILL. + * it was AUTO_DEF. Similarly for @a h. */ LayoutCell &place(gcn::Widget *, int x, int y, int w = 1, int h = 1); @@ -107,10 +107,15 @@ class LayoutArray */ void matchColWidth(int n1, int n2); + /** + * Spawns a cell over several columns/rows. + */ + void extend(int x, int y, int w, int h); + /** * Computes and sets the positions of all the widgets. - * @param nW width of the array, used to resize the FILL columns. - * @param nH height of the array, used to resize the FILL rows. + * @param nW width of the array, used to resize the AUTO_ columns. + * @param nH height of the array, used to resize the AUTO_ rows. */ void reflow(int nX, int nY, int nW, int nH); @@ -133,7 +138,7 @@ class LayoutArray /** * Gets the column/row sizes along a given axis. - * @param upp target size for the array. Ignored if FILL. + * @param upp target size for the array. Ignored if AUTO_DEF. */ std::vector< short > getSizes(int dim, int upp) const; @@ -219,6 +224,12 @@ class LayoutCell void setRowHeight(int n, int h) { getArray().setRowHeight(n, h); } + /** + * @see LayoutArray::extend. + */ + void extend(int x, int y, int w, int h) + { getArray().extend(x, y, w, h); } + /** * Sets the minimum widths and heights of this cell and of all the * inner cells. @@ -267,7 +278,7 @@ class LayoutCell * be a single table or a tree of nested tables. * * The size of a given table column can either be set manually or be chosen - * from the widest widget of the column. An empty column has a FILL width, + * from the widest widget of the column. An empty column has a AUTO_DEF width, * which means it will be extended so that the layout fits its minimum width. * * The process is similar for table rows. By default, there is a spacing of 4 @@ -292,9 +303,15 @@ class Layout: public LayoutCell */ void reflow(int &nW, int &nH); + /** + * When the minimum size of the layout is less than the available size, + * the remaining pixels are equally split amongst the FILL items. + */ enum { - FILL = -42, /**< Expand until the layout as the expected size. */ + AUTO_DEF = -42, /**< Default value, behaves like AUTO_ADD. */ + AUTO_SET = -43, /**< Uses the share as the new size. */ + AUTO_ADD = -44, /**< Adds the share to the current size. */ }; private: -- cgit v1.2.3-70-g09d2 From f97ddedaa9672c78147fc13282bd14a5be46eb19 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 10 Apr 2008 22:03:57 +0000 Subject: Fixed some compiler warnings and don't try to load particle effects when no file is set. --- ChangeLog | 7 +++++++ src/gui/skill.cpp | 46 +++++++++++++++++++++++---------------------- src/gui/trade.h | 2 +- src/gui/widgets/layout.h | 2 +- src/log.h | 4 ++-- src/resources/mapreader.cpp | 6 ++++++ src/resources/spritedef.cpp | 2 -- 7 files changed, 41 insertions(+), 28 deletions(-) (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 597a5c0c..0477f10b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-04-12 Bjørn Lindeijer + + * src/gui/widgets/layout.h, src/gui/skill.cpp, src/gui/trade.h, + src/log.h, src/resources/mapreader.cpp, src/resources/spritedef.cpp: + Fixed some compiler warnings and don't try to load particle effects + when no file is set. + 2008-04-08 Bjørn Lindeijer * src/map.cpp, src/gui/viewport.cpp, src/tileset.h, src/map.h, diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 09e7a10d..48d64202 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -103,26 +103,27 @@ void SkillDialog::update() Skill_Tab::Skill_Tab(std::string type): type(type) { - int skillnum; + int skillNum = 0; + if (type == "Weapon") { - skillnum = CHAR_SKILL_WEAPON_NB; + skillNum = CHAR_SKILL_WEAPON_NB; } else if (type == "Magic") { - skillnum = CHAR_SKILL_MAGIC_NB; + skillNum = CHAR_SKILL_MAGIC_NB; } else if (type == "Craft") { - skillnum = CHAR_SKILL_CRAFT_NB; + skillNum = CHAR_SKILL_CRAFT_NB; } - mSkillNameLabels.resize(skillnum); - mSkillLevelLabels.resize(skillnum); - mSkillExpLabels.resize(skillnum); - mSkillProgress.resize(skillnum); + mSkillNameLabels.resize(skillNum); + mSkillLevelLabels.resize(skillNum); + mSkillExpLabels.resize(skillNum); + mSkillProgress.resize(skillNum); - for (int a=0; a < skillnum; a++) + for (int a=0; a < skillNum; a++) { mSkillNameLabels.at(a) = new gcn::Label(""); mSkillNameLabels.at(a)->setPosition(1, a*32 ); @@ -148,28 +149,29 @@ Skill_Tab::Skill_Tab(std::string type): type(type) void Skill_Tab::update() { setOpaque(false); - int skillnum; - int skillbegin; + int skillNum = 0; + int skillBegin; + if (type == "Weapon") { - skillnum = CHAR_SKILL_WEAPON_NB; - skillbegin = CHAR_SKILL_WEAPON_BEGIN - CHAR_SKILL_BEGIN; + skillNum = CHAR_SKILL_WEAPON_NB; + skillBegin = CHAR_SKILL_WEAPON_BEGIN - CHAR_SKILL_BEGIN; } else if (type == "Magic") { - skillnum = CHAR_SKILL_MAGIC_NB; - skillbegin = CHAR_SKILL_MAGIC_BEGIN - CHAR_SKILL_BEGIN; + skillNum = CHAR_SKILL_MAGIC_NB; + skillBegin = CHAR_SKILL_MAGIC_BEGIN - CHAR_SKILL_BEGIN; } else if (type == "Craft") { - skillnum = CHAR_SKILL_CRAFT_NB; - skillbegin = CHAR_SKILL_CRAFT_BEGIN - CHAR_SKILL_BEGIN; + skillNum = CHAR_SKILL_CRAFT_NB; + skillBegin = CHAR_SKILL_CRAFT_BEGIN - CHAR_SKILL_BEGIN; } - for (int a = 0; a < skillnum; a++) + for (int a = 0; a < skillNum; a++) { - int baseLevel = player_node->getAttributeBase(a + skillbegin + CHAR_SKILL_BEGIN); - int effLevel = player_node->getAttributeEffective(a + skillbegin + CHAR_SKILL_BEGIN); + int baseLevel = player_node->getAttributeBase(a + skillBegin + CHAR_SKILL_BEGIN); + int effLevel = player_node->getAttributeEffective(a + skillBegin + CHAR_SKILL_BEGIN); std::string skillLevel("Lvl: " + toString(baseLevel)); if (effLevel < baseLevel) @@ -182,11 +184,11 @@ void Skill_Tab::update() } mSkillLevelLabels.at(a)->setCaption(skillLevel); - std::pair exp = player_node->getExperience(a + skillbegin); + std::pair exp = player_node->getExperience(a + skillBegin); std::string sExp (toString(exp.first) + " / " + toString(exp.second)); - mSkillNameLabels.at(a)->setCaption(LocalPlayer::getSkillName(a + skillbegin)); + mSkillNameLabels.at(a)->setCaption(LocalPlayer::getSkillName(a + skillBegin)); mSkillNameLabels.at(a)->adjustSize(); mSkillLevelLabels.at(a)->adjustSize(); mSkillExpLabels.at(a)->setCaption(sExp); diff --git a/src/gui/trade.h b/src/gui/trade.h index cd943a41..449de573 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -96,7 +96,7 @@ class TradeWindow : public Window, gcn::ActionListener, SelectionListener { PREPARING, /**< Players are adding items. */ PROPOSING, /**< Local player is proposing a trade. */ - ACCEPTING, /**< Distant player is proposing a trade. */ + ACCEPTING /**< Distant player is proposing a trade. */ }; /** diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 2d81ad81..5914b5c1 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -311,7 +311,7 @@ class Layout: public LayoutCell { AUTO_DEF = -42, /**< Default value, behaves like AUTO_ADD. */ AUTO_SET = -43, /**< Uses the share as the new size. */ - AUTO_ADD = -44, /**< Adds the share to the current size. */ + AUTO_ADD = -44 /**< Adds the share to the current size. */ }; private: diff --git a/src/log.h b/src/log.h index dd1c0f91..5abf46a5 100644 --- a/src/log.h +++ b/src/log.h @@ -64,8 +64,8 @@ class Logger void log(const char *log_text, ...); /** - * Log an error and quit. The error will pop-up in Windows and will be - * printed to standard error everywhere else. + * Log an error and quit. The error will pop-up on Windows and Mac, and + * will be printed to standard error everywhere else. */ void error(const std::string &error_text); diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 9c6c52aa..33616c0a 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -258,8 +258,14 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) logger->log("- Loading object name: %s type: %s at %d:%d", objName.c_str(), objType.c_str(), objX, objY); + if (objType == "PARTICLE_EFFECT") { + if (objName.empty()) { + logger->log(" Warning: No particle file given"); + continue; + } + map->addParticleEffect(objName, objX, objY); } else diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 11821a60..9d98184a 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -51,8 +51,6 @@ SpriteDef::getAction(SpriteAction action) const SpriteDef *SpriteDef::load(std::string const &animationFile, int variant) { - ResourceManager *resman = ResourceManager::getInstance(); - std::string::size_type pos = animationFile.find('|'); std::string palettes; if (pos != std::string::npos) -- cgit v1.2.3-70-g09d2 From 4b9e2b6c41e740a3eac10078d5fa4fbc63788bbe Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 11 Apr 2008 13:31:52 +0000 Subject: Ported trunk over to Guichan 0.8.0. Based on merge from 0.0 branch, but because of quite a bit of GUI differences there were additional changes and probably additional issues. You have been warned. ;) Merged revisions 4045-4049,4051-4059 via svnmerge from https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r4045 | b_lindeijer | 2008-04-07 17:23:07 +0200 (Mon, 07 Apr 2008) | 3 lines Upgraded to Guichan 0.8.0 (merge from guichan-0.8 branch, except for gcn::TabbedArea usage) ........ r4059 | b_lindeijer | 2008-04-09 16:25:42 +0200 (Wed, 09 Apr 2008) | 2 lines Fixed problem with row height in shop list box. ........ --- ChangeLog | 36 +++++++++++++ INSTALL | 2 +- NEWS | 2 + src/CMakeLists.txt | 2 - src/Makefile.am | 4 +- src/gui/button.cpp | 2 +- src/gui/buy.cpp | 5 +- src/gui/buy.h | 9 ++-- src/gui/char_select.cpp | 7 ++- src/gui/chat.cpp | 26 ++++----- src/gui/checkbox.cpp | 6 +-- src/gui/checkbox.h | 2 +- src/gui/guildlistbox.cpp | 19 ++++--- src/gui/guildlistbox.h | 18 ------- src/gui/guildwindow.cpp | 4 +- src/gui/inttextbox.cpp | 2 +- src/gui/inventorywindow.cpp | 2 +- src/gui/inventorywindow.h | 9 ++-- src/gui/itemcontainer.cpp | 17 +++--- src/gui/itemcontainer.h | 20 ++++--- src/gui/itemshortcutwindow.cpp | 9 ++-- src/gui/itemshortcutwindow.h | 7 ++- src/gui/listbox.cpp | 21 -------- src/gui/listbox.h | 31 ----------- src/gui/login.cpp | 2 +- src/gui/playerbox.cpp | 8 +-- src/gui/playerbox.h | 2 +- src/gui/quitdialog.cpp | 12 ++--- src/gui/radiobutton.cpp | 2 +- src/gui/scrollarea.cpp | 24 ++++----- src/gui/scrollarea.h | 2 +- src/gui/selectionlistener.h | 68 ------------------------ src/gui/sell.cpp | 2 +- src/gui/sell.h | 7 ++- src/gui/setup_audio.cpp | 4 +- src/gui/setup_joystick.cpp | 6 +-- src/gui/setup_video.cpp | 18 +++---- src/gui/shoplistbox.cpp | 29 +--------- src/gui/shoplistbox.h | 28 ++-------- src/gui/slider.cpp | 2 +- src/gui/tabbedcontainer.cpp | 4 +- src/gui/textbox.cpp | 4 +- src/gui/textfield.cpp | 8 +-- src/gui/textfield.h | 2 +- src/gui/trade.cpp | 2 +- src/gui/trade.h | 6 +-- src/gui/widgets/dropdown.cpp | 15 +++--- src/gui/widgets/dropdown.h | 2 +- src/gui/window.cpp | 117 ++++++++--------------------------------- src/gui/window.h | 77 +++------------------------ src/gui/windowlistener.h | 86 ------------------------------ 51 files changed, 213 insertions(+), 588 deletions(-) delete mode 100644 src/gui/selectionlistener.h delete mode 100644 src/gui/windowlistener.h (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 0477f10b..18f172fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ Fixed some compiler warnings and don't try to load particle effects when no file is set. +2008-04-09 Bjørn Lindeijer + + * src/gui/shoplistbox.cpp, src/gui/shoplistbox.h: Fixed problem with + row height in shop list box. + 2008-04-08 Bjørn Lindeijer * src/map.cpp, src/gui/viewport.cpp, src/tileset.h, src/map.h, @@ -297,6 +302,15 @@ design decisions. * data/items.xml: Fixed a few messed up slot numbers. +2008-01-28 Bjørn Lindeijer + + * src/gui/sell.cpp, src/gui/window.cpp, src/gui/inventorywindow.h, + src/gui/buy.h, src/gui/itemshortcutwindow.cpp, + src/gui/inventorywindow.cpp, src/gui/buy.cpp, src/gui/sell.h, + src/gui/window.h, src/gui/windowlistener.h, + src/gui/itemshortcutwindow.h, src/CMakeLists.txt, src/Makefile.am: + Used the gcn::WidgetListener instead of our WindowListener. + 2008-01-26 Bjørn Lindeijer * src/gui/truetypefont.cpp: Image alpha should also be set to 1, in @@ -316,6 +330,28 @@ * src/net/beinghandler.cpp, src/resources/spritedef.h: Fixed broken communication of attack directions. +2008-01-23 Bjørn Lindeijer + + * src/gui/char_server.cpp, src/gui/window.cpp, src/gui/checkbox.h, + src/gui/playerbox.h, src/gui/button.cpp, src/gui/chat.cpp, + src/gui/slider.cpp, src/gui/tabbedcontainer.cpp, src/gui/textfield.h, + src/gui/shoplistbox.cpp, src/gui/register.cpp, + src/gui/radiobutton.cpp, src/gui/textbox.cpp, src/gui/login.cpp, + src/gui/setup_audio.cpp, src/gui/setup_video.cpp, + src/gui/textfield.cpp, src/gui/playerbox.cpp, + src/gui/setup_joystick.cpp, src/gui/scrollarea.h, + src/gui/windowlistener.h, src/gui/checkbox.cpp, + src/gui/scrollarea.cpp: Compile against Guichan 0.8.0. Some issues + with ShopListBox left and not trying to use their new TabbedArea, + SelectionListener and WidgetListener yet. Also needs more testing. + * src/gui/trade.cpp, src/gui/sell.cpp, src/gui/inventorywindow.h, + src/gui/selectionlistener.h, src/gui/itemcontainer.h, + src/gui/shoplistbox.cpp, src/gui/shoplistbox.h, src/gui/listbox.h, + src/gui/buy.h, src/gui/inventorywindow.cpp, src/gui/buy.cpp, + src/gui/itemcontainer.cpp, src/gui/sell.h, src/gui/trade.h, + src/gui/listbox.cpp, src/CMakeLists.txt, src/Makefile.am: Used the + gcn::SelectionListener instead of our own. + 2008-01-20 Philipp Sehmisch * data/items.xml: Added max-per-slot property to all items. diff --git a/INSTALL b/INSTALL index ea8a4f81..a346a2e5 100644 --- a/INSTALL +++ b/INSTALL @@ -21,7 +21,7 @@ and some libraries. The required libraries are: * SDL_image http://www.libsdl.org/projects/SDL_image/ * SDL_ttf http://www.libsdl.org/projects/SDL_ttf/ * ENet 1.2 http://enet.bespin.org/ -* Guichan 0.7.x http://guichan.sourceforge.net/ +* Guichan 0.8.x http://guichan.sourceforge.net/ * libxml2 http://www.xmlsoft.org/ * physfs 1.0.x http://icculus.org/physfs/ * zlib 1.2.x http://www.gzip.org/zlib/ diff --git a/NEWS b/NEWS index ebdae676..51a181d0 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +0.0.24.1 (7 April 2008) + 0.0.24 (24 December 2007) - Added female specific hair styles - Added user-definable key settings diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cda186d..b783efcb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,7 +148,6 @@ SET(SRCS gui/scrollarea.h gui/sdlinput.cpp gui/sdlinput.h - gui/selectionlistener.h gui/sell.cpp gui/sell.h gui/serverdialog.cpp @@ -198,7 +197,6 @@ SET(SRCS gui/window.h gui/windowcontainer.cpp gui/windowcontainer.h - gui/windowlistener.h net/beinghandler.cpp net/beinghandler.h net/buysellhandler.cpp diff --git a/src/Makefile.am b/src/Makefile.am index d9b3fc8d..c46fe481 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -102,7 +102,6 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/scrollarea.h \ gui/sdlinput.cpp \ gui/sdlinput.h \ - gui/selectionlistener.h \ gui/sell.cpp \ gui/sell.h \ gui/serverdialog.cpp \ @@ -150,7 +149,6 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/window.h \ gui/windowcontainer.cpp \ gui/windowcontainer.h \ - gui/windowlistener.h \ net/beinghandler.h \ net/beinghandler.cpp \ net/buysellhandler.h \ @@ -340,4 +338,4 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ INCLUDES = \ $(all_includes) \ -DTMW_DATADIR=\""$(pkgdatadir)/"\" \ - -DLOCALEDIR=\""$(localedir)"\" \ No newline at end of file + -DLOCALEDIR=\""$(localedir)"\" diff --git a/src/gui/button.cpp b/src/gui/button.cpp index e47f90f8..c6bc4ccb 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -82,7 +82,7 @@ Button::Button(const std::string& caption, const std::string &actionEventId, void Button::init() { - setBorderSize(0); + setFrameSize(0); if (mInstances == 0) { diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index d2e12a85..49d19675 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -178,9 +178,8 @@ void BuyDialog::action(const gcn::ActionEvent &event) } } -void BuyDialog::selectionChanged(const SelectionEvent &event) +void BuyDialog::valueChanged(const gcn::SelectionEvent &event) { - // Reset amount of items and update labels mAmountItems = 1; mSlider->setValue(1); @@ -192,7 +191,7 @@ void BuyDialog::selectionChanged(const SelectionEvent &event) void BuyDialog::updateButtonsAndLabels() { - int selectedItem = mShopItemList->getSelected(); + const int selectedItem = mShopItemList->getSelected(); int price = 0; if (selectedItem > -1) diff --git a/src/gui/buy.h b/src/gui/buy.h index 4e129611..ec7419be 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -25,9 +25,9 @@ #define _TMW_BUY_H #include +#include #include "window.h" -#include "selectionlistener.h" #include "../guichanfwd.h" @@ -40,7 +40,8 @@ class ListBox; * * \ingroup Interface */ -class BuyDialog : public Window, public gcn::ActionListener, SelectionListener +class BuyDialog : public Window, public gcn::ActionListener, + gcn::SelectionListener { public: /** @@ -82,10 +83,8 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener /** * Updates the labels according to the selected item. - * - * @see SelectionListener::selectionChanged */ - void selectionChanged(const SelectionEvent &event); + void valueChanged(const gcn::SelectionEvent &event); /** * Returns the name of item number i in the shop inventory. diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index a691f4ec..b2d3b53e 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -323,7 +323,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): mFemale->setPosition( 100, 120 ); // Default to a Male character - mMale->setMarked(true); + mMale->setSelected(true); mMale->setActionEventId("gender"); mFemale->setActionEventId("gender"); @@ -375,13 +375,12 @@ CharCreateDialog::action(const gcn::ActionEvent &event) mCreateButton->setEnabled(false); unsigned int genderSelected; - if( mMale->isMarked() ){ + if (mMale->isSelected()) { genderSelected = GENDER_MALE; } else { genderSelected = GENDER_FEMALE; } - Net::AccountServer::Account::createCharacter( getName(), mPlayer->getHairStyle(), @@ -418,7 +417,7 @@ CharCreateDialog::action(const gcn::ActionEvent &event) UpdateSliders(); } else if (event.getId() == "gender"){ - if( mMale->isMarked() ) { + if (mMale->isSelected()) { mPlayer->setGender(GENDER_MALE); } else { mPlayer->setGender(GENDER_FEMALE); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index f6b54d29..1efee8ed 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -67,14 +67,14 @@ ChatWindow::ChatWindow(): textOutput->setMaxRow((int) config.getValue("ChatLogLength", 0)); ScrollArea *scrollArea = new ScrollArea(textOutput); scrollArea->setPosition( - scrollArea->getBorderSize(), scrollArea->getBorderSize()); + scrollArea->getFrameSize(), scrollArea->getFrameSize()); scrollArea->setScrollPolicy( gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); scrollArea->setOpaque(false); GCContainer *tab = new GCContainer(); - tab->setWidth(getWidth() - 2 * tab->getBorderSize()); - tab->setHeight(getHeight() - 2 * tab->getBorderSize()); + tab->setWidth(getWidth() - 2 * tab->getFrameSize()); + tab->setHeight(getHeight() - 2 * tab->getFrameSize()); tab->setOpaque(false); tab->add(scrollArea); @@ -109,15 +109,15 @@ ChatWindow::logic() const gcn::Rectangle area = getChildrenArea(); - mChatInput->setPosition(mChatInput->getBorderSize(), + mChatInput->setPosition(mChatInput->getFrameSize(), area.height - mChatInput->getHeight() - - mChatInput->getBorderSize()); - mChatInput->setWidth(area.width - 2 * mChatInput->getBorderSize()); - mContainer->setWidth(area.width - 2 * mContainer->getBorderSize()); - mContainer->setHeight(area.height - 2 * mContainer->getBorderSize() - + mChatInput->getFrameSize()); + mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize()); + mContainer->setWidth(area.width - 2 * mContainer->getFrameSize()); + mContainer->setHeight(area.height - 2 * mContainer->getFrameSize() - mChatInput->getHeight() - 5); - mScrollArea->setWidth(area.width - 2 * mScrollArea->getBorderSize()); - mScrollArea->setHeight(area.height - 2 * mScrollArea->getBorderSize() - + mScrollArea->setWidth(area.width - 2 * mScrollArea->getFrameSize()); + mScrollArea->setHeight(area.height - 2 * mScrollArea->getFrameSize() - mChatInput->getHeight() - 26); Window::logic(); } @@ -475,12 +475,12 @@ ChatWindow::createNewChannelTab(std::string channelName) textOutput->setOpaque(false); textOutput->disableLinksAndUserColors(); ScrollArea *scrollArea = new ScrollArea(textOutput); - scrollArea->setPosition(scrollArea->getBorderSize(), scrollArea->getBorderSize()); + scrollArea->setPosition(scrollArea->getFrameSize(), scrollArea->getFrameSize()); scrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); scrollArea->setOpaque(false); GCContainer *tab = new GCContainer(); - tab->setWidth(getWidth() - 2 * tab->getBorderSize()); - tab->setHeight(getHeight() - 2 * tab->getBorderSize()); + tab->setWidth(getWidth() - 2 * tab->getFrameSize()); + tab->setHeight(getHeight() - 2 * tab->getFrameSize()); tab->add(scrollArea); tab->setOpaque(false); mContainer->addTab(tab, channelName); diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index fab4780c..5b300d33 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -34,8 +34,8 @@ Image *CheckBox::checkBoxChecked; Image *CheckBox::checkBoxDisabled; Image *CheckBox::checkBoxDisabledChecked; -CheckBox::CheckBox(const std::string& caption, bool marked): - gcn::CheckBox(caption, marked) +CheckBox::CheckBox(const std::string& caption, bool selected): + gcn::CheckBox(caption, selected) { if (instances == 0) { @@ -68,7 +68,7 @@ void CheckBox::drawBox(gcn::Graphics* graphics) { Image *box; - if (mMarked) { + if (isSelected()) { if (isEnabled()) { box = checkBoxChecked; } else { diff --git a/src/gui/checkbox.h b/src/gui/checkbox.h index 468a7f38..262e63ae 100644 --- a/src/gui/checkbox.h +++ b/src/gui/checkbox.h @@ -40,7 +40,7 @@ class CheckBox : public gcn::CheckBox { /** * Constructor. */ - CheckBox(const std::string& caption, bool marked = false); + CheckBox(const std::string& caption, bool selected = false); /** * Destructor. diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp index 1a392d2d..11661235 100644 --- a/src/gui/guildlistbox.cpp +++ b/src/gui/guildlistbox.cpp @@ -30,27 +30,26 @@ GuildListBox::GuildListBox(): ListBox(NULL) { - } void GuildListBox::draw(gcn::Graphics *graphics) { if (!mListModel) return; - + graphics->setColor(gcn::Color(110, 160, 255)); graphics->setFont(getFont()); - + int fontHeight = getFont()->getHeight(); - + // Draw rectangle below the selected list element if (mSelected >= 0) { graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected, getWidth(), fontHeight)); } - + // TODO: Add online status image - + // Draw the list elements for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); @@ -71,7 +70,7 @@ void GuildListBox::setSelected(int selected) // Update mSelected with bounds checking mSelected = std::min(mListModel->getNumberOfElements() - 1, std::max(-1, selected)); - + gcn::Widget *parent; parent = (gcn::Widget*)getParent(); if (parent) @@ -82,8 +81,8 @@ void GuildListBox::setSelected(int selected) parent->showWidgetPart(this, scroll); } } - - fireSelectionChangedEvent(); + + distributeValueChangedEvent(); } void GuildListBox::mousePressed(gcn::MouseEvent &event) @@ -93,6 +92,6 @@ void GuildListBox::mousePressed(gcn::MouseEvent &event) // TODO: Add guild functions, ie private messaging int y = event.getY(); setSelected(y / getFont()->getHeight()); - generateAction(); + distributeActionEvent(); } } diff --git a/src/gui/guildlistbox.h b/src/gui/guildlistbox.h index befaef1f..262012a4 100644 --- a/src/gui/guildlistbox.h +++ b/src/gui/guildlistbox.h @@ -49,24 +49,6 @@ public: void mousePressed(gcn::MouseEvent &event); - /** - * Adds a listener to the list that's notified each time a change to - * the selection occurs. - */ - void addSelectionListener(SelectionListener *listener) - { - mListeners.push_back(listener); - } - - /** - * Removes a listener from the list that's notified each time a change - * to the selection occurs. - */ - void removeSelectionListener(SelectionListener *listener) - { - mListeners.remove(listener); - } - /** * Sets the index of the selected element. */ diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 970c6ce1..eb0faa35 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -173,8 +173,8 @@ void GuildWindow::newGuildTab(const std::string &guildName) // Create new tab GCContainer *tab = new GCContainer(); - tab->setWidth(getWidth() - 2 * tab->getBorderSize()); - tab->setHeight(getHeight() - 2 * tab->getBorderSize()); + tab->setWidth(getWidth() - 2 * tab->getFrameSize()); + tab->setHeight(getHeight() - 2 * tab->getFrameSize()); tab->setOpaque(false); ListBox *list = new ListBox(); list->setListModel(player_node->getGuild(guildName)); diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextbox.cpp index 5ae3dd93..17e87afd 100644 --- a/src/gui/inttextbox.cpp +++ b/src/gui/inttextbox.cpp @@ -51,7 +51,7 @@ IntTextBox::keyPressed(gcn::KeyEvent &event) int i; s >> i; setInt(i); - generateAction(); + distributeActionEvent(); } void IntTextBox::setRange(int min, int max) diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 0ef1ab35..bd224cf0 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -144,7 +144,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event) } } -void InventoryWindow::selectionChanged(const SelectionEvent &event) +void InventoryWindow::valueChanged(const gcn::SelectionEvent &event) { Item *item = mItems->getItem(); ItemInfo const *info = item ? &item->getInfo() : NULL; diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 34883c1c..01fb118c 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -26,10 +26,9 @@ #include #include - +#include #include -#include "selectionlistener.h" #include "window.h" #include "../guichanfwd.h" @@ -45,7 +44,7 @@ class ItemContainer; class InventoryWindow : public Window, public gcn::ActionListener, public gcn::KeyListener, - public SelectionListener + public gcn::SelectionListener { public: /** @@ -82,10 +81,8 @@ class InventoryWindow : public Window, /** * Updates labels to currently selected item. - * - * @see SelectionListener::selectionChanged. */ - void selectionChanged(const SelectionEvent &event); + void valueChanged(const gcn::SelectionEvent &event); private: void updateButtons(); /**< Updates button states. */ diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 1abb8f0b..eddb6011 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -24,9 +24,9 @@ #include "itemcontainer.h" #include +#include #include "sdlinput.h" -#include "selectionlistener.h" #include "../graphics.h" #include "../inventory.h" @@ -159,20 +159,19 @@ void ItemContainer::setSelectedItem(Item *item) if (mSelectedItem != item) { mSelectedItem = item; - fireSelectionChangedEvent(); + distributeValueChangedEvent(); } } -void -ItemContainer::fireSelectionChangedEvent() +void ItemContainer::distributeValueChangedEvent() { - SelectionEvent event(this); - SelectionListeners::iterator i_end = mListeners.end(); - SelectionListeners::iterator i; + SelectionListenerIterator iter; - for (i = mListeners.begin(); i != i_end; ++i) + for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); + ++iter) { - (*i)->selectionChanged(event); + gcn::SelectionEvent event(this); + (*iter)->valueChanged(event); } } diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 8be338dd..fad59171 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -34,7 +34,10 @@ class Image; class Inventory; class Item; -class SelectionListener; + +namespace gcn { + class SelectionListener; +} /** * An item container. Used to show items in inventory and trade dialog. @@ -104,18 +107,18 @@ class ItemContainer : public gcn::Widget, * Adds a listener to the list that's notified each time a change to * the selection occurs. */ - void addSelectionListener(SelectionListener *listener) + void addSelectionListener(gcn::SelectionListener *listener) { - mListeners.push_back(listener); + mSelectionListeners.push_back(listener); } /** * Removes a listener from the list that's notified each time a change * to the selection occurs. */ - void removeSelectionListener(SelectionListener *listener) + void removeSelectionListener(gcn::SelectionListener *listener) { - mListeners.remove(listener); + mSelectionListeners.remove(listener); } enum { @@ -145,7 +148,7 @@ class ItemContainer : public gcn::Widget, /** * Sends out selection events to the list of selection listeners. */ - void fireSelectionChangedEvent(); + void distributeValueChangedEvent(); /** * Gets the slot index based on the cursor position. @@ -164,7 +167,10 @@ class ItemContainer : public gcn::Widget, bool mSwapItems; int mDragPosX, mDragPosY; - std::list mListeners; + typedef std::list SelectionListenerList; + typedef SelectionListenerList::iterator SelectionListenerIterator; + + SelectionListenerList mSelectionListeners; }; #endif diff --git a/src/gui/itemshortcutwindow.cpp b/src/gui/itemshortcutwindow.cpp index cf266290..c7b2bd05 100644 --- a/src/gui/itemshortcutwindow.cpp +++ b/src/gui/itemshortcutwindow.cpp @@ -38,7 +38,7 @@ ItemShortcutWindow::ItemShortcutWindow() mItems = new ItemShortcutContainer(); - int border = SCROLL_PADDING * 2 + getPadding() * 2; + const int border = SCROLL_PADDING * 2 + getPadding() * 2; setMinWidth(mItems->getBoxWidth() + border); setMinHeight(mItems->getBoxHeight() + border); setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border); @@ -50,7 +50,6 @@ ItemShortcutWindow::ItemShortcutWindow() add(mInvenScroll); - addWindowListener(this); loadWindowState("ItemShortcut"); } @@ -65,9 +64,11 @@ void ItemShortcutWindow::logic() Window::logic(); } -void ItemShortcutWindow::windowResized(const WindowEvent &event) +void ItemShortcutWindow::widgetResized(const gcn::Event &event) { - const gcn::Rectangle area = getChildrenArea(); + Window::widgetResized(event); + + const gcn::Rectangle &area = getChildrenArea(); mInvenScroll->setSize( area.width - SCROLL_PADDING, diff --git a/src/gui/itemshortcutwindow.h b/src/gui/itemshortcutwindow.h index 1dde8686..51685e49 100644 --- a/src/gui/itemshortcutwindow.h +++ b/src/gui/itemshortcutwindow.h @@ -25,7 +25,6 @@ #define _TMW_ITEMSHORTCUTWINDOW_H #include "window.h" -#include "windowlistener.h" #include "../guichanfwd.h" @@ -36,7 +35,7 @@ class ItemShortcutContainer; * * \ingroup Interface */ -class ItemShortcutWindow : public Window, WindowListener +class ItemShortcutWindow : public Window { public: /** @@ -55,9 +54,9 @@ class ItemShortcutWindow : public Window, WindowListener void logic(); /** - * Called whenever the window is resized. + * Called whenever the widget changes size. */ - void windowResized(const WindowEvent &event); + void widgetResized(const gcn::Event &event); private: ItemShortcutContainer *mItems; diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 61c7e078..ac18c2cd 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -23,8 +23,6 @@ #include "listbox.h" -#include "selectionlistener.h" - #include #include #include @@ -67,13 +65,6 @@ void ListBox::draw(gcn::Graphics *graphics) } } -void -ListBox::setSelected(int selected) -{ - gcn::ListBox::setSelected(selected); - fireSelectionChangedEvent(); -} - void ListBox::mouseDragged(gcn::MouseEvent &event) { @@ -81,15 +72,3 @@ ListBox::mouseDragged(gcn::MouseEvent &event) // selection to be updated as is default in many GUIs. mousePressed(event); } - -void ListBox::fireSelectionChangedEvent() -{ - SelectionEvent event(this); - SelectionListeners::iterator i_end = mListeners.end(); - SelectionListeners::iterator i; - - for (i = mListeners.begin(); i != i_end; ++i) - { - (*i)->selectionChanged(event); - } -} diff --git a/src/gui/listbox.h b/src/gui/listbox.h index 21172a22..03a8b541 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -50,37 +50,6 @@ class ListBox : public gcn::ListBox void draw(gcn::Graphics *graphics); void mouseDragged(gcn::MouseEvent &event); - - /** - * Adds a listener to the list that's notified each time a change to - * the selection occurs. - */ - void addSelectionListener(SelectionListener *listener) - { - mListeners.push_back(listener); - } - - /** - * Removes a listener from the list that's notified each time a change - * to the selection occurs. - */ - void removeSelectionListener(SelectionListener *listener) - { - mListeners.remove(listener); - } - - /** - * Sets the index of the selected element. - */ - virtual void setSelected(int selected); - - protected: - /** - * Sends out selection events to the list of selection listeners. - */ - void fireSelectionChangedEvent(); - - std::list mListeners; }; #endif diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 57ad00c5..f1b32d48 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -94,7 +94,7 @@ LoginDialog::action(const gcn::ActionEvent &event) { mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); - mLoginData->remember = mKeepCheck->isMarked(); + mLoginData->remember = mKeepCheck->isSelected(); mLoginData->registerLogin = false; mOkButton->setEnabled(false); diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index 8e5f1827..2c633b72 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -39,7 +39,7 @@ ImageRect PlayerBox::background; PlayerBox::PlayerBox(const Player *player): mPlayer(player) { - setBorderSize(2); + setFrameSize(2); if (instances == 0) { @@ -83,7 +83,7 @@ PlayerBox::draw(gcn::Graphics *graphics) { // Draw character int x, y, bs; - bs = getBorderSize(); + bs = getFrameSize(); x = getWidth() / 2 - 16 + bs; y = getHeight() / 2 + bs; mPlayer->draw(static_cast(graphics), x, y); @@ -91,10 +91,10 @@ PlayerBox::draw(gcn::Graphics *graphics) } void -PlayerBox::drawBorder(gcn::Graphics *graphics) +PlayerBox::drawFrame(gcn::Graphics *graphics) { int w, h, bs; - bs = getBorderSize(); + bs = getFrameSize(); w = getWidth() + bs * 2; h = getHeight() + bs * 2; diff --git a/src/gui/playerbox.h b/src/gui/playerbox.h index 6bba1b51..c226e750 100644 --- a/src/gui/playerbox.h +++ b/src/gui/playerbox.h @@ -64,7 +64,7 @@ class PlayerBox : public gcn::ScrollArea /** * Draws the background and border of the scroll area. */ - void drawBorder(gcn::Graphics *graphics); + void drawFrame(gcn::Graphics *graphics); private: const Player *mPlayer; /**< The character used for display */ diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index c9d974a6..7ed4f913 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -65,13 +65,13 @@ QuitDialog::QuitDialog(bool* quitGame, QuitDialog** pointerToMe): state == STATE_LOGIN_ATTEMPT || state == STATE_UPDATE) { - mForceQuit->setMarked(true); + mForceQuit->setSelected(true); add(mForceQuit); } else { // Only added if we are connected to an accountserver or gameserver - mLogoutQuit->setMarked(true); + mLogoutQuit->setSelected(true); add(mLogoutQuit); add(mSwitchAccountServer); @@ -104,11 +104,11 @@ QuitDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { - if (mForceQuit->isMarked()) + if (mForceQuit->isSelected()) { state = STATE_FORCE_QUIT; } - else if (mLogoutQuit->isMarked()) + else if (mLogoutQuit->isSelected()) { if ((state == STATE_GAME) && (mQuitGame)) { @@ -116,7 +116,7 @@ QuitDialog::action(const gcn::ActionEvent &event) } state = STATE_EXIT; } - else if (mSwitchAccountServer->isMarked()) + else if (mSwitchAccountServer->isSelected()) { if ((state == STATE_GAME) && (mQuitGame)) { @@ -124,7 +124,7 @@ QuitDialog::action(const gcn::ActionEvent &event) } state = STATE_SWITCH_ACCOUNTSERVER_ATTEMPT; } - else if (mSwitchCharacter->isMarked()) + else if (mSwitchCharacter->isSelected()) { if (mQuitGame) *mQuitGame = true; diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index e318116a..0ac4dea8 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -67,7 +67,7 @@ void RadioButton::drawBox(gcn::Graphics* graphics) { Image *box = NULL; - if (mMarked) { + if (isSelected()) { if (isEnabled()) { box = radioChecked; } else { diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index cf555ef4..97384fa3 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -153,12 +153,12 @@ void ScrollArea::logic() if (getHorizontalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { content->setWidth(getChildrenArea().width - - 2 * content->getBorderSize()); + 2 * content->getFrameSize()); } if (getVerticalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { content->setHeight(getChildrenArea().height - - 2 * content->getBorderSize()); + 2 * content->getFrameSize()); } } } @@ -204,15 +204,15 @@ void ScrollArea::draw(gcn::Graphics *graphics) { graphics->pushClipArea(getChildrenArea()); - if (content->getBorderSize() > 0) + if (content->getFrameSize() > 0) { gcn::Rectangle rec = content->getDimension(); - rec.x -= content->getBorderSize(); - rec.y -= content->getBorderSize(); - rec.width += 2 * content->getBorderSize(); - rec.height += 2 * content->getBorderSize(); + rec.x -= content->getFrameSize(); + rec.y -= content->getFrameSize(); + rec.width += 2 * content->getFrameSize(); + rec.height += 2 * content->getFrameSize(); graphics->pushClipArea(rec); - content->drawBorder(graphics); + content->drawFrame(graphics); graphics->popClipArea(); } @@ -223,9 +223,9 @@ void ScrollArea::draw(gcn::Graphics *graphics) } } -void ScrollArea::drawBorder(gcn::Graphics *graphics) +void ScrollArea::drawFrame(gcn::Graphics *graphics) { - int bs = getBorderSize(); + int bs = getFrameSize(); int w = getWidth() + bs * 2; int h = getHeight() + bs * 2; @@ -240,10 +240,10 @@ void ScrollArea::setOpaque(bool opaque) mOpaque = opaque; if (mOpaque) { - setBorderSize(2); + setFrameSize(2); } else { - setBorderSize(0); + setFrameSize(0); } } diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h index 504842cc..9fb7093d 100644 --- a/src/gui/scrollarea.h +++ b/src/gui/scrollarea.h @@ -65,7 +65,7 @@ class ScrollArea : public gcn::ScrollArea { /** * Draws the background and border of the scroll area. */ - void drawBorder(gcn::Graphics *graphics); + void drawFrame(gcn::Graphics *graphics); /** * Sets whether the widget should draw its background or not. diff --git a/src/gui/selectionlistener.h b/src/gui/selectionlistener.h deleted file mode 100644 index 917a4871..00000000 --- a/src/gui/selectionlistener.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_SELECTIONLISTENER_H__ -#define _TMW_SELECTIONLISTENER_H__ - -#include -#include - -/** - * An event that characterizes a change in the current selection. - * - * \ingroup GUI - */ -class SelectionEvent : public gcn::Event -{ - public: - /** - * Constructor. - */ - SelectionEvent(gcn::Widget *source): - gcn::Event(source) - { - } -}; - -/** - * The listener that's notified when a selection value changes. - * - * \ingroup GUI - */ -class SelectionListener -{ - public: - /** - * Virtual destructor. - */ - virtual ~SelectionListener() {} - - /** - * Called whenever the value of the selection changes. - */ - virtual void selectionChanged(const SelectionEvent &event) = 0; -}; - -typedef std::list SelectionListeners; - -#endif diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index bc683c0b..e101ad39 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -182,7 +182,7 @@ void SellDialog::action(const gcn::ActionEvent &event) } } -void SellDialog::selectionChanged(const SelectionEvent &event) +void SellDialog::valueChanged(const gcn::SelectionEvent &event) { // Reset amount of items and update labels mAmountItems = 1; diff --git a/src/gui/sell.h b/src/gui/sell.h index cde862d5..63a16770 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -25,10 +25,9 @@ #define _TMW_SELL_H #include +#include #include "window.h" -#include "selectionlistener.h" -#include "windowlistener.h" #include "../guichanfwd.h" @@ -41,7 +40,7 @@ class ShopListBox; * * \ingroup Interface */ -class SellDialog : public Window, gcn::ActionListener, SelectionListener +class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener { public: /** @@ -76,7 +75,7 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener * * @see SelectionListener::selectionChanged */ - void selectionChanged(const SelectionEvent &event); + void valueChanged(const gcn::SelectionEvent &event); /** * Gives Player's Money amount diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 89c21e2b..a02b3c20 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -72,7 +72,7 @@ Setup_Audio::Setup_Audio(): void Setup_Audio::apply() { - if (mSoundCheckBox->isMarked()) + if (mSoundCheckBox->isSelected()) { config.setValue("sound", 1); try { @@ -97,7 +97,7 @@ void Setup_Audio::apply() void Setup_Audio::cancel() { - mSoundCheckBox->setMarked(mSoundEnabled); + mSoundCheckBox->setSelected(mSoundEnabled); sound.setSfxVolume(mSfxVolume); mSfxSlider->setValue(mSfxVolume); diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 59cfefa4..dfa446ab 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -45,7 +45,7 @@ Setup_Joystick::Setup_Joystick(): mCalibrateButton->setPosition(10, 30 + mCalibrateLabel->getHeight()); mOriginalJoystickEnabled = (int)config.getValue("joystickEnabled", 0) != 0; - mJoystickEnabled->setMarked(mOriginalJoystickEnabled); + mJoystickEnabled->setSelected(mOriginalJoystickEnabled); mJoystickEnabled->addActionListener(this); @@ -62,7 +62,7 @@ void Setup_Joystick::action(const gcn::ActionEvent &event) if (event.getSource() == mJoystickEnabled) { - joystick->setEnabled(mJoystickEnabled->isMarked()); + joystick->setEnabled(mJoystickEnabled->isSelected()); } else { @@ -85,7 +85,7 @@ void Setup_Joystick::cancel() { joystick->setEnabled(mOriginalJoystickEnabled); } - mJoystickEnabled->setMarked(mOriginalJoystickEnabled); + mJoystickEnabled->setSelected(mOriginalJoystickEnabled); } void Setup_Joystick::apply() diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index ee46396b..fcdb6c51 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -157,7 +157,7 @@ Setup_Video::Setup_Video(): mFpsField->setEnabled(mFps > 0); mFpsSlider->setValue(mFps); mFpsSlider->setEnabled(mFps > 0); - mFpsCheckBox->setMarked(mFps > 0); + mFpsCheckBox->setSelected(mFps > 0); mCustomCursorCheckBox->setActionEventId("customcursor"); mAlphaSlider->setActionEventId("guialpha"); @@ -245,7 +245,7 @@ Setup_Video::~Setup_Video() void Setup_Video::apply() { // Full screen changes - bool fullscreen = mFsCheckBox->isMarked(); + bool fullscreen = mFsCheckBox->isSelected(); if (fullscreen != (config.getValue("screen", 0) == 1)) { // checks for opengl usage @@ -272,9 +272,9 @@ void Setup_Video::apply() } // OpenGL change - if (mOpenGLCheckBox->isMarked() != mOpenGLEnabled) + if (mOpenGLCheckBox->isSelected() != mOpenGLEnabled) { - config.setValue("opengl", mOpenGLCheckBox->isMarked() ? 1 : 0); + config.setValue("opengl", mOpenGLCheckBox->isSelected() ? 1 : 0); // OpenGL can currently only be changed by restarting, notify user. new OkDialog(_("Changing OpenGL"), @@ -315,9 +315,9 @@ Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, void Setup_Video::cancel() { - mFsCheckBox->setMarked(mFullScreenEnabled); - mOpenGLCheckBox->setMarked(mOpenGLEnabled); - mCustomCursorCheckBox->setMarked(mCustomCursorEnabled); + mFsCheckBox->setSelected(mFullScreenEnabled); + mOpenGLCheckBox->setSelected(mOpenGLEnabled); + mCustomCursorCheckBox->setSelected(mCustomCursorEnabled); mAlphaSlider->setValue(mOpacity); mOverlayDetailSlider->setValue(mOverlayDetail); @@ -341,7 +341,7 @@ void Setup_Video::action(const gcn::ActionEvent &event) else if (event.getId() == "customcursor") { config.setValue("customcursor", - mCustomCursorCheckBox->isMarked() ? 1 : 0); + mCustomCursorCheckBox->isSelected() ? 1 : 0); } else if (event.getId() == "fpslimitslider") { @@ -379,7 +379,7 @@ void Setup_Video::action(const gcn::ActionEvent &event) } else if (event.getId() == "fpslimitcheckbox") { - if (mFpsCheckBox->isMarked()) + if (mFpsCheckBox->isSelected()) { mFps = (int) mFpsSlider->getValue(); } diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index e6d3c516..ba77be47 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -23,8 +23,6 @@ #include "shoplistbox.h" -#include "selectionlistener.h" - #include #include #include @@ -101,37 +99,12 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) } } -void ShopListBox::setSelected(int selected) -{ - if (!mListModel) - { - mSelected = -1; - } - else - { - // Update mSelected with bounds checking - mSelected = std::min(mListModel->getNumberOfElements() - 1, - std::max(-1, selected)); - - gcn::Widget *parent = getParent(); - if (parent && mSelected >= 0) - { - gcn::Rectangle scroll; - scroll.y = mRowHeight * mSelected; - scroll.height = mRowHeight; - parent->showWidgetPart(this, scroll); - } - } - - fireSelectionChangedEvent(); -} - void ShopListBox::mousePressed(gcn::MouseEvent &event) { if (event.getButton() == gcn::MouseEvent::LEFT) { setSelected(event.getY() / mRowHeight); - generateAction(); + distributeActionEvent(); } } diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h index 44a68445..d5e2d836 100644 --- a/src/gui/shoplistbox.h +++ b/src/gui/shoplistbox.h @@ -27,8 +27,6 @@ #include "listbox.h" #include "shop.h" -class SelectionListener; - /** * A list box, meant to be used inside a scroll area. Same as the Guichan list * box except this one doesn't have a background, instead completely relying @@ -54,30 +52,12 @@ class ShopListBox : public ListBox */ void draw(gcn::Graphics *graphics); - void mousePressed(gcn::MouseEvent &event); - /** - * Adds a listener to the list that's notified each time a change to - * the selection occurs. + * Returns the height of a row. */ - void addSelectionListener(SelectionListener *listener) - { - mListeners.push_back(listener); - } + unsigned int getRowHeight() const { return mRowHeight; } - /** - * Removes a listener from the list that's notified each time a change - * to the selection occurs. - */ - void removeSelectionListener(SelectionListener *listener) - { - mListeners.remove(listener); - } - - /** - * Sets the index of the selected element. - */ - void setSelected(int selected); + void mousePressed(gcn::MouseEvent &event); /** * gives information about the current player's money @@ -104,7 +84,7 @@ class ShopListBox : public ListBox */ ShopItems *mShopItems; - int mRowHeight; /**< Row Height */ + unsigned int mRowHeight; /**< Row Height */ bool mPriceCheck; }; diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index f0170a1b..c94c7bfb 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -64,7 +64,7 @@ Slider::~Slider() void Slider::init() { int x, y, w, h,o1,o2; - setBorderSize(0); + setFrameSize(0); // Load resources if (mInstances == 0) diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp index 8fb2f598..d6267e65 100644 --- a/src/gui/tabbedcontainer.cpp +++ b/src/gui/tabbedcontainer.cpp @@ -82,8 +82,8 @@ void TabbedContainer::logic() { if (mActiveContent) { mActiveContent->setSize( - getWidth() - 2 * mActiveContent->getBorderSize(), - getHeight() - TABHEIGHT - 2 * mActiveContent->getBorderSize()); + getWidth() - 2 * mActiveContent->getFrameSize(), + getHeight() - TABHEIGHT - 2 * mActiveContent->getFrameSize()); } Container::logic(); diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index 329813e5..84c8ad4b 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -32,14 +32,14 @@ TextBox::TextBox(): gcn::TextBox() { setOpaque(false); - setBorderSize(0); + setFrameSize(0); } TextBox::TextBox(const std::string& text): gcn::TextBox(text) { setOpaque(false); - setBorderSize(0); + setFrameSize(0); } void TextBox::setText(const std::string &text) diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 11659b8b..4fd85d36 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -44,7 +44,7 @@ ImageRect TextField::skin; TextField::TextField(const std::string& text): gcn::TextField(text) { - setBorderSize(2); + setFrameSize(2); if (instances == 0) { @@ -97,10 +97,10 @@ void TextField::draw(gcn::Graphics *graphics) graphics->drawText(mText, 1 - mXScroll, 1); } -void TextField::drawBorder(gcn::Graphics *graphics) +void TextField::drawFrame(gcn::Graphics *graphics) { int w, h, bs; - bs = getBorderSize(); + bs = getFrameSize(); w = getWidth() + bs * 2; h = getHeight() + bs * 2; @@ -184,7 +184,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } break; case Key::ENTER: - generateAction(); + distributeActionEvent(); break; case Key::HOME: diff --git a/src/gui/textfield.h b/src/gui/textfield.h index e36380e3..36f921ac 100644 --- a/src/gui/textfield.h +++ b/src/gui/textfield.h @@ -53,7 +53,7 @@ class TextField : public gcn::TextField { /** * Draws the background and border. */ - void drawBorder(gcn::Graphics *graphics); + void drawFrame(gcn::Graphics *graphics); /** * Processes one keypress. diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index bb3d702f..c098c04c 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -147,7 +147,7 @@ void TradeWindow::tradeItem(Item *item, int quantity) item->increaseQuantity(-quantity); } -void TradeWindow::selectionChanged(const SelectionEvent &event) +void TradeWindow::valueChanged(const gcn::SelectionEvent &event) { Item *item; diff --git a/src/gui/trade.h b/src/gui/trade.h index 449de573..c8ece8d9 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -25,9 +25,9 @@ #define _TMW_TRADE_H #include +#include #include "window.h" -#include "selectionlistener.h" #include "../guichanfwd.h" @@ -41,7 +41,7 @@ class ScrollArea; * * \ingroup Interface */ -class TradeWindow : public Window, gcn::ActionListener, SelectionListener +class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener { public: /** @@ -84,7 +84,7 @@ class TradeWindow : public Window, gcn::ActionListener, SelectionListener * Updates the labels and makes sure only one item is selected in * either my inventory or partner inventory. */ - void selectionChanged(const SelectionEvent &event); + void valueChanged(const gcn::SelectionEvent &event); /** * Called when receiving actions from the widgets. diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 6863aa01..b33a55cf 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -42,7 +42,7 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::DropDown::DropDown(listModel, scrollArea, listBox) { - setBorderSize(2); + setFrameSize(2); // Initialize graphics if (instances == 0) @@ -103,7 +103,7 @@ void DropDown::draw(gcn::Graphics* graphics) if (mDroppedDown) { - h = mOldH; + h = mFoldedUpHeight; } else { @@ -151,19 +151,18 @@ void DropDown::draw(gcn::Graphics* graphics) } } -void DropDown::drawBorder(gcn::Graphics *graphics) +void DropDown::drawFrame(gcn::Graphics *graphics) { - int w, h, bs; - bs = getBorderSize(); - w = getWidth() + bs * 2; - h = getHeight() + bs * 2; + const int bs = getFrameSize(); + const int w = getWidth() + bs * 2; + const int h = getHeight() + bs * 2; static_cast(graphics)->drawImageRect(0, 0, w, h, skin); } void DropDown::drawButton(gcn::Graphics *graphics) { - int height = mDroppedDown ? mOldH : getHeight(); + int height = mDroppedDown ? mFoldedUpHeight : getHeight(); static_cast(graphics)-> drawImage(buttons[mDroppedDown][mPushed], getWidth() - height, 1); diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 37e754af..d0dab7d2 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -64,7 +64,7 @@ class DropDown : public gcn::DropDown void draw(gcn::Graphics* graphics); - void drawBorder(gcn::Graphics* graphics); + void drawFrame(gcn::Graphics* graphics); protected: diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 7629e2e7..75288eb5 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -106,7 +106,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): instances++; - setBorderSize(0); + setFrameSize(0); setPadding(3); setTitleBarHeight(20); @@ -121,6 +121,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent): // Windows are invisible by default setVisible(false); + + addWidgetListener(this); } Window::~Window() @@ -202,84 +204,12 @@ void Window::draw(gcn::Graphics *graphics) drawChildren(graphics); } -void Window::setContentWidth(int width) -{ - setWidth(width + 2 * getPadding()); -} - -void Window::setContentHeight(int height) -{ - setHeight(height + getPadding() + getTitleBarHeight()); -} - void Window::setContentSize(int width, int height) { setSize(width + 2 * getPadding(), height + getPadding() + getTitleBarHeight()); } -void Window::setSize(int width, int height) -{ - if (width == mDimension.width && height == mDimension.height) return; - - // No call to ancestor! Infinite loop otherwise. - mDimension.width = width; - mDimension.height = height; - - if (mGrip) - { - gcn::Rectangle const &area = getChildrenArea(); - mGrip->setPosition(width - mGrip->getWidth() - area.x, - height - mGrip->getHeight() - area.y); - } - - if (mLayout) - { - int w = width - 2 * getPadding(), - h = height - getPadding() - getTitleBarHeight(); - mLayout->reflow(w, h); - } - - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); -} - -void Window::setWidth(int width) -{ - setSize(width, mDimension.height); -} - -void Window::setHeight(int height) -{ - setSize(mDimension.width, height); -} - -void Window::setPosition(int x, int y) -{ - if (x == mDimension.x && y == mDimension.y) return; - - // No call to ancestor! - mDimension.x = x; - mDimension.y = y; - - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); -} - -void Window::setDimension(const gcn::Rectangle &dimension) -{ - setPosition(dimension.x, dimension.y); - setSize(dimension.width, dimension.height); -} - -void Window::setX(int x) -{ - setPosition(x, mDimension.y); -} - -void Window::setY(int y) -{ - setPosition(mDimension.x, y); -} - void Window::setLocationRelativeTo(gcn::Widget *widget) { int wx, wy; @@ -331,6 +261,23 @@ void Window::setResizable(bool r) } } +void Window::widgetResized(const gcn::Event &event) +{ + if (mGrip) + { + gcn::Rectangle const &area = getChildrenArea(); + mGrip->setPosition(getWidth() - mGrip->getWidth() - area.x, + getHeight() - mGrip->getHeight() - area.y); + } + + if (mLayout) + { + int w = getWidth() - 2 * getPadding(); + int h = getHeight() - getPadding() - getTitleBarHeight(); + mLayout->reflow(w, h); + } +} + void Window::setCloseButton(bool flag) { mCloseButton = flag; @@ -407,7 +354,7 @@ void Window::mouseReleased(gcn::MouseEvent &event) } // This should be the responsibility of Guichan (and is from 0.8.0 on) - mIsMoving = false; + mMoved = false; } void Window::mouseExited(gcn::MouseEvent &event) @@ -449,7 +396,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) gcn::Window::mouseDragged(event); // Keep guichan window inside screen when it may be moved - if (isMovable() && mIsMoving) + if (isMovable() && mMoved) { int newX = std::max(0, getX()); int newY = std::max(0, getY()); @@ -458,7 +405,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) setPosition(newX, newY); } - if (mouseResize && !mIsMoving) + if (mouseResize && !mMoved) { const int dx = event.getX() - mDragOffsetX; const int dy = event.getY() - mDragOffsetY; @@ -585,24 +532,6 @@ int Window::getResizeHandles(gcn::MouseEvent &event) return resizeHandles; } -void Window::fireWindowEvent(const WindowEvent &event) -{ - WindowListeners::iterator i_end = mListeners.end(); - WindowListeners::iterator i = mListeners.begin(); - - switch (event.getType()) - { - case WindowEvent::WINDOW_MOVED: - for (; i != i_end; ++i) - { (*i)->windowMoved(event); } - break; - case WindowEvent::WINDOW_RESIZED: - for (; i != i_end; ++i) - { (*i)->windowResized(event); } - break; - } -} - Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index df756be3..9f5969f0 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -25,11 +25,10 @@ #define _TMW_WINDOW_H__ #include +#include #include "../guichanfwd.h" -#include "windowlistener.h" - class ConfigListener; class ContainerPlacer; class Image; @@ -45,7 +44,7 @@ class WindowContainer; * * \ingroup GUI */ -class Window : public gcn::Window +class Window : public gcn::Window, gcn::WidgetListener { public: friend class WindowConfigListener; @@ -78,56 +77,11 @@ class Window : public gcn::Window */ void draw(gcn::Graphics *graphics); - /** - * Sets the width of the window contents. - */ - void setContentWidth(int width); - - /** - * Sets the height of the window contents. - */ - void setContentHeight(int height); - /** * Sets the size of this window. */ void setContentSize(int width, int height); - /** - * Sets the size of this window. - */ - void setSize(int width, int height); - - /** - * Sets the width of this window. - */ - void setWidth(int width); - - /** - * Sets the height of this window. - */ - void setHeight(int height); - - /** - * Sets the position and size of this window. - */ - void setDimension(const gcn::Rectangle &dimension); - - /** - * Sets the position of this window. - */ - void setPosition(int x, int y); - - /** - * Sets the window x coordinate. - */ - void setX(int x); - - /** - * Sets the window y coordinate. - */ - void setY(int y); - /** * Sets the location relative to the given widget. */ @@ -138,6 +92,11 @@ class Window : public gcn::Window */ void setResizable(bool resize); + /** + * Called whenever the widget changes size. + */ + void widgetResized(const gcn::Event &event); + /** * Sets whether or not the window has a close button. */ @@ -256,20 +215,6 @@ class Window : public gcn::Window */ void resetToDefaultSize(); - /** - * Adds a listener to the list that's notified when the window is - * moved or resized. - */ - void addWindowListener(WindowListener *listener) - { mListeners.push_back(listener); } - - /** - * Removes a listener from the list that's notified when the window is - * moved or resized. - */ - void removeWindowListener(WindowListener *listener) - { mListeners.remove(listener); } - enum ResizeHandles { TOP = 0x01, @@ -349,14 +294,6 @@ class Window : public gcn::Window * where two borders are moved at the same time. */ static const int resizeBorderWidth = 10; - - private: - /** - * Sends out a window event to the list of selection listeners. - */ - void fireWindowEvent(const WindowEvent &event); - - WindowListeners mListeners; }; #endif diff --git a/src/gui/windowlistener.h b/src/gui/windowlistener.h deleted file mode 100644 index 24f6a7b8..00000000 --- a/src/gui/windowlistener.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_WINDOW_LISTENER_H_ -#define _TMW_WINDOW_LISTENER_H_ - -#include -#include - -/** - * An event that characterizes a window move or resize. - * - * \ingroup GUI - */ -class WindowEvent : public gcn::Event -{ - public: - /** - * Constructor. - */ - WindowEvent(gcn::Window *source, int type): - gcn::Event(source) - { - mType = type; - } - - /** - * Returns the event type. - */ - int getType() const - { return mType; } - - enum WindowEventType - { - WINDOW_MOVED, - WINDOW_RESIZED - }; -}; - -/** - * The listener that's notified when a window is moved or resized. - * - * \ingroup GUI - */ -class WindowListener -{ - public: - /** - * Virtual destructor. - */ - virtual ~WindowListener() {} - - /** - * Called whenever the window is moved. - */ - virtual void windowMoved(const WindowEvent &) {} - - /** - * Called whenever the window is resized. - */ - virtual void windowResized(const WindowEvent &) {} -}; - -typedef std::list WindowListeners; - -#endif -- cgit v1.2.3-70-g09d2 From bbb40f595e6e20e5106a23e6aa606b825b1e62b4 Mon Sep 17 00:00:00 2001 From: David Athay Date: Mon, 14 Apr 2008 17:05:29 +0000 Subject: Added new TabbedArea which extends gui::TabbedArea. Changed Guild and Chat windows to use new TabbedArea. Added private messaging. --- ChangeLog | 8 +++++ src/gui/chat.cpp | 68 ++++++++++++++++++++++----------------- src/gui/chat.h | 14 +++++--- src/gui/guildwindow.cpp | 45 +++++++++++++------------- src/gui/guildwindow.h | 5 ++- src/gui/widgets/tabbedarea.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++ src/gui/widgets/tabbedarea.h | 60 ++++++++++++++++++++++++++++++++++ src/net/chathandler.cpp | 11 +++++++ 8 files changed, 224 insertions(+), 60 deletions(-) create mode 100644 src/gui/widgets/tabbedarea.cpp create mode 100644 src/gui/widgets/tabbedarea.h (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 4c12aa32..c5dcee84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-04-14 David Athay + + * src/gui/guildwindow.cpp, src/gui/chat.cpp, + src/gui/widgets/tabbedarea.h, src/gui/widgets/tabbedarea.cpp, + src/gui/chat.h, src/gui/guildwindow.h, src/net/chathandler.cpp: + Added new TabbedArea which extends gui::TabbedArea. Changed Guild and + Chat windows to use new TabbedArea. Added private messaging. + 2008-04-12 Yohann Ferreira * src/CMakeLists.txt: Fixed a compilation error using Cmake. diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 1efee8ed..0602c671 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -30,12 +30,12 @@ #include "browserbox.h" #include "chatinput.h" -#include "gccontainer.h" #include "scrollarea.h" #include "sdlinput.h" -#include "tabbedcontainer.h" #include "windowcontainer.h" +#include "widgets/tabbedarea.h" + #include "../channelmanager.h" #include "../channel.h" #include "../configuration.h" @@ -53,7 +53,7 @@ ChatWindow::ChatWindow(): mTmpVisible(false) { setResizable(true); - setDefaultSize(0, (windowContainer->getHeight() - 123), 600, 100); + setDefaultSize(0, (windowContainer->getHeight() - 105), 600, 100); setTitleBarHeight(5); loadWindowState("Chat"); @@ -72,24 +72,18 @@ ChatWindow::ChatWindow(): gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); scrollArea->setOpaque(false); - GCContainer *tab = new GCContainer(); - tab->setWidth(getWidth() - 2 * tab->getFrameSize()); - tab->setHeight(getHeight() - 2 * tab->getFrameSize()); - tab->setOpaque(false); - tab->add(scrollArea); + mChatTabs = new TabbedArea(); + mChatTabs->addTab("General", scrollArea); + mChatTabs->setWidth(getWidth()); + mChatTabs->setHeight(getHeight()); - mContainer = new TabbedContainer(); - mContainer->addTab(tab, "General"); - mContainer->setOpaque(false); mChannelOutput["General"] = textOutput; mChannelScroll["General"] = scrollArea; - mTabs["General"] = tab; - mTextOutput = textOutput; mScrollArea = scrollArea; - add(mContainer); + add(mChatTabs); add(mChatInput); // Add key listener to chat input to be able to respond to up/down @@ -99,23 +93,20 @@ ChatWindow::ChatWindow(): ChatWindow::~ChatWindow() { - for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); + delete mChatTabs; } void ChatWindow::logic() { // todo: only do this when the size changes (updateWidgets?) - const gcn::Rectangle area = getChildrenArea(); mChatInput->setPosition(mChatInput->getFrameSize(), area.height - mChatInput->getHeight() - mChatInput->getFrameSize()); mChatInput->setWidth(area.width - 2 * mChatInput->getFrameSize()); - mContainer->setWidth(area.width - 2 * mContainer->getFrameSize()); - mContainer->setHeight(area.height - 2 * mContainer->getFrameSize() - - mChatInput->getHeight() - 5); + mScrollArea->setWidth(area.width - 2 * mScrollArea->getFrameSize()); mScrollArea->setHeight(area.height - 2 * mScrollArea->getFrameSize() - mChatInput->getHeight() - 26); @@ -225,7 +216,8 @@ ChatWindow::action(const gcn::ActionEvent &event) mCurHist = mHistory.end(); // Send the message to the server - chatSend(player_node->getName(), message, mContainer->getActiveWidget()); + gcn::Tab *tab = mChatTabs->getSelectedTab(); + chatSend(player_node->getName(), message, tab->getCaption()); // Clear the text from the chat input mChatInput->setText(""); @@ -280,7 +272,8 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg, // Prepare ordinary message if (msg[0] != '/') { - if (mContainer->getActiveWidget() == "General") + gcn::Tab *tab = mChatTabs->getSelectedTab(); + if (tab->getCaption() == "General") { Net::GameServer::Player::say(msg); } @@ -311,6 +304,7 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg, chatLog("/announce > Global announcement (GM only)", BY_SERVER, channelName); chatLog("/where > Display map name", BY_SERVER, channelName); chatLog("/who > Display number of online users", BY_SERVER, channelName); + chatLog("/msg > Send a private message to a user", BY_SERVER, channelName); chatLog("/list > Display all public channels", BY_SERVER, channelName); chatLog("/register > Register a new channel", BY_SERVER, channelName); chatLog("/join > Join an already registered channel", BY_SERVER, channelName); @@ -328,6 +322,14 @@ void ChatWindow::chatSend(std::string const &nick, std::string const &msg, MessageOut outMsg(0x00c1); */ } + else if (command == "msg") + { + std::string::size_type pos = arg.find(' ', 1); + std::string recipient(arg, 0, pos-1); + std::string text(arg, pos+1); + chatLog("* " + text, BY_SERVER); + Net::ChatServer::privMsg(recipient, text); + } else if (command == "register") { chatLog("Requesting to register channel " + arg, BY_SERVER); @@ -458,8 +460,10 @@ ChatWindow::removeChannel(short channelId) Channel* channel = channelManager->findById(channelId); if(channel) { - mContainer->removeTab(channel->getName()); - mTabs.erase(channel->getName()); + gcn::Tab *tab = mChatTabs->getTab(channel->getName()); + if (!tab) + return; + mChatTabs->removeTab(tab); mChannelOutput.erase(channel->getName()); mChannelScroll.erase(channel->getName()); channelManager->removeChannel(channel); @@ -478,13 +482,8 @@ ChatWindow::createNewChannelTab(std::string channelName) scrollArea->setPosition(scrollArea->getFrameSize(), scrollArea->getFrameSize()); scrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); scrollArea->setOpaque(false); - GCContainer *tab = new GCContainer(); - tab->setWidth(getWidth() - 2 * tab->getFrameSize()); - tab->setHeight(getHeight() - 2 * tab->getFrameSize()); - tab->add(scrollArea); - tab->setOpaque(false); - mContainer->addTab(tab, channelName); - mTabs[channelName] = tab; + + mChatTabs->addTab(channelName, scrollArea); mChannelOutput[channelName] = textOutput; mChannelScroll[channelName] = scrollArea; mScrollArea = scrollArea; @@ -553,3 +552,12 @@ ChatWindow::setVisible(bool isVisible) */ mTmpVisible = false; } + +bool +ChatWindow::tabExists(const std::string &tabName) +{ + gcn::Tab *tab = mChatTabs->getTab(tabName); + if (tab) + return true; + return false; +} diff --git a/src/gui/chat.h b/src/gui/chat.h index 19795dd3..d605def0 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -37,8 +37,9 @@ class BrowserBox; class ScrollArea; -class TabbedContainer; -class GCContainer; +//class TabbedContainer; +//class GCContainer; +class TabbedArea; enum { @@ -213,6 +214,10 @@ class ChatWindow : public Window, public gcn::ActionListener, void setVisible(bool visible); + /** Check if tab with that name already exists */ + bool + tabExists(const std::string &tabName); + private: bool mTmpVisible; @@ -229,11 +234,12 @@ class ChatWindow : public Window, public gcn::ActionListener, #if 0 /** Constructs failed messages for actions */ std::string const_msg(CHATSKILL); -#endif - std::map mTabs; TabbedContainer *mContainer; /**< Tabbed container for tabbing between channels */ GCContainer *mTab; /**< Tabs */ +#endif + + TabbedArea *mChatTabs; /** < Chat Tabbed area for holding each channel */ gcn::TextField *mChatInput; /**< Input box for typing chat messages */ std::map mChannelOutput; /**< Map each TextOutput to a tab */ std::map mChannelScroll; /**< Map each ScrollArea to a tab */ diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index eb0faa35..7b69f9bf 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -26,14 +26,13 @@ #include "button.h" #include "chat.h" #include "confirm_dialog.h" -#include "gccontainer.h" #include "guildlistbox.h" #include "scrollarea.h" -#include "tabbedcontainer.h" #include "textdialog.h" #include "windowcontainer.h" #include "widgets/layout.h" +#include "widgets/tabbedarea.h" #include "../guild.h" #include "../log.h" @@ -45,12 +44,14 @@ #include +#include + GuildWindow::GuildWindow(): Window(player_node->getName()), mFocus(false) { setCaption("Guild"); - setResizable(true); + setResizable(false); setCloseButton(true); setMinWidth(200); setMinHeight(280); @@ -63,14 +64,12 @@ GuildWindow::GuildWindow(): mGuildButton[1]->setEnabled(false); mGuildButton[2]->setEnabled(false); - mGuildsContainer = new TabbedContainer(); - - mGuildsContainer->setOpaque(false); + mGuildTabs = new TabbedArea(); place(0, 0, mGuildButton[0]); place(1, 0, mGuildButton[1]); place(2, 0, mGuildButton[2]); - place(0, 1, mGuildsContainer); + place(0, 1, mGuildTabs); Layout &layout = getLayout(); layout.setColWidth(0, 48); layout.setColWidth(1, 65); @@ -80,7 +79,7 @@ GuildWindow::GuildWindow(): GuildWindow::~GuildWindow() { - for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); + delete mGuildTabs; } void GuildWindow::update() @@ -102,13 +101,14 @@ void GuildWindow::action(const gcn::ActionEvent &event) // Stats Part if (eventId == "CREATE_GUILD") { - if (mGuildsContainer->getNumberOfTabs() > 1) + if (mGuildTabs->getNumberOfTabs() > 1) { // This is just to limit the number of guild tabs that are created // TODO: Either limit this server side, or fix the interface issue chatWindow->chatLog("Current maximum number of guilds ownable is 2", BY_SERVER); return; } + // Set focus so that guild name to be created can be typed. mFocus = true; guildDialog = new TextDialog("Guild Name", "Choose your guild's name", this); @@ -129,7 +129,7 @@ void GuildWindow::action(const gcn::ActionEvent &event) if (guild) { Net::ChatServer::Guild::quitGuild(guild); - chatWindow->chatLog("Guild " + mGuildsContainer->getActiveWidget() + " quit", BY_SERVER); + chatWindow->chatLog("Guild " + mGuildTabs->getSelectedTab()->getCaption() + " quit", BY_SERVER); } } else if (eventId == "CREATE_GUILD_OK") @@ -172,27 +172,25 @@ void GuildWindow::newGuildTab(const std::string &guildName) { // Create new tab - GCContainer *tab = new GCContainer(); - tab->setWidth(getWidth() - 2 * tab->getFrameSize()); - tab->setHeight(getHeight() - 2 * tab->getFrameSize()); - tab->setOpaque(false); ListBox *list = new ListBox(); list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); - tab->add(sa); - mGuildsContainer->addTab(tab, guildName); - mGuildsContainer->setDimension(gcn::Rectangle(28,35,280,250)); - - mTabs.push_back(tab); + mGuildTabs->addTab(guildName, sa); + mGuildTabs->setDimension(gcn::Rectangle(28,35,140,250)); updateTab(); } void GuildWindow::updateTab() { - setTab(mGuildsContainer->getActiveWidget()); + gcn::Tab *tab = mGuildTabs->getSelectedTab(); + if (tab) + { + setTab(tab->getCaption()); + } + mGuildTabs->logic(); } void GuildWindow::setTab(const std::string &guildName) @@ -217,7 +215,7 @@ bool GuildWindow::isFocused() short GuildWindow::getSelectedGuild() { - Guild *guild = player_node->getGuild(mGuildsContainer->getActiveWidget()); + Guild *guild = player_node->getGuild(mGuildTabs->getSelectedTab()->getCaption()); if (guild) { return guild->getId(); @@ -248,7 +246,8 @@ void GuildWindow::removeTab(int guildId) Guild* guild = player_node->getGuild(guildId); if (guild) { - mGuildsContainer->removeTab(guild->getName()); + gcn::Tab *tab = mGuildTabs->getTab(guild->getName()); + mGuildTabs->removeTab(tab); } - mGuildsContainer->logic(); + mGuildTabs->logic(); } diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index 5f7600e5..f6cb38fd 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -45,9 +45,9 @@ class LocalPlayer; class TextDialog; class ConfirmDialog; class GuildListBox; -class TabbedContainer; class ScrollArea; class GCContainer; +class TabbedArea; class GuildWindow : public Window, public gcn::ActionListener { @@ -124,10 +124,9 @@ private: TextDialog *guildDialog; TextDialog *inviteDialog; ConfirmDialog *acceptDialog; - TabbedContainer *mGuildsContainer; + TabbedArea *mGuildTabs; GuildListBox *mGuildMembersList; ScrollArea *mScrollArea; - std::vector mTabs; bool mFocus; std::string invitedGuild; }; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp new file mode 100644 index 00000000..6ba27622 --- /dev/null +++ b/src/gui/widgets/tabbedarea.cpp @@ -0,0 +1,73 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#include "tabbedarea.h" + +#include + +TabbedArea::TabbedArea() : gcn::TabbedArea() +{ + mWidgetContainer->setOpaque(false); +} + +int TabbedArea::getNumberOfTabs() +{ + return mTabs.size(); +} + +gcn::Tab* TabbedArea::getTab(const std::string &name) +{ + std::vector< std::pair >::iterator itr = mTabs.begin(), + itr_end = mTabs.end(); + while (itr != itr_end) + { + if ((*itr).first->getCaption() == name) + { + return (*itr).first; + } + ++itr; + } +} + +void TabbedArea::draw(gcn::Graphics *graphics) +{ + if (mTabs.empty()) + { + return; + } + + std::vector< std::pair >::iterator itr; + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first == mSelectedTab) + { + mTabs[i].second->setWidth(getWidth()); + mTabs[i].second->setHeight(getHeight()); + mTabs[i].second->logic(); + break; + } + } + + gcn::TabbedArea::draw(graphics); +} diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h new file mode 100644 index 00000000..42275fae --- /dev/null +++ b/src/gui/widgets/tabbedarea.h @@ -0,0 +1,60 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#ifndef _TMW_TABBEDAREA_H +#define _TMW_TABBEDAREA_H + +#include +#include + +#include + +/** + * A tabbed area, the same as the guichan tabbed area in 0.8, but extended + */ +class TabbedArea : public gcn::TabbedArea +{ + public: + /** + * Constructor. + */ + TabbedArea(); + + /** + * Draw the tabbed area. + */ + void draw(gcn::Graphics *graphics); + + /** + * Return how many tabs have been created + */ + int getNumberOfTabs(); + + /** + * Return tab with specified name as caption + */ + gcn::Tab* getTab(const std::string &name); +}; + +#endif + diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index d10c1556..4d48865a 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -137,6 +137,17 @@ void ChatHandler::handleMessage(MessageIn &msg) chatWindow->chatLog("End of channel list", BY_SERVER); break; + case CPMSG_PRIVMSG: + userNick = msg.readString(); + chatMsg = msg.readString(); + + if (!chatWindow->tabExists(userNick)) + { + chatWindow->createNewChannelTab(userNick); + chatWindow->chatLog(userNick + ": " + chatMsg, BY_OTHER, userNick); + } + break; + case CPMSG_PUBMSG: channelId = msg.readInt16(); userNick = msg.readString(); -- cgit v1.2.3-70-g09d2 From e2e4ceb9fa8a72ad94853f74724676fff82b15c0 Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 15 Apr 2008 15:42:04 +0000 Subject: Added online status of guild members --- ChangeLog | 11 +++++++++++ data/graphics/gui/circle-gray.png | Bin 0 -> 295 bytes data/graphics/gui/circle-green.png | Bin 0 -> 299 bytes src/Makefile.am | 2 ++ src/gui/guildlistbox.cpp | 35 ++++++++++++++++++++++++++--------- src/gui/guildlistbox.h | 26 +++++++++++++++++--------- src/gui/guildwindow.cpp | 18 +++++++++++++++--- src/gui/guildwindow.h | 7 ++++++- src/gui/widgets/tabbedarea.cpp | 15 ++++++++++++++- src/gui/widgets/tabbedarea.h | 6 ++++++ src/net/chathandler.cpp | 23 ++++++++++++++++++++++- src/net/chatserver/chatserver.cpp | 9 +++++++++ src/net/chatserver/chatserver.h | 2 ++ src/net/guildhandler.cpp | 11 +++++++++++ src/net/protocol.h | 2 +- tmw.cbp | 5 ++--- 16 files changed, 144 insertions(+), 28 deletions(-) create mode 100644 data/graphics/gui/circle-gray.png create mode 100644 data/graphics/gui/circle-green.png (limited to 'src/gui/widgets') diff --git a/ChangeLog b/ChangeLog index 63d46e50..f45af6e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-04-15 David Athay + + * src/gui/guildlistbox.cpp, src/gui/guildwindow.h + src/gui/widgets/tabbedarea.h, src/gui/widgets/tabbedarea.cpp, + src/gui/guildlistbox.h, src/gui/guildwindow.cpp, + src/net/guildhandler.cpp, src/net/protocol.h, src/net/chathandler.cpp, + src/net/chatserver/chatserver.cpp, src/net/chatserver/chatserver.h, + src/Makefile.am, data/graphics/gui/circle-green.png + data/graphics/gui/circle-gray.png, tmw.cbp: Added online status of + guild members. + 2008-04-14 Yohann Ferreira * src/CMakeLists.txt: Fixed (again) a compilation error using CMake. diff --git a/data/graphics/gui/circle-gray.png b/data/graphics/gui/circle-gray.png new file mode 100644 index 00000000..719b0b10 Binary files /dev/null and b/data/graphics/gui/circle-gray.png differ diff --git a/data/graphics/gui/circle-green.png b/data/graphics/gui/circle-green.png new file mode 100644 index 00000000..bab39e05 Binary files /dev/null and b/data/graphics/gui/circle-green.png differ diff --git a/src/Makefile.am b/src/Makefile.am index c46fe481..3cfa64ea 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,6 +7,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/layout.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ + gui/widgets/tabbedarea.cpp \ + gui/widgets/tabbedarea.h \ gui/box.h \ gui/box.cpp \ gui/browserbox.cpp \ diff --git a/src/gui/guildlistbox.cpp b/src/gui/guildlistbox.cpp index 11661235..1c14fd55 100644 --- a/src/gui/guildlistbox.cpp +++ b/src/gui/guildlistbox.cpp @@ -1,6 +1,6 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright 2008 The Mana World Development Team * * This file is part of The Mana World. * @@ -18,25 +18,32 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id$ + * $Id $ */ #include "guildlistbox.h" #include "../graphics.h" +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + #include GuildListBox::GuildListBox(): ListBox(NULL) { + onlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-green.png"); + offlineIcon = ResourceManager::getInstance()->getImage("graphics/gui/circle-gray.png"); } -void GuildListBox::draw(gcn::Graphics *graphics) +void GuildListBox::draw(gcn::Graphics *gcnGraphics) { if (!mListModel) return; + Graphics *graphics = static_cast(gcnGraphics); + graphics->setColor(gcn::Color(110, 160, 255)); graphics->setFont(getFont()); @@ -48,17 +55,22 @@ void GuildListBox::draw(gcn::Graphics *graphics) getWidth(), fontHeight)); } - // TODO: Add online status image - // Draw the list elements for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) { - graphics->drawText(mListModel->getElementAt(i), 1, y); + // Draw online status + bool online = mUsers[mListModel->getElementAt(i)]; + Image *icon = online ? onlineIcon : offlineIcon; + if (icon) + graphics->drawImage(icon, 1, y); + // Draw Name + graphics->setColor(gcn::Color(0, 0, 0)); + graphics->drawText(mListModel->getElementAt(i), 33, y); } } - +/* void GuildListBox::setSelected(int selected) { if (!mListModel) @@ -84,14 +96,19 @@ void GuildListBox::setSelected(int selected) distributeValueChangedEvent(); } - +*/ void GuildListBox::mousePressed(gcn::MouseEvent &event) { if (event.getButton() == gcn::MouseEvent::LEFT) { - // TODO: Add guild functions, ie private messaging int y = event.getY(); setSelected(y / getFont()->getHeight()); distributeActionEvent(); } + // TODO: Add guild functions, ie private messaging +} + +void GuildListBox::setOnlineStatus(const std::string &user, bool online) +{ + mUsers[user] = online; } diff --git a/src/gui/guildlistbox.h b/src/gui/guildlistbox.h index 262012a4..0f030d0a 100644 --- a/src/gui/guildlistbox.h +++ b/src/gui/guildlistbox.h @@ -1,6 +1,6 @@ /* * The Mana World - * Copyright 2004 The Mana World Development Team + * Copyright 2008 The Mana World Development Team * * This file is part of The Mana World. * @@ -18,17 +18,20 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id$ + * $Id $ */ #ifndef _TMW_GUI_GUILDLISTBOX_H #define _TMW_GUI_GUILDLISTBOX_H +#include #include #include #include "listbox.h" +class Image; + class GuildListBox : public ListBox { public: @@ -37,22 +40,27 @@ public: */ GuildListBox(); - /** - * Set ListModel - */ - void setList(gcn::ListModel *listModel); - /** * Draws the list box. */ - void draw(gcn::Graphics *graphics); + void draw(gcn::Graphics *gcnGraphics); void mousePressed(gcn::MouseEvent &event); /** * Sets the index of the selected element. */ - void setSelected(int selected); +// void setSelected(int selected); + + /** + * Set whether a member is online or offline + */ + void setOnlineStatus(const std::string &user, bool online); + +private: + Image *onlineIcon; + Image *offlineIcon; + std::map mUsers; }; #endif diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 7b69f9bf..7237a870 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -84,7 +84,7 @@ GuildWindow::~GuildWindow() void GuildWindow::update() { - + updateTab(); } void GuildWindow::draw(gcn::Graphics *g) @@ -172,7 +172,7 @@ void GuildWindow::newGuildTab(const std::string &guildName) { // Create new tab - ListBox *list = new ListBox(); + GuildListBox *list = new GuildListBox(); list->setListModel(player_node->getGuild(guildName)); ScrollArea *sa = new ScrollArea(list); sa->setDimension(gcn::Rectangle(5, 5, 135, 250)); @@ -224,7 +224,8 @@ short GuildWindow::getSelectedGuild() return 0; } -void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName) +void GuildWindow::openAcceptDialog(const std::string &inviterName, + const std::string &guildName) { std::string msg = inviterName + " has invited you to join the guild " + guildName; chatWindow->chatLog(msg, BY_SERVER); @@ -248,6 +249,17 @@ void GuildWindow::removeTab(int guildId) { gcn::Tab *tab = mGuildTabs->getTab(guild->getName()); mGuildTabs->removeTab(tab); + updateTab(); } mGuildTabs->logic(); } + +void GuildWindow::setOnline(const std::string &guildName, const std::string &member, + bool online) +{ + GuildListBox *box = dynamic_cast(mGuildTabs->getWidget(guildName)); + if (box) + { + box->setOnlineStatus(member, online); + } +} diff --git a/src/gui/guildwindow.h b/src/gui/guildwindow.h index f6cb38fd..b85ca3a5 100644 --- a/src/gui/guildwindow.h +++ b/src/gui/guildwindow.h @@ -112,6 +112,12 @@ public: */ void removeTab(int guildId); + /** + * Set guild member status in userlist + */ + void setOnline(const std::string &guildName, const std::string &member, + bool online); + protected: /** * Get selected guild tab @@ -125,7 +131,6 @@ private: TextDialog *inviteDialog; ConfirmDialog *acceptDialog; TabbedArea *mGuildTabs; - GuildListBox *mGuildMembersList; ScrollArea *mScrollArea; bool mFocus; std::string invitedGuild; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 6ba27622..20c100e5 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -56,7 +56,6 @@ void TabbedArea::draw(gcn::Graphics *graphics) return; } - std::vector< std::pair >::iterator itr; unsigned int i; for (i = 0; i < mTabs.size(); i++) { @@ -71,3 +70,17 @@ void TabbedArea::draw(gcn::Graphics *graphics) gcn::TabbedArea::draw(graphics); } + +gcn::Widget* TabbedArea::getWidget(const std::string &name) +{ + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first->getCaption() == name) + { + return mTabs[i].second; + } + } + + return NULL; +} diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 42275fae..3f58acde 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -24,6 +24,7 @@ #ifndef _TMW_TABBEDAREA_H #define _TMW_TABBEDAREA_H +#include #include #include @@ -54,6 +55,11 @@ class TabbedArea : public gcn::TabbedArea * Return tab with specified name as caption */ gcn::Tab* getTab(const std::string &name); + + /** + * Return selected tab's widget + */ + gcn::Widget* getWidget(const std::string &name); }; #endif diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 4d48865a..d8a228ea 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -35,6 +35,7 @@ #include "../game.h" #include "../gui/chat.h" +#include "../gui/guildwindow.h" #include "../utils/tostring.h" @@ -49,6 +50,7 @@ ChatHandler::ChatHandler() CPMSG_LIST_CHANNELS_RESPONSE, CPMSG_PUBMSG, CPMSG_QUIT_CHANNEL_RESPONSE, + CPMSG_LIST_CHANNELUSERS_RESPONSE, /* SMSG_BEING_CHAT, SMSG_PLAYER_CHAT, @@ -106,9 +108,13 @@ void ChatHandler::handleMessage(MessageIn &msg) channelName = msg.readString(); std::string announcement = msg.readString(); std::vector userList; + std::string user; while(msg.getUnreadLength()) { - userList.push_back(msg.readString()); + user = msg.readString(); + if (user == "") + break; + userList.push_back(user); } chatWindow->addChannel(channelId, channelName); chatWindow->createNewChannelTab(channelName); @@ -125,6 +131,8 @@ void ChatHandler::handleMessage(MessageIn &msg) while(msg.getUnreadLength()) { channelName = msg.readString(); + if (channelName == "") + break; std::ostringstream numUsers; numUsers << msg.readInt16(); if(channelName != "") @@ -164,6 +172,19 @@ void ChatHandler::handleMessage(MessageIn &msg) chatWindow->removeChannel(channelId); } break; + + case CPMSG_LIST_CHANNELUSERS_RESPONSE: + channelName = msg.readString(); + while(msg.getUnreadLength()) + { + userNick = msg.readString(); + if (userNick == "") + { + break; + } + guildWindow->setOnline(channelName, userNick, true); + } + break; /* // Received speech from being case SMSG_BEING_CHAT: diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp index 93fdc828..67cb5796 100644 --- a/src/net/chatserver/chatserver.cpp +++ b/src/net/chatserver/chatserver.cpp @@ -128,3 +128,12 @@ void Net::ChatServer::getChannelList() connection->send(msg); } + +void Net::ChatServer::getUserList(const std::string &channel) +{ + MessageOut msg(PCMSG_LIST_CHANNELUSERS); + + msg.writeString(channel); + + connection->send(msg); +} diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h index c4e0003d..b49d0c9e 100644 --- a/src/net/chatserver/chatserver.h +++ b/src/net/chatserver/chatserver.h @@ -54,6 +54,8 @@ namespace Net void getChannelList(); + void getUserList(const std::string &channel); + } } diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp index 494dcdc0..fd23546c 100644 --- a/src/net/guildhandler.cpp +++ b/src/net/guildhandler.cpp @@ -99,20 +99,30 @@ void GuildHandler::handleMessage(MessageIn &msg) if(msg.readInt8() == ERRMSG_OK) { std::string guildMember; + std::string guildName; Guild *guild; + short guildId = msg.readInt16(); guild = player_node->getGuild(guildId); + if (!guild) return; + + guildName = guild->getName(); + while(msg.getUnreadLength()) { guildMember = msg.readString(); if(guildMember != "") { guild->addMember(guildMember); + guildWindow->setOnline(guildName, guildMember, false); } } + guildWindow->updateTab(); + + Net::ChatServer::getUserList(guildName); } } break; @@ -126,6 +136,7 @@ void GuildHandler::handleMessage(MessageIn &msg) if (guild) { guild->addMember(guildMember); + guildWindow->setOnline(guild->getName(), guildMember, false); } guildWindow->updateTab(); } break; diff --git a/src/net/protocol.h b/src/net/protocol.h index 748a4e11..79e1f2ca 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -171,7 +171,7 @@ enum { CPMSG_USERJOINED = 0x0450, // W channel, S name CPMSG_USERLEFT = 0x0451, // W channel, S name PCMSG_LIST_CHANNELUSERS = 0x0460, // S channel - CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S users + CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S channel, S users XXMSG_INVALID = 0x7FFF }; diff --git a/tmw.cbp b/tmw.cbp index d503d01d..d30bb0e2 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -303,9 +303,6 @@ - -