-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVmMap.h
170 lines (152 loc) · 5.54 KB
/
VmMap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* -*-c++-*-
* This file is part of vice-mapper.
*
* vice-mapper 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 3 of the License, or
* (at your option) any later version.
*
* vice-mapper 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 vice-mapper. If not, see <https://www.gnu.org/licenses/>.
*
* File: VmMap.h
* Date: Tue May 5 22:44:11 2020
* Author: pottendo (pottendo)
*
* Abstract:
* map_window class
*
* Modifications:
* $Log$
*/
#ifndef __map_window_h__
#define __map_window_h__
#include <gtkmm/window.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/grid.h>
#include <gtkmm/hvbox.h>
#include <gtkmm/entry.h>
#include <gtkmm/filechooserwidget.h>
#include <gtkmm/printoperation.h>
#include "VmTile.h"
#include "VmMapControls.h"
#include "dialogs.h"
const int map_max = 100; /* 100x100 tiles should be enough */
const int def_resX = 384; /* typical C64 screen resolution */
const int def_resY = 272;
const int def_crx = 32;
const int def_cry = 36;
const double def_zoom = 3.0;
const std::string def_basename = "vice-screen-";
const std::string def_cfg_ext = ".vsm";
const std::string mapper_version = MAPPER_VERSION;
class VmMap : public Gtk::ScrolledWindow
{
int get_empty_area(int from_x, int from_y, int to_x, int to_y);
bool process_line(std::string);
bool dirty, tiles_placed;
protected:
class MyScw : public Gtk::ScrolledWindow
{
bool space_modifier;
bool button_press;
// Signal handlers:
bool on_scroll_event(GdkEventScroll *scroll_event) override;
bool on_motion_notify_event(GdkEventMotion* motion_event) override;
bool on_key_press_event(GdkEventKey *key_event) override;
bool on_key_release_event(GdkEventKey *key_event) override;
bool on_enter_notify_event(GdkEventCrossing* crossing_event) override;
/*
bool on_button_press_event(GdkEventButton *button_event) override;
bool on_button_release_event(GdkEventButton *button_event) override;
*/
public:
MyScw();
VmMapControls *mc;
Glib::RefPtr<Gdk::Cursor> move_cursor;
};
class MapPreview : public Gtk::DrawingArea {
Gtk::Entry *header, *footer;
Glib::RefPtr<Gdk::Pixbuf> out_image;
protected:
bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
// bool on_configure_event(GdkEventConfigure *configure_event) override;
public:
MapPreview();
virtual ~MapPreview() {};
inline Glib::RefPtr<Gdk::Pixbuf> get_out_image(void) { return out_image; }
void set_header(std::string s) { header->set_text(s); };
void set_footer(std::string s) { footer->set_text(s); };
void render_preview(void);
void save(std::string name);
};
class MapPrint : public Gtk::PrintOperation {
Glib::RefPtr<Gdk::Pixbuf> print_image;
protected:
void on_begin_print(const Glib::RefPtr<Gtk::PrintContext>& context) override;
void on_request_page_setup(const Glib::RefPtr<Gtk::PrintContext>& context,
int page_no, const Glib::RefPtr<Gtk::PageSetup>& setup) override;
void on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& context, int page_nr) override;
public:
MapPrint();
virtual ~MapPrint();
static Glib::RefPtr<VmMap::MapPrint> create();
void print(void) { this->run(); }
};
// Child widgets:
Gtk::Grid map_grid;
MyScw scw;
Glib::RefPtr<Gdk::Pixbuf> m_empty;
VmTile *tiles[map_max+1][map_max+1];
VmMapControls *ctrls;
Gtk::Frame *map_frame;
MapPreview *map_preview;
Gtk::Window *preview_win;
Gtk::FileChooserWidget *file_chooser;
Glib::RefPtr<MapPrint> po;
Glib::RefPtr<Gtk::PrintSettings> pr_settings;
Glib::RefPtr<Gtk::PageSetup> pr_pagesettings;
public:
VmMap();
virtual ~VmMap();
static int nr_tiles; // managed non-empty tiles
inline void set_dirty(bool d) { dirty=d; ctrls->set_dirty(d); }
inline bool is_dirty(void) { return dirty; }
inline bool is_placed(void) { return tiles_placed; }
void update_state(void);
void add_tile(VmTile *);
void remove_tile(VmTile *, bool map_remove = false);
void add_unplaced_tile(VmTile *t) { ctrls->add_tile(t); }
void reload_unplaced_tiles(char *path = NULL);
void fill_empties();
void scale_all(void);
void xchange_tiles(VmTile *s, VmTile *d);
inline VmTile *get_tile(int x, int y) { return tiles[x][y]; }
inline void set_tile(int x, int y, VmTile *t = nullptr) { tiles[x][y] = t; }
inline int get_nrtiles(void) { return nr_tiles; }
inline Glib::RefPtr<Gtk::PrintSettings> get_pr_settings(void) { return pr_settings; }
static Glib::RefPtr<Gdk::Pixbuf> empty_image;
static double scale_factor_x;
static double scale_factor_y;
static std::string current_path;
static std::string current_ext;
static std::string current_basename;
void resize_map(void);
void remove_map(void);
void open_map(void);
void export_map(void);
void export_map_updatefn(void);
void export_map_commit(bool save);
void print(void);
Glib::RefPtr<Gdk::Pixbuf> get_out_image(void) { return map_preview->get_out_image(); }
void commit_changes(void) { if (dirty) { ctrls->commit_changes(); } }
void save_settings(void);
bool load_settings(void);
void update_preview(void) { map_preview->render_preview(); }
};
#endif /* __map_window_h__ */