profile
viewpoint
Gleb Mazovetskiy glebm Google London https://twitter.com/glebm Open-source all the things.

diasurgical/devilutionX 2758

Diablo build for modern operating systems

brianhempel/active_record_union 372

UNIONs in ActiveRecord! Adds proper union and union_all methods to ActiveRecord::Relation.

cvrebert/lmvtfy 299

LMVTFY: Let Me Validate That For You

glebm/authlogic_openid 3

Extension of the Authlogic library to add OpenID support.

glebm/blog-glebm-com 3

Sources for blog.glebm.com

glebm/actionmailer_inline_css 2

Seamlessly integrate Alex Dunae's premailer with ActionMailer.

glebm/active_merchant 1

Active Merchant is a simple payment abstraction library used in and sponsored by Shopify. It is written by Tobias Luetke, Cody Fauser, and contributors. The aim of the project is to feel natural to Ruby users and to abstract as many parts as possible away from the user to offer a consistent interface across all supported gateways.

glebm/apache_config 1

Apache config parser and printer

glebm/bootstrap-wysihtml5-rails 1

WYSIWYG editor for Bootstrap, integrated in Rails assets pipeline

glebm/activerecord-import 0

Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyon

startedArkq/bluez-alsa

started time in 2 days

startedvicwomg/pikaraoke

started time in 3 days

startedSimonIT/spotifylyrics

started time in 3 days

startedgedrick/SpotifyKaraoke

started time in 3 days

startedImperialCollegeLondon/sharpy

started time in 6 days

startedddrone/language

started time in 22 days

pull request commentjiaaro/pydub

utils.py: Fix "invalid escape sequence \(" warning

Please merge?

glebm

comment created time in a month

issue closedwaxeye-org/waxeye

Online demo fails on case insensitive quoted strings

I typed this grammar into the online demo:

A <- "a"

I expected it to work equivalently to this one:

A <- [aA]

However, it failed to compile with the following error message:

