DrawBackground(const std::string & s)1 void DrawBackground(const std::string& s) {
2 backg_ = std::make_unique<ncpp::Visual>(s.c_str());
3 ncvisual_options opts{};
4 opts.scaling = NCSCALE_STRETCH;
5 opts.n = *nc_.get_stdplane();
6 opts.blitter = NCBLIT_3x2;
7 opts.flags = NCVISUAL_OPTION_CHILDPLANE;
8 backg_->blit(&opts);
9 }
10
DrawLogo(const ncpp::Plane & score,const ncpp::Plane & board,const std::string & s)11 void DrawLogo(const ncpp::Plane& score,
12 const ncpp::Plane& board,
13 const std::string& s) {
14 auto logo = std::make_unique<ncpp::Visual>(s.c_str());
15 auto rows = nc_.get_stdplane()->get_dim_y() -
16 (score.get_dim_y() + score.get_abs_y()) - 2;
17 auto cols = board.get_abs_x() - score.get_abs_x() - 1;
18 logop_ = std::make_unique<ncpp::Plane>(rows, cols,
19 score.get_abs_y() + 2, score.get_abs_x());
20 ncvisual_options opts{};
21 opts.scaling = NCSCALE_STRETCH;
22 opts.n = *logop_;
23 opts.blitter = NCBLIT_PIXEL;
24 logo->blit(&opts);
25 }
26
DrawBoard()27 void DrawBoard() { // draw all fixed components of the game
28 // FIXME limit these catches to I/O errors!
29 try{
30 DrawBackground(BackgroundFile);
31 }catch(...){
32 stdplane_->printf(1, 1, "couldn't load bground from %s", BackgroundFile.c_str());
33 }
34 unsigned y, x;
35 stdplane_->get_dim(&y, &x);
36 board_top_y_ = y - (BOARD_HEIGHT + 2);
37 board_ = std::make_unique<ncpp::Plane>(BOARD_HEIGHT, BOARD_WIDTH * 2,
38 board_top_y_, x / 2 - (BOARD_WIDTH + 1));
39 uint64_t channels = 0;
40 ncchannels_set_fg_rgb(&channels, 0x00b040);
41 ncchannels_set_bg_alpha(&channels, NCALPHA_TRANSPARENT);
42 board_->double_box(0, channels, BOARD_HEIGHT - 1, BOARD_WIDTH * 2 - 1, NCBOXMASK_TOP);
43 ncchannels_set_fg_alpha(&channels, NCALPHA_TRANSPARENT);
44 board_->set_base("", 0, channels);
45 scoreplane_ = std::make_unique<ncpp::Plane>(2, 30, y - BOARD_HEIGHT, 2, nullptr);
46 uint64_t scorechan = 0;
47 ncchannels_set_bg_alpha(&scorechan, NCALPHA_TRANSPARENT);
48 ncchannels_set_fg_alpha(&scorechan, NCALPHA_TRANSPARENT);
49 scoreplane_->set_base("", 0, scorechan);
50 scoreplane_->set_bg_alpha(NCALPHA_TRANSPARENT);
51 scoreplane_->set_fg_rgb(0xd040d0);
52 char* n = notcurses_accountname();
53 scoreplane_->printf(0, 1, "%s", n);
54 free(n);
55 scoreplane_->set_fg_rgb(0x00d0a0);
56 try{
57 DrawLogo(*scoreplane_, *board_, LogoFile);
58 }catch(...){
59 stdplane_->printf(1, 1, "couldn't load logo from %s", LogoFile.c_str());
60 }
61 UpdateScore();
62 nc_.render();
63 }
64