Welcome, Guest. Please login or register.

Author Topic: Programming a Window in C to hold a picture/background  (Read 3116 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show all replies
Programming a Window in C to hold a picture/background
« on: January 09, 2012, 04:35:16 AM »
I would like to learn how to load or program a picture into a window. ANyone have the necessary C code examples or tutorial for that?

I am trying my hand for the first time to program in the AmigaOS environment. I am familiar with most debugging messages and can muddle my through tutorials - I have only been at it for a week and have mad enough progress to say loosely  I have learned a fewthingd about Screens and windows. But I am trolling for mor information. I am Using Louis Se GCC environment - I really like the way it is set up and I am trying to get the basics down but this loading and keeping an image in a window is giving me trouble - mayhaps someone has a lexicon of sorts that explaina the GCC library structure as I am pretty sure I need a more developed Library cache - many of the examples I have found do not compile and the error list is mostly in something like assembler or the like. I am used to debugging: on line 57 etc etc but the errors i get look like this:


Any suggestions are greatly welcome and appreciated.:)
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show all replies
Re: Programming a Window in C to hold a picture/background
« Reply #1 on: January 10, 2012, 12:12:58 AM »
Yep - been using those tutorials mostly - they are really a good place to learn but they only go as far as a simple selecter program - which is cool nd it will come in handy - the getting an image into a window is the heart of my frustration.

A little nudge in the code direction would be helpful.

Nova - that code, I am pretty sure is just an error trap - not very load-an-image based though. but thank anyway. If it does more would you mind explaining it to me?
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show all replies
Re: Programming a Window in C to hold a picture/background
« Reply #2 on: January 10, 2012, 06:05:39 AM »
Quote from: Steady;675107
These are linker errors.

The C environment accesses IntuitionBase, DataTypesBase and GfxBase as global variables, but they are not defined in any module.

This should be fixed by adding the following include references as they define the globals you need:

#include
#include
#include

Good luck.


Code: [Select]



#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/datatypes.h>
#include <datatypes/pictureclass.h>

int main (void)

{
struct RDArgs *rdargs;
struct {
char *file;
char *pubscreen;
} args = {0};
int rc = RETURN_FAIL;
struct Screen *scr;
Object *dto;
struct BitMapHeader *bmhd;
struct BitMap *bm;
WORD winw,winh;
struct Window *win;
struct IntuiMessage *imsg;
BOOL cont;

rdargs = ReadArgs (&quot;FILE/A,PUBSCREEM/K&quot;,(LONG *)&args,NULL);
if (!rdargs)
{
PrintFault (IoErr(),NULL);
return (RETURN_FAIL);
}

if (scr = LockPubScreen (args.pubscreen))
{

if (dto = NewDTObject (args.file,DTA_GroupID,GID_PICTURE,PDTA_Remap,TRUE,PDTA_Screen,scr,TAG_END))
{
DoDTMethod (dto,NULL,NULL,DTM_PROCLAYOUT,NULL,TRUE);
GetDTAttrs (dto,(ULONG) PDTA_BitMapHeader,&bmhd,(ULONG) PDTA_BitMap,&bm,TAG_END);

if (bm && bmhd)
{
winw = bmhd->bmh_Width + scr->WBorLeft + scr->WBorRight;
winh = bmhd->bmh_Height + scr->WBorTop + scr->RastPort.TxHeight + 1 + scr->WBorBottom;

if (win = OpenWindowTags (NULL,
WA_Left, (scr->Width - winw) / 2,
WA_Top, (scr->Height - winh) / 2,
WA_Width, winw,
WA_Height, winh,
WA_Title, args.file,
WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE | WFLG_NOCAREREFRESH,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
TAG_END))
{
rc = RETURN_OK;

BltBitMapRastPort (bm,0,0,win->RPort,win->BorderLeft,win->BorderTop,win->GZZWidth,win->GZZHeight,0xc0);

cont = TRUE;
do {
if (Wait ((1L << win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
cont = FALSE;
while (imsg = (struct IntuiMessage *) GetMsg (win->UserPort))
{
switch (imsg->Class)
{
case IDCMP_VANILLAKEY:
if (imsg->Code == 0x1b) /* Esc */
cont = FALSE;
break;
case IDCMP_CLOSEWINDOW:
cont = FALSE;
break;
}
ReplyMsg ((struct Message *) imsg);
}
}
while (cont);
CloseWindow (win);
}

}
else
Printf (&quot;image cannot be rendered into the named pubscreen\n&quot;);

DisposeDTObject (dto);
}
else
{
Printf (GetDTString (IoErr()),args.file);
Printf (&quot;\n&quot;);
}

UnlockPubScreen (NULL,scr);
}
else
Printf (&quot;cannot lock pubscreen\n&quot;);

return (rc);
}


Thats the whole file - someone slid it to me in the effort to clarify my getting a picture into a window. As you can see the #includes are already there. I hope you have some more magic for me beecause all my spells have been spent hours ago.

Thanks:)
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show all replies
Re: Programming a Window in C to hold a picture/background
« Reply #3 on: January 12, 2012, 10:23:16 PM »
I have really been searching for information or code examples but I have found nothing that explains how to program a picture into an amiga window or screen... PLEASE - someone must have an idea where I can look or offer som sort of code that I can do this with. :furious:

The example I posted has proven to be useless btw.
« Last Edit: January 12, 2012, 10:25:43 PM by Morbane »
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show all replies
Re: Programming a Window in C to hold a picture/background
« Reply #4 on: January 13, 2012, 06:29:19 AM »
Quote from: Mazze;675531
Why? It loads a picture with the Datatypes system and blits it into a window. What do you expect?

I was hoping it would compile and run so I can learn something. I tried it in 3 compilers GCC , DEVCC, Codeblocks - no luck with all three, though DEVCC had the least amount of errors but I cant decipherthem. Damn.
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show all replies
Re: Programming a Window in C to hold a picture/background
« Reply #5 on: January 13, 2012, 12:57:05 PM »
Thanks for your input - this is what I am getting:


:confused:
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show all replies
Re: Programming a Window in C to hold a picture/background
« Reply #6 on: January 13, 2012, 08:50:37 PM »
problem solved - got help from English Amiga Board.:roflmao:
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?