RacketContractError: memf: contract violation
  expected: (any/c . -> any/c)
  given: #<void>
    at https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:1988:14
    at Object.makeArgumentError (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:2048:12)
    at Object.argerror (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:4399:48)
    at Object.memf (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:14319:27)
    at visit_case_literal (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25591:12)
    at visit_exp1743 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25433:32)
    at loop1626 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11615:11)
    at cl965 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11620:23)
    at Object.<anonymous> (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11692:27)
    at lift_only_sub_exp1735 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25368:10)
    at visit_sequence1741 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25390:14)
    at loop1626 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11615:11)
    at cl965 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11620:23)
    at Object.<anonymous> (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11692:27)
    at lift_only_sub_exp1735 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25368:10)
    at visit_alternation1740 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25383:14)
    at expand_def1751 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25496:14)
    at loop1626 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11615:11)
    at cl965 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11620:23)
    at Object.<anonymous> (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:11692:27)
    at Object.expand_grammar (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25498:15)
    at Object.transform_grammar (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:25941:32)
    at transform_and_set_start32 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:28494:10)
    at cl3 (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:28506:12)
    at https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:28520:25
    at Object.generate_parser [as generateParser] (https://waxeye-org.github.io/waxeye/genfiles/racketscript-waxeye-compiler.js:28552:22)
    at safeWaxeyeCompiler (https://waxeye-org.github.io/waxeye/demo.js:39:36)
    at compile (https://waxeye-org.github.io/waxeye/demo.js:47:43)
    at https://waxeye-org.github.io/waxeye/demo.js:155:11

closed time in a month

bkil

issue commentwaxeye-org/waxeye

Online demo fails on case insensitive quoted strings

Fixed! I've adds the missing functions to RacketScript and re-deployed the demo site

bkil

comment created time in a month

push eventwaxeye-org/waxeye

Gleb Mazovetskiy

commit sha 7a17abef175bef4efd9ff721ac6d833fa82c1f77

gh-pages built at 723da0475fc0c8e3dd43da46665ef7c62734857b (master)

view details

push time in a month

push eventwaxeye-org/waxeye

Gleb Mazovetskiy

commit sha 723da0475fc0c8e3dd43da46665ef7c62734857b

Web demo: Work around traceur compilation issue It adds `export {__rjs_quoted__};` to the end of the file, which is a syntax error in a non-module file.

view details

push time in a month

push eventwaxeye-org/waxeye

Gleb Mazovetskiy

commit sha 08c238ea4fde4fda912f78b9e523755425f2c5fb

Update nodejs dependencies

view details

push time in a month

delete branch glebm/racketscript

delete branch : char-fns

delete time in a month

push eventglebm/racketscript

Gleb Mazovetskiy

commit sha b0843d4217947f4a593e3f6e3b8254a2a4ffcabd

Implement more char functions 1. All `char-*?` Unicode property test methods. 2. `char-upcase` and `char-downcase`. Fixes #170

view details

push time in a month

push eventglebm/racketscript

Gleb Mazovetskiy

commit sha a23d9c3513e3980bf3cbbe0342d03428515c1587

Implement more char functions 1. All `char-*?` Unicode property test methods. 2. `char-upcase` and `char-downcase`. Fixes #170

view details

push time in a month

PR opened vishesh/racketscript

Implement more char functions
  1. All char-*? Unicode property test methods.
  2. char-upcase and char-downcase.

Fixes #170

+237 -55

0 comment

5 changed files

pr created time in a month

push eventglebm/racketscript

Gleb Mazovetskiy

commit sha b8a4fbcac5fdb5fc0ccc70a703ed0f64af92febb

Implement more char functions 1. All `char-*?` Unicode property test methods. 2. `char-upcase` and `char-downcase`. Fixes #170

view details

push time in a month

push eventglebm/racketscript

Gleb Mazovetskiy

commit sha 0682a551696d34dd7a9d028ac06c3c803139d1b3

Implement more char functions 1. All `char-*?` Unicode property test methods. 2. `char-upcase` and `char-downcase`. Fixes #170

view details

push time in a month

create barnchglebm/racketscript

branch : char-fns

created branch time in a month

issue commentwaxeye-org/waxeye

Online demo fails on case insensitive quoted strings

Filed https://github.com/vishesh/racketscript/issues/170

bkil

comment created time in a month

issue openedvishesh/racketscript

Implement Unicode property testing functions (e.g. `char-alphabetic?`)

Now that browsers support Unicode property escapes, we can finally implement Unicode property testing functions in RacketScript.

created time in a month

issue commentwaxeye-org/waxeye

Online demo fails on case insensitive quoted strings

Perhaps RacketScript does not implement char-alphabetic?

bkil

comment created time in a month

issue closedtwbs/bootstrap-rubygem

Changelog for latest releases

Hi, seems several latest releases do not have a changelog (not in changelog file nor in GitHub releases page) Could this be fixed? I've using dependabot to update my requirements and empty changelog is not very good on upgrade process

closed time in a month

ShockwaveNN

issue commenttwbs/bootstrap-rubygem

Changelog for latest releases

There were no changes to the gem-specific code since the last entry. The changelog for Bootstrap itself is available here https://github.com/twbs/bootstrap/releases and won't be duplicated in this repo.

ShockwaveNN

comment created time in a month

pull request commenttwbs/bootstrap

Update current_ruby_version to 5.0.0.alpha1

The hyphen is not a valid character for a rubygem version IIRC

glebm

comment created time in a month

create barnchtwbs/bootstrap

branch : glebm-patch-1

created branch time in a month

PR opened twbs/bootstrap

Update current_ruby_version to 5.0.0.alpha1
+1 -1

0 comment

1 changed file

pr created time in a month

issue closedtwbs/bootstrap-rubygem

5.0.0-alpha1 not available

According to the Bootstrap v5 documentation, there should be a Bootstrap 5 alpha-version of the gem: https://v5.getbootstrap.com/docs/5.0/getting-started/download/

However it doesn't seem to be the case: https://rubygems.org/gems/bootstrap

closed time in a month

arndeash

issue commenttwbs/bootstrap-rubygem

5.0.0-alpha1 not available

5.0.0.alpha1 released

arndeash

comment created time in a month

created tagtwbs/bootstrap-rubygem

tagv5.0.0.alpha1

Bootstrap 4 rubygem for Rails / Sprockets / Hanami / etc

created time in a month

push eventtwbs/bootstrap-rubygem

Gleb Mazovetskiy

commit sha 43f87174d8d3a9b473c12fd807511b46bf7b4bd4

updater/js.rb: Update paths for v5

view details

Gleb Mazovetskiy

commit sha 7a49218515236263500473bae362eecfd8884435

rake update[a1708ec2a38d331c4c9eacac08ce9c9839649476]

view details

Gleb Mazovetskiy

commit sha 953fc5083026e5c1b7756d122956db65344ddcb3

Bump to v5.0.0.alpha1

view details

push time in a month

created tagtwbs/bootstrap-rubygem

tagv4.5.2

Bootstrap 4 rubygem for Rails / Sprockets / Hanami / etc

created time in 2 months

create barnchtwbs/bootstrap-rubygem

branch : 4.5-stable

created branch time in 2 months

push eventtwbs/bootstrap-rubygem

Gleb Mazovetskiy

commit sha 3fdec8b995d200174099adbfec898c5677918868

rake update[v4.5.2]

view details

Gleb Mazovetskiy

commit sha ca9e27946b00f0600ed3ca346e09ca0bb7e12899

Bump to v4.5.2

view details

push time in 2 months

startediooxa/article

started time in 2 months

PR opened jiaaro/pydub

utils.py: Fix "invalid escape sequence \(" warning
+4 -4

0 comment

1 changed file

pr created time in 2 months

push eventglebm/pydub

Gleb Mazovetskiy

commit sha 5658398518f84a7669ba75b8abbb368ce48e145d

utils.py: Fix "invalid escape sequence \(" warning

view details

push time in 2 months

fork glebm/pydub

Manipulate audio with a simple and easy high level interface

http://pydub.com

fork in 2 months

startedodashi/latexify_py

started time in 2 months

Pull request review commentdiasurgical/devilutionX

Fix compilation on Switch

 set(PORTLIBS_PATH ${DEVKITPRO}/portlibs) set(PORTLIBS ${PORTLIBS_PATH}/switch)
 set(CMAKE_FIND_ROOT_PATH ${DEVKITA64} ${LIBNX} ${PORTLIBS})
 
+# Allow FIND_PACKAGE to find SDL2_ttf and other libraries
+set(CMAKE_PREFIX_PATH "${DEVKITPRO}/portlibs/switch/")

Strange that this is needed. We already have ${PORTLIBS} in CMAKE_FIND_ROOT_PATH (line 24).

rsn8887

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 void Render(const UiScrollBar &ui_sb) 	{
 		const SDL_Rect rect = UpArrowRect(ui_sb);
 		const int frame = static_cast<int>(scrollBarState.upArrowPressed ? ScrollBarArrowFrame_UP_ACTIVE : ScrollBarArrowFrame_UP);
-		DrawArt(rect.x, rect.y, ui_sb.arrow, frame, rect.w);
+		DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
 	}
 	{
 		const SDL_Rect rect = DownArrowRect(ui_sb);
 		const int frame = static_cast<int>(scrollBarState.downArrowPressed ? ScrollBarArrowFrame_DOWN_ACTIVE : ScrollBarArrowFrame_DOWN);
-		DrawArt(rect.x, rect.y, ui_sb.arrow, frame, rect.w);
+		DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
 	}
 
 	// Thumb:
-	{
+	if (SelectedItemMax - SelectedItemMin > 0) {
 		const SDL_Rect rect = ThumbRect(
 		    ui_sb, SelectedItem - SelectedItemMin, SelectedItemMax - SelectedItemMin + 1);
-		DrawArt(rect.x, rect.y, ui_sb.thumb);
+		DrawArt(rect.x, rect.y, ui_sb->m_thumb);
 	}
 }
 
-void Render(const UiEdit &ui_edit)
+void Render(const UiEdit *ui_edit)
 {
-	DrawSelector(ui_edit.rect);
-	SDL_Rect rect = ui_edit.rect;
+	DrawSelector(ui_edit->m_rect);
+	SDL_Rect rect = ui_edit->m_rect;
 	rect.x += 43;
 	rect.y += 1;
 	rect.w -= 86;
-	DrawArtStr(ui_edit.value, rect, ui_edit.flags, /*drawTextCursor=*/true);
+	DrawArtStr(ui_edit->m_value, rect, ui_edit->m_iFlags, /*drawTextCursor=*/true);
 }
 
-void RenderItem(UiItem *item)
+void RenderItem(UiItemBase *item)
 {
 	if (item->has_flag(UIS_HIDDEN))
 		return;
-	switch (item->type) {
+	switch (item->m_type) {
 	case UI_TEXT:
-		Render(&item->text);
+		Render((UiText *)item);
 		break;
 	case UI_ART_TEXT:
-		Render(item->art_text);
+		Render((UiArtText *)item);
 		break;
 	case UI_IMAGE:
-		Render(item->image);
+		Render((UiImage *)item);
 		break;
 	case UI_ART_TEXT_BUTTON:
-		Render(item->art_text_button);
+		Render((UiArtTextButton *)item);
 		break;
 	case UI_BUTTON:
-		RenderButton(&item->button);
+		RenderButton((UiButton *)item);
 		break;
 	case UI_LIST:
-		Render(item->list);
+		Render((UiList *)item);
 		break;
 	case UI_SCROLLBAR:
-		Render(item->scrollbar);
+		Render((UiScrollBar *)item);
 		break;
 	case UI_EDIT:
-		Render(item->edit);
+		Render((UiEdit *)item);
 		break;
 	}
 }
 
-bool HandleMouseEventArtTextButton(const SDL_Event &event, const UiArtTextButton &ui_button)
+bool HandleMouseEventArtTextButton(const SDL_Event &event, UiArtTextButton *ui_button)

The itemRect function should be marked const

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 enum UiFlags { 	UIS_HIDDEN = 1 << 10,
 };
 
-struct UiItemBase {
-	constexpr UiItemBase(SDL_Rect rect, int flags)
-	    : rect(rect)
-	    , flags(flags)
+class UiItemBase {
+public:
+	UiItemBase(SDL_Rect rect, int flags)
 	{
-	}
+		m_rect = rect;
+		m_iFlags = flags;
+	};
+
+	UiItemBase(Sint16 x, Sint16 y, Uint16 item_width, Uint16 item_height, int flags)
+	{
+		SDL_Rect tmp;
+		tmp.x = x;
+		tmp.y = y;
+		tmp.w = item_width;
+		tmp.h = item_height;
+
+		m_rect = tmp;
+		m_iFlags = flags;
+	};
+
+	virtual ~UiItemBase() {};
 
 	bool has_flag(UiFlags flag) const
 	{
-		return flags & flag;
+		return m_iFlags & flag;
 	}
 
 	bool has_any_flag(int flags) const
 	{
-		return (this->flags & flags) != 0;
+		return (m_iFlags & flags) != 0;
 	}
 
 	void add_flag(UiFlags flag)
 	{
-		flags |= flag;
+		m_iFlags |= flag;
 	}
 
 	void remove_flag(UiFlags flag)
 	{
-		flags &= ~flag;
+		m_iFlags &= ~flag;
 	}
 
-	SDL_Rect rect;
-	int flags;
+	//protected:
+	UiType m_type;
+	SDL_Rect m_rect;
+	int m_iFlags;
 };
 
-struct UiImage : public UiItemBase {
-	constexpr UiImage(Art *art, bool animated, int frame, SDL_Rect rect, int flags = 0)
+//=============================================================================
+
+class UiImage : public UiItemBase {
+public:
+	UiImage(Art *art, SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , art(art)
-	    , animated(animated)
-	    , frame(frame)
 	{
-	}
+		m_type = UI_IMAGE;
+		m_art = art;
+		m_animated = false;
+		m_frame = 0;
+	};
 
-	constexpr UiImage(Art *art, int frame, SDL_Rect rect, int flags = 0)
-	    : UiImage(art, /*animated=*/false, frame, rect, flags)
+	UiImage(Art *art, bool bAnimated, int iFrame, SDL_Rect rect, int flags)
+	    : UiItemBase(rect, flags)
 	{
-	}
+		m_type = UI_IMAGE;
+		m_art = art;
+		m_animated = bAnimated;
+		m_frame = iFrame;
+	};
 
-	constexpr UiImage(Art *art, SDL_Rect rect, int flags = 0)
-	    : UiImage(art, /*frame=*/0, rect, flags)
+	UiImage(Art *art, int frame, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
+		m_type = UI_IMAGE;
+		m_art = art;
+		m_animated = false;
+		m_frame = frame;
 	}
 
-	Art *art;
-	bool animated;
-	int frame;
+	~UiImage() {};
+
+	//private:
+	Art *m_art;
+	bool m_animated;
+	int m_frame;
 };
 
-// Plain text (TTF).
-struct UiText : public UiItemBase {
-	constexpr UiText(const char *text, SDL_Color color, SDL_Rect rect, int flags = 0)
-	    : UiItemBase(rect, flags)
-	    , color(color)
-	    , shadow_color { 0, 0, 0, 0 }
-	    , text(text)
-	    , render_cache(NULL)
-	{
-	}
+//=============================================================================
 
-	constexpr UiText(const char *text, SDL_Rect rect, int flags = 0)
-	    : UiText(text, SDL_Color { 243, 243, 243, 0 }, rect, flags)
+class UiArtText : public UiItemBase {
+public:
+	UiArtText(const char *text, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
-	}
-
-	SDL_Color color;
-	SDL_Color shadow_color;
-	const char *text;
+		m_type = UI_ART_TEXT;
+		m_text = text;
+	};
 
-	// State:
-	TtfSurfaceCache *render_cache;
+	~UiArtText() {};
 
-	void FreeCache()
-	{
-		delete render_cache;
-		render_cache = NULL;
-	}
+	//private:
+	const char *m_text;
 };
 
-// Text drawn with Diablo sprites.
-struct UiArtText : public UiItemBase {
-	constexpr UiArtText(const char *text, SDL_Rect rect, int flags = 0)
+//=============================================================================
+
+class UiScrollBar : public UiItemBase {
+public:
+	UiScrollBar(Art *bg, Art *thumb, Art *arrow, SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , text(text)
 	{
-	}
+		m_type = UI_SCROLLBAR;
+		m_bg = bg;
+		m_thumb = thumb;
+		m_arrow = arrow;
+	};
 
-	const char *text;
+	//private:
+	Art *m_bg;
+	Art *m_thumb;
+	Art *m_arrow;
 };
 
-// Clickable Diablo sprites text.
-struct UiArtTextButton : public UiItemBase {
-	constexpr UiArtTextButton(const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
+//=============================================================================
+
+class UiArtTextButton : public UiItemBase {
+public:
+	UiArtTextButton(const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , text(text)
-	    , action(action)
 	{
-	}
-
-	const char *text;
-	void (*action)();
+		m_type = UI_ART_TEXT_BUTTON;
+		m_text = text;
+		m_action = action;
+	};
+	//private:
+	const char *m_text;
+	void (*m_action)();
 };
 
-// A button (uses Diablo sprites).
-struct UiButton : public UiItemBase {
-	enum FrameKey {
-		DEFAULT = 0,
-		PRESSED,
-		DISABLED
-	};
+//=============================================================================
 
-	constexpr UiButton(Art *art, const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
+class UiEdit : public UiItemBase {
+public:
+	UiEdit(char *value, std::size_t max_length, SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , art(art)
-	    , text(text)
-	    , action(action)
-	    , pressed(false)
-	    , render_cache(NULL)
 	{
+		m_type = UI_EDIT;
+		m_value = value;
+		m_max_length = max_length;
 	}
 
-	Art *art;
+	//private:
+	char *m_value;
+	std::size_t m_max_length;
+};
 
-	const char *text;
-	void (*action)();
+//=============================================================================
 
-	// State
-	bool pressed;
-	TtfSurfaceCache *render_cache;
+// Plain text (TTF)
 
-	void FreeCache()
+class UiText : public UiItemBase {
+public:
+	UiText(const char *text, SDL_Color color1, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
-		delete render_cache;
-		render_cache = NULL;
-	}
-};
+		m_type = UI_TEXT;
+		m_color = color1;
 
-struct UiListItem {
-	constexpr UiListItem(const char *text = "", int value = 0)
-	    : text(text)
-	    , value(value)
-	{
+		SDL_Color color2 = { 0, 0, 0, 0 };
+		m_shadow_color = color2;
+
+		m_text = text;
+		m_render_cache = NULL;
 	}
-	const char *text;
-	int value;
-};
 
-struct UiList : public UiItemBase {
-	template <std::size_t N>
-	constexpr UiList(
-	    UiListItem (&items)[N],
-	    Sint16 x,
-	    Sint16 y,
-	    Uint16 item_width,
-	    Uint16 item_height,
-	    int flags)
-	    : UiItemBase({ x, y, item_width, static_cast<Uint16>(item_height * N) }, flags)
-	    , x(x)
-	    , y(y)
-	    , item_width(item_width)
-	    , item_height(item_height)
-	    , items(items)
-	    , length(N)
+	UiText(const char *text, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
-	}
+		m_type = UI_TEXT;
 
-	Sint16 x;
-	Sint16 y;
-	Uint16 item_width;
-	Uint16 item_height;
-	UiListItem *items;
-	std::size_t length;
+		SDL_Color color1 = { 243, 243, 243, 0 };
+		m_color = color1;
 
-	SDL_Rect itemRect(std::size_t i) const
-	{
-		return { x, static_cast<Sint16>(y + item_height * i), item_width, item_height };
+		SDL_Color color2 = { 0, 0, 0, 0 };
+		m_shadow_color = color2;
+
+		m_text = text;
+		m_render_cache = NULL;
 	}
 
-	UiListItem *itemAt(Sint16 y) const
+	//private:
+	SDL_Color m_color;
+	SDL_Color m_shadow_color;
+	const char *m_text;
+
+	// State:
+	TtfSurfaceCache *m_render_cache;
+
+	virtual void FreeCache()
 	{
-		ASSERT(y >= rect.y);
-		const std::size_t index = (y - rect.y) / item_height;
-		ASSERT(index < length);
-		return &items[index];
+		delete m_render_cache;
+		m_render_cache = NULL;
 	}
 };
 
-struct UiScrollBar : public UiItemBase {
-	constexpr UiScrollBar(Art *bg, Art *thumb, Art *arrow, SDL_Rect rect, int flags = 0)
-	    : UiItemBase(rect, flags)
-	    , bg(bg)
-	    , thumb(thumb)
-	    , arrow(arrow)
-	{
-	}
+//=============================================================================
 
-	Art *bg;
-	Art *thumb;
-	Art *arrow;
-};
+// A button (uses Diablo sprites)
 
-struct UiEdit : public UiItemBase {
-	constexpr UiEdit(char *value, std::size_t max_length, SDL_Rect rect, int flags)
+class UiButton : public UiItemBase {
+public:
+	UiButton(Art *art, const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , value(value)
-	    , max_length(max_length)
-
 	{
+		m_type = UI_BUTTON;
+		m_art = art;
+		m_text = text;
+		m_action = action;
+		m_pressed = false;
+		m_render_cache = NULL;
 	}
 
-	char *value;
-	std::size_t max_length;
-};
+	enum FrameKey {
+		DEFAULT = 0,
+		PRESSED,
+		DISABLED
+	};
 
-struct UiItem {
-	constexpr UiItem(UiText text)
-	    : type(UI_TEXT)
-	    , text(text)
-	{
-	}
+	//private:
+	Art *m_art;
 
-	constexpr UiItem(UiArtText text)
-	    : type(UI_ART_TEXT)
-	    , art_text(text)
-	{
-	}
+	const char *m_text;
+	void (*m_action)();
 
-	constexpr UiItem(UiArtTextButton art_text_button)
-	    : type(UI_ART_TEXT_BUTTON)
-	    , art_text_button(art_text_button)
-	{
-	}
+	// State
+	bool m_pressed;
+	TtfSurfaceCache *m_render_cache;
 
-	constexpr UiItem(UiImage image)
-	    : type(UI_IMAGE)
-	    , image(image)
+	virtual void FreeCache()
 	{
+		delete m_render_cache;
+		m_render_cache = NULL;
 	}
+};
 
-	constexpr UiItem(UiButton button)
-	    : type(UI_BUTTON)
-	    , button(button)
-	{
-	}
+//=============================================================================
 
-	constexpr UiItem(UiList list)
-	    : type(UI_LIST)
-	    , list(list)
+class UiListItem {
+public:
+	UiListItem(const char *text = "", int value = 0)
 	{
+		m_text = text;
+		m_value = value;
 	}
 
-	constexpr UiItem(UiScrollBar scrollbar)
-	    : type(UI_SCROLLBAR)
-	    , scrollbar(scrollbar)
+	~UiListItem()
 	{
 	}
 
-	constexpr UiItem(UiEdit edit)
-	    : type(UI_EDIT)
-	    , edit(edit)
-	{
-	}
+	//private:
+	const char *m_text;
+	int m_value;
+};
 
-	UiType type;
-	union {
-		UiText text;
-		UiArtText art_text;
-		UiImage image;
-		UiArtTextButton art_text_button;
-		UiButton button;
-		UiList list;
-		UiScrollBar scrollbar;
-		UiEdit edit;
-		UiItemBase common;
-	};
+typedef std::vector<UiListItem *> vUiListItem;
 
-	bool has_flag(UiFlags flag) const
+class UiList : public UiItemBase {
+public:
+	UiList(vUiListItem vItems, Sint16 x, Sint16 y, Uint16 item_width, Uint16 item_height, int flags = 0)
+	    : UiItemBase(x, y, item_width, item_height * vItems.size(), flags)
 	{
-		return common.has_flag(flag);
-	}
+		m_type = UI_LIST;
+		m_vecItems = vItems;
+		m_x = x;
+		m_y = y;
+		m_width = item_width;
+		m_height = item_height;
+	};
 
-	bool has_any_flag(int flags) const
+	~UiList() {};
+
+	SDL_Rect itemRect(int i)

This function should be const

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 enum UiFlags { 	UIS_HIDDEN = 1 << 10,
 };
 
-struct UiItemBase {
-	constexpr UiItemBase(SDL_Rect rect, int flags)
-	    : rect(rect)
-	    , flags(flags)
+class UiItemBase {
+public:
+	UiItemBase(SDL_Rect rect, int flags)
 	{
-	}
+		m_rect = rect;
+		m_iFlags = flags;
+	};
+
+	UiItemBase(Sint16 x, Sint16 y, Uint16 item_width, Uint16 item_height, int flags)
+	{
+		SDL_Rect tmp;
+		tmp.x = x;
+		tmp.y = y;
+		tmp.w = item_width;
+		tmp.h = item_height;
+
+		m_rect = tmp;
+		m_iFlags = flags;
+	};
+
+	virtual ~UiItemBase() {};
 
 	bool has_flag(UiFlags flag) const
 	{
-		return flags & flag;
+		return m_iFlags & flag;
 	}
 
 	bool has_any_flag(int flags) const
 	{
-		return (this->flags & flags) != 0;
+		return (m_iFlags & flags) != 0;
 	}
 
 	void add_flag(UiFlags flag)
 	{
-		flags |= flag;
+		m_iFlags |= flag;
 	}
 
 	void remove_flag(UiFlags flag)
 	{
-		flags &= ~flag;
+		m_iFlags &= ~flag;
+	}
+
+	virtual void FreeCache()

Why this is on the base class now? Do we want to call it in the destructor?

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 enum UiFlags { 	UIS_HIDDEN = 1 << 10,
 };
 
-struct UiItemBase {
-	constexpr UiItemBase(SDL_Rect rect, int flags)
-	    : rect(rect)
-	    , flags(flags)
+class UiItemBase {
+public:
+	UiItemBase(SDL_Rect rect, int flags)
 	{
-	}
+		m_rect = rect;
+		m_iFlags = flags;
+	};
+
+	UiItemBase(Sint16 x, Sint16 y, Uint16 item_width, Uint16 item_height, int flags)
+	{
+		SDL_Rect tmp;
+		tmp.x = x;
+		tmp.y = y;
+		tmp.w = item_width;
+		tmp.h = item_height;
+
+		m_rect = tmp;
+		m_iFlags = flags;
+	};
+
+	virtual ~UiItemBase() {};
 
 	bool has_flag(UiFlags flag) const
 	{
-		return flags & flag;
+		return m_iFlags & flag;
 	}
 
 	bool has_any_flag(int flags) const
 	{
-		return (this->flags & flags) != 0;
+		return (m_iFlags & flags) != 0;
 	}
 
 	void add_flag(UiFlags flag)
 	{
-		flags |= flag;
+		m_iFlags |= flag;
 	}
 
 	void remove_flag(UiFlags flag)
 	{
-		flags &= ~flag;
+		m_iFlags &= ~flag;
+	}
+
+	virtual void FreeCache()
+	{
 	}
 
-	SDL_Rect rect;
-	int flags;
+	//protected:
+	UiType m_type;
+	SDL_Rect m_rect;
+	int m_iFlags;
 };
 
-struct UiImage : public UiItemBase {
-	constexpr UiImage(Art *art, bool animated, int frame, SDL_Rect rect, int flags = 0)
+//=============================================================================
+
+class UiImage : public UiItemBase {
+public:
+	UiImage(Art *art, SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , art(art)
-	    , animated(animated)
-	    , frame(frame)
 	{
-	}
+		m_type = UI_IMAGE;
+		m_art = art;
+		m_animated = false;
+		m_frame = 0;
+	};
 
-	constexpr UiImage(Art *art, int frame, SDL_Rect rect, int flags = 0)
-	    : UiImage(art, /*animated=*/false, frame, rect, flags)
+	UiImage(Art *art, bool bAnimated, int iFrame, SDL_Rect rect, int flags)
+	    : UiItemBase(rect, flags)
 	{
-	}
+		m_type = UI_IMAGE;
+		m_art = art;
+		m_animated = bAnimated;
+		m_frame = iFrame;
+	};
 
-	constexpr UiImage(Art *art, SDL_Rect rect, int flags = 0)
-	    : UiImage(art, /*frame=*/0, rect, flags)
+	UiImage(Art *art, int frame, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
+		m_type = UI_IMAGE;
+		m_art = art;
+		m_animated = false;
+		m_frame = frame;
 	}
 
-	Art *art;
-	bool animated;
-	int frame;
+	~UiImage() {};
+
+	//private:
+	Art *m_art;
+	bool m_animated;
+	int m_frame;
 };
 
-// Plain text (TTF).
-struct UiText : public UiItemBase {
-	constexpr UiText(const char *text, SDL_Color color, SDL_Rect rect, int flags = 0)
-	    : UiItemBase(rect, flags)
-	    , color(color)
-	    , shadow_color { 0, 0, 0, 0 }
-	    , text(text)
-	    , render_cache(NULL)
-	{
-	}
+//=============================================================================
 
-	constexpr UiText(const char *text, SDL_Rect rect, int flags = 0)
-	    : UiText(text, SDL_Color { 243, 243, 243, 0 }, rect, flags)
+class UiArtText : public UiItemBase {
+public:
+	UiArtText(const char *text, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
-	}
-
-	SDL_Color color;
-	SDL_Color shadow_color;
-	const char *text;
+		m_type = UI_ART_TEXT;
+		m_text = text;
+	};
 
-	// State:
-	TtfSurfaceCache *render_cache;
+	~UiArtText() {};
 
-	void FreeCache()
-	{
-		delete render_cache;
-		render_cache = NULL;
-	}
+	//private:
+	const char *m_text;
 };
 
-// Text drawn with Diablo sprites.
-struct UiArtText : public UiItemBase {
-	constexpr UiArtText(const char *text, SDL_Rect rect, int flags = 0)
+//=============================================================================
+
+class UiScrollBar : public UiItemBase {
+public:
+	UiScrollBar(Art *bg, Art *thumb, Art *arrow, SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , text(text)
 	{
-	}
+		m_type = UI_SCROLLBAR;
+		m_bg = bg;
+		m_thumb = thumb;
+		m_arrow = arrow;
+	};
 
-	const char *text;
+	//private:
+	Art *m_bg;
+	Art *m_thumb;
+	Art *m_arrow;
 };
 
-// Clickable Diablo sprites text.
-struct UiArtTextButton : public UiItemBase {
-	constexpr UiArtTextButton(const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
+//=============================================================================
+
+class UiArtTextButton : public UiItemBase {
+public:
+	UiArtTextButton(const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , text(text)
-	    , action(action)
 	{
-	}
-
-	const char *text;
-	void (*action)();
+		m_type = UI_ART_TEXT_BUTTON;
+		m_text = text;
+		m_action = action;
+	};
+	//private:
+	const char *m_text;
+	void (*m_action)();
 };
 
-// A button (uses Diablo sprites).
-struct UiButton : public UiItemBase {
-	enum FrameKey {
-		DEFAULT = 0,
-		PRESSED,
-		DISABLED
-	};
+//=============================================================================
 
-	constexpr UiButton(Art *art, const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
+class UiEdit : public UiItemBase {
+public:
+	UiEdit(char *value, std::size_t max_length, SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , art(art)
-	    , text(text)
-	    , action(action)
-	    , pressed(false)
-	    , render_cache(NULL)
 	{
+		m_type = UI_EDIT;
+		m_value = value;
+		m_max_length = max_length;
 	}
 
-	Art *art;
+	//private:
+	char *m_value;
+	std::size_t m_max_length;
+};
 
-	const char *text;
-	void (*action)();
+//=============================================================================
 
-	// State
-	bool pressed;
-	TtfSurfaceCache *render_cache;
+// Plain text (TTF)
 
-	void FreeCache()
+class UiText : public UiItemBase {
+public:
+	UiText(const char *text, SDL_Color color1, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
-		delete render_cache;
-		render_cache = NULL;
-	}
-};
+		m_type = UI_TEXT;
+		m_color = color1;
 
-struct UiListItem {
-	constexpr UiListItem(const char *text = "", int value = 0)
-	    : text(text)
-	    , value(value)
-	{
+		SDL_Color color2 = { 0, 0, 0, 0 };
+		m_shadow_color = color2;
+
+		m_text = text;
+		m_render_cache = NULL;
 	}
-	const char *text;
-	int value;
-};
 
-struct UiList : public UiItemBase {
-	template <std::size_t N>
-	constexpr UiList(
-	    UiListItem (&items)[N],
-	    Sint16 x,
-	    Sint16 y,
-	    Uint16 item_width,
-	    Uint16 item_height,
-	    int flags)
-	    : UiItemBase({ x, y, item_width, static_cast<Uint16>(item_height * N) }, flags)
-	    , x(x)
-	    , y(y)
-	    , item_width(item_width)
-	    , item_height(item_height)
-	    , items(items)
-	    , length(N)
+	UiText(const char *text, SDL_Rect rect, int flags = 0)
+	    : UiItemBase(rect, flags)
 	{
-	}
+		m_type = UI_TEXT;
 
-	Sint16 x;
-	Sint16 y;
-	Uint16 item_width;
-	Uint16 item_height;
-	UiListItem *items;
-	std::size_t length;
+		SDL_Color color1 = { 243, 243, 243, 0 };
+		m_color = color1;
 
-	SDL_Rect itemRect(std::size_t i) const
-	{
-		return { x, static_cast<Sint16>(y + item_height * i), item_width, item_height };
+		SDL_Color color2 = { 0, 0, 0, 0 };
+		m_shadow_color = color2;
+
+		m_text = text;
+		m_render_cache = NULL;
 	}
 
-	UiListItem *itemAt(Sint16 y) const
+	//private:
+	SDL_Color m_color;
+	SDL_Color m_shadow_color;
+	const char *m_text;
+
+	// State:
+	TtfSurfaceCache *m_render_cache;
+
+	virtual void FreeCache()
 	{
-		ASSERT(y >= rect.y);
-		const std::size_t index = (y - rect.y) / item_height;
-		ASSERT(index < length);
-		return &items[index];
+		delete m_render_cache;
+		m_render_cache = NULL;
 	}
 };
 
-struct UiScrollBar : public UiItemBase {
-	constexpr UiScrollBar(Art *bg, Art *thumb, Art *arrow, SDL_Rect rect, int flags = 0)
-	    : UiItemBase(rect, flags)
-	    , bg(bg)
-	    , thumb(thumb)
-	    , arrow(arrow)
-	{
-	}
+//=============================================================================
 
-	Art *bg;
-	Art *thumb;
-	Art *arrow;
-};
+// A button (uses Diablo sprites)
 
-struct UiEdit : public UiItemBase {
-	constexpr UiEdit(char *value, std::size_t max_length, SDL_Rect rect, int flags)
+class UiButton : public UiItemBase {
+public:
+	UiButton(Art *art, const char *text, void (*action)(), SDL_Rect rect, int flags = 0)
 	    : UiItemBase(rect, flags)
-	    , value(value)
-	    , max_length(max_length)
-
 	{
+		m_type = UI_BUTTON;
+		m_art = art;
+		m_text = text;
+		m_action = action;
+		m_pressed = false;
+		m_render_cache = NULL;
 	}
 
-	char *value;
-	std::size_t max_length;
-};
+	enum FrameKey {
+		DEFAULT = 0,
+		PRESSED,
+		DISABLED
+	};
 
-struct UiItem {
-	constexpr UiItem(UiText text)
-	    : type(UI_TEXT)
-	    , text(text)
-	{
-	}
+	//private:
+	Art *m_art;
 
-	constexpr UiItem(UiArtText text)
-	    : type(UI_ART_TEXT)
-	    , art_text(text)
-	{
-	}
+	const char *m_text;
+	void (*m_action)();
 
-	constexpr UiItem(UiArtTextButton art_text_button)
-	    : type(UI_ART_TEXT_BUTTON)
-	    , art_text_button(art_text_button)
-	{
-	}
+	// State
+	bool m_pressed;
+	TtfSurfaceCache *m_render_cache;
 
-	constexpr UiItem(UiImage image)
-	    : type(UI_IMAGE)
-	    , image(image)
+	virtual void FreeCache()
 	{
+		delete m_render_cache;
+		m_render_cache = NULL;
 	}
+};
 
-	constexpr UiItem(UiButton button)
-	    : type(UI_BUTTON)
-	    , button(button)
-	{
-	}
+//=============================================================================
 
-	constexpr UiItem(UiList list)
-	    : type(UI_LIST)
-	    , list(list)
+class UiListItem {
+public:
+	UiListItem(const char *text = "", int value = 0)
 	{
+		m_text = text;
+		m_value = value;
 	}
 
-	constexpr UiItem(UiScrollBar scrollbar)
-	    : type(UI_SCROLLBAR)
-	    , scrollbar(scrollbar)
+	~UiListItem()
 	{
 	}
 
-	constexpr UiItem(UiEdit edit)
-	    : type(UI_EDIT)
-	    , edit(edit)
-	{
-	}
+	//private:
+	const char *m_text;
+	int m_value;
+};
 
-	UiType type;
-	union {
-		UiText text;
-		UiArtText art_text;
-		UiImage image;
-		UiArtTextButton art_text_button;
-		UiButton button;
-		UiList list;
-		UiScrollBar scrollbar;
-		UiEdit edit;
-		UiItemBase common;
-	};
+typedef std::vector<UiListItem *> vUiListItem;
 
-	bool has_flag(UiFlags flag) const
+class UiList : public UiItemBase {
+public:
+	UiList(vUiListItem vItems, Sint16 x, Sint16 y, Uint16 item_width, Uint16 item_height, int flags = 0)
+	    : UiItemBase(x, y, item_width, item_height * vItems.size(), flags)
 	{
-		return common.has_flag(flag);
-	}
+		m_type = UI_LIST;
+		m_vecItems = vItems;
+		m_x = x;
+		m_y = y;
+		m_width = item_width;
+		m_height = item_height;
+	};
 
-	bool has_any_flag(int flags) const
+	~UiList() {};
+
+	SDL_Rect itemRect(int i)
 	{
-		return common.has_any_flag(flags);
+		SDL_Rect tmp;
+		tmp.x = m_x;
+		tmp.y = m_y + m_height * i;
+		tmp.w = m_width;
+		tmp.h = m_height;
+
+		return tmp;
 	}
 
-	const SDL_Rect &rect() const
+	UiListItem *itemAt(Sint16 y) const
 	{
-		return common.rect;
+		ASSERT(y >= m_rect.y);
+		const std::size_t index = (y - m_rect.y) / m_height;
+		ASSERT(index < m_vecItems.size());
+		return m_vecItems[index];
 	}
 
-	void FreeCache()
+	UiListItem *GetItem(int i)
 	{
-		switch (type) {
-		case UI_BUTTON:
-			button.FreeCache();
-			break;
-		case UI_TEXT:
-			text.FreeCache();
-			break;
-		default:
-			break;
-		}
+		return m_vecItems[i];
 	}
+
+	//private:
+	Sint16 m_x, m_y;
+	Uint16 m_width, m_height;
+	std::vector<UiListItem *> m_vecItems;
 };
 
+typedef std::vector<UiItemBase *> vUiItemBase;

Typedefing vector makes the code harder to read. It also makes it unobvious when something expensive happens, such as an entire vector is being copied (e.g. passed-by-value). Or when delete isn't done on each element.

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 void Deinit() 		UnloadTtfFont();
 	if (textInputWasActive)
 		SDL_StartTextInput();
-	for (std::size_t i = 0; i < dialogItemsSize; ++i) {
-		dialogItems[i].FreeCache();
+
+	for (std::size_t i = 0; i < vecOkDialog.size(); i++) {
+		UiItemBase *pUIItem = vecOkDialog[i];
+		if (pUIItem)

delete NULL; is safe

Generally, when checking for nullptr it's better to be explicit (if (pUIItem != NULL)) because implicit boolean conversion operator can be overriden.

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 void DrawArt(int screenX, int screenY, Art *art, int nFrame, Uint16 srcW, Uint16 	if (screenY >= SCREEN_HEIGHT || screenX >= SCREEN_WIDTH || art->surface == NULL)
 		return;
 
-	SDL_Rect src_rect = {
-		0,
-		static_cast<Sint16>(nFrame * art->h()),
-		static_cast<Uint16>(art->w()),
-		static_cast<Uint16>(art->h())
-	};
+	SDL_Rect src_rect;
+	src_rect.x = 0;
+	src_rect.y = static_cast<Sint16>(nFrame * art->h());

No need for static_cast if not doing aggregate initialization ({...}), an implicit cast happens on assignment.

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 void Render(const UiScrollBar &ui_sb) 	{
 		const SDL_Rect rect = UpArrowRect(ui_sb);
 		const int frame = static_cast<int>(scrollBarState.upArrowPressed ? ScrollBarArrowFrame_UP_ACTIVE : ScrollBarArrowFrame_UP);
-		DrawArt(rect.x, rect.y, ui_sb.arrow, frame, rect.w);
+		DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
 	}
 	{
 		const SDL_Rect rect = DownArrowRect(ui_sb);
 		const int frame = static_cast<int>(scrollBarState.downArrowPressed ? ScrollBarArrowFrame_DOWN_ACTIVE : ScrollBarArrowFrame_DOWN);
-		DrawArt(rect.x, rect.y, ui_sb.arrow, frame, rect.w);
+		DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
 	}
 
 	// Thumb:
-	{
+	if (SelectedItemMax - SelectedItemMin > 0) {
 		const SDL_Rect rect = ThumbRect(
 		    ui_sb, SelectedItem - SelectedItemMin, SelectedItemMax - SelectedItemMin + 1);
-		DrawArt(rect.x, rect.y, ui_sb.thumb);
+		DrawArt(rect.x, rect.y, ui_sb->m_thumb);
 	}
 }
 
-void Render(const UiEdit &ui_edit)
+void Render(const UiEdit *ui_edit)
 {
-	DrawSelector(ui_edit.rect);
-	SDL_Rect rect = ui_edit.rect;
+	DrawSelector(ui_edit->m_rect);
+	SDL_Rect rect = ui_edit->m_rect;
 	rect.x += 43;
 	rect.y += 1;
 	rect.w -= 86;
-	DrawArtStr(ui_edit.value, rect, ui_edit.flags, /*drawTextCursor=*/true);
+	DrawArtStr(ui_edit->m_value, rect, ui_edit->m_iFlags, /*drawTextCursor=*/true);
 }
 
-void RenderItem(UiItem *item)
+void RenderItem(UiItemBase *item)
 {
 	if (item->has_flag(UIS_HIDDEN))
 		return;
-	switch (item->type) {
+	switch (item->m_type) {
 	case UI_TEXT:
-		Render(&item->text);
+		Render((UiText *)item);
 		break;
 	case UI_ART_TEXT:
-		Render(item->art_text);
+		Render((UiArtText *)item);
 		break;
 	case UI_IMAGE:
-		Render(item->image);
+		Render((UiImage *)item);
 		break;
 	case UI_ART_TEXT_BUTTON:
-		Render(item->art_text_button);
+		Render((UiArtTextButton *)item);
 		break;
 	case UI_BUTTON:
-		RenderButton(&item->button);
+		RenderButton((UiButton *)item);
 		break;
 	case UI_LIST:
-		Render(item->list);
+		Render((UiList *)item);
 		break;
 	case UI_SCROLLBAR:
-		Render(item->scrollbar);
+		Render((UiScrollBar *)item);
 		break;
 	case UI_EDIT:
-		Render(item->edit);
+		Render((UiEdit *)item);
 		break;
 	}
 }
 
-bool HandleMouseEventArtTextButton(const SDL_Event &event, const UiArtTextButton &ui_button)
+bool HandleMouseEventArtTextButton(const SDL_Event &event, UiArtTextButton *ui_button)

Is it necessary to remove const here (and throughout)?

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 void Render(const UiScrollBar &ui_sb) 	{
 		const SDL_Rect rect = UpArrowRect(ui_sb);
 		const int frame = static_cast<int>(scrollBarState.upArrowPressed ? ScrollBarArrowFrame_UP_ACTIVE : ScrollBarArrowFrame_UP);
-		DrawArt(rect.x, rect.y, ui_sb.arrow, frame, rect.w);
+		DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
 	}
 	{
 		const SDL_Rect rect = DownArrowRect(ui_sb);
 		const int frame = static_cast<int>(scrollBarState.downArrowPressed ? ScrollBarArrowFrame_DOWN_ACTIVE : ScrollBarArrowFrame_DOWN);
-		DrawArt(rect.x, rect.y, ui_sb.arrow, frame, rect.w);
+		DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
 	}
 
 	// Thumb:
-	{
+	if (SelectedItemMax - SelectedItemMin > 0) {
 		const SDL_Rect rect = ThumbRect(
 		    ui_sb, SelectedItem - SelectedItemMin, SelectedItemMax - SelectedItemMin + 1);
-		DrawArt(rect.x, rect.y, ui_sb.thumb);
+		DrawArt(rect.x, rect.y, ui_sb->m_thumb);
 	}
 }
 
-void Render(const UiEdit &ui_edit)
+void Render(const UiEdit *ui_edit)
 {
-	DrawSelector(ui_edit.rect);
-	SDL_Rect rect = ui_edit.rect;
+	DrawSelector(ui_edit->m_rect);
+	SDL_Rect rect = ui_edit->m_rect;
 	rect.x += 43;
 	rect.y += 1;
 	rect.w -= 86;
-	DrawArtStr(ui_edit.value, rect, ui_edit.flags, /*drawTextCursor=*/true);
+	DrawArtStr(ui_edit->m_value, rect, ui_edit->m_iFlags, /*drawTextCursor=*/true);
 }
 
-void RenderItem(UiItem *item)
+void RenderItem(UiItemBase *item)
 {
 	if (item->has_flag(UIS_HIDDEN))
 		return;
-	switch (item->type) {
+	switch (item->m_type) {
 	case UI_TEXT:
-		Render(&item->text);
+		Render((UiText *)item);

static_cast<UiText *> is better because it at least checks that UiText is a subclass of UiItemBase.

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 void CreditsRenderer::Render() 	// We use unscaled coordinates for calculation throughout.
 	Sint16 dest_y = VIEWPORT.y - (offset_y - lines_begin * LINE_H);
 	for (std::size_t i = 0; i < lines_.size(); ++i, dest_y += LINE_H) {
-		auto &line = lines_[i];

Does C++03 not have references?

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 class LinesBuffer { 			empty_ = true;
 	}
 
-	void push_back(CachedLine &&line)
+	void push_back(CachedLine line)

CachedLine is small so shouldn't make a difference

AJenbo

comment created time in 2 months

Pull request review commentdiasurgical/devilutionX

Ui refactor

 struct SurfaceDeleter { 	}
 };
 
-using SurfacePtr = std::unique_ptr<SDL_Surface, SurfaceDeleter>;
-
 struct CachedLine {
-	CachedLine() = default;
-
-	explicit CachedLine(std::size_t index, SurfacePtr surface)
-	    : index(index)
-	    , surface(std::move(surface))
-	    , palette_version(pal_surface_palette_version)
+	CachedLine(std::size_t index, SDL_Surface *surface)
 	{
+		m_index = index;
+		m_surface = surface;
 	}
 
-	std::size_t index;
-	SurfacePtr surface;
+	std::size_t m_index;
+	SDL_Surface *m_surface;

SurfacePtr handled surface deletion. With a regular pointer, deletion now has to be done manually.

Can add accessor methods and put delete there and the destructor.

AJenbo

comment created time in 2 months

push eventod-contrib/commander

Gleb Mazovetskiy

commit sha 58f735c1f17f1fcb6f0b69068e44cdaababcdafb

RetroFW: X-OD-Scaling 2 -> 0 2 is called "original" but it actually downscales on 320x480 0 is stretch, and will do nothing if the resolution is already native Thanks @pingflood

view details

push time in 2 months

issue commentglebm/i18n-tasks

Multi-line strings as translations keys are not being properly recognized by the health task

Here is where the I18n.t calls are handled for .rb files, in case you want to give fixing it a go:

https://github.com/glebm/i18n-tasks/blob/0d0c16b11d0e0c7d5d7f920495dd214caacfd2b6/lib/i18n/tasks/scanners/ruby_ast_scanner.rb#L61-L88

juanmanuelramallo

comment created time in 2 months

pull request commentglebm/od-buildroot

Add FBA package

No, both this and https://github.com/od-contrib/buildroot-rg350-old-kernel/releases use libpng16 by default. However, they also provide the older libpng14 for backwards compatibility, so you can link against the older version explicitly. (e.g. -lpng14 or lpng1.4 instead of -lpng)

glebm

comment created time in 3 months

pull request commentglebm/od-buildroot

Add FBA package

@nl255 The buildroot you're using likely has a newer version of libpng than the firmware. Which firmware are you using? Try using the corresponding buildroot.

glebm

comment created time in 3 months

Pull request review commentglebm/order_query

Make it compatible with Rails 6.1

 def parse!(direction)     # @return [:first, :last] the default nulls order, based on the given     #   scope's connection adapter name.     def default(scope, dir)-      case scope.connection_config[:adapter]+      case scope.connection.adapter_name

Does this establish a connection? The previous version didn't though I'm not sure if this makes any difference.

vitobotta

comment created time in 3 months

more