\usetikzlibrary{arrows.meta}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}
\usetikzlibrary{circuits.logic.US}
\usetikzlibrary{plotmarks}


\tikzset{
	gate/.style = {
		draw,
		rectangle,
		fill = white,
		line width = 0.35mm
	},
	qubit/.style = {
		fill = \bgcolor,
		line width = 0.35mm
	},
	wire/.style = {
		line width = 1
	},
	wirejoin/.style = {
		fill = oblue,
		draw = oblue,
		line width = 1.5
	},
	wireijoin/.style = {
		fill = white,
		draw = oblue,
		line width = 1.5
	},
}

% Macros


% Do NOT put a semicolon after qubox,
% it gives a "character ; not found" error.
% LaTeX is odd.
\def\qubox#1#2#3#4#5{
	% 1: point ne
	% 2: point ne x offset
	% 3: point sw
	% 4: point sw x offset
	% 5: label text
	\draw[
		line width = 1,
		fill = white,
		draw = black
	]
		([shift={(#2 + 0.1, 0.4)}] #1.center)
		-- ([shift={(#2 + 0.1, -0.4)}] #1.center |- #3.center)
		-- ([shift={(#4 - 0.1, -0.4)}] #3.center)
		-- ([shift={(#4 - 0.1, 0.4)}] #1.center -| #3.center)
		-- cycle
	;
	\node at ($([shift={(#2,0)}] #1)!0.5!([shift={(#4,0)}] #3)$) {#5};
}

\def\ghostqubox#1#2#3#4#5{
	% 1: point ne
	% 2: point ne x offset
	% 3: point sw
	% 4: point sw x offset
	% 5: label text
	\draw[
		line width = 1,
		fill = white,
		draw = gray,
		dashed
	]
		([shift={(#2 + 0.1, 0.4)}] #1.center)
		-- ([shift={(#2 + 0.1, -0.4)}] #1.center |- #3.center)
		-- ([shift={(#4 - 0.1, -0.4)}] #3.center)
		-- ([shift={(#4 - 0.1, 0.4)}] #1.center -| #3.center)
		-- cycle
	;
	\node[gray] at ($([shift={(#2,0)}] #1)!0.5!([shift={(#4,0)}] #3)$) {#5};
}