Drawing images with transparent parts

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
KcDan
Posts: 13
Joined: Tue Jan 24, 2006 7:58 am
Location: Delaware
Contact:

Drawing images with transparent parts

Post by KcDan »

Hello, I'm Dan. I am currently working on a Shell that will emulate to an extent Windows, like controls such as windows, buttons, edit box's, static controls, and ect.

Currently I'm working on the cursor drawing. Im new to LUA but not to programming, I have no idea of how to make parts of an image transparent. I've read the LUA tutorial http://wiki.ps2dev.org/psp:lua_player:tutorial and I still dont understand how to do it. Could someone please enlighten me?

Here beith the image
Image
fullerlee
Posts: 54
Joined: Thu Nov 03, 2005 9:46 am

Post by fullerlee »

I've been using a paint program to specify transparent parts of the png. Blit in luaplayer will take into account whichever parts of the image are transparent.

If you don't have a paint program capable of doing this (such as Paint Shop Pro or Photoshop), try GIMP (http://www.gimp.org) - it's free and very good.

Lee
KcDan
Posts: 13
Joined: Tue Jan 24, 2006 7:58 am
Location: Delaware
Contact:

Post by KcDan »

Thanks, it now works as expected.

So far in my program I have implemented the creation of windows, buttons, static text, and progress bars. I'm going to add one or two more controls and then start working on the messaging system like windows has (SendMessageA(hwnd,msg,wparam,lparam)).

EDIT:

Code: Select all

hMsgBox=CreateWindow(20,20,200,100,"Notice")
hMsgBoxOk=CreateButton(7,4,50,15,"Ok",hMsgBox)
hMsgBoxcancel=CreateButton(146,83,50,15,"Cancel",hMsgBox)
hMsgBoxPBar=CreateProgressBar(5,59,150,20,0,100,50,hMsgBox)

hWin=CreateWindow(250,60,150,100,"Window")
hWinMsg=CreateStatic(20,10,96,80,"This is the message that is displayed.",hWin)
Image
mrn
Posts: 116
Joined: Wed Nov 02, 2005 2:26 am

Post by mrn »

Nice tools.
I'd propose to ALLOW "hot keys" whenever a message box appears by also printing them. Example:

[O OK] [X Cancel] [> Next] [< Prev] etc.

imho, such hot-keyes should become standard in the PSP-Lua world..
KcDan
Posts: 13
Joined: Tue Jan 24, 2006 7:58 am
Location: Delaware
Contact:

Post by KcDan »

I've worked on this a lot and here's a screenshot of an app being run on it.Image
It's a fully working calculator. To close the window simply press the x in the top right corner of the window. Now to add windows being dragged by the titlebar...

Heres the code for the calculator to show how simple it was to make (thanks to KawaGeo and ema for evaluate method)

Code: Select all

--Main proc where all messages are sent
function MainProc&#40;wnd,msg,wparam,lparam&#41;
   if wnd==hCalculator then 
      if msg==wm_lclick then
        if wparam==hCalculator_1 then
          CalculatorEquation=CalculatorEquation.."1"
        elseif wparam==hCalculator_2 then
          CalculatorEquation=CalculatorEquation.."2"
        elseif wparam==hCalculator_3 then
          CalculatorEquation=CalculatorEquation.."3"
        elseif wparam==hCalculator_4 then
          CalculatorEquation=CalculatorEquation.."4"
        elseif wparam==hCalculator_5 then
          CalculatorEquation=CalculatorEquation.."5"
        elseif wparam==hCalculator_6 then
          CalculatorEquation=CalculatorEquation.."6"
        elseif wparam==hCalculator_7 then
          CalculatorEquation=CalculatorEquation.."7"
        elseif wparam==hCalculator_8 then
          CalculatorEquation=CalculatorEquation.."8"
        elseif wparam==hCalculator_9 then
          CalculatorEquation=CalculatorEquation.."9"
        elseif wparam==hCalculator_0 then
          CalculatorEquation=CalculatorEquation.."0"
        elseif wparam==hCalculator_equal then
          script = "return "..CalculatorEquation
          CalculatorEquation = assert&#40;loadstring&#40;script&#41;&#41;&#40;&#41; 
        elseif wparam==hCalculator_period then
          CalculatorEquation=CalculatorEquation.."."
        elseif wparam==hCalculator_plus then
          CalculatorEquation=CalculatorEquation.."+"
        elseif wparam==hCalculator_minus then
          CalculatorEquation=CalculatorEquation.."-"
        elseif wparam==hCalculator_mult then
          CalculatorEquation=CalculatorEquation.."*"
        elseif wparam==hCalculator_div then
          CalculatorEquation=CalculatorEquation.."/"
        elseif wparam==hCalculator_cls then
          CalculatorEquation="0"
        end
        SetWindowText&#40;hCalculator_ans,CalculatorEquation&#41;
      end
   end
