Показать сообщение отдельно
Старый 22.09.2009, 18:00   #5
abcdef
Знающий
 
Регистрация: 16.09.2008
Сообщений: 299
Написано 71 полезных сообщений
(для 123 пользователей)
Ответ: алгоритмы j2me для рисованного интерфейса

Пример эмулятор консольного вывода стандартным шрифтом телефона в граф. режиме (реализован перенос и прокрутка)
//console demo. arT(c).  e-mail: [email protected]
var
  tx,ty : integer;  //положение курсора и максимальная высота букв
  tw,th : integer;  //размеры области вывода
  tb,tc : integer;  //цвет фона и букв
  sleep : integer;  //скорость прокрутки
procedure print(s : string);
//консольный вывод, управляющие символы: chr(10)-курсор на новую строку, chr(13)-курсор в начало строки
var
  c,i,len,xx : integer;
begin
  setColor(((tc div $10000) and $FF),((tc div $100) and $FF),(tc and $FF));
  c:=getStringHeight(s);
  if c>ty then ty:=c;
  len:=length(s)-1;
  for i:=0 to len do
  begin
    c:=ord(getChar(s,i));
    if (c>=32) then xx:=tx+getStringWidth(chr(c))+1
    else if (c=10) then xx:=tw
    else if (c=13) then tx:=0;
    if (xx>=tw) then  //scroll screen
    begin
      drawImage(imageFromCanvas(0,ty,tw,th-ty),0,0);
      setColor(((tb div $10000) and $FF),((tb div $100) and $FF),(tb and $FF)); //back color
      fillRect(0,th-ty,tw,ty);
      setColor(((tc div $10000) and $FF),((tc div $100) and $FF),(tc and $FF)); //text color
      repaint;
      delay(sleep);
      ty:=getStringHeight(s);
      xx:=xx-tx;
      tx:=0;
    end;
    if (c>=32) then begin drawText(chr(c),tx,th-ty); tx:=xx; end;
  end;
  repaint;
end;


procedure init;
begin
  tw:=getWidth;
  th:=96; //getHeight;
  tx:=0;
  sleep:=200;
  tb:=0*$10000+0*$100+20;     //backRGB
  tc:=230*$10000+230*$100+120; //textRGB
  setColor(((tb div $10000) and $FF),((tb div $100) and $FF),(tb and $FF));
  fillRect(0,0,tw,th);
end;


var
  i : integer;
begin
  init;
  print('console output demo'+chr(10));
  for i:=0 to 18 do
  begin
    tc:=$10000*i*40+$100*i*40+i*40;
    print('text'+chr(13));
    delay(150);
  end;
  print(chr(10));
  print('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'+chr(10));
  print('1'+chr(10));
  print('2'+chr(10));
  print('END');
  repeat delay(100); until false;
end.
(Offline)
 
Ответить с цитированием