Creating a bitmap on the fly, then using it on a button. Possible?

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating a bitmap on the fly, then using it on a button. Possible?

Kagehi
I have had plua installed on my Palm for a while now, but opted to
avoid it, since I had more experience with Basic, which I also have on
there. Of course, smallbasic has no real GUI controls and it turns out
its fill functions are fracked... This leads me to trying plua. It has
one advantage, in that I can set some parts as editable text fields,
no more:

if pen(1) then
  if pen(2) and pen (3) are in the box when my text is then
    moveto some_where
    input "What do you want to change this to?", val
  ...

Pain in the ass.. Not mind you that plua's insistence on using
'someotherfunction(object)' to get a value from it, instead of doing
what most controls in everything else from VB to wxlua does and ask
the control, i.e. 'control.value', isn't going to be annoying. Ok, I
am sure you are going to argue that on Palm that isn't easy. Your
wrong though, since such things are usually defined like:

function value() {
  self.iunknown(getattrib, valueattrib, val)
  return val
}

Its just stuffing the retrieval function into a function that is part
of the object. Having to do it so indirectly was just ... odd.

Anyway. I want to replace my "fake" buttons with real ones now, but I
am not sure if that means I have to somehow create small bitmaps and
save them as resources, then muddle with them that way, or if there is
some way to just draw the bitmap, read it into a buffer, then hand the
buffer over to the button(s) as the bitmap resource, which imho makes
"way" more sense, and is probably how most languages would handle it.

I suspect the answer to the later is "no", in which case, I hope that
at some point we get an editor that has a resource manager as well,
including basic bitmap manipulation, so we don't have to code this
stuff on a PC, then compile it, then dump a non-editable version to
the Palm. Hard to do quick and dirty program code when miles from the
nearest PC that way. Not to mention hard to do what I am trying to do,
which is fiddle with the code *while* playing the online game I am
designing the helper application for. Popping out of the game to fix
code, then do a hotsync to upload the changes, is just *slightly*
counter productive. lol

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Dado Sutter-2-2
Hard to help everyone...........
   Lua (and plua) are meant to be FUN, not to help stressed people to get
rid of stone-age languages.

-- Dado



On 6/21/07, Patrick Elliott <[hidden email]> wrote:

>
>   I have had plua installed on my Palm for a while now, but opted to
> avoid it, since I had more experience with Basic, which I also have on
> there. Of course, smallbasic has no real GUI controls and it turns out
> its fill functions are fracked... This leads me to trying plua. It has
> one advantage, in that I can set some parts as editable text fields,
> no more:
>
> if pen(1) then
> if pen(2) and pen (3) are in the box when my text is then
> moveto some_where
> input "What do you want to change this to?", val
> ...
>
> Pain in the ass.. Not mind you that plua's insistence on using
> 'someotherfunction(object)' to get a value from it, instead of doing
> what most controls in everything else from VB to wxlua does and ask
> the control, i.e. 'control.value', isn't going to be annoying. Ok, I
> am sure you are going to argue that on Palm that isn't easy. Your
> wrong though, since such things are usually defined like:
>
> function value() {
> self.iunknown(getattrib, valueattrib, val)
> return val
> }
>
> Its just stuffing the retrieval function into a function that is part
> of the object. Having to do it so indirectly was just ... odd.
>
> Anyway. I want to replace my "fake" buttons with real ones now, but I
> am not sure if that means I have to somehow create small bitmaps and
> save them as resources, then muddle with them that way, or if there is
> some way to just draw the bitmap, read it into a buffer, then hand the
> buffer over to the button(s) as the bitmap resource, which imho makes
> "way" more sense, and is probably how most languages would handle it.
>
> I suspect the answer to the later is "no", in which case, I hope that
> at some point we get an editor that has a resource manager as well,
> including basic bitmap manipulation, so we don't have to code this
> stuff on a PC, then compile it, then dump a non-editable version to
> the Palm. Hard to do quick and dirty program code when miles from the
> nearest PC that way. Not to mention hard to do what I am trying to do,
> which is fiddle with the code *while* playing the online game I am
> designing the helper application for. Popping out of the game to fix
> code, then do a hotsync to upload the changes, is just *slightly*
> counter productive. lol
>
>  
>


[Non-text portions of this message have been removed]

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Cameron Kaiser
In reply to this post by Kagehi
> Pain in the ass.. Not mind you that plua's insistence on using
> 'someotherfunction(object)' to get a value from it, instead of doing
> what most controls in everything else from VB to wxlua does and ask
> the control, i.e. 'control.value', isn't going to be annoying. Ok, I
> am sure you are going to argue that on Palm that isn't easy. Your
> wrong though, since such things are usually defined like:
>
> function value() {
>   self.iunknown(getattrib, valueattrib, val)
>   return val
> }
>
> Its just stuffing the retrieval function into a function that is part
> of the object. Having to do it so indirectly was just ... odd.

