Rick's b.log - 2023/08/14 |
|
It is the 21st of November 2024 You are 18.118.19.123, pleased to meet you! |
|
mailto:
blog -at- heyrick -dot- eu
Anyway, I'm working on something. I'm not going to say what at the moment, but it runs in a single-tasking mode (no, it's not a game), and in order to be able to accept input from the user in a nicer method than OS_ReadLine (that's basically INPUT), I decided to create a "dialogue manager".
Based upon the way OPL used to work on the Psion organiser, there are six primary stages of creating a dialogue:
It is acceptable to call dialogue_do() multiple times, so you can check values on exit from the UI and pop up a message if something is wrong, then go back to dialogue_do() so the user can do something about it.
Multiple dialogues are possible. Only the most recently used is the current. This is a dialogue manager, not a window manager. ☺ But it does mean you can use a dialogue on top of a dialogue to notify the user of problems.
Here is some example code.
This would make the following dialogue.
You can see most of the different sorts of objects there.
If we edit the code around dialogue_do() as follows...
It will demonstrate overlaid dialogues as shown just below. Also worth noting is that since we aren't interested in reading anything back from this dialogue, there's no need to bother with any of the handles. Just create it, show it, wait for the user to do something, then discard it.
193 lines of header file, and 1857 lines of code. Not bad for a weekend. Well, I say weekend. I wrote most of the code yesterday.
I cut off the Molex plug and soldered the terminals to the associated pads within the headphones. As I didn't have sticky to hold the battery in place, I Blue Petered something using a piece of plastic cut from the bottom of a cheese pack.
As you can see, from the green indicator (rather than blue), the active noise cancelling is working again. As the old battery was on the way out, that only worked sometimes.
The ear pads are a bit naff, but they're the headphones I wear at work and while out shopping, so it's nice to get them operating again - and with the noise cancelling too. Nice!
So, asides from some outliers like Cathedral City, it seems as if most of the cheddar in France (from my sample of two supermarkets!) comes from this one factory in Scotland.
Now, this isn't as crazy as it might seem, as the factory is owned and run by Lactalis, which being a multinational will have some experience in all of the Brexit-inflicted bullshit that have caused problems with imports into Europe.
So, having a big French company running this Scottish cheese factory is perhaps the best way to get imports into the EU sorted. Granted, it might reduce choice (my Cathedral City that is sometimes available from the Leclerc in Big Town is aged nine months...), but on the other hand a reduced choice is better than erratic or no choice.
But, yeah... got fed up with my hair so an old pair of scissors and five minutes of inept snipping at random bits and... it probably looks crap but I might manage a shrug if I try really hard.
Some coding
I'm having a "pont" today. This means that since the previous two days were a weekend, and tomorrow is a public holiday, we're not working this single day in the middle.
That's good, because, honestly, I felt like crap this morning. Got up at half six, fed furry and had tea, then went back to bed.
Next thing I know, it's just going ten.
I don't like Mondays.
This is a simple call to dialogue_init() passing a dialogue title. This sets up the memory for an empty dialogue.
There are various types of object that can be added. Text messages, check boxes, radio options, string input, selection choices, buttons...
If you will need to read information from the dialogue in the future, you will need to remember the object handle.
This will iterate through the added objects and will work out how big the dialogue needs to be to fit everything into it, and to place it centred on the screen.
At this point, dialogue content cannot be changed except as provided by the user interface. You can't add/remove objects.
This is a simple call to dialogue_do() that will handle the entire UI behaviour, and will return TRUE
if the user clicked the Primary (OK) button or pressed Enter; or FALSE
if the Cancel button or pressed Escape.
In this case, dialogue_dismiss() will, if there's a previous dialogue, restore the previous dialogue context.
// At the top
dialogue_handle diaref = NULL;
object_handle behaviour = NULL;
object_handle runaround = NULL;
object_handle throwstuff = NULL;
object_handle newname = NULL;
int optval = 0;
[...]
// Create the dialogue
diaref = dialogue_init("How to handle the world");
dialogue_addtext("The world is screwed. How do you intend to cope with it?");
behaviour = dialogue_addradio("Behaviour", "Scream", "Panic quietly", "Meh",
"Laugh", "Get drunk", "", "", "", 2);
runaround = dialogue_addcheck("Options", "Run around with arms in the air", TRUE);
throwstuff = dialogue_addcheck("", "Throw random items of furniture", FALSE);
dialogue_addtext("If you wish to be known by another name, enter it below.");
newname = dialogue_addstring("Name", "Tiamat", STRING_MAX);
dialogue_addbuttons("Accept reality", "Deny everything");
// Show it on-screen
dialogue_show(DIA_NORMAL);
// Handle the dialogue UI
if ( dialogue_do() )
{
// TRUE response, user clicked OK button
OS_CLI("ScreenSave $.dialogue");
// You would read options like this
optval = dialogue_readcheck(runaround);
// is TRUE if option checked, else FALSE
}
// else FALSE if user clicked Cancel button
// We're done, so dismiss this dialogue
dialogue_dismiss();
An example dialogue.
Spans the entire width of the dialogue and just contains some text.
A little checkbox that you can use to turn options on and off. Comprised of an optional caption (on the left) and object description text, along with a default value (if it's to be checked or not).
A set of options (up to eight) with rounded selection buttons (to make them appear different to the checkbox). It's called "radio" because like the buttons on an old-fashioned radio, only one can be selected. Clicking one will deselect the others. As before, an optional caption, option descriptions, and which one is selected by default.
This is a simple string entry editor. When the white part is clicked in, the UI switches to character entry mode, and characters entered on the keyboard will be inserted into the string shown. A red caret (not shown) will dictate the current edit location. Delete
or Backspace
remove the character to the left of the caret, and since this is RISC OS ^U
will erase the entire string. You can specify custom lengths up to the maximum (31 characters).
If you provide an array of strings, this creates an icon with up/down arrows and you can click to choose a different option, which will change what is shown in the object. Consider, for example, a list of countries or favourite pizza toppings. Holding Ctrl while clicking will go forward/backward ten entries in order to make things faster.
You can specify one or two buttons. The first is the obligatory primary button (shown on the right) which is the action that results in a TRUE response from the dialogue. Pressing Enter
will also provide a TRUE response as if the user clicked the primary button.
The second is an optional cancel button (shown on the left), which is the button that results in a FALSE response from the dialogue. Pressing Escape
will do the same thing, but note that pressing Escape
will always return a FALSE response regardless of whether or not a cancel button is visible.
// Handle the dialogue UI
if ( dialogue_do() )
{
// TRUE response, user clicked OK button
// One can overlay a dialogue on another
// We aren't remembering any handles as we only want to show this,
// so the handles aren't required.
dialogue_init("Critical error!");
dialogue_addtext("Unfortunately reality is broken and your chosen");
dialogue_addtext("options cannot be applied.");
dialogue_addtext("Please die, and then try again.");
dialogue_addbuttons("Terminate", "");
dialogue_show(DIA_ERROR);
dialogue_do();
dialogue_dismiss(); // will restore the previous dialogue context
}
No, that isn't right, something went wrong!
It's simple, but it does what I wanted and it looks better than simply asking the user to enter input.
Headphone repair
Amazon dispatched my battery yesterday evening. Colis Privé got it to me in the morning before, even, the post person had been around.
The replacement battery.
The headphones, fixed.Cheese origins
Speaking of cheddar packs, I bought myself another pack of the Super U's own brand sliced cheddar. In the shop I turned the pack over, read the back, and would have burst into laughter if I had anything that resembled a functional emotional response. I did, sort of, manage a smirk.
Oh, look, Stranraer.
To put this into context, British tourists are not allowed to take any meat or dairy products with them. Which means, yes, cheese and pickle sandwiches and bacon butties may be confiscated by customs.
It's pathetic, but since the UK is no longer part of the EU customs area... it's "what the people voted for", apparently. I think, having been a part of the EEC then the EU for as long as I've been alive, people didn't really appreciate exactly how much freedom the customs arrangements actually gave everybody. I mean, my brain nearly exploded when the Brexiteers tried to say that leaving the EU would be less red tape (how's that one working out?).
Besides, I've been eating the Seriously Strong since before I even came to France!
Buddleia
As part of my tidying up outside, I have cut away all of the dead bits of the buddleia. Remember, this was a mess of brambles as tall as me.
What's left of the buddleia.Hair
Look mummy! I've changed my gender! 😂
I'm more upset about the lack of colour.Car service
Today was the day that I had predicted to take my little car for it's service. Well, since I haven't gone to Big Town, or vide greniers, or anywhere actually... I still have 914km before the counter hits zero.
That's about six and a half weeks at current use.
No comments yet...
© 2023 Rick Murray |
This web page is licenced for your personal, private, non-commercial use only. No automated processing by advertising systems is permitted. RIPA notice: No consent is given for interception of page transmission. |