ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/src/frontend/client/widgets/map_widget.cpp
Revision: 1.6
Committed: Sun Oct 24 20:31:53 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.5: +11 -6 lines
Log Message:
use EV and plain sockets instead of asio

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include "dclient/widgets/map.h"
2     #include "dclient/render_glyph.h"
3    
4     #include "deliantra/data/glyph.h"
5     #include "deliantra/data/map.h"
6    
7 sf-pippijn 1.6 #include <ndk/application.hh>
8     #include <ndk/color.hh>
9     #include <ndk/pen.hh>
10 sf-pippijn 1.1
11 sf-pippijn 1.6 #define HIGHLIGHT_PLAYER 0
12 sf-pippijn 1.5
13 sf-pippijn 1.1 map_widget::map_widget (ndk::panel *parent)
14     : frame ("", parent)
15     , map (nullptr)
16     {
17     }
18    
19     void
20     map_widget::update (data::map const &map)
21     {
22     this->map = &map;
23     }
24    
25    
26     static u16
27     select_face (u16 const (&face)[3], int layer)
28     {
29     if (layer == -1)
30     return face[2]
31     ? face[2]
32     : face[1]
33     ? face[1]
34     : face[0]
35     ;
36     return face[layer];
37     }
38    
39    
40     void
41     map_widget::draw ()
42     {
43     frame::draw ();
44    
45     if (!map)
46     return;
47    
48     static int const layer = -1;
49    
50 sf-pippijn 1.5 int const W = (this->width () - 2) / 2;
51     int const H = (this->height () - 2);
52 sf-pippijn 1.1 ndk::pen pen (*this);
53    
54 sf-pippijn 1.5 static data::glyph const space = { { { 0, 0, L' ' }, { 0, 0, L' ' } } };
55     #if HIGHLIGHT_PLAYER
56     static data::glyph const player = { { { 0, 0, L'@' }, { 13, 13, L'@' } } };
57 sf-pippijn 1.2 #endif
58 sf-pippijn 1.1
59 sf-pippijn 1.6 int const zerox = -(W - map->w - 1) / 4;
60     int const zeroy = -(H - map->h - 1) / 2;
61 sf-pippijn 1.1
62 sf-pippijn 1.5 #if HIGHLIGHT_PLAYER
63     int const playerx = W;
64     int const playery = H / 2;
65 sf-pippijn 1.2 #endif
66 sf-pippijn 1.1
67     for (int y = zeroy; y < H + zeroy; y++)
68     {
69     int const mapy = y + map->y;
70     if (!map->rows.has (mapy))
71     continue;
72 sf-pippijn 1.5 auto const &row = map->rows[mapy];
73 sf-pippijn 1.1 for (int x = zerox; x < W + zerox; x++)
74     {
75 sf-pippijn 1.5 int const mapx = x + map->x - 2;
76 sf-pippijn 1.1 if (!row.has (mapx))
77     continue;
78 sf-pippijn 1.5 data::map::cell const &cell = row[mapx];
79 sf-pippijn 1.1 u32 const face = select_face (cell.face, layer);
80    
81     data::glyph const *glyph;
82    
83 sf-pippijn 1.5 int const winy = y - zeroy + 1;
84     int const winx = x * 2 - zerox + 1;
85 sf-pippijn 1.1
86 sf-pippijn 1.6 #if HIGHLIGHT_PLAYER
87 sf-pippijn 1.1 if (winx == playerx && winy == playery)
88     glyph = &player;
89 sf-pippijn 1.6 #else
90     if (0)
91     ;
92     #endif
93 sf-pippijn 1.1 else if (face && face < data::glyphs.size ()) // TODO: warn about face >= size
94     glyph = &data::glyphs[face];
95     else
96     glyph = &space;
97    
98 sf-pippijn 1.2 return_unless (pen.move (winx, winy));
99 sf-pippijn 1.1 write (pen, *glyph, cell.darkness);
100     }
101     }
102    
103 sf-pippijn 1.5 #if HIGHLIGHT_PLAYER
104 sf-pippijn 1.1 // 19:15 < n0nsense> pippijn: kannst du nethack-mäßig noch den cursor auf den player setzen?
105 sf-pippijn 1.5 if (active ())
106     {
107     pen.move (playerx, playery);
108     ndk::app->cursor_on ();
109     }
110     else
111     ndk::app->cursor_off ();
112 sf-pippijn 1.1 #endif
113    
114     if (getenv ("DCLIENT_ONESHOT"))
115     {
116 sf-pippijn 1.4 delete ndk::app;
117 sf-pippijn 1.1 exit (0);
118     }
119 sf-pippijn 1.5
120     pen.set_color ({ }); // reset
121 sf-pippijn 1.1 }