Author Topic: Add function to the gc class  (Read 26124 times)

0 Members and 3 Guests are viewing this topic.

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #15 on: September 02, 2011, 01:55:46 pm »
Shouldn't that be possible? Isn't it just stored in a property of the object? Your workaround is also a good solution, but not as clean as I'd like. :p

What do you mean, the color can be changed when drawing an image?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #16 on: September 02, 2011, 02:00:35 pm »
Well, the gc object stores stuff in places we can't reach (its C based I guess).

After drawing an image, the current color is the color of the last pixel in the image. This mean that it uses setColorRGB somehow (or setColorRGB uses the same color memory location or whatever)

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: Add function to the gc class
« Reply #17 on: September 02, 2011, 02:01:31 pm »
Shouldn't that be possible? Isn't it just stored in a property of the object? Your workaround is also a good solution, but not as clean as I'd like. :p

What do you mean, the color can be changed when drawing an image?

There is a glitch in OS 3.01 and 3.0.2 (understand what you want with this sentence ;) ).
When you draw an image, the last pixel affect the global color and global alpha
« Last Edit: September 02, 2011, 02:02:23 pm by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #18 on: September 02, 2011, 02:05:39 pm »
Mmm, okay. Than I'll have to create my own setColor function, and actually also a custom image function to solve that bug... Well, let's get back to work.  :D

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Add function to the gc class
« Reply #19 on: September 02, 2011, 02:42:47 pm »
About your graphics library, maybe we can merge our project together  ?

I mean put your library in the BetterLuaAPI project, which is open to everybody who wants to improve it.

Of course your name would appear on the top :)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #20 on: September 02, 2011, 02:57:54 pm »
Mmm, I'm not really sure about that. On one side I think it's a great idea: it's always better to have more people working on something and your BetterLuaAPI has a couple of great functions. On the other hand your library takes a different approach than the one I'm working on: I'm trying to keep all drawing code in the graphic context object, all logic (like clicks) in a to-be-created screen object and I've got a couple of other different ideas... Furthermore I'm a bit like a minimalist programmer, for example (to be blunt): I don't see the point in your color table or a square function...

Not to mention that I've got just 50 lines of code... What do you think?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Add function to the gc class
« Reply #21 on: September 02, 2011, 04:03:43 pm »
Heya Frog by the way and welcome to the forums. Glad to see another TI-Nspire programmer around.

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #22 on: September 02, 2011, 04:40:08 pm »
Thanks, this sure is a warm welcome. :)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Add function to the gc class
« Reply #23 on: September 02, 2011, 04:43:11 pm »
Mmm, I'm not really sure about that. On one side I think it's a great idea: it's always better to have more people working on something and your BetterLuaAPI has a couple of great functions. On the other hand your library takes a different approach than the one I'm working on: I'm trying to keep all drawing code in the graphic context object, all logic (like clicks) in a to-be-created screen object and I've got a couple of other different ideas... Furthermore I'm a bit like a minimalist programmer, for example (to be blunt): I don't see the point in your color table or a square function...

Not to mention that I've got just 50 lines of code... What do you think?

Well I could (and I probably will, one day) rewrite how my "library" works.
Maybe I'll do something like you.

However, about that colortable, you know, I just put some things there and people can take whatever functions they want, that's all. If they don't need some stuff they just don't take it :P
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #24 on: September 03, 2011, 04:16:59 am »
Yeah, you're right. People don't have to take everything, they can just take the functions they need. I'll just continue writing my library from the ground up for now, and I'll post it when it's largely finished.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Add function to the gc class
« Reply #25 on: September 03, 2011, 06:14:11 pm »
Great, good luck :)

And btw, about that ti.timage color leak, TI knows about it, it's been reported.
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #26 on: September 08, 2011, 01:27:59 pm »
I feel kind of stupid to ask this, but how do you add a property to platform.window? I'm currently using a custom window class, but that class has just one property called screen. Obviously it's a bit strange to have a custom window class with just one property while there's already a window class available. I tried the same thing as described above among other things, but nothing works. How can I do this? ;)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Add function to the gc class
« Reply #27 on: September 08, 2011, 03:38:32 pm »
Hmm, it works for me the same way.
Here is an examle:
Code: (Lua) [Select]
window = getmetatable(platform.window)

function window:pixels()
  return self:height()*self:width()
end

function on.paint(gc)
  gc:drawString(tostring(platform.window:pixels()),10,10,"top")
end

Offline Frog

  • LV2 Member (Next: 40)
  • **
  • Posts: 35
  • Rating: +0/-0
    • View Profile
Re: Add function to the gc class
« Reply #28 on: September 08, 2011, 04:31:35 pm »
Yes, that's true. But I somehow can't add new properties. For example I'm trying to do this:

Code: [Select]
-- Doesn't work: attempt to index local 'self' (a user data value)
platform.window.screen = main

-- Doesn't work, I can call the function but the function throws the same error.
function window:setScreen(screen)
    self.screen = screen
end
platform.window:setScreen(main)

But both methods don't work. The only thing that does work is modifying to metatable directly, so by doing window.screen = main, but I don't really like doing that (except for the default value).

Am I doing something wrong?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Add function to the gc class
« Reply #29 on: September 08, 2011, 05:16:38 pm »
Well, I think platform.window.screen is equivalent to platform.window["screen"], and platform.window isn't a table as far as I know.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman