OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
chapterscreen.cpp
Go to the documentation of this file.
1#include "chapterscreen.h"
2
3#include <Tempest/Painter>
4#include <Tempest/SoundEffect>
5
6#include "utils/gthfont.h"
7#include "gothic.h"
8#include "resources.h"
9
10using namespace Tempest;
11
14
15void ChapterScreen::show(const Show& s) {
17 if(!active)
19 active = true;
20 title = s.title;
21 subTitle = s.subtitle;
22 if(s.time>0)
23 timer.start(uint64_t(s.time));
24 timer.timeout.bind(this,&ChapterScreen::close);
26 update();
27 }
28
29void ChapterScreen::paintEvent(Tempest::PaintEvent &e) {
30 if(!active || !back)
31 return;
32
33 const float scale = Gothic::interfaceScale(this);
34 const int32_t width = int32_t(float(Gothic::options().newChapterSize.w)*scale);
35 const int32_t height = int32_t(float(Gothic::options().newChapterSize.h)*scale);
36 const int32_t offset = int32_t(50*scale);
37
38 Painter p(e);
39 int x = (w()-width )/2;
40 int y = (h()-height)/2;
41 p.setBrush(*back);
42 p.drawRect(x,y,width,height,
43 0,0,back->w(),back->h());
44
45 {
46 auto& fnt = Resources::font("font_old_20_white.tga",Resources::FontType::Normal,scale);
47 auto sz = fnt.textSize(title);
48 fnt.drawText(p,x+(width-sz.w)/2,y+offset+int(fnt.pixelSize()),title);
49 }
50
51 {
52 auto& fnt = Resources::font(scale);
53 auto sz = fnt.textSize(subTitle);
54 fnt.drawText(p,x+(width-sz.w)/2,y+height-offset,subTitle);
55 }
56 }
57
58void ChapterScreen::close() {
59 if(!active)
60 return;
62 active=false;
63 }
64
65void ChapterScreen::keyDownEvent(KeyEvent &e) {
66 if(!active){
67 e.ignore();
68 return;
69 }
70
71 if(e.key!=Event::K_ESCAPE){
72 e.ignore();
73 return;
74 }
75 close();
76 }
77
79 }
void keyUpEvent(Tempest::KeyEvent &e)
void keyDownEvent(Tempest::KeyEvent &e)
void show(const Show &image)
void paintEvent(Tempest::PaintEvent &e)
void pushPause()
Definition gothic.cpp:451
static auto options() -> const Options &
Definition gothic.cpp:496
static float interfaceScale(const Tempest::Widget *w)
Definition gothic.cpp:471
void popPause()
Definition gothic.cpp:455
static Gothic & inst()
Definition gothic.cpp:249
void emitGlobalSoundWav(std::string_view wav)
Definition gothic.cpp:432
static const GthFont & font(const float scale)
static const Tempest::Texture2d * loadTexture(std::string_view name, bool forceMips=false)