Amiga-Development

Please login or register.

Login with username, password and session length
Advanced search  

News:

Created for developers of all Amiga camps

Author Topic: CLIs and Color Pens  (Read 3073 times)

0 Members and 1 Guest are viewing this topic.

adminZRt75

  • Administrator
  • Hero Member
  • *****
  • Posts: 590
    • View Profile
CLIs and Color Pens
« on: December 16, 2012, 11:30:03 AM »

Started by EdanaII on utilitybase

EDanaII
Just some guy...

   Posted: 2006-Nov-9 22:41:50

OK, proviso first. As I've mentioned before, I'm an experienced developer but not with C or C++ or the Amiga. Just for giggles, I decided to resurrect a thrilling game from yesteryear and tinker with it.

I've modified the program to highlight text using ASCII escape codes. The problem is, the color I get isn't always the color I want. When I run the program under AmiKit, color highlighting is decent, if not perfect. But under OS 3.9 (without AmiKit), it's worse and, naturally, under a four color Amiga, I suspect it would be worse still.

So, my question is, what's the best way to control the color pens of the OS while using the CLI? I assume I can fetch information about the color depth of the Workbench I'm running under and modify the color index, as needed. But I'm looking for any suggestions I can find on how I might accomplish this in a simple fashion.

Oh, also, while I'm thinking about it. When opening a regular window, the system always opens a console window too. I remember there was a way to keep the console window from opening, but it's been so long, I've forgotten how to do that. Can anyone help there too?

Ed.



itix
Member

   Posted: 2006-Nov-10 09:00:49
      Oh, also, while I'm thinking about it. When opening a regular window, the system always opens a console window too. I remember there was a way to keep the console window from opening, but it's been so long, I've forgotten how to do that. Can anyone help there too?



Arguments are the same you use to open your console window. Check your shell icon tooltypes...



Thomas
Member

   Posted: 2006-Nov-11 17:09:59 ยท Edited by: Thomas
      So, my question is, what's the best way to control the color pens of the OS while using the CLI?



AFAIK it's not possible. The shell only knows pen numbers, it does not have any control over pen colors. The only possibility is to write a program (not a shell script) which can use functions of graphics.library to determine an appropriate pen number.

For example you could use ObtainBestPen with an RGB value, then you get a pen number which you could use in Esc sequences. Before your program quits you should call ReleasePen.

Edit: I think I missed an important fact: the shell is also limited to the first 8 pens, so working with ObtainBestPen only is a good idea if your shell window is on a 8-color screen.

Another solution perhaps is to open an own screen with just eight fixed colors and open the shell window on this screen.

Bye,
Thomas



falemagn
Member

   Posted: 2006-Nov-11 19:30:10

@ Thomas

I remember having read somewhere, once, that in AOS3.5 they introduced a method to select CLI colors by specifing RGB values, rather than pen numbers. I don't remember where I read it and which is the CSI, though.



EDanaII
Just some guy...

   Posted: 2006-Nov-15 22:34:04

@ itix

I couldn't find any shell icon tooltypes. Maybe I'm looking in the wrong places? Suggestions?


@ Thomas

I definately don't want to open a new screen. What I'd like to do is, simply, find the color registors in question, change their colors to what I need for the duration of the program, and then restore them when I'm done.

Is the graphics.library the right place to start? I'll check there then.


@ falemagn

Any ideas where I might find that information? Even the tiniest clue would be greatly appreciated. :)

Ed.



itix
Member

   Posted: 2006-Nov-15 22:50:41

Unfortunately I misunderstood your problem. I thought you wanted console window (you can use AUTO attribute to not open it immediately) but you dont want console window at all.

There is way to prevent opening of console window but I have no idea why or how, sorry :/



Thomas
Member

   Posted: 2006-Nov-16 12:51:30
      What I'd like to do is, simply, find the color registors in question, change their colors to what I need for the duration of the program, and then restore them when I'm done.



This is not allowed in AmigaOS. You can do it, but it is 1970's style programming. In a multitasking environment where the same display is shared among several programs, this is definitely bad style. That's the reason why pen allocation and shared pens were introduced.

If multiple programs of this kind would run at the same time, eventually colors would not be restored to the original value. This is definitely not what the user wants.

Bye,
Thomas



EDanaII
Just some guy...

   Posted: 2006-Nov-16 16:10:10

That's an excellent point.

However, last night I decided to change strategies. Rather than controlling the pens myself, since the program comes with a configuration file, I decided I'll let the user (should I decide to return it to the PD) choose which color pens they use. That will, at least, allow them to either adjust their WB colors or to pick an existing color.

This leads me to a new question, however. Is there a way for a CLI program launched from an icon to read tooltypes? I experimented the other night to see if tooltypes were passed to the argv variable in C but got no results. Any suggestions?

Ed.



Thomas
Member

   Posted: 2006-Nov-16 17:30:21
      Is there a way for a CLI program launched from an icon to read tooltypes?



A CLI program (more specific: a CLI-only program) usually crashes when it is called from Workbench, so there is no point in attempting to read the tooltypes anyway.

However, for a C program it works like this (actually it depends on the compiler, but most compilers do it like this):

If argc >= 1 then the program was called from a CLI and argv[0] contains the program name, argv[1] the first parameter and so on.

If argc == 0, then the program was called from the Workbench and argv is not a (char **) but a (struct WBStartup *). You then use wbstartup->sm_ArgList[0] to determine the program name and GetDiskObject() to open the icon. The tooltypes are then found in diskobject->do_ToolTypes. Don't forget to FreeDiskObject when you are finished.

struct WBStartup is defined in workbench/startup.h
struct DiskObject is defined in workbench/workbench.h

You can use GetDiskObject from a CLI program, too. It does not even need Workbench to be started, only icon.library has to be present.

Bye,
Thomas
Logged

magorium

  • Full Member
  • ***
  • Posts: 221
  • Programming is an art form that fights back
    • View Profile
Re: CLIs and Color Pens
« Reply #1 on: March 29, 2014, 12:04:36 PM »

hi EDanaII,

Thomas is correct in his writings.

I've used exactly similar approach with wbXcli tool to read the tooltypes and act on them accordingly. So it works on Aros as well  ;D

Regarding the pencolor thing... well, that also kinda works from a cli program. SetPencolor utility for Aros just locks the given screen (or default public screen, usually workbench, when omitted).

Once you got the screenpointer, the rest is a 1-2-3 of Rastport, Viewport and Colormap. Colors can then be adjusted as you like.

Thomas is right though, it is a non recommended way of doing things and you can seriously mess up things, especially when you do not obey the shared-pen logic (which setpencolor happily contradicts ;D ). At least it makes some people happy...  ::)
Logged