Skip to content

Commit 4a3a947

Browse files
committed
fixes
1 parent b62b982 commit 4a3a947

File tree

12 files changed

+121
-80
lines changed

12 files changed

+121
-80
lines changed

src/ui/dom/Container.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,19 @@ void Container::UpdateMouseOver( GSE_CALLABLE ) {
161161
const bool Container::ProcessEvent( GSE_CALLABLE, const input::Event& event ) {
162162
switch ( event.type ) {
163163
case input::EV_MOUSE_OUT: {
164+
if ( !m_is_mouse_over ) {
165+
//return false; // TODO: why this breaks _hover styles?
166+
}
167+
m_is_mouse_over = false;
164168
if ( m_mouse_over_object ) {
165169
SetMouseOverChild( GSE_CALL, nullptr, { event.data.mouse.x, event.data.mouse.y } );
166170
}
167-
m_is_mouse_over = false;
168171
break;
169172
}
170173
case input::EV_MOUSE_OVER: {
174+
if ( m_is_mouse_over ) {
175+
//return false; // TODO: why this breaks _hover styles?
176+
}
171177
m_is_mouse_over = true;
172178
break;
173179
}
@@ -440,5 +446,14 @@ void Container::RemoveChild( GSE_CALLABLE, Object* obj, const bool nodestroy ) {
440446
}
441447
}
442448

449+
void Container::DetachUI() {
450+
for ( const auto& it : m_children ) {
451+
it.second->DetachUI();
452+
}
453+
Object::DetachUI();
454+
}
455+
456+
457+
443458
}
444459
}

src/ui/dom/Container.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Cache;
1414
}
1515