end

--Control creation
hCalculator=CreateWindow&#40;20,20,157,172,"Calculator"&#41;

hCalculator_1=CreateButton&#40;10,100,30,30,"1",hCalculator&#41;
hCalculator_2=CreateButton&#40;45,100,30,30,"2",hCalculator&#41;
hCalculator_3=CreateButton&#40;80,100,30,30,"3",hCalculator&#41;
hCalculator_4=CreateButton&#40;10,65,30,30,"4",hCalculator&#41;
hCalculator_5=CreateButton&#40;45,65,30,30,"5",hCalculator&#41;
hCalculator_6=CreateButton&#40;80,65,30,30,"6",hCalculator&#41;
hCalculator_7=CreateButton&#40;10,30,30,30,"7",hCalculator&#41;
hCalculator_8=CreateButton&#40;45,30,30,30,"8",hCalculator&#41;
hCalculator_9=CreateButton&#40;80,30,30,30,"9",hCalculator&#41;
hCalculator_0=CreateButton&#40;10,135,30,30,"0",hCalculator&#41;
hCalculator_equal=CreateButton&#40;80,135,30,30,"=",hCalculator&#41;
hCalculator_period=CreateButton&#40;45,135,30,30,".",hCalculator&#41;
hCalculator_plus=CreateButton&#40;115,30,30,30,"+",hCalculator&#41;
hCalculator_minus=CreateButton&#40;115,65,30,30,"-",hCalculator&#41;
hCalculator_mult=CreateButton&#40;115,100,30,30,"*",hCalculator&#41;
hCalculator_div=CreateButton&#40;115,135,30,30,"/",hCalculator&#41;

hCalculator_ans=CreateStatic&#40;10,5,100,20,"0",hCalculator&#41;
hCalculator_cls=CreateButton&#40;115,5,30,20,"C",hCalculator&#41;
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

hmm looks very familiar
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Post by Zenurb »

You could in theory emulate the entire windows drawing api.

Have you written some kind of events into your API? (e.g. mouse clicks bringing a window to topmost status, window movement, window painting, etc.)
Proud Dvorak User
US 1.5 PSP (Original)
KcDan
Posts: 13
Joined: Tue Jan 24, 2006 7:58 am
Location: Delaware
Contact:

Post by KcDan »

Zenurb wrote:You could in theory emulate the entire windows drawing api.

Have you written some kind of events into your API? (e.g. mouse clicks bringing a window to topmost status, window movement, window painting, etc.)
I have an initiate message, paint message, left click message, right click message, left and right over message, and a close message. Coding with it kinda sucks so Ima scratch this project and work on a better planned organized project like this. But for this being my first project in LUA and on PSP I'd say I did a pretty good job.
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Post by Zenurb »

I'd prefer to see a more object orientated language like Ruby become a PSP "Player" language. Ruby could probably be more easily intergrated into it and would allow for proper object orientatism. Sadly this probably wont come true :( I can't port it because I don't know a thing about C.
Proud Dvorak User
US 1.5 PSP (Original)
my psprecious
Posts: 24
Joined: Fri Feb 17, 2006 5:08 am

Post by my psprecious »

another thing you can do to .png that will help get smaller image is to turn them to indexed colr (yeah you only get 256 colors but you can do amazing stuff with 256 colors) and you can have the transparency to, good way to make smaller files.

lil update, indexed color will preserve the invisibility around the image but not transparency on an image, for that you need rgb
Post Reply