Skip to content

Commit ba63448

Browse files
committed
feat: fade out the background behind dialog windows
1 parent ef1e3e5 commit ba63448

File tree

7 files changed

+94
-5
lines changed

7 files changed

+94
-5
lines changed

resources/base_config/zquest.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ merge_cpane_compact = 1
2525
zoom_fav_compact = 1
2626
zoom_cmd_compact = 1
2727

28+
dlg_tint_r = 0
29+
dlg_tint_g = 0
30+
dlg_tint_b = 0
31+
dlg_tint_a = 128
32+
2833
[Theme]
2934
theme_filename = themes/mooshmood.ztheme
3035

src/base/render.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ void RenderTreeItem::remove_child(RenderTreeItem* child)
3030
child->parent = nullptr;
3131
}
3232
}
33-
const std::vector<RenderTreeItem*>& RenderTreeItem::get_children() const
33+
std::vector<RenderTreeItem*> const& RenderTreeItem::get_children() const
34+
{
35+
return children;
36+
}
37+
std::vector<RenderTreeItem*>& RenderTreeItem::get_children()
3438
{
3539
return children;
3640
}
@@ -162,6 +166,9 @@ RenderTreeItem::~RenderTreeItem()
162166
al_destroy_bitmap(bitmap);
163167
if(a4_bitmap)
164168
destroy_bitmap(a4_bitmap);
169+
}
170+
if(owned_tint)
171+
{
165172
if(tint)
166173
delete tint;
167174
}
@@ -347,6 +354,7 @@ static void render_tree_draw_item(RenderTreeItem* rti)
347354
int th = y1 - y0;
348355
if (rti->tint)
349356
{
357+
al_draw_scaled_bitmap(rti->bitmap, 0, 0, w, h, x0, y0, tw, th, 0);
350358
al_draw_tinted_scaled_bitmap(rti->bitmap, *rti->tint, 0, 0, w, h, x0, y0, tw, th, 0);
351359
}
352360
else
@@ -643,3 +651,35 @@ void remove_dlg_layer(RenderTreeItem* rti)
643651
}
644652
delete rti;
645653
}
654+
655+
ALLEGRO_COLOR dialog_tint = al_premul_rgba(0, 0, 0, 64);
656+
ALLEGRO_COLOR* override_dlg_tint = nullptr;
657+
static size_t dlg_tint_pause = 0;
658+
void reload_dialog_tints()
659+
{
660+
std::vector<RenderTreeItem*>& children = rti_dialogs.get_children();
661+
if(children.empty()) return;
662+
for(size_t q = 0; q < children.size()-1; ++q)
663+
{
664+
children[q]->tint = dlg_tint_pause ? nullptr :
665+
(override_dlg_tint ? override_dlg_tint : &dialog_tint);
666+
}
667+
children.back()->tint = nullptr;
668+
}
669+
ALLEGRO_COLOR& get_dlg_tint()
670+
{
671+
return override_dlg_tint ? *override_dlg_tint : dialog_tint;
672+
}
673+
void pause_dlg_tint(bool pause)
674+
{
675+
if(pause)
676+
++dlg_tint_pause;
677+
else if(dlg_tint_pause)
678+
--dlg_tint_pause;
679+
}
680+
bool dlg_tint_paused()
681+
{
682+
return dlg_tint_pause;
683+
}
684+
685+

src/base/render.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,16 @@ class RenderTreeItem
9797
BITMAP* a4_bitmap = nullptr;
9898
bool freeze_a4_bitmap_render = false;
9999
ALLEGRO_COLOR* tint = nullptr;
100-
bool owned = false;
100+
bool owned = false, owned_tint = false;
101101

102102
RenderTreeItem(std::string name, RenderTreeItem* parent = nullptr);
103103
~RenderTreeItem();
104104

105105
void add_child(RenderTreeItem* child);
106106
void add_child_before(RenderTreeItem* child, RenderTreeItem* before_child);
107107
void remove_child(RenderTreeItem* child);
108-
const std::vector<RenderTreeItem*>& get_children() const;
108+
std::vector<RenderTreeItem*>& get_children();
109+
std::vector<RenderTreeItem*> const& get_children() const;
109110
bool has_children() const;
110111
void handle_dirty();
111112
void mark_dirty();
@@ -167,11 +168,16 @@ void zc_set_palette_range(PALETTE pal, int start, int end, bool=false);
167168
void render_a4_a5(BITMAP* src,int sx,int sy,int dx,int dy,int w,int h,int maskind = 0,uint32_t* backpal = nullptr);
168169

