1
Fork 0
jacker/patternview.hpp

366 lines
11 KiB
C++
Raw Normal View History

2010-01-30 02:02:21 +02:00
#pragma once
#include <gtkmm.h>
#if !defined(GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED)
#error GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED must be set.
#endif
2010-01-30 18:51:04 +02:00
#include "model.hpp"
2010-01-30 02:02:21 +02:00
namespace Jacker {
2010-01-31 20:00:28 +02:00
class PatternCursor;
class PatternView;
//=============================================================================
class CellRenderer {
public:
CellRenderer();
2010-01-31 20:00:28 +02:00
virtual ~CellRenderer() {}
virtual void render_background(PatternCursor &cursor,
2010-02-02 21:52:11 +02:00
bool selected);
virtual void render_cell(PatternCursor &cursor,
2010-02-02 21:52:11 +02:00
Pattern::Event *event, bool draw_cursor,
bool selected);
virtual int get_width();
virtual int get_item(int x);
2010-02-02 08:42:48 +02:00
virtual int get_item_count();
2010-02-03 10:51:13 +02:00
virtual bool on_key_press_event(GdkEventKey* event_key,
2010-02-03 12:04:32 +02:00
Pattern::Event &event, int item);
2010-02-03 10:51:13 +02:00
void set_view(PatternView &view);
PatternView *get_view() const;
protected:
PatternView *view;
2010-01-31 20:00:28 +02:00
};
//=============================================================================
class CellRendererNote : public CellRenderer {
public:
2010-02-03 12:04:32 +02:00
enum {
ItemNote = 0,
ItemOctave,
ItemCount
};
virtual void render_cell(PatternCursor &cursor,
2010-02-02 21:52:11 +02:00
Pattern::Event *event, bool draw_cursor,
bool selected);
virtual int get_width();
virtual int get_item(int x);
2010-02-02 08:42:48 +02:00
virtual int get_item_count();
2010-02-03 19:05:08 +02:00
virtual bool on_key_press_event(GdkEventKey* event_key,
Pattern::Event &event, int item);
2010-01-31 20:00:28 +02:00
};
//=============================================================================
2010-02-03 12:04:32 +02:00
class CellRendererHex : public CellRenderer {
2010-01-31 20:00:28 +02:00
public:
2010-02-03 12:04:32 +02:00
CellRendererHex(int value_length);
int value_length;
virtual void render_cell(PatternCursor &cursor,
2010-02-02 21:52:11 +02:00
Pattern::Event *event, bool draw_cursor,
bool selected);
virtual int get_width();
virtual int get_item(int x);
2010-02-02 08:42:48 +02:00
virtual int get_item_count();
2010-02-03 12:04:32 +02:00
virtual bool on_key_press_event(GdkEventKey* event_key,
Pattern::Event &event, int item);
2010-01-31 20:00:28 +02:00
};
//=============================================================================
2010-02-06 11:26:25 +02:00
class CellRendererCommand : public CellRenderer {
public:
CellRendererCommand();
virtual void render_cell(PatternCursor &cursor,
Pattern::Event *event, bool draw_cursor,
bool selected);
virtual int get_width();
virtual int get_item(int x);
virtual int get_item_count();
virtual bool on_key_press_event(GdkEventKey* event_key,
Pattern::Event &event, int item);
};
//=============================================================================
2010-01-31 20:00:28 +02:00
class PatternCursor {
2010-02-02 21:52:11 +02:00
friend class PatternSelection;
2010-01-31 20:00:28 +02:00
public:
PatternCursor();
2010-01-31 20:00:28 +02:00
void origin();
void next_row();
void next_channel();
2010-02-07 12:21:59 +02:00
void prev_channel();
2010-01-31 20:00:28 +02:00
void next_param();
2010-02-07 12:21:59 +02:00
// moves to the first param, then to the first channel,
// then to the first row
void home();
// moves to the last param, then to the last channel,
// then to the last row
void end();
2010-01-31 20:00:28 +02:00
int get_row() const;
int get_channel() const;
int get_param() const;
int get_item() const;
2010-02-02 21:52:11 +02:00
int get_column() const;
void set_row(int row);
void set_channel(int channel);
void set_param(int param);
void set_item(int item);
2010-01-31 20:00:28 +02:00
2010-02-02 08:42:48 +02:00
void set_last_item();
bool is_last_item() const;
void navigate_row(int delta);
void navigate_column(int delta);
2010-02-02 08:42:48 +02:00
2010-01-31 20:00:28 +02:00
// true if param is the last param in a channel
bool is_last_param() const;
2010-02-07 12:21:59 +02:00
void set_last_param();
bool is_last_channel() const;
void set_last_channel();
bool is_last_row() const;
void set_last_row();
2010-01-31 20:00:28 +02:00
void get_pos(int &x, int &y) const;
void set_pos(int x, int y);
2010-02-02 22:52:27 +02:00
void get_cell_size(int &w, int &h, bool include_margin=false) const;
2010-01-31 20:00:28 +02:00
PatternView *get_view() const;
void set_view(PatternView &view);
// true if cursor shares row/channel/param with other cursor
bool is_at(const PatternCursor &other) const;
2010-02-07 19:43:01 +02:00
std::string debug_string() const;
const PatternCursor &operator =(const Pattern::Event &event);
2010-01-31 20:00:28 +02:00
protected:
PatternView *view;
2010-01-31 20:00:28 +02:00
// index of current row
int row;
// index of current channel
int channel;
// index of current parameter
int param;
// index of parameter item
int item;
2010-01-31 20:00:28 +02:00
};
2010-01-30 02:02:21 +02:00
//=============================================================================
2010-02-02 21:52:11 +02:00
class PatternSelection {
public:
PatternSelection();
bool in_range(const PatternCursor &cursor) const;
void set_active(bool active);
bool get_active() const;
void set_view(PatternView &view);
2010-02-02 21:52:11 +02:00
2010-02-02 22:52:27 +02:00
bool get_rect(int &x, int &y, int &width, int &height) const;
void sort();
2010-02-02 21:52:11 +02:00
PatternCursor p0;
PatternCursor p1;
2010-02-07 18:28:33 +02:00
2010-02-07 19:43:01 +02:00
std::string debug_string() const;
2010-02-02 21:52:11 +02:00
protected:
bool active;
2010-02-07 18:28:33 +02:00
PatternView *view;
2010-02-02 22:52:27 +02:00
2010-02-02 21:52:11 +02:00
};
//=============================================================================
2010-01-30 02:02:21 +02:00
class PatternView : public Gtk::Widget {
public:
2010-02-02 09:05:45 +02:00
enum {
CharBegin = 32,
CharEnd = 128,
};
2010-02-02 22:52:27 +02:00
enum InteractMode {
InteractNone = 0,
2010-02-07 14:27:55 +02:00
InteractSelect,
2010-02-02 22:52:27 +02:00
};
typedef sigc::signal<void, int, const Pattern::Event &> type_play_event_request;
2010-02-11 11:08:09 +02:00
typedef sigc::signal<void> type_return_request;
2010-02-11 17:29:53 +02:00
typedef sigc::signal<void, int> type_play_request;
2010-02-15 18:58:07 +02:00
typedef sigc::signal<void, const std::string &,
const std::string &, const std::string &> type_navigation_status_request;
2010-02-07 16:02:07 +02:00
2010-01-30 02:02:21 +02:00
PatternView(BaseObjectType* cobject,
const Glib::RefPtr<Gtk::Builder>& builder);
2010-02-06 20:42:01 +02:00
void set_model(class Model &model);
2010-02-11 11:00:01 +02:00
void set_song_event(Song::iterator event);
2010-02-12 08:15:30 +02:00
Song::iterator get_song_event();
2010-02-06 16:41:59 +02:00
Pattern *get_pattern() const;
2010-01-30 02:02:21 +02:00
virtual void on_realize();
virtual bool on_expose_event(GdkEventExpose* event);
virtual bool on_motion_notify_event(GdkEventMotion *event);
virtual bool on_button_press_event(GdkEventButton* event);
virtual bool on_button_release_event(GdkEventButton* event);
virtual bool on_key_press_event(GdkEventKey* event);
virtual bool on_key_release_event(GdkEventKey* event);
2010-02-01 23:54:27 +02:00
virtual void on_size_allocate(Gtk::Allocation& allocation);
2010-02-07 15:01:35 +02:00
void set_cursor(const PatternCursor &cursor, bool select=false);
2010-02-02 22:52:27 +02:00
void set_cursor(int x, int y);
2010-01-30 18:51:04 +02:00
Glib::RefPtr<Gdk::GC> gc;
Glib::RefPtr<Gdk::GC> xor_gc;
2010-01-30 18:51:04 +02:00
Glib::RefPtr<Gdk::Colormap> cm;
2010-01-31 20:00:28 +02:00
Glib::RefPtr<Pango::Layout> pango_layout;
2010-01-30 18:51:04 +02:00
Glib::RefPtr<Gdk::Window> window;
2010-02-02 12:02:07 +02:00
std::vector< Glib::RefPtr<Gdk::Pixmap> > chars;
2010-01-30 18:51:04 +02:00
2010-02-02 21:52:11 +02:00
std::vector<Gdk::Color> colors;
2010-01-31 20:00:28 +02:00
CellRendererNote note_renderer;
2010-02-03 12:04:32 +02:00
CellRendererHex byte_renderer;
2010-02-06 11:26:25 +02:00
CellRendererCommand command_renderer;
int cursor_x, cursor_y;
2010-02-06 11:38:46 +02:00
//CellRendererHex word_renderer;
2010-02-05 21:49:45 +02:00
class Model *model;
2010-02-01 23:54:27 +02:00
void set_scroll_adjustments(Gtk::Adjustment *hadjustment,
Gtk::Adjustment *vadjustment);
void on_adjustment_value_changed();
void draw_text(int x, int y, const char *text);
2010-02-07 15:01:35 +02:00
void navigate(int delta_x, int delta_y, bool select=false);
2010-02-03 20:14:33 +02:00
void show_cursor();
2010-02-06 11:33:16 +02:00
void show_cursor(const PatternCursor &cur, bool page_jump=false);
int get_page_scroll_size() const;
int get_page_step_size() const;
2010-02-03 10:51:13 +02:00
int get_frames_per_bar() const;
void set_row_height(int height);
int get_row_height() const;
void set_cell_renderer(int param, CellRenderer *renderer);
CellRenderer *get_cell_renderer(int param) const;
int get_cell_count() const;
void set_origin(int x, int y);
void get_origin(int &x, int &y);
void set_cell_margin(int margin);
int get_cell_margin() const;
void set_channel_margin(int margin);
int get_channel_margin() const;
void get_cell_size(int param, int &w, int &h, bool include_margin=false) const;
void get_cell_pos(int row, int channel, int param,
int &x, int &y) const;
bool get_cell_location(int x, int y, int &row, int &channel,
int &param, int &item) const;
int get_channel_width() const;
int get_param_offset(int param) const;
2010-02-03 08:55:07 +02:00
void set_font_size(int width, int height);
void get_font_size(int &width, int &height) const;
2010-02-05 21:49:45 +02:00
2010-02-06 16:08:57 +02:00
void set_octave(int octave);
int get_octave() const;
2010-02-06 16:41:59 +02:00
void set_play_position(int pos);
2010-02-06 20:42:01 +02:00
void invalidate();
2010-02-07 16:02:07 +02:00
2010-02-07 18:28:33 +02:00
Pattern::iterator get_event(PatternCursor &cur);
2010-02-07 16:02:07 +02:00
void play_event(const Pattern::Event &event);
2010-02-11 19:34:08 +02:00
void play_from_cursor();
void play_from_mouse_cursor();
2010-02-13 13:53:41 +02:00
void play_pattern();
2010-02-07 18:28:33 +02:00
2010-02-13 22:11:46 +02:00
void cut_block();
void copy_block();
void paste_block();
2010-02-07 18:28:33 +02:00
void clear_block();
2010-02-13 22:11:46 +02:00
void on_clipboard_get(Gtk::SelectionData &data, guint info);
void on_clipboard_clear();
2010-02-13 23:06:22 +02:00
void on_clipboard_received(const Gtk::SelectionData &data);
2010-02-14 01:35:51 +02:00
void begin_block();
void end_block();
void cycle_block_selection();
2010-03-06 19:26:04 +02:00
void transpose(int step);
void interpolate();
2010-02-13 22:11:46 +02:00
2010-02-07 19:43:01 +02:00
void move_frames(int step, bool all_channels=false);
2010-02-16 08:40:50 +02:00
void reset();
2010-02-11 11:08:09 +02:00
type_play_event_request signal_play_event_request();
type_return_request signal_return_request();
2010-02-11 17:29:53 +02:00
type_play_request signal_play_request();
2010-02-15 18:58:07 +02:00
type_navigation_status_request signal_navigation_status_request();
2010-01-30 02:02:21 +02:00
protected:
2010-02-06 16:41:59 +02:00
void invalidate_play_position();
void invalidate_cursor();
void invalidate_selection();
2010-02-07 19:43:01 +02:00
void invalidate_range(const PatternSelection &range);
void clip_cursor(PatternCursor &c);
2010-02-01 23:54:27 +02:00
void update_adjustments();
2010-02-15 18:58:07 +02:00
void update_navigation_status();
2010-02-02 22:52:27 +02:00
InteractMode interact_mode;
2010-02-01 23:54:27 +02:00
2010-02-11 13:20:52 +02:00
Song::iterator song_event;
2010-02-01 23:54:27 +02:00
Gtk::Adjustment *hadjustment;
Gtk::Adjustment *vadjustment;
2010-02-01 11:25:13 +02:00
PatternCursor cursor;
2010-02-02 21:52:11 +02:00
PatternSelection selection;
2010-02-13 23:06:22 +02:00
std::string clipboard_jsong;
typedef std::vector<CellRenderer *> CellRendererArray;
// height of active row
int row_height;
// cell renderers indexed by param
CellRendererArray renderers;
// start x and y position
int origin_x, origin_y;
// margin between cells
int cell_margin;
// margin between channels
int channel_margin;
// how wide is a pattern character
2010-02-03 08:55:07 +02:00
int font_width;
// how high is a pattern character
2010-02-03 08:55:07 +02:00
int font_height;
2010-02-06 16:08:57 +02:00
// current base octave
int octave;
2010-02-06 16:41:59 +02:00
int play_position;
2010-02-07 15:01:35 +02:00
bool select_at_cursor;
2010-02-07 16:02:07 +02:00
type_play_event_request _play_event_request;
2010-02-11 11:08:09 +02:00
type_return_request _return_request;
2010-02-11 17:29:53 +02:00
type_play_request _play_request;
2010-02-15 18:58:07 +02:00
type_navigation_status_request _navigation_status_request;
2010-01-30 02:02:21 +02:00
};
//=============================================================================
} // namespace Jacker