Example of GetScreenMode() available? (Solved)

12 posts / 0 new
Last post
LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 1 week ago
Joined: 2011-05-26 03:58
Example of GetScreenMode() available? (Solved)

I have looked in the usual places, so far without luck.
Even a very short example would be helpful.

Then again, I often find what I need right AFTER asking for help here.

Thanks In Advance,
LyleHaze

xenic
xenic's picture
Offline
Last seen: 2 years 7 months ago
Joined: 2011-05-07 04:52
Re: Example of GetScreenMode() available?

@LyleHaze
Since there are no other responses, I searched my collection of sourcecode examples and only found one file where GetScreenMode() is used. However, the only way I was able to access those sources was by cloning the repository with OS4 "Sgit". Assuming you have OS4 Sgit installed you should be able to checkout the Netsurf sources by changing directories to an empty one and enter in a shell:

sgit clone git://git.netsurf-browser.org/netsurf.git netsurf

Be sure you have your shell window expanded to full width or the download will take too long.
Once the dowload is completed you should look in netsurf/frontends/amiga/gui_options.c for some code that may help you.

X1000 - OS 4.1FE

gazelle
gazelle's picture
Offline
Last seen: 1 year 9 months ago
Joined: 2011-04-13 12:52
Re: Example of GetScreenMode() available?

You can also access the repository online:
frontends/amiga/gui_options.c

But it's using the getscreenmode.gadget and I didn't find a GetScreenMode() function (in the OS4 SDK)?

LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 1 week ago
Joined: 2011-05-26 03:58
Re: Example of GetScreenMode() available?

Thanks to you both.
I was unable to retrieve the source from the first reply, but the second one hooked me right up.
And it is GetScreenMode.gadget. You are correct.
It LOOKS like what I am doing should work. the screenmode gadget is rendered, and I get the proper message when it is pressed. But the IDoMethod() fails. No screenmode request opens..
I'm sure it's something simple, now more than ever. I will keep at it.
thanks again to you both for your help. At least I know what it should look like. :)

LyleHaze

xenic
xenic's picture
Offline
Last seen: 2 years 7 months ago
Joined: 2011-05-07 04:52
Re: Example of GetScreenMode() available?