1616
namespace ui {
17+
18+
class UI;
19+
1720
namespace dom {
1821

1922
#define FACTORY( _name, _class ) Factory( GSE_CALL, _name, [ this ]( GSE_CALLABLE, const properties_t& p ) { return new _class( GSE_CALL, m_ui, m_factory_owner, p ); })
@@ -88,6 +91,10 @@ class Container : public Area {
8891
void AddChild( GSE_CALLABLE, Object* obj, const bool is_visible );
8992
void RemoveChild( GSE_CALLABLE, Object* obj, const bool nodestroy = false );
9093

94+
protected:
95+
friend class ui::UI;
96+
void DetachUI() override;
97+
9198
};
9299

93100
}

src/ui/dom/Drawable.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,6 @@ void Drawable::GeometryHandler( const geometry_handler_type_t type, const std::f
108108
m_geometry_handler_ids.push_back( m_geometry->AddHandler( type, f ) );
109109
}
110110

111-
const bool Drawable::ProcessEvent( GSE_CALLABLE, const input::Event& event ) {
112-
switch ( event.type ) {
113-
case input::EV_MOUSE_OVER: {
114-
m_is_mouse_over = true;
115-
break;
116-
}
117-
case input::EV_MOUSE_OUT: {
118-
m_is_mouse_over = false;
119-
break;
120-
}
121-
default: {
122-
}
123-
}
124-
return Object::ProcessEvent( GSE_CALL, event );
125-
}
126-
127111
void Drawable::Show() {
128112
if ( !m_is_visible ) {
129113
Object::Show();

src/ui/dom/Drawable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ class Drawable : public Object {
2222

2323
void GeometryHandler( const geometry_handler_type_t type, const std::function< void() >& f );
2424

25-
virtual const bool ProcessEvent( GSE_CALLABLE, const input::Event& event ) override;
26-
2725
void Show() override;
2826
void Hide() override;
2927

src/ui/dom/Object.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ void Object::Destroy( GSE_CALLABLE ) {
204204
}
205205
Hide();
206206
SetClasses( GSE_CALL, {} );
207-
if ( m_is_iterable_set ) {
208-
m_ui->RemoveIterable( this );
207+
if ( m_ui ) {
208+
if ( m_is_iterable_set ) {
209+
m_ui->RemoveIterable( this );
210+
}
209211
}
210212
{
211-
std::lock_guard guard( m_actors_mutex );
212213
auto* const scene = m_ui->GetScene();
214+
std::lock_guard guard( m_actors_mutex );
213215
for ( const auto& actor : m_actors ) {
214216
scene->RemoveActor( actor );
215217
}
@@ -324,6 +326,7 @@ void Object::Actor( scene::actor::Actor* actor ) {
324326
scene::actor::Actor::RF_IGNORE_CAMERA |
325327
scene::actor::Actor::RF_IGNORE_LIGHTING
326328
);
329+
ASSERT( m_ui, "ui detached" );
327330
m_ui->GetScene()->AddActor( actor );
328331
{
329332
std::lock_guard guard( m_actors_mutex );
@@ -337,15 +340,17 @@ void Object::ClearActors() {
337340
if ( g ) {
338341
g = g->AsRectangle();
339342
}
340-
auto* const scene = m_ui->GetScene();
341-
for ( const auto& actor : m_actors ) {
342-
scene->RemoveActor( actor );
343-
if ( g ) {
344-
((geometry::Rectangle*)g)->Clear();
343+
if ( m_ui ) {
344+
auto* const scene = m_ui->GetScene();
345+
for ( const auto& actor : m_actors ) {
346+
scene->RemoveActor( actor );
347+
if ( g ) {
348+
( (geometry::Rectangle*)g )->Clear();
349+
}
350+
delete actor;
345351
}
346-
delete actor;
352+
m_actors.clear();
347353
}
348-
m_actors.clear();
349354
}
350355

351356
void Object::Property( GSE_CALLABLE, const std::string& name, const gse::value_type_t& type, gse::Value* const default_value, const property_flag_t flags, const f_on_set_t& f_on_set, const f_on_unset_t& f_on_unset ) {
@@ -402,6 +407,7 @@ void Object::Iterable( const std::function< void() >& f ) {
402407
ASSERT( !m_is_destroyed, "Iterable: object is destroyed" );
403408
ASSERT( !m_is_iterable_set, "iterable already set" );
404409
m_is_iterable_set = true;
410+
ASSERT( m_ui, "ui detached" );
405411
m_ui->AddIterable( this, f );
406412
}
407413

@@ -542,13 +548,15 @@ void Object::Globalize( GSE_CALLABLE, const std::function< void() >& f_on_deglob
542548
if ( m_is_globalized ) {
543549
Deglobalize( GSE_CALL );
544550
}
551+
ASSERT( m_ui, "ui detached" );
545552
ASSERT( m_parent == m_ui->GetRoot(), "can only globalize children of root object" );
546553
m_ui->SetGlobalSingleton( GSE_CALL, this, f_on_deglobalize );
547554
m_is_globalized = true;
548555
}
549556

550557
void Object::Deglobalize( GSE_CALLABLE ) {
551558
if ( m_is_globalized ) {
559+
ASSERT( m_ui, "ui detached" );
552560
ASSERT( m_parent == m_ui->GetRoot(), "can only deglobalize children of root object" );
553561
m_ui->RemoveGlobalSingleton( GSE_CALL, this );
554562
m_is_globalized = false;
@@ -644,6 +652,7 @@ void Object::SetClasses( GSE_CALLABLE, const std::vector< std::string >& names )
644652
ASSERT( m_classes.empty(), "not initialized but classes not empty" );
645653
}
646654
m_classes.reserve( names.size() );
655+
ASSERT( m_ui, "ui detached" );
647656
for ( const auto& name : names ) {
648657
auto* c = m_ui->GetClass( name );
649658
if ( !c ) {
@@ -714,5 +723,10 @@ void Object::UnsetPropertyFromClass( GSE_CALLABLE, const std::string& key ) {
714723
}
715724
}
716725

726+
void Object::DetachUI() {
727+
ASSERT( m_ui, "ui already detached" );
728+
m_ui = nullptr;
729+
}
730+
717731
}
718732
}

src/ui/dom/Object.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Object : public gse::GCWrappable {
9999

100100
void UpdateProperty( const std::string& name, gse::Value* const v );
101101

102-
UI* const m_ui;
102+
UI* m_ui;
103103
gc::Space* const m_gc_space;
104104
const properties_t m_initial_properties;
105105

@@ -179,6 +179,9 @@ class Object : public gse::GCWrappable {
179179
virtual void SetPropertyFromClass( GSE_CALLABLE, const std::string& key, gse::Value* const value, const class_modifier_t modifier );
180180
virtual void UnsetPropertyFromClass( GSE_CALLABLE, const std::string& key );
181181

182+
protected:
183+
friend class ui::UI;
184+
virtual void DetachUI();
182185
};
183186

184187
}

src/ui/dom/Panel.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,29 @@ void Panel::UpdateBorderTexture() {
7070
m_surface->GetGeometry()->SetPadding( std::ceil( m_border_corners / 2 ) );
7171
auto* texture = m_border_surface->GetOwnedTexturePtr();
7272
const auto& a = m_geometry->AsRectangle()->m_area;
73-
if ( texture->Resize( std::round( a.width ), std::round( a.height ) ) ) {
74-
auto* bitmap = texture->GetBitmap();
75-
if ( bitmap ) {
76-
memset( bitmap, 0, texture->GetBitmapSize() );
77-
if ( m_border_color != types::Color{} ) {
78-
long int r = std::ceil( std::fmin( m_border_corners, std::min( a.width, a.height ) / 2 - 1 ) );
79-
for ( auto x = r ; x < a.width - r ; x++ ) {
80-
texture->SetPixel( x, 0, m_border_color );
81-
texture->SetPixel( x, a.height - 1, m_border_color );
82-
}
83-
for ( auto y = r ; y < a.height - r ; y++ ) {
84-
texture->SetPixel( 0, y, m_border_color );
85-
texture->SetPixel( a.width - 1, y, m_border_color );
86-
}
87-
for ( auto i = 0 ; i < r ; i++ ) {
88-
texture->SetPixel( i, r - i, m_border_color );
89-
texture->SetPixel( r - i, i, m_border_color );
90-
texture->SetPixel( a.width - 1 - i, r - i, m_border_color );
91-
texture->SetPixel( a.width - 1 - ( r - i ), i, m_border_color );
92-
texture->SetPixel( a.width - 1 - i, a.height - 1 - ( r - i ), m_border_color );
93-
texture->SetPixel( a.width - 1 - ( r - i ), a.height - 1 - i, m_border_color );
94-
texture->SetPixel( i, a.height - 1 - ( r - i ), m_border_color );
95-
texture->SetPixel( r - i, a.height - 1 - i, m_border_color );
96-
}
73+
texture->Resize( std::round( a.width ), std::round( a.height ) );
74+
auto* bitmap = texture->GetBitmap();
75+
if ( bitmap ) {
76+
memset( bitmap, 0, texture->GetBitmapSize() );
77+
if ( m_border_color != types::Color{} ) {
78+
long int r = std::ceil( std::fmin( m_border_corners, std::min( a.width, a.height ) / 2 - 1 ) );
79+
for ( auto x = r ; x < a.width - r ; x++ ) {
80+
texture->SetPixel( x, 0, m_border_color );
81+
texture->SetPixel( x, a.height - 1, m_border_color );
82+
}
83+
for ( auto y = r ; y < a.height - r ; y++ ) {
84+
texture->SetPixel( 0, y, m_border_color );
85+
texture->SetPixel( a.width - 1, y, m_border_color );
86+
}
87+
for ( auto i = 0 ; i < r ; i++ ) {
88+
texture->SetPixel( i, r - i, m_border_color );
89+
texture->SetPixel( r - i, i, m_border_color );
90+
texture->SetPixel( a.width - 1 - i, r - i, m_border_color );
91+
texture->SetPixel( a.width - 1 - ( r - i ), i, m_border_color );
92+
texture->SetPixel( a.width - 1 - i, a.height - 1 - ( r - i ), m_border_color );
93+
texture->SetPixel( a.width - 1 - ( r - i ), a.height - 1 - i, m_border_color );
94+
texture->SetPixel( i, a.height - 1 - ( r - i ), m_border_color );
95+
texture->SetPixel( r - i, a.height - 1 - i, m_border_color );
9796
}
9897
}
9998
texture->FullUpdate(); // TODO: optimize?

src/ui/dom/Root.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Root::Root( GSE_CALLABLE, UI* const ui )
1717
Show();
1818
}
1919

20+
Root::~Root() {
21+
Container::DetachUI();
22+
}
23+
2024
void Root::Resize( const uint16_t window_width, const uint16_t window_height ) {
2125
m_geometry->SetWidth( window_width );
2226
m_geometry->SetHeight( window_height );

src/ui/dom/Root.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace dom {
1111
class Root : public Container {
1212
public:
1313
Root( GSE_CALLABLE, UI* const ui );
14+
virtual ~Root();
1415

1516
private:
1617
friend class ui::UI;

src/ui/dom/Scrollview.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Scrollview::Scrollview( DOM_ARGS_T, const bool factories_allowed )
2626
auto* g = m_inner->GetGeometry();
2727
g->SetParent( m_geometry );
2828
g->SetOverflowMode( geometry::Geometry::OM_RESIZE );
29+
g->SetLeft( 0 );
30+
g->SetTop( 0 );
2931
g->m_on_resize = [ this ]( const size_t width, const size_t height ) {
3032
if ( !m_is_updating ) {
3133
m_is_updating = true;
@@ -175,6 +177,9 @@ void Scrollview::UpdateScrollbars( size_t width, size_t height ) {
175177
height = g->GetInnerHeight();
176178
}
177179

180+
ASSERT( width < VERY_BIG_NUMBER, "scrollbars width overflow" );
181+
ASSERT( height < VERY_BIG_NUMBER, "scrollbars height overflow" );
182+
178183
const auto vscroll_w = m_vscroll->GetGeometry()->m_area.width;
179184
const auto hscroll_h = m_hscroll->GetGeometry()->m_area.height;
180185
auto outer_w = m_geometry->m_area.width;

0 commit comments

Comments
 (0)