summaryrefslogtreecommitdiffstats
path: root/src/Gui/Renderer/RoomListRenderer.cpp
blob: 83b0402a642c97432897225b1e78312632ec927b (plain)
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
/*
 * RoomListRenderer.cpp
 *
 * Copyright (C) 2010 Matthias Schiffer <matthias@gamezock.de>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "RoomListRenderer.h"
#include <Data/Room.h>

#include <pangomm/layout.h>

namespace ZoomEdit {
namespace Gui {
namespace Renderer {

void RoomListRenderer::get_size_vfunc(Gtk::Widget &/*widget*/, const Gdk::Rectangle * /*cell_area*/,
    int * /*x_offset*/, int * /*y_offset*/, int * /*width*/, int *height) const {
  int xpad, ypad;
  get_padding(xpad, ypad);

  *height = 60 + ypad*2;
}

void RoomListRenderer::render_vfunc(const Glib::RefPtr<Gdk::Drawable> &window, Gtk::Widget &widget,
    const Gdk::Rectangle &/*background_area*/, const Gdk::Rectangle &cell_area,
    const Gdk::Rectangle &/*expose_area*/, Gtk::CellRendererState /*flags*/) {

  Data::Room *room = reinterpret_cast<Data::Room*>(value.get_value());

  int xpad, ypad;
  get_padding(xpad, ypad);

  int x = xpad + cell_area.get_x();
  int y = ypad + cell_area.get_y();

  int width = cell_area.get_width() - 2*xpad;
  int height = cell_area.get_height() - 2*ypad;

  Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(window);
  gc->set_rgb_fg_color(Gdk::Color("000000"));

  Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(widget.get_pango_context());

  layout->set_width(width);
  layout->set_height(height);
  layout->set_markup("<b>" + room->getId() + "</b>");

  window->draw_layout(gc, x, y, layout);
}

}
}
}