Перейти к публикации
Alleksh

Графический интерфейс для компьютеров из RP

Рекомендованные сообщения

Alleksh

Я хочу представить вам свой код для формирования UI.
Код:

HEX
: GetX 301 C@ ;
: GetY 302 C@ ;

: SetX 301 C! ;
: SetY 302 C! ;

: ++ DUP @ 1+ OVER ! ;
: -- DUP @ 1- OVER ! ;


A0 ALLOT CONSTANT nowUI

VARIABLE UIsize
: GetButton 2 * nowUI + @ ;

: AddButton 
UIsize @ 2 * nowUI + ! 
UIsize ++ ;

: ClearUI nowUI A0 0 FILL 0 UIsize ! ;

// ( addr1 addr2 y x -- ) CreateNewButton
// addr1 - ptr to str
// addr2 - ptr to func if button was pressed
: CreateNewButton 
CREATE 
, , ,
100 
100 STRLEN ALLOT 100 STRLEN 1+ MOVE ;


// ( fromx fromy tox toy -- ) Hover
: Hover 
30C C! 30D C! 
30B C! 30A C!
2 307 C!
BEGIN 307 C@ 0= UNTIL ;


// ( fromx fromy tox toy -- ) Clear
: Clear 308 C!
30C C! 30D C!
30A C! 30B C!
1 307 C!
BEGIN 307 C@ 0= UNTIL ;


VARIABLE buffer

// ( buttonID -- ) Show button
: RenderButton 
GetButton EXECUTE buffer !
buffer @ C@ SetX
buffer @ 2 + C@ SetY
buffer @ 6 + TYPE ;

// ( buttonID -- ) (Un)Hover button
: HoverButton
GetButton EXECUTE buffer !
buffer @ C@
buffer @ 2 + C@ 1
buffer @ 6 + STRLEN Hover ;

VARIABLE selectedButtonID

// ( buttonID -- ) Render button
: RenderButtons UIsize @ 0 ?DO I RenderButton LOOP ;

// ( -- ) Select other button in list
: SelectOtherButton+ 
selectedButtonID @ HoverButton
selectedButtonID @ 1+ UIsize @ <
IF selectedButtonID ++
ELSE 0 selectedButtonID !
THEN selectedButtonID @ HoverButton ;

// ( -- ) Select other button in list
: SelectOtherButton- 
selectedButtonID @ HoverButton
selectedButtonID @ 1- 0 >=
IF   selectedButtonID --
ELSE UIsize @ selectedButtonID !
THEN selectedButtonID @ HoverButton ;

// ( buttonID -- ) Execute button command
: ExecuteButton GetButton EXECUTE 4 + @ EXECUTE ;

// ( -- ) Load ui
: LoadUI PAGE
RenderButtons
0 HoverButton
0 selectedButtonID !
BEGIN 
KEY
DUP 82 = IF DROP SelectOtherButton- ELSE
DUP 83 = IF DROP SelectOtherButton+ ELSE 
D = IF selectedButtonID @ ExecuteButton THEN THEN THEN AGAIN ;

Чтобы добавить кнопку, которая будет вызывать function, нужно написать:

100 80 ACCEPT %ТекстКнопки%
100 ' function Y X CreateNewButton %ButtonName%
' %ButtonName% AddButton

Пример:
image.png.1a3b6d26bddaebc173549e4030addaad.png
 

  • Нравится 1

Поделиться сообщением


Ссылка на сообщение
Гость
Эта тема закрыта для публикации сообщений.

×
×
  • Создать...