Я создаю кнопку переключения с помощью библиотеки SwinGame.Прямо сейчас я борюсь с тем, чтобы заставить его переключаться.Этот бит выглядит так:
var
clr: Color;
clicked: Boolean;
boolcheck: String;
begin
OpenGraphicsWindow('Toggle button test', windowsWidth, windowsHeight);
clr := ColorWhite;
clicked := true;
boolcheck := 'true';
repeat
ClearScreen(clr);
ProcessEvents();
//Play button and Pause button
if (ButtonClicked(buttonX-buttonRadius, buttonY-buttonRadius, buttonRadius*2, buttonRadius*2) = true) and (clicked = true) then
begin
clr := ColorRed;
clicked := false;
boolcheck := 'false';
DrawAButton();
end
else if (ButtonClicked(buttonX-buttonRadius, buttonY-buttonRadius, buttonRadius*2, buttonRadius*2) = true) and (clicked = false) then
begin
clr := ColorBlue;
clicked := true;
boolcheck := 'true';
DrawADifferentButton();
end;
DrawText(echo, ColorBlack, 'arial.ttf', 14, 55, 55);
RefreshScreen();
until WindowCloseRequested();
end;
По сути, я намеревался сделать это так, если пользователь нажимает на эту область окна с помощью ButtonClicked()
(функция SwinGame), а переменная clicked имеет значение false, тогдацвет фона будет красным, если не синим.Но по какой-то причине я смогла только поменять его на красный, синий вообще не появился.Я выполнил некоторые действия по устранению неполадок, создав переменную boolcheck
, и увидел, что переменная постоянно выставляется в true, я видел, что она менялась на false в течение доли секунды, а затем обратно на true .... Но я не ставилclicked
начальное определение переменной внутри цикла, так почему же оно не остается ложным?
РЕДАКТИРОВАТЬ: Вот определение функции ButtonClicked
function ButtonClicked(posX, posY: Single; w, h: Integer): Boolean;
var
x, y: Single;
begin
x := MouseX();
y := MouseY();
result := false;
if MouseClicked(LeftButton) then
begin
if (x >= posX) and (x <= w + posX) and (y >= posY) and (y <= h + posY) then
begin
result := true;
end;
end;
end;