169170
extern BITMAP* zqdialog_bg_bmp;
171+
extern ALLEGRO_COLOR* override_dlg_tint;
170172
void popup_zqdialog_start(int x = 0, int y = 0, int w = -1, int h = -1, int transp = 0xFF);
171173
void popup_zqdialog_end();
172174
void popup_zqdialog_start_a5();
173175
void popup_zqdialog_end_a5();
174176
RenderTreeItem* add_dlg_layer(int x = 0, int y = 0, int w = -1, int h = -1);
175177
void remove_dlg_layer(RenderTreeItem* rti);
178+
void reload_dialog_tints();
179+
ALLEGRO_COLOR& get_dlg_tint();
180+
void pause_dlg_tint(bool pause);
181+
bool dlg_tint_paused();
176182

177183
#endif

src/launcher/launcher.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ static void configure_render_tree()
575575
});
576576
rti_dialogs.visible = true;
577577
}
578+
reload_dialog_tints();
578579
}
579580

580581
static void render_launcher()

src/zc/render.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ static void configure_render_tree()
252252
rti_game.tint = nullptr;
253253
rti_infolayer.tint = nullptr;
254254
}
255+
reload_dialog_tints();
255256
}
256257

257258
static ALLEGRO_STATE infobmp_old_state;

src/zq/render.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ static RenderTreeItem rti_root("root");
99
static RenderTreeItem rti_screen("screen");
1010
static RenderTreeItem rti_mmap("mmap");
1111
static RenderTreeItem rti_tooltip("tooltip");
12+
static RenderTreeItem rti_tint("tint");
1213

1314
static int zc_gui_mouse_x()
1415
{
@@ -44,13 +45,17 @@ static void init_render_tree()
4445
rti_tooltip.transparency_index = 0;
4546
clear_bitmap(rti_tooltip.a4_bitmap);
4647

48+
rti_tint.bitmap = create_a5_bitmap(screen->w, screen->h);
49+
rti_tint.visible = false;
50+
4751
set_bitmap_create_flags(true);
4852
rti_mmap.bitmap = create_a5_bitmap(screen->w, screen->h);
4953

5054
rti_screen.add_child(&rti_mmap);
5155

5256
rti_root.add_child(&rti_screen);
5357
rti_root.add_child(&rti_tooltip);
58+
rti_root.add_child(&rti_tint);
5459
rti_root.add_child(&rti_dialogs);
5560

5661
gui_mouse_x = zc_gui_mouse_x;
@@ -64,7 +69,7 @@ static void init_render_tree()
6469
static void configure_render_tree()
6570
{
6671
static bool scaling_force_integer = zc_get_config("zquest", "scaling_force_integer", 0) != 0;
67-
72+
6873
int resx = al_get_display_width(all_get_display());
6974
int resy = al_get_display_height(all_get_display());
7075

@@ -107,9 +112,38 @@ static void configure_render_tree()
107112
.xscale = xscale,
108113
.yscale = yscale,
109114
});
115+
rti_tint.set_transform({
116+
.x = (int)(resx - w*xscale) / 2,
117+
.y = (int)(resy - h*yscale) / 2,
118+
.xscale = xscale,
119+
.yscale = yscale,
120+
});
110121
}
111-
122+
112123
rti_dialogs.visible = rti_dialogs.has_children();
124+
rti_tint.visible = rti_dialogs.visible && !dlg_tint_paused();
125+
126+
if(rti_dialogs.visible)
127+
{
128+
auto& tint = get_dlg_tint();
129+
if(!override_dlg_tint)
130+
{
131+
tint = al_premul_rgba(
132+
zc_get_config("ZQ_GUI","dlg_tint_r",0),
133+
zc_get_config("ZQ_GUI","dlg_tint_g",0),
134+
zc_get_config("ZQ_GUI","dlg_tint_b",0),
135+
zc_get_config("ZQ_GUI","dlg_tint_a",128)
136+
);
137+
}
138+
139+
ALLEGRO_STATE oldstate;
140+
al_store_state(&oldstate, ALLEGRO_STATE_TARGET_BITMAP);
141+
al_set_target_bitmap(rti_tint.bitmap);
142+
al_clear_to_color(tint);
143+
al_restore_state(&oldstate);
144+
}
145+
146+
reload_dialog_tints();
113147
}
114148

115149
ALLEGRO_BITMAP* get_overlay_bmp()

src/zq/zquest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14805,6 +14805,7 @@ int32_t onScreenPalette()
1480514805

1480614806
large_dialog(screen_pal_dlg);
1480714807
auto old_valid = Map.CurrScr()->valid;
14808+
pause_dlg_tint(true);
1480814809
while(true)
1480914810
{
1481014811
auto ret = do_zqdialog(screen_pal_dlg,2);
@@ -14830,6 +14831,7 @@ int32_t onScreenPalette()
1483014831
break;
1483114832
}
1483214833
}
14834+
pause_dlg_tint(false);
1483314835

1483414836
rebuild_trans_table();
1483514837

0 commit comments

Comments
 (0)