How to query WIZ keys?

Started by deetee, October 28, 2010, 09:34:30 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EugeneP

Yes, when I first encountered Fenix I had strange feeling as if authors wanted to mix Pascal and C.

deetee

Hi all!

Actually I was a little bit lost - I should have seen for myself that it is some kind of bitwise-or-assignment. But the brain stops to work if you go to google first. :)

I would like to develop a text editor for my WIZ with touchscreen support - similar to keeEDIT for my N-Gage (see http://web.uta4you.at/shop/). But starting with some "curiosities" of WIZ and bennu is hard.

Regards
deetee

EugeneP

Text editor in Bennu is quite a task!

The first question will be: How to store text file in memory?

PS
Nothing personal. I was in really bad mood that day.

deetee

I saw in the bennu-reference functions like Fopen, Fclose, Fputs and Fgets which seems to be C-like - and hopefully there is a function to allocate memory.

But first I have to do some key-, font- and touchscreen-experiments.

Regards
deetee

EugeneP

I would not not mind to have book reader and text editor purely written in Bennu, so I wish you good luck.

deetee

I like WIZWRITE.

I tried to convice ZX81 to add some touchscreen support, but he has no time to expand this good program. So I try it by myself (with bennu).

Where can I get "text editor" for the WIZ (or did you mean WIZWRITE from ZX81?) - I couldn't find it - Does it have (good) touchscreen support.

Regards
deetee

handsource-dyko

Writing a text editor in bennu...
Well it's possible, but not practical. You need to write textinput functions yourself, wich isn't hard, but you need to work a lot
with pointers. You can allocate memory yourself with bennu. Bennu provides most of the familiar C functions.

But, bennu has no proper gui lib. Yes thare are some  of them around, but their either incomplete or provide limited functionality.
Maybe someone should port the sdl gui Agar to a bennu extension lib. It would be very usefull. So, any kind of controls have to be
written by yourself.

About the C/pascal mix, I personally like it a lot. I can look up any C book for general concepts, and they easily translate to bennu,
but in a nicer sort of way. Bennu/div took the good things from both languages, what I find good about it in contrast to C is that
it less cryptic since it uses Pascal style keywords. Yet I see some examples of programs written like C programs, and I find these less
readable.

Anyway, be carefull when you use someonelse's code, make sure that you undestand it before you use it. It's sometimes better to 
rewrite it to your own taste/style that you are comfortable with. I do this a lot, especially for readabilty. Changing one or two character
identifiers to meaningfull names, adding more comments etc.

EugeneP

QuoteWell it's possible, but not practical.
Yes, I mean it, but yet writing such editor is possible. It would be quite a work of art.

deetee

Hi!

Finally I want to post some quick code which allows to play with keys and touchscreen on the WIZ or PC:

import "mod_text";
import "mod_key";
import "mod_joy";
import "mod_string";
import "mod_proc";
import "mod_mouse";


const
KEY_UP=0; KEY_UPLEFT= 1; KEY_LEFT=2; KEY_DOWNLEFT=3;
KEY_DOWN=4; KEY_DOWNRIGHT=5;
KEY_RIGHT=6; KEY_UPRIGHT=7;
KEY_MENU=8; KEY_SELECT=9; KEY_L=10; KEY_R=11;
KEY_A=12; KEY_B=13; KEY_X=14; KEY_Y=15;
KEY_VOLUP=16; KEY_VOLDOWN=17; KEY_CLICK=18;
KEY_LAST=19;
end

function byte key_query()
begin
if    (joy_getbutton(0,KEY_UP))        return KEY_UP;
elseif(joy_getbutton(0,KEY_UPLEFT))    return KEY_UPLEFT;
elseif(joy_getbutton(0,KEY_LEFT))      return KEY_LEFT;
elseif(joy_getbutton(0,KEY_DOWNLEFT))  return KEY_DOWNLEFT;
elseif(joy_getbutton(0,KEY_DOWN))      return KEY_DOWN;
elseif(joy_getbutton(0,KEY_DOWNRIGHT)) return KEY_DOWNRIGHT;
elseif(joy_getbutton(0,KEY_RIGHT))     return KEY_RIGHT;
elseif(joy_getbutton(0,KEY_UPRIGHT))   return KEY_UPRIGHT;
elseif(joy_getbutton(0,KEY_MENU))      return KEY_MENU;
elseif(joy_getbutton(0,KEY_SELECT))    return KEY_SELECT;
elseif(joy_getbutton(0,KEY_L))         return KEY_L;
elseif(joy_getbutton(0,KEY_R))         return KEY_R;
elseif(joy_getbutton(0,KEY_A))         return KEY_A;
elseif(joy_getbutton(0,KEY_B))         return KEY_B;
elseif(joy_getbutton(0,KEY_X))         return KEY_X;
elseif(joy_getbutton(0,KEY_Y))         return KEY_Y;
elseif(joy_getbutton(0,KEY_VOLUP))     return KEY_VOLUP;
elseif(joy_getbutton(0,KEY_VOLDOWN))   return KEY_VOLDOWN;
elseif(joy_getbutton(0,KEY_CLICK))     return KEY_CLICK;
else return(0); end
end


process main()
private
int escape=0, was_clicked=0;
string str1="", str2="";
begin

repeat
  str1="WIZ-Key:"+itoa(key_query())+" Character: "+chr(ascii)+" "+itoa(ascii);
  write_string(0,320/2,200/2,4,&str1);

  if((was_clicked==1) && (! mouse.left))
   str2="x:"+itoa(mouse.x)+" y:"+itoa(mouse.y);
   write_string(0,320/2,240/2,4,&str2);

  end;
  was_clicked = mouse.left;

  if(key(_ESC) or joy_getbutton(0,KEY_MENU)) escape=1; end
  frame;
until(escape);

let_me_alone();
end


As you could see I did the key query the direct way (with joy_getbutton() and without jkeys.lib).
In addition I inserted some touchscreen-code from this forum to test touchscreen-inputs.

Thank you for helping (so far)
Regards
deetee

EugeneP

#24
Glad for you  :)
I am not the person who have rights to say this, but: WELCOME! :) :) :)

----- edit:
After some playing with jkey a also wrote my own input abstraction.

SplinterGU

Quote from: deetee on November 03, 2010, 01:03:20 PM
Hi!

Finally I want to post some quick code which allows to play with keys and touchscreen on the WIZ or PC:

import "mod_text";
import "mod_key";
import "mod_joy";
import "mod_string";
import "mod_proc";
import "mod_mouse";


const
KEY_UP=0; KEY_UPLEFT= 1; KEY_LEFT=2; KEY_DOWNLEFT=3;
KEY_DOWN=4; KEY_DOWNRIGHT=5;
KEY_RIGHT=6; KEY_UPRIGHT=7;
KEY_MENU=8; KEY_SELECT=9; KEY_L=10; KEY_R=11;
KEY_A=12; KEY_B=13; KEY_X=14; KEY_Y=15;
KEY_VOLUP=16; KEY_VOLDOWN=17; KEY_CLICK=18;
KEY_LAST=19;
end

function byte key_query()
begin
if    (joy_getbutton(0,KEY_UP))        return KEY_UP;
elseif(joy_getbutton(0,KEY_UPLEFT))    return KEY_UPLEFT;
elseif(joy_getbutton(0,KEY_LEFT))      return KEY_LEFT;
elseif(joy_getbutton(0,KEY_DOWNLEFT))  return KEY_DOWNLEFT;
elseif(joy_getbutton(0,KEY_DOWN))      return KEY_DOWN;
elseif(joy_getbutton(0,KEY_DOWNRIGHT)) return KEY_DOWNRIGHT;
elseif(joy_getbutton(0,KEY_RIGHT))     return KEY_RIGHT;
elseif(joy_getbutton(0,KEY_UPRIGHT))   return KEY_UPRIGHT;
elseif(joy_getbutton(0,KEY_MENU))      return KEY_MENU;
elseif(joy_getbutton(0,KEY_SELECT))    return KEY_SELECT;
elseif(joy_getbutton(0,KEY_L))         return KEY_L;
elseif(joy_getbutton(0,KEY_R))         return KEY_R;
elseif(joy_getbutton(0,KEY_A))         return KEY_A;
elseif(joy_getbutton(0,KEY_B))         return KEY_B;
elseif(joy_getbutton(0,KEY_X))         return KEY_X;
elseif(joy_getbutton(0,KEY_Y))         return KEY_Y;
elseif(joy_getbutton(0,KEY_VOLUP))     return KEY_VOLUP;
elseif(joy_getbutton(0,KEY_VOLDOWN))   return KEY_VOLDOWN;
elseif(joy_getbutton(0,KEY_CLICK))     return KEY_CLICK;
else return(0); end
end


process main()
private
int escape=0, was_clicked=0;
string str1="", str2="";
begin

repeat
  str1="WIZ-Key:"+itoa(key_query())+" Character: "+chr(ascii)+" "+itoa(ascii);
  write_string(0,320/2,200/2,4,&str1);

  if((was_clicked==1) && (! mouse.left))
   str2="x:"+itoa(mouse.x)+" y:"+itoa(mouse.y);
   write_string(0,320/2,240/2,4,&str2);

  end;
  was_clicked = mouse.left;

  if(key(_ESC) or joy_getbutton(0,KEY_MENU)) escape=1; end
  frame;
until(escape);

let_me_alone();
end


As you could see I did the key query the direct way (with joy_getbutton() and without jkeys.lib).
In addition I inserted some touchscreen-code from this forum to test touchscreen-inputs.

Thank you for helping (so far)
Regards
deetee

I don't suggest use this key_query function, if you press 2 keys at same time you only get 1 of they, for example, if you press A and B, you only get A.

use jkeys.lib.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

deetee

Hello SplinterGU - cool to get an advice from the master himself.

You are right - querying for example a "MENU-SELECT-Reset" is not possible with my function. I will use some better (jkeys-like) solution if I am a little bit more familiar with bennu.

Regards
deetee

Drumpi

Just take your time. There are a lot of combinations to do a "key-input" method, so you must try and find a way you like.
Splinter and me discuss it a lot of times, and have it's own way to do this. Splinter uses his jkeys.lib, it's the easier way to noobs, but i prefer a key scanning and variable increment (or put it to "0" if not), so if this variable have "1", it's recently pressed, if more, more time has pressed, if "0", is not pressed.

Maybe you prefer to use jkeys.lib initially, but (personal opinion) try to search your own style.

Good luck with text editor, i really need one, but i don't have time to do it ;)
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

SplinterGU

directly joy_button if you use it several times in your code is more expensive, for this point, I did jkey.lib on this way.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2