@LyleHaze
I copied the GetScreenMode.gadget into some simple reaction example source with some modifications and I got a requester to pop up:

  1. /* Layout example without RA Macros */
  2. /* Compile = gcc layout.c -lauto -o layout */
  3.  
  4. #define ALL_REACTION_CLASSES
  5. #define WindowClass IWindow->WINDOW_GetClass()
  6. #define LayoutClass ILayout->LAYOUT_GetClass()
  7. #define StringClass IString->STRING_GetClass()
  8.  
  9. #include <signal.h>
  10. #include <stdio.h>
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14. #include <reaction/reaction.h>
  15.  
  16. enum
  17. {
  18. OID_WINDOW,
  19. OID_LAYOUT,
  20. OID_STRINGGADGET,
  21. OID_BUTTONLAYOUT,
  22. OID_BUTTON1,
  23. OID_BUTTON2,
  24. OID_SCREENMODE,
  25. OID_LAST
  26. };
  27.  
  28. int main(void)
  29. {
  30. struct Window *win = NULL;
  31. uint32 signals = 0;
  32. uint32 signalmask = 0;
  33. Object *objects[OID_LAST];
  34. uint32 result = 0;
  35. uint32 screenmodeid = 0;
  36. int16 code = 0;
  37. BOOL done = FALSE;
  38. char *StringInput[256];
  39. struct Gadget *gad;
  40.  
  41. signal(SIGINT, SIG_IGN);
  42.  
  43.  
  44. /* Create the window object. */
  45. if ( (objects[OID_WINDOW] = IIntuition->NewObject(WindowClass, NULL,
  46. WA_Title, "ReAction AppWindow",
  47. WA_DragBar, TRUE,
  48. WA_CloseGadget, TRUE,
  49. WA_SizeGadget, TRUE,
  50. WA_DragBar, TRUE,
  51. WA_DepthGadget, TRUE,
  52. WA_Activate, TRUE,
  53. WA_InnerWidth, 400,
  54. WA_InnerHeight, 100,
  55. WINDOW_Position, WPOS_CENTERSCREEN,
  56. WINDOW_AppWindow, TRUE,
  57. WINDOW_IconifyGadget, TRUE,
  58. WINDOW_Layout, objects[OID_LAYOUT] = IIntuition->NewObject(LayoutClass, NULL,
  59. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  60. LAYOUT_SpaceOuter, TRUE,
  61. LAYOUT_DeferLayout, TRUE,
  62.  
  63. LAYOUT_AddChild, objects[OID_STRINGGADGET] = IIntuition->NewObject(StringClass, NULL,
  64. GA_ID,OID_STRINGGADGET,
  65. GA_ReadOnly, FALSE,
  66. GA_RelVerify, TRUE,
  67. STRINGA_WorkBuffer, StringInput,
  68. TAG_END),
  69.  
  70. LAYOUT_AddChild, objects[OID_SCREENMODE] = IIntuition->NewObject(NULL, "getscreenmode.gadget",
  71. GA_ID, OID_SCREENMODE,
  72. GA_RelVerify, TRUE,
  73. GA_Disabled,FALSE,
  74. GETSCREENMODE_DisplayID,0,
  75. GETSCREENMODE_MinDepth, 0,
  76. GETSCREENMODE_MaxDepth, 32,
  77. TAG_END),
  78.  
  79. /* This is the embedded layout gadget that will allow gadgets to be placed side-by-side */
  80. LAYOUT_AddChild, objects[OID_BUTTONLAYOUT] = IIntuition->NewObject(LayoutClass, NULL,
  81. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ, /* I think that's what it's called from memory. Check autodocs */
  82.  
  83. /* This is now part of the OID_BUTTONLAYOUT layout gadget */
  84. // LAYOUT_AddChild, objects[OID_BUTTON1] = IIntuition->NewObject(ButtonClass, NULL,
  85. LAYOUT_AddChild, objects[OID_BUTTON1] = IIntuition->NewObject(NULL, "button.gadget",
  86. GA_ID,OID_BUTTON1,
  87. GA_ReadOnly, FALSE,
  88. GA_Text,"Do Nothing",
  89. GA_RelVerify, TRUE,
  90. TAG_END),
  91.  
  92. /* This is now part of the OID_BUTTONLAYOUT layout gadget */
  93. // LAYOUT_AddChild, objects[OID_BUTTON2] = IIntuition->NewObject(ButtonClass, NULL,
  94. LAYOUT_AddChild, objects[OID_BUTTON2] = IIntuition->NewObject(NULL, "button.gadget",
  95. GA_ID, OID_BUTTON2,
  96. GA_ReadOnly, FALSE,
  97. GA_Text, "Quit",
  98. GA_RelVerify, TRUE,
  99. TAG_END),
  100.  
  101. TAG_END),
  102. TAG_END),
  103. TAG_END)))
  104. {
  105. if (!(win = (struct Window*)IIntuition->IDoMethod(objects[OID_WINDOW], WM_OPEN, NULL)))
  106. {
  107. IIntuition->DisposeObject(objects[OID_WINDOW]);
  108. return RETURN_ERROR;
  109. }
  110. IIntuition->GetAttr(WINDOW_Window, objects[OID_WINDOW], (APTR)&win);
  111. IIntuition->GetAttr(WINDOW_SigMask, objects[OID_WINDOW], &signalmask);
  112. signalmask = (signalmask | SIGBREAKF_CTRL_C);
  113.  
  114. while ( !done )
  115. {
  116. signals = IExec->Wait(signalmask);
  117. if (signals & SIGBREAKF_CTRL_C) break;
  118. while ((result = IIntuition->IDoMethod(objects[OID_WINDOW], WM_HANDLEINPUT, &code)))
  119. {
  120. switch (result & WMHI_CLASSMASK)
  121. {
  122. case WMHI_CLOSEWINDOW:
  123. done = TRUE;
  124. break;
  125. case WMHI_GADGETUP:
  126. switch (result & WMHI_GADGETMASK)
  127. {
  128. case OID_BUTTON2:
  129. done = TRUE;
  130. break;
  131. case OID_BUTTON1:
  132. printf("Do Nothing\n");
  133. break;
  134. case OID_SCREENMODE:
  135. IIntuition->IDoMethod(objects[OID_SCREENMODE],
  136. GSM_REQUEST,win);
  137. IIntuition->GetAttr(GETSCREENMODE_DisplayID,
  138. objects[OID_SCREENMODE],
  139. (ULONG *)&screenmodeid);
  140. if(screenmodeid)
  141. {
  142. printf("ScreenModeID: 0x%lx\n", screenmodeid);
  143. }
  144. break;
  145. case OID_STRINGGADGET:
  146. gad = (struct Gadget *)objects[OID_STRINGGADGET];
  147. printf( "Contents: %s\n", ((struct StringInfo *)(gad->SpecialInfo))->Buffer);
  148. break;
  149. default:
  150. break;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. else
  157. {
  158. return RETURN_ERROR;
  159. }
  160. if (objects[OID_WINDOW]) IIntuition->DisposeObject(objects[OID_WINDOW]);
  161. return RETURN_OK;
  162.  
  163. }

X1000 - OS 4.1FE

LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 1 week ago
Joined: 2011-05-26 03:58
Re: Example of GetScreenMode() available?

Outstanding!
And it arrives at the start of my weekend. :)
after removing some "stray \240"s that were inserted by the web site, it works great.

Thank You. I appreciate the assist. And now this stands as example for others too.

Follow Up: Most intereting. The example worked the first time(s) I tried, but could not open the window after a fresh reboot. I ran Odyssey, then ran the example again, no window. I ran Score, then ran the example, it works again. So it is depending on _something_ to be loaded already. I'll not bother digging any deeper.
It's a great help, and since I already have a current copy of Score, I'll not have any troubles with it at all! :)

LyleHaze

LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 1 week ago
Joined: 2011-05-26 03:58
Re: Example of GetScreenMode() available?

Follow-Up:
My "IDoMethod()" call was not right.
I now have a working screen requester, and tomorrow I'll add screen opening and prefs stuff to support it.
Again, my thanks for the help!

LyleHaze

xenic
xenic's picture
Offline
Last seen: 2 years 7 months ago
Joined: 2011-05-07 04:52
Re: Example of GetScreenMode() available? (Solved)

@LyleHaze


Follow Up: Most intereting. The example worked the first time(s) I tried, but could not open the window after a fresh reboot. I ran Odyssey, then ran the example again, no window. I ran Score, then ran the example, it works again. So it is depending on _something_ to be loaded already. I'll not bother digging any deeper.

I retested "layout" and had the same problem. I think I found the problem but I can't find any way to edit my post with the example.
If I add the definition:

#define GetScreenModeClass IGetScreenMode->GETSCREENMODE_GetClass()

and change the line:

LAYOUT_AddChild, objects[OID_SCREENMODE] = IIntuition->NewObject(NULL, "getscreenmode.gadget",

to the line:

LAYOUT_AddChild, objects[OID_SCREENMODE] = IIntuition->NewObject(GetScreenModeClass, NULL,

then the program seems to always work.

The getscreenmode_gc.doc autodoc states this:
GETSCREENMODE_GetClass
This function is deprecated as of V52.
Use the "getscreenmode.gadget" public class ID instead.

When I used "getscreenmode.gadget" it only worked when certain other programs were running. All I can say is WTF.

At least you got your program working, which was the point of this topic.

X1000 - OS 4.1FE

salass00
salass00's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 11:27
Re: Example of GetScreenMode() available? (Solved)


When I used "getscreenmode.gadget" it only worked when certain other programs were running. All I can say is WTF.

That's because your program doesn't open the gadgets/getscreenmode.gadget library before trying to use it.

If before running your program you run another program that does correctly open this library then your program will "work" but only by luck. If you were to quit the other program and something caused the class library to be expunged then your program would crash.

Using -lauto doesn't help in this case because your code does not reference GetScreenModeBase or IGetScreenMode anywhere so the relevant constructor/destructor code from libauto won't be linked in.

salass00
salass00's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 11:27
Re: Example of GetScreenMode() available? (Solved)

You can force the libauto code to be linked in by adding something like:

  1. if (GetScreenModeBase == NULL) {
  2. /* The code should never get here */
  3. return 20;
  4. }

to the beginning of your main() function, but I recommend using IIntuition->OpenClass() and passing the class pointer directly to NewObject() instead as this is more efficient.

LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 1 week ago
Joined: 2011-05-26 03:58
Re: Example of GetScreenMode() available? (Solved)

For myself, I have "canned" code to open/close libraries/interfaces, classes, and all the common stuff, so I just added getscreenmode.gadget to the list. I understand that libauto is really convenient, but I am old-school, and prefer a bit more control over what's getting opened and how.

And it's working nicely. When screens are opened by Score, they look a bit rough, but the getscreenmode gadget is working fine and I'm sure the rest is just about using the right tags.

LyleHaze

xenic
xenic's picture
Offline
Last seen: 2 years 7 months ago
Joined: 2011-05-07 04:52
Re: Example of GetScreenMode() available? (Solved)

@salass00
Thanks for the info. However, I think the autodocs need updating to replace the recommendation to use something like "getscreenmode.gadget" or "getfont.gadget" with the method you stated. It might also be nice to update include/include_h/reaction/reaction.h to include missing classes like diffview.

X1000 - OS 4.1FE

Log in or register to post comments