It's odd to you, but not to those of us who are in fact from backgrounds
where this is typical. Not everyone has the same background as you do.

> Anyway. I want to replace my "fake" buttons with real ones now, but I
> am not sure if that means I have to somehow create small bitmaps and
> save them as resources, then muddle with them that way, or if there is
> some way to just draw the bitmap, read it into a buffer, then hand the
> buffer over to the button(s) as the bitmap resource, which imho makes
> "way" more sense, and is probably how most languages would handle it.

Why would "most languages" handle it that way? It's just as valid to use
a bitmap reference to something predefined. Again, this is all in where
you're "coming rom."

> I suspect the answer to the later is "no", in which case, I hope that
> at some point we get an editor that has a resource manager as well,
> including basic bitmap manipulation, so we don't have to code this
> stuff on a PC, then compile it, then dump a non-editable version to
> the Palm.

It sounds to me like this problem is more with workflow, not with Plua.
Why not use a real on-board resource editor (RsrcEdit comes to mind)?

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
  Cameron Kaiser * Floodgap Systems * www.floodgap.com * [hidden email]
-- This product moves when used. -- Actual label, children's scooter ----------
Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Kagehi
In reply to this post by Dado Sutter-2-2
--- In [hidden email], "Dado Sutter" <dadosutter@...> wrote:
>
> Hard to help everyone...........
>    Lua (and plua) are meant to be FUN, not to help stressed people
to get
> rid of stone-age languages.
>
> -- Dado
>

Umm. What?? First off, Lua is now widely used in "lots" of places for
serious work. It has even replaced VBScript as the main language in
the telnet game client I use, which previously had a hodge podge of
"well, if you think we need php and I can get it to work, why not..",
languages in it, and is replacing quite a few languages, including
Java in a lot of places. And frankly, I am not surprised, Java is a
pain in the ass to use. As for stone age.. Have you really made a
serious comparison between Lua and Basic? Most of the language
conventions are damn similar to start with. As for the one issue I
ranted about, wxlua also supports GUI. And **it** uses the same Gui
conventions as every other one, which means it uses functions in the
control to expose data, not things like gettext to return them, so
plua isn't even doing what common versions of lua do.

You want to argue that Plua is "just for fun", then fine. I can live
with that. It just means I have to muck with code right out of the
smallbasic app I made to do what I want. This is the code I use there:

if pen(1) or pen(3) then
  if lt = 0 then
    lt = ticks
  elseif ticks > lt + 20 then
    lt = ticks
    gosub do_pen
  endif
endif

label:do_pen
  if pen(1) >= 150 and pen (1) <= 165 then
    'Handle left arrows
    if pen(2) >= 2 and pen (2) <= 19 then
      p = p + 1 * abs(p > 0)
    ...

Basically, the **only** code changes are going to be like:

ev, a1, a2 = gui.event()
if ev = penDown then
  if lt = 0 then
    lt = ???
  elseif ??? then
    lt = ???
    call do_pen(a1, a2)
  endif
endif

then

if a1 >= 150 and a1 <= 165 then
  ...

Mind you, the doc file I am looking at indicated that you can't
currently get system ticks or do datediff and some other things
needed, but its not hard to change the code to increment a value
instead, then test to see if its exceeded last_count + some_amount.
Using system time or number of system ticks is just less sloppy, just
as actually being able to use buffered bitmaps, instead of drawing to
the screen, then fiddling with mouse positions, is less sloppy.

In any case, with the exception of some functions that are not
available, like "ticks", and a minor change in how "input" works, I
could drop the entire smallbasic program I wrote into plua and it
would run "as is". So much for, getting rid of "stone aged"
languages... lol

Now, is there someone here interesting in answering the question I
asked, instead of making snide comments?
   

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

migueletto
--- In [hidden email], "Patrick Elliott" <shadowfyr55@...> wrote:

> As for stone age.. Have you really made a
> serious comparison between Lua and Basic? Most of the language
> conventions are damn similar to start with.

They may look similar on the surface, but once you learn about tables,
metatables, closures, first-order values, etc, you see that Lua is
years ahead ... Sure, you can use Lua as a BASIC-like language, but
that does not place the Lua at the same level of BASIC. Anyway, as I
always say, every language has its own merits and audience.

