ListBrowser LBNCA_FGPen odd behavior?

This forum is for general developer support questions.
Post Reply
blmara
Posts: 76
Joined: Thu Jun 23, 2011 9:03 am
Location: Vantaa, Finland

ListBrowser LBNCA_FGPen odd behavior?

Post by blmara »

Hi,

I'm trying to use listbrowser.gadget node pens to display different information state. However, I noticed that LBNCA_FGPen doesn't work as I expected. in SetListBrowserNodeAttrs autodoc there are following lines:

LBNCA_FGPen (int16)
LBNCA_BGPen (int16)
The pens to be used for rendering the text or integer in this
column. Requires that the LBFLG_CUSTOMPENS flag in LBNA_Flags
be specified otherwise the default system pens will be used.

Defaults to TEXTPEN and BACKGROUNDPEN.

In my example code below I would expect the 1st and 2nd listbrowser node would be of the same colour (pen TEXTPEN) but as the screenshot proves they are not. Have I understood something wrong

Code: Select all

/* listbrowser Example
gcc -o testlbpen testlbpen -lauto
quit
*/

/**
 **  Simple test for listbrowser LBNCA_FGPen
 **/

#include <classes/window.h>
#include <gadgets/layout.h>
#include <gadgets/listbrowser.h>
[attachment=0]grab_290x255x24.jpg[/attachment]
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/window.h>
#include <proto/listbrowser.h>

STRPTR nodetexts[] = {
	"Node 1",
	"Node 2",
	"Node 3",
	NULL
};

int main()
{
	Object *winobj,*lbobj;
	struct Window *win;
	struct ColumnInfo *cinfos;
	struct List lbnodes;
	struct Node *node;
	int i,pen;

	cinfos = IListBrowser->AllocLBColumnInfo(1,
		LBCIA_Column,0,
			LBCIA_Title,"Test listbrowser",
	TAG_DONE);
	
	IExec->NewList(&lbnodes);
	for (i = 0;nodetexts[i];i++)
	{
		if (node = IListBrowser->AllocListBrowserNode(1,
			LBNA_Flags,LBFLG_CUSTOMPENS,
			LBNA_Column,0,
				LBNCA_Text,nodetexts[i],
		TAG_DONE))
		{
			/* note: no pen set when i == 0 */
			if (i == 1)
				IListBrowser->SetListBrowserNodeAttrs(node,LBNA_Column,0,LBNCA_FGPen,TEXTPEN,TAG_DONE);
			else
				if (i == 2)
					IListBrowser->SetListBrowserNodeAttrs(node,LBNA_Column,0,LBNCA_FGPen,DISABLEDTEXTPEN,TAG_DONE);
			IExec->AddTail(&lbnodes,node);
		}
	}

	winobj = IIntuition->NewObject(NULL, "window.class",
		WA_Activate, TRUE,
		WA_DepthGadget, TRUE,
		WA_DragBar, TRUE,
		WA_CloseGadget, TRUE,
		WA_SizeGadget, TRUE,
		WA_Width,280,
		WA_Height,200,
		WA_Title,"Test ListBrowser node pens",
		WINDOW_Layout, IIntuition->NewObject(NULL, "layout.gadget",
			LAYOUT_AddChild, lbobj = IIntuition->NewObject(NULL, "listbrowser.gadget",
			LISTBROWSER_ColumnInfo,cinfos,
			LISTBROWSER_Labels,&lbnodes,
                TAG_DONE),
           TAG_DONE),
        TAG_DONE);

	if (winobj != NULL)
        {
		win = (struct Window *)IIntuition->IDoMethod(winobj, WM_OPEN);

		if (win !=  NULL)
		{
			uint32 signal = 0;
	                BOOL done = FALSE;

			IIntuition->GetAttr(WINDOW_SigMask, winobj, &signal);

			while (!done)
			{
				uint32 wait = IExec->Wait(signal);

				if ( wait & signal )
				{
					uint32 result = WMHI_LASTMSG;
					int16 code = 0;

					while ((result = IIntuition->IDoMethod(winobj, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG)
					{
						switch (result & WMHI_CLASSMASK)
						{
							case WMHI_CLOSEWINDOW:
								done = TRUE;
								break;

						}
					}
				}
			}
		}
		IIntuition->DisposeObject(winobj);
	}
	IListBrowser->FreeListBrowserList(&lbnodes);
	IListBrowser->FreeLBColumnInfo(cinfos);
}
Marko
Attachments
grab_290x255x24.jpg
grab_290x255x24.jpg (10.13 KiB) Viewed 4550 times
Marko
User avatar
Rigo
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 360
Joined: Mon Jan 17, 2011 9:42 pm

Re: ListBrowser LBNCA_FGPen odd behavior?

Post by Rigo »

The pen definitions (TEXTPEN, SHINEPEN etc) are indexes into the dri_Pens[] array in the DrawInfo sctructure.

You can always specify a direct pen number from ObtainBestPen/FindColor etc too.

Simon
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: ListBrowser LBNCA_FGPen odd behavior?

Post by thomasrapp »

Yes, the sentence "Defaults to TEXTPEN and BACKGROUNDPEN" is misleading. Actually they default to DrawInfo->dri_Pens[TEXTPEN] and DrawInfo->dri_Pens[BACKGROUNDPEN].
blmara
Posts: 76
Joined: Thu Jun 23, 2011 9:03 am
Location: Vantaa, Finland

Re: ListBrowser LBNCA_FGPen odd behavior?

Post by blmara »

Rigo wrote:The pen definitions (TEXTPEN, SHINEPEN etc) are indexes into the dri_Pens[] array in the DrawInfo sctructure.

You can always specify a direct pen number from ObtainBestPen/FindColor etc too.

Simon
Ok, that corrected my program's behavior and I also agree with Thomas that the autodoc sentence could be more precise! Thanks for both!

Marko
Marko
Post Reply