2 * Copyright (C) 2009 by Aiwota Programmer
3 * aiwotaprog@tetteke.tk
5 * This file is part of Dialektos.
7 * Dialektos is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * Dialektos is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Dialektos. If not, see <http://www.gnu.org/licenses/>.
21 #include "text_view_drawable.hxx"
23 #include <glibmm/refptr.h>
25 #include <gdkmm/drawable.h>
26 #include <gtkmm/style.h>
27 #include <boost/foreach.hpp>
28 #include "text_line.hxx"
29 #include "text_element_plain.hxx"
30 #include "text_view_drawing_set.hxx"
39 Drawable::Drawable(): PointerTrackable() {}
41 Drawable::~Drawable() {}
43 bool Drawable::on_expose_event(GdkEventExpose* event) {
44 const double value = adjustment_.get_value();
45 Glib::RefPtr<Gdk::Drawable> window = get_window();
46 Glib::RefPtr<const Gtk::Style> style = get_style();
47 Glib::RefPtr<const Gdk::GC> gc = style->get_base_gc(Gtk::STATE_NORMAL);
48 window->draw_rectangle(gc, true, 0, 0, get_width(), get_height());
52 set.layout = pango_layout_;
54 set.adj_value = value;
55 set.start_element = pressed_element_;
56 set.start_index = pressed_index_;
57 set.end_element = hovered_element_;
58 set.end_index = hovered_index_;
60 if (pressed_element_ && hovered_element_) {
61 std::pair<gdouble, gdouble> pressed_xy = pressed_element_->get_xy();
62 std::pair<gdouble, gdouble> hovered_xy = hovered_element_->get_xy();
64 if ((pressed_element_ == hovered_element_
65 && pressed_index_ > hovered_index_) ||
66 (pressed_xy.second == hovered_xy.second
67 && pressed_xy.first > hovered_xy.first) ||
68 (pressed_xy.second > hovered_xy.second)) {
69 std::swap(set.start_element, set.end_element);
70 std::swap(set.start_index, set.end_index);
74 const int area_bottom = get_height() + value;
76 BOOST_FOREACH(TextLine& line, line_list_) {
77 if (line.get_y() > area_bottom) break;
78 if (line.get_btm_y() >= value) line.draw(set);
84 } // namespace text_view
87 } // namespace dialektos