> As for the one issue I
> ranted about, wxlua also supports GUI. And **it** uses the same Gui
> conventions as every other one, which means it uses functions in the
> control to expose data, not things like gettext to return them, so
> plua isn't even doing what common versions of lua do.

The original Lua version is text-only, no GUI. Many people have
extended it to suppor GUIs in different ways, Plua is one, wxLua is
another, IUP another one. Again, each one has good and bad points.
 
> Mind you, the doc file I am looking at indicated that you can't
> currently get system ticks or do datediff and some other things
> needed

Have you looked at os.clock() ? This standard Lua function is also
supported in Plua. Try print(os.clock()) a few times in the
interactive mode to see it in action.

Regards,
Marcio.

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

migueletto
In reply to this post by Kagehi
--- In [hidden email], "Patrick Elliott" <shadowfyr55@...> wrote:

> I suspect the answer to the later is "no", in which case, I hope that
> at some point we get an editor that has a resource manager as well,
> including basic bitmap manipulation, so we don't have to code this
> stuff on a PC, then compile it, then dump a non-editable version to
> the Palm.

In PalmOS, graphic buttons require the bitmap to be stored in a resource.

I know of at least three onboard bitmap/resource editors, although I
do not use any. You may want to try "BIRD" (freeware):
http://www.ppcompiler.org/

Or RsrcEdit (shareware):
http://quartus.net/products/rsrcedit/

Or TbmpEdit (open source):
http://tbmpedit.sourceforge.net/

Regards,
Marcio.


Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Kagehi
In reply to this post by migueletto
--- In [hidden email], "migueletto" <mmand@...> wrote:

>
> --- In [hidden email], "Patrick Elliott" <shadowfyr55@> wrote:
>
> > As for stone age.. Have you really made a
> > serious comparison between Lua and Basic? Most of the language
> > conventions are damn similar to start with.
>
> They may look similar on the surface, but once you learn about tables,
> metatables, closures, first-order values, etc, you see that Lua is
> years ahead ... Sure, you can use Lua as a BASIC-like language, but
> that does not place the Lua at the same level of BASIC. Anyway, as I
> always say, every language has its own merits and audience.
>
Yeah. Seen some examples of that. The telnet client that uses it
actually has a *much* improved method of dealing with color changes on
a line using those tables. Before, you had to figure out *which* line
you wanted, then do some complicated stuff that stepped through it, to
return each code, one at a time. Lot easier when you get a table that
already contains them all. In any case, seeing the stuff Lua can do, I
tend to think of it as, "What MS should have done with VB, only,
missing a few things, like switch/select commands that they ironically
got right." lol Mind you, there is an alternate method to getting
switches in Lua, its just not quite as straight forward.

> > As for the one issue I
> > ranted about, wxlua also supports GUI. And **it** uses the same Gui
> > conventions as every other one, which means it uses functions in the
> > control to expose data, not things like gettext to return them, so
> > plua isn't even doing what common versions of lua do.
>
> The original Lua version is text-only, no GUI. Many people have
> extended it to suppor GUIs in different ways, Plua is one, wxLua is
> another, IUP another one. Again, each one has good and bad points.
>  
Yeah. One would think though that people would at some point consider
learning from each others mistakes, not just making new ones, sight
unseen, then wondering why new mistakes crop up. ;) Seriously though,
you are correct that all of them have flaws. Been fighting with the
**intentional** flaw MS put in MFC for a while, which doesn't let you
late bind objects and recieve events from them. The solutions are
convoluted and insane, or require stuff you can't use on anything that
won't run .NET. Guess what the now open sourced telnet client uses..
MFC, intended to run on everything back to 9x... All they seem to do
is replace one set of, "Oh, sorry, you can't do that!", with a new set
of restrictions on what you can do, and often for no apparently sane
reason.

Oh, you might as "why" a telnet client would need this.. Well, so you
can show images non-inlined from game servers that support the MXP
<image> tag, or you can borrow the icons from EQ and display your
inventory in a GUI, like graphical RPGs do, or design your own form
for searching info on items you are keeping track of, etc. Kind of
hard to do now, since you can create an external exe, use some minimal
code to load it, some hacks to get "it" to send back data, but you
can't simply have the object inform the client+script that something
happened, then act on it. Really **bad** if your control is something
like a plugin for Winamp, which can't talk to the client, doesn't know
how to direct messages through the client and where its events can't
trigger the client to suspend and run the right script function. Its
been driving me rather nuts for a while now. lol

> > Mind you, the doc file I am looking at indicated that you can't
> > currently get system ticks or do datediff and some other things
> > needed
>
> Have you looked at os.clock() ? This standard Lua function is also
> supported in Plua. Try print(os.clock()) a few times in the
> interactive mode to see it in action.
>
Actually, no. Didn't see it on the list of functions supported in the
docs, so didn't know to look for it at all. Thanks, that should help a
lot.

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Kagehi
In reply to this post by migueletto
--- In [hidden email], "migueletto" <mmand@...> wrote:

>
> --- In [hidden email], "Patrick Elliott" <shadowfyr55@> wrote:
>
> > I suspect the answer to the later is "no", in which case, I hope that
> > at some point we get an editor that has a resource manager as well,
> > including basic bitmap manipulation, so we don't have to code this
> > stuff on a PC, then compile it, then dump a non-editable version to
> > the Palm.
>
> In PalmOS, graphic buttons require the bitmap to be stored in a
resource.

>
> I know of at least three onboard bitmap/resource editors, although I
> do not use any. You may want to try "BIRD" (freeware):
> http://www.ppcompiler.org/
>
> Or RsrcEdit (shareware):
> http://quartus.net/products/rsrcedit/
>
> Or TbmpEdit (open source):
> http://tbmpedit.sourceforge.net/
>
> Regards,
> Marcio.
>

Ok, now I am going to ask a real dumb question. How does Plua know
which "resource" belongs to the app then? Do you just give it the same
name as the application, but with an .rc extension? Anyway, I will
look into these.

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

migueletto
In reply to this post by Kagehi
--- In [hidden email], "Patrick Elliott" <shadowfyr55@...> wrote:

> > Have you looked at os.clock() ? This standard Lua function is also
> > supported in Plua. Try print(os.clock()) a few times in the
> > interactive mode to see it in action.
> >
> Actually, no. Didn't see it on the list of functions supported in the
> docs, so didn't know to look for it at all. Thanks, that should help a
> lot.

The Plua documentation only shows extensions to Lua or functions that
are not supported (like datediff). To know everything that is
available you should read the Lua documentation:

http://www.lua.org/manual/5.0/

Regards,
Marcio.


Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

migueletto
In reply to this post by Kagehi
--- In [hidden email], "Patrick Elliott" <shadowfyr55@...> wrote:

> > In PalmOS, graphic buttons require the bitmap to be stored in a
> > resource.

> Ok, now I am going to ask a real dumb question. How does Plua know
> which "resource" belongs to the app then? Do you just give it the same
> name as the application, but with an .rc extension? Anyway, I will
> look into these.

It does not know. This is one the funny things in PalmOS. When you
call the PalmOS API to open a resource, it will search for a matching
resource in all open resource databases, stopping at the first match.
The databases are searched in the reverse order in which they were
opened. So, if your bitmap resource is not stored inside the
application PRC (which is always open while the application is
runnig), you could open another resource database first, and then
create the button.

Regards,
Marcio.


Reply | Threaded
Open this post in threaded view
|

RE: Re: Creating a bitmap on the fly, then using it on a button. Possible?

Blake Winton-3
In reply to this post by Kagehi
> missing a few things, like switch/select commands

I find that in any language I use, I eventually move away from switch or
select commands to tables containing function pointers (or classes with
a single "run" method in Java).  They're just way easier to maintain,
and after having to convert a couple of hundred-odd switch statements to
tables of functions, I now figure that it's just easier to skip the
switch
statement in the first place.  ;)

Later,
Blake.
Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Kagehi
In reply to this post by migueletto
--- In [hidden email], "migueletto" <mmand@...> wrote:

>
> --- In [hidden email], "Patrick Elliott" <shadowfyr55@> wrote:
>
> > > In PalmOS, graphic buttons require the bitmap to be stored in a
> > > resource.
>
> > Ok, now I am going to ask a real dumb question. How does Plua know
> > which "resource" belongs to the app then? Do you just give it the same
> > name as the application, but with an .rc extension? Anyway, I will
> > look into these.
>
> It does not know. This is one the funny things in PalmOS. When you
> call the PalmOS API to open a resource, it will search for a matching
> resource in all open resource databases, stopping at the first match.
> The databases are searched in the reverse order in which they were
> opened. So, if your bitmap resource is not stored inside the
> application PRC (which is always open while the application is
> runnig), you could open another resource database first, and then
> create the button.
>
This OS is going to give me a head ache. For example, for some
fracking reason, every time I make changes to the file "--gui.lua",
which I am using to try to code this, then something takes place that
causes a reset, even if I am *not* any longer running Plua, it reverts
the file back the "original" contents from the first time I created
and tried to run it. Every change I have tried to make since just
vanishes. I am not sure if this is a bug in how Plua calls the editor,
some crazy interaction with BackupBuddyVFS or a failure to hotsync
properly, or what. I have BTW "tried" to do a hotsynch before any
reset happens, which should, one would assume, save the changes.

Ok, it "is" saving the changes, I just looked in the hotsync data and
found all my changes are in the document on the PC, but *not* on the
version installed on the Palm... This is real weird. Any ideas what
the heck is going on?

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Kagehi
In reply to this post by Cameron Kaiser
--- In [hidden email], Cameron Kaiser <spectre@...> wrote:

>
> > Pain in the ass.. Not mind you that plua's insistence on using
> > 'someotherfunction(object)' to get a value from it, instead of doing
> > what most controls in everything else from VB to wxlua does and ask
> > the control, i.e. 'control.value', isn't going to be annoying. Ok, I
> > am sure you are going to argue that on Palm that isn't easy. Your
> > wrong though, since such things are usually defined like:
> >
> > function value() {
> >   self.iunknown(getattrib, valueattrib, val)
> >   return val
> > }
> >
> > Its just stuffing the retrieval function into a function that is part
> > of the object. Having to do it so indirectly was just ... odd.
>
> It's odd to you, but not to those of us who are in fact from backgrounds
> where this is typical. Not everyone has the same background as you do.
>
Hmm. Like a Mac program with a resource fork? Sorry, but as a basic
rule, the code for blitting an image to the screen is the same whether
its a raw bitmap, icon, etc. in a resource file, or one you generate
internally. The only difference is that, if you use the code for
resources to handle them, you usually can't access the buffers for
them. This doesn't mean they don't use the same type of graphical
buffer, it can't be copied to other buffers for editing, etc. It just
means that if you use drawicon or some such function, its going to
hide what it is *really* doing underneath. Personally, this sort of
thing bugs me. I want programs to do what **I** tell them to do, not
what someone else thought I should be *allowed* to do. That is where I
am coming from.

> > I suspect the answer to the later is "no", in which case, I hope that
> > at some point we get an editor that has a resource manager as well,
> > including basic bitmap manipulation, so we don't have to code this
> > stuff on a PC, then compile it, then dump a non-editable version to
> > the Palm.
>
> It sounds to me like this problem is more with workflow, not with Plua.
> Why not use a real on-board resource editor (RsrcEdit comes to mind)?
>
Umm. Tried three of them. Bird was the only one I could get to work
reliably, and unless you know how to a) edit the bitmap using a hex
editor or b) none of them allow you to "create" a blank resource file,
even if two of them allowed you to add new resources to them. I might
as well just use a PC side application to create the .prc file, since
one won't let me edit bitmaps, the second won't support high res
images and the last one crashed and caused a reset when I tried to
just "look" at one of the images in an existing file. All in all, they
didn't impress me, and not just due to not working. They also look
like most other hacker code projects, including mine. Lots of obscure
names, unclear buttons, assumptions about what the users already
"knows", too little sanity checks, to make sure they don't blow
something up, etc. I don't mind those, if I have a clue what I am
doing. If not, then I at least hope there is decent documentation some
place. The page of the last one I looked at basically said, "Sorry, no
documentation, but it should be obvious from the buttons what things
do, if/when any of them work." Ack!!!

Anyway. I think I will give up on trying to mess with resource images.
Easier to draw a couple of arrows, pop them into buffers, then blit
then into place as needed. Its not like doing that is any worse than
the method I am already using in the smallbasic version. lol

Reply | Threaded
Open this post in threaded view
|

Re: Creating a bitmap on the fly, then using it on a button. Possible?

Kagehi
In reply to this post by Blake Winton-3
--- In [hidden email], "Blake Winton" <blake@...> wrote:

>
> > missing a few things, like switch/select commands
>
> I find that in any language I use, I eventually move away from switch or
> select commands to tables containing function pointers (or classes with
> a single "run" method in Java).  They're just way easier to maintain,
> and after having to convert a couple of hundred-odd switch statements to
> tables of functions, I now figure that it's just easier to skip the
> switch
> statement in the first place.  ;)
>
Well, yeah, once you know you can do that. lol Still, its kind of like
using the old "a = a + abs(some_condition) -
abs(some_other_condition)" trick. Its far more readable to have
everything in one place sometimes, instead of having a table, where
you have to jump around a bit to figure out "where" things are going.
Its less a, "It works better.", than a, "Its easier to see what its
actually doing.", situation. Especially if you are not making calls to
functions, but just executing 1-2 lines of code for each branch. But
yeah, its not needed, any more than "goto" is now, but some times the
solution that is available is not always exactly... optimal.