1 /* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*- 2 * 3 * Quadra, an action puzzle game 4 * Copyright (C) 1998-2000 Ludus Design 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 #ifndef HEADER_LISTBOX 21 #define HEADER_LISTBOX 22 23 #include <vector> 24 25 #include "types.h" 26 #include "error.h" 27 #include "inter.h" 28 29 class Zone_listbox; 30 31 class Zone_listupdown: public Zone_text_select { 32 friend class Zone_listup; 33 friend class Zone_listdown; 34 Zone_listbox *parent; 35 int count; 36 public: 37 Zone_listupdown(Zone_listbox *par, const char *s, int py); 38 virtual void waiting(); 39 virtual void leaved(); 40 virtual void dirt(); 41 }; 42 43 class Zone_listup: public Zone_listupdown { 44 public: 45 Zone_listup(Zone_listbox *par); 46 virtual void clicked(int quel); 47 }; 48 49 class Zone_listdown: public Zone_listupdown { 50 public: 51 Zone_listdown(Zone_listbox *par); 52 virtual void clicked(int quel); 53 }; 54 55 class Listable { 56 public: 57 char list_name[64]; 58 Font *font; 59 Listable(const char *s, Font *f=NULL); ~Listable()60 virtual ~Listable() { 61 } 62 virtual bool is_equal(Listable *source); 63 }; 64 65 class Zone_listtext: public Zone_text { 66 Zone_listbox *parent; 67 int quel; 68 bool high; 69 public: 70 Zone_listtext(Zone_listbox *par, int i); 71 virtual void clicked(int quel); 72 virtual void draw(); 73 virtual void dirt(); 74 virtual void entered(); 75 virtual void leaved(); 76 }; 77 78 class Zone_listbox: public Zone_watch_int { 79 friend class Zone_listupdown; 80 friend class Zone_listup; 81 friend class Zone_listdown; 82 friend class Zone_listtext; 83 Bitmap *back; 84 Zone_listup *zup; 85 Zone_listdown *zdown; 86 Font *font2; 87 std::vector<Listable*> elements; // list of the list_box elements 88 int first_item; // first displayed item in list_box 89 std::vector<Zone_listtext*> list; // list of the displayed zone_text 90 std::vector<Listable*> sort_list; // temporary list of elements to sort 91 static int compare_sort(const void *arg1, const void *arg2); 92 Video_bitmap *screen; 93 bool selectable; 94 public: 95 Zone_listbox(Inter* in, Bitmap *fond, Font *f, int *pval, int px, int py, int pw, int ph); 96 virtual ~Zone_listbox(); 97 virtual void draw(); 98 virtual void dirt(); 99 virtual void enable(); 100 virtual void disable(); 101 virtual void process(); add_item(const char * s)102 void add_item(const char *s) { 103 add_item(new Listable(s)); 104 } 105 void add_item(Listable *e); 106 void replace_item(int i, Listable *e); 107 void remove_item(Listable *e); 108 Listable *get_selected(); 109 void clear(); 110 void sync_list(); 111 void unselect(); 112 void empty(); 113 void select(int q); 114 int search(Listable *source); 115 bool in_listbox(const Zone *z); // asks if 'z' is an element of the listbox 116 void init_sort(); 117 void add_sort(Listable *l); 118 void end_sort(); 119 }; 120 121 #endif 122