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

Давайте складывать сюда свои оптимизированные алгоритмы и примеры для создания графических интерфейсов, меню, и т.д.
___
Вот моя реализация собственного шрифта с минимальными потребностями в памяти и без использования png-картинок.
//Raster font 8x8 form PC BIOS.
//programming by arT (c). e-mail: [email protected]
//
//Пример создания и работы с собственным растровым шрифтом в MidletPascal
//каждый символ занимает 64 bit (два числах типа integer).
//в примере заготовлены две кодовые таблицы: оригинальная CP866 (dos) и конвертированная в CP1251 (win).
//Исходный шрифт взят из знакогенератора BIOS.
//
//Используемые подпрограммы:
//procedure text(x,y : integer; s : string); - вывод текста "s" в позиции "x,y"
//function win2utf(s : string) : string; - конвертироание из win в utf8 кодировку
//function utf2win(s : string) : string; - конвертироание из utf8 в win кодировку

var
  f : array[0..511] of integer; //битовый образ шрифта 0..255,8x8
  s : string;
  c : char;
  i,j,k,h,w : integer;
  bool : boolean;

procedure text(x,y : integer; s : string);
// вывод шрифта 8x8 из битового образа f[0..511]
var
  c,i,j,p,len : integer;
begin
  len:=length(s)-1;
  for i:=0 to len do
  begin
    p:=(ord(getChar(s,i)) and 255)*2;
    for j:=0 to 1 do 
    begin
      c:=f[p+j];
      if ((c and 2147483648)<>0) or (c<0) then plot(x,y);
      if ((c and 1073741824)<>0) then plot(x+1,y);
      if ((c and 536870912)<>0)  then plot(x+2,y);
      if ((c and 268435456)<>0)  then plot(x+3,y);
      if ((c and 134217728)<>0)  then plot(x+4,y);
      if ((c and 67108864)<>0)   then plot(x+5,y);
      if ((c and 33554432)<>0)   then plot(x+6,y);
      if ((c and 16777216)<>0)   then plot(x+7,y);
      y:=y+1;
      if ((c and 8388608)<>0)    then plot(x,y);
      if ((c and 4194304)<>0)    then plot(x+1,y);
      if ((c and 2097152)<>0)    then plot(x+2,y);
      if ((c and 1048576)<>0)    then plot(x+3,y);
      if ((c and 524288)<>0)     then plot(x+4,y);
      if ((c and 262144)<>0)     then plot(x+5,y);
      if ((c and 131072)<>0)     then plot(x+6,y);
      if ((c and 65536)<>0)      then plot(x+7,y);
      y:=y+1;
      if ((c and 32768)<>0)      then plot(x,y);
      if ((c and 16384)<>0)      then plot(x+1,y);
      if ((c and 8192)<>0)       then plot(x+2,y);
      if ((c and 4096)<>0)       then plot(x+3,y);
      if ((c and 2048)<>0)       then plot(x+4,y);
      if ((c and 1024)<>0)       then plot(x+5,y);
      if ((c and 512)<>0)        then plot(x+6,y);
      if ((c and 256)<>0)        then plot(x+7,y);
      y:=y+1;
      if ((c and 128)<>0)        then plot(x,y);
      if ((c and 64)<>0)         then plot(x+1,y);
      if ((c and 32)<>0)         then plot(x+2,y);
      if ((c and 16)<>0)         then plot(x+3,y);
      if ((c and 8)<>0)          then plot(x+4,y);
      if ((c and 4)<>0)          then plot(x+5,y);
      if ((c and 2)<>0)          then plot(x+6,y);
      if ((c and 1)<>0)          then plot(x+7,y);
      y:=y+1;
    end;
    y:=y-8;  
    x:=x+8;
  end;
end;

function win2utf(s : string) : string;
var  {rus_ansi to unicode}
  i,c : integer;
begin
  for i:=length(s)-1 downto 0 do
  begin
    c:=ord(getChar(s,i)) and 255;
    if (c>=192) then  s:=setChar(s,chr(c+848),i);
    if (c=168)  then  s:=setChar(s,chr($0401),i); {Ё}
    if (c=184)  then  s:=setChar(s,chr($0451),i); {ё}
  end;
  win2utf := s;
end;


function utf2win(s : string) : string;
var
  i,c : integer;
begin
  for i:=length(s)-1 downto 0 do
  begin
    c:=ord(getChar(s,i));
    if (c>255)   then  s:=setChar(s,chr(c-848),i);
    if (c=$0401) then  s:=setChar(s,chr(168),i); {Ё}
    if (c=$0451) then  s:=setChar(s,chr(184),i); {ё}
  end;
  utf2win := s;
end;

begin
  //{CP866} s:='0,0,2122425729,-1114013314,2130697215,-1008205954,1828650750,2084048896,272137470,2084048896,947665150,-19525576,272137470,-25423816,272137470,-25423816,272137470,-25423816,3958338,1113996288,3958338,1113996288,252120957,-858993544,1013343846,1008238104,1013343846,1008238104,2137227107,1667753664,417021159,-415442152,-2132739842,-119504896,34488062,1041105408,406617624,410926104,1717986918,1711302144,2145115003,454761216,1046559846,1715242620,0,2122219008,406617624,2117867775,406617624,404232192,404232216,2117867520,1576190,202899456,3170558,1613758464,49344,-1057095680,2385663,1713635328,1588350,-65536,16777086,1008205824,0,0,406600728,402659328,1717969920,0,1819082348,-26448896,406741052,108795904,13028376,812041728,946616438,-590580224,404238336,0,202911792,806882304,806882316,202911744,6700287,1013317632,1579134,404226048,0,1579056,126,0,0,1579008,101455920,1623228416,2093403862,-423199744,406329368,404258304,2093352476,812056064,2093352508,113671168,473722060,-32760320,-20922116,113671168,945864956,-960070656,-20575208,808464384,2093401724,-960070656,2093401726,101480448,1579008,1579008,1579008,1579056,101455920,403441152,32256,8257536,1613764620,405823488,2093354008,402659328,2093407966,-557811712,946652926,-960051712,-60397956,1718025216,1013366976,-1067041792,-127113626,1718417408,-27105160,1751318016,-27105160,1751183360,1013366976,-832161280,-960051458,-960051712,1008211992,404241408,504105996,-859015168,-429495176,1818682880,-262119328,1650916864,-957415682,-691616256,-957942050,-825833984,2093401798,-960070656,-60397956,1616965632,2093401798,-959546354,-60397956,1818682880,2093375544,214334464,2122209816,404241408,-960051514,-960070656,-960051514,-965986304,-960051498,-687969280,-960074696,1824966144,1717986876,404241408,-20542440,845610496,1009791024,808467456,-1067438056,201720320,1007422476,202128384,272133318,0,0,255,806882304,0,30732,2093774336,-530547610,1718017024,31942,-1060733952,470580428,-859015680,31942,-20939776,1013342456,1616965632,30412,-864285448,-530551690,1718019584,402667544,404241408,100664838,107374140,-530553236,2020402688,941103128,404241408,60670,-690563584,56422,1717986816,31942,-960070656,56422,1719427312,30412,-864285666,56438,1616965632,32448,2080832512,808516656,808852480,52428,-859015680,50886,-965986304,50902,-687969280,50796,946652672,50886,-964819204,32332,405962240,236460144,404229632,404232216,404232192,1880627214,404254720,1994129408,0,1063020,-960037376,1046922950,-20527616,-26845060,1718025216,-60397956,1718025216,-26845088,1616965632,506881638,1718026179,-27105160,1751318016,-690586568,2094454272,2093352508,113671168,-960049442,-152648192,952553182,-152648192,-429495176,1818682880,506881638,1718011392,-957415682,-691616256,-960051458,-960051712,2093401798,-960070656,-20527418,-960051712,-60397978,2086727680,2093400256,-1060733952,2119833624,404241408,-960051586,113671168,2094454486,2081437696,-960074696,1824966144,-858993460,-858980858,-960051586,101058048,-690563370,-690553344,-690563370,-690553085,-252661700,909523968,-960051466,-555813376,-262119300,1717992448,2022442558,109869056,-589900042,-690562048,2126956230,2120664576,30732,2093774336,108839036,-960070656,64614,2087123968,65126,1616965632,15468,1819082438,31942,-20939776,54908,947705344,31942,482769920,50894,-554244608,3720910,-554244608,58988,2020402688,15974,1718019584,50942,-19479040,50886,-20527616,31942,-960070656,65222,-960051712,289673540,289673540,1437226410,1437226410,-579347081,-579347081,404232216,404232216,404232440,404232216,418912504,404232216,909522678,909522486,254,909522486,16259320,404232216,922093302,909522486,909522486,909522486,16647926,909522486,922093310,0,909522686,0,418912504,0,248,404232216,404232223,0,404232447,0,255,404232216,404232223,404232216,255,0,404232447,404232216,404690975,404232216,909522487,909522486,909586495,0,4141111,909522486,922157311,0,16711927,909522486,909586487,909522486,16711935,0,922157303,909522486,419365119,0,909522687,0,16711935,404232216,255,909522486,909522495,0,404690975,0,2037791,404232216,63,909522486,909522687,909522486,419371263,404232216,404232440,0,31,404232216,-1,-1,255,-1,-252645136,-252645136,252645135,252645135,-256,0,64614,1719427312,31942,-1060733952,32346,404241408,50886,-964819332,31958,-696512456,50796,946652672,52428,-858980858,50886,2114323968,54998,-690553344,54998,-690553085,61616,1010187264,50886,-153160192,61536,2087123968,31942,516324352,56534,-153691136,32454,2120664576,1828610680,1617100288,1811971270,-20939776,1013367032,-1067041792,15971,2019769856,1215836208,808482816,-872402896,808482816,952551038,113671168,1815660230,-964819332,946629688,0,24,402653184,0,402653184,235670540,1815878656,-1882329092,-590558208,13008070,-964901376,15420,1010565120,0,0,';
  {CP1251} s:='0,0,2122425729,-1114013314,2130697215,-1008205954,1828650750,2084048896,272137470,2084048896,947665150,-19525576,272137470,-25423816,272137470,-25423816,272137470,-25423816,3958338,1113996288,3958338,1113996288,252120957,-858993544,1013343846,1008238104,1013343846,1008238104,2137227107,1667753664,417021159,-415442152,-2132739842,-119504896,34488062,1041105408,406617624,410926104,1717986918,1711302144,2145115003,454761216,1046559846,1715242620,0,2122219008,406617624,2117867775,406617624,404232192,404232216,2117867520,1576190,202899456,3170558,1613758464,49344,-1057095680,2385663,1713635328,1588350,-65536,16777086,1008205824,0,0,406600728,402659328,1717969920,0,1819082348,-26448896,406741052,108795904,13028376,812041728,946616438,-590580224,404238336,0,202911792,806882304,806882316,202911744,6700287,1013317632,1579134,404226048,0,1579056,126,0,0,1579008,101455920,1623228416,2093403862,-423199744,406329368,404258304,2093352476,812056064,2093352508,113671168,473722060,-32760320,-20922116,113671168,945864956,-960070656,-20575208,808464384,2093401724,-960070656,2093401726,101480448,1579008,1579008,1579008,1579056,101455920,403441152,32256,8257536,1613764620,405823488,2093354008,402659328,2093407966,-557811712,946652926,-960051712,-60397956,1718025216,1013366976,-1067041792,-127113626,1718417408,-27105160,1751318016,-27105160,1751183360,1013366976,-832161280,-960051458,-960051712,1008211992,404241408,504105996,-859015168,-429495176,1818682880,-262119328,1650916864,-957415682,-691616256,-957942050,-825833984,2093401798,-960070656,-60397956,1616965632,2093401798,-959546354,-60397956,1818682880,2093375544,214334464,2122209816,404241408,-960051514,-960070656,-960051514,-965986304,-960051498,-687969280,-960074696,1824966144,1717986876,404241408,-20542440,845610496,1009791024,808467456,-1067438056,201720320,1007422476,202128384,272133318,0,0,255,806882304,0,30732,2093774336,-530547610,1718017024,31942,-1060733952,470580428,-859015680,31942,-20939776,1013342456,1616965632,30412,-864285448,-530551690,1718019584,402667544,404241408,100664838,107374140,-530553236,2020402688,941103128,404241408,60670,-690563584,56422,1717986816,31942,-960070656,56422,1719427312,30412,-864285666,56438,1616965632,32448,2080832512,808516656,808852480,52428,-859015680,50886,-965986304,50902,-687969280,50796,946652672,50886,-964819204,32332,405962240,236460144,404229632,404232216,404232192,1880627214,404254720,1994129408,0,1063020,-960037376,1046922950,-20527616,-26845060,1718025216,-60397956,1718025216,-26845088,1616965632,506881638,1718026179,-27105160,1751318016,-690586568,2094454272,2093352508,113671168,-960049442,-152648192,952553182,-152648192,-429495176,1818682880,506881638,1718011392,-957415682,-691616256,-960051458,-960051712,2093401798,-960070656,-20527418,-960051712,-60397978,2086727680,2093400256,-1060733952,2119833624,404241408,-960051586,113671168,2094454486,2081437696,-960074696,1824966144,-858993460,-858980858,-960051586,101058048,-690563370,-690553344,-690563370,-690553085,-252661700,909523968,-960051466,-555813376,-262119300,1717992448,2022442558,109869056,-589900042,-690562048,2126956230,2120664576,30732,2093774336,108839036,-960070656,64614,2087123968,65126,1616965632,15468,1819082438,31942,-20939776,54908,947705344,31942,482769920,1828610680,1617100288,3720910,-554244608,58988,2020402688,15974,1718019584,50942,-19479040,50886,-20527616,31942,-960070656,65222,-960051712,289673540,289673540,1437226410,1437226410,-579347081,-579347081,404232216,404232216,404232440,404232216,418912504,404232216,909522678,909522486,254,909522486,1811971270,-20939776,922093302,909522486,909522486,909522486,16647926,909522486,922093310,0,909522686,0,418912504,0,248,404232216,1046922950,-20527616,-26845060,1718025216,-60397956,1718025216,-26845088,1616965632,506881638,1718026179,-27105160,1751318016,-690586568,2094454272,2093352508,113671168,-960049442,-152648192,952553182,-152648192,-429495176,1818682880,506881638,1718011392,-957415682,-691616256,-960051458,-960051712,2093401798,-960070656,-20527418,-960051712,-60397978,2086727680,2093400256,-1060733952,2119833624,404241408,-960051586,113671168,2094454486,2081437696,-960074696,1824966144,-858993460,-858980858,-960051586,101058048,-690563370,-690553344,-690563370,-690553085,-252661700,909523968,-960051466,-555813376,-262119300,1717992448,2022442558,109869056,-589900042,-690562048,2126956230,2120664576,30732,2093774336,108839036,-960070656,64614,2087123968,65126,1616965632,15468,1819082438,31942,-20939776,54908,947705344,31942,482769920,50894,-554244608,3720910,-554244608,58988,2020402688,15974,1718019584,50942,-19479040,50886,-20527616,31942,-960070656,65222,-960051712,64614,1719427312,31942,-1060733952,32346,404241408,50886,-964819332,31958,-696512456,50796,946652672,52428,-858980858,50886,2114323968,54998,-690553344,54998,-690553085,61616,1010187264,50886,-153160192,61536,2087123968,31942,516324352,56534,-153691136,32454,2120664576,';
  j:=0;
  for i:=0 to 511 do
  begin
    bool:=false;
    repeat
      c:=getChar(s,j);
      if (c='-') then bool:=true;
      j:=j+1;
    until (c>='0') and (c<='9');
    k:=0;
    repeat
      k:=k*10+(ord(c)-ord('0'));
      c:=getChar(s,j);
      j:=j+1;
    until (c<'0') or (c>'9');
    if bool=true then k:=-k;
    f[i]:=k;
  end;
  w:=getWidth;
  h:=getHeight;
  setColor(0,0,0);
  fillRect(0,0,w,h);
  setColor(0,255,0);
  //{test} drawText(win2utf(utf2win('АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя')),0,20);
  text(0,0,utf2win('PC BIOS code page'));
  setColor(0,255,255);
  text(0,8,utf2win('Привет мир!'));
  repaint;	
  repeat delay(1000); until false;
end.

Последний раз редактировалось abcdef, 27.08.2009 в 17:56.
(Offline)
 
Ответить с цитированием
Эти 7 пользователя(ей) сказали Спасибо abcdef за это полезное сообщение:
Banan (28.08.2009), baton4ik (17.12.2009), DannN (27.08.2009), Phantom (31.08.2009), scimitar (02.12.2009), t()}{@ (31.07.2010), Tronix (27.08.2009)