forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

User-Defined Text & Format Labelson a Dwg Surface (%gr)

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Sun Sep 14, 2014 3:07 pm    Post subject: User-Defined Text & Format Labelson a Dwg Surface (%gr) Reply with quote

I'd like to write some code which allows the user to input their own FORMATTED TEXT STRINGS onto a drawing surface (%gr) in specific locations, ... a kind of 'user defined labels'.
e.g. imagine drawing a polygon and the having a ''label'' with the area of the polygon marked next to it, which the user can write out and format as they want.
Exactly like how you would edit some text in MS Word or Excel for example.
What I haven''t worked out (if it's actually possible) is how to :
a) make the text such that it''s user-modifiable i.e. you click on the text and can modify it directly on-screen, either in it''s final location or in a seperate ''working '' area and then when it''s drafted transfer it to the desired location.. What control would be best for that ? Maybe I need to have a seperate edit box, ''record'' the formats required, and then when it''s ready have a call back to write it to the desired locn on the drawing surface ? I've seen that %eb has a lot of explanation associated relating to 'EDIT_INFO' structure, but seems only to allow changing of font (maybe) and colour.
b) how to create for the user a tool bar which basically includes the usual text editing functions you''d find on the formatting toolbar in Word for example (font selection (drop down), bold-italic-underline , and also: subscript, superscript, and how to make it so the user highlights the required text to re-format and then it appears as such in the ''edit box''. Exactly as you would do in word, or Excel
I think I need to use DRAW_CHARACTERS etc.... (not using the format codes available) to then put the text as defined onto the screen itself in the required place, but it doesn''t seem to have the options for sub-/super-scripts for example (unlike for bold and underlined text) The options also for equation writing (like those present in the format code: %eqn) also appear not to be options if writing via DRAW_CHARACTERS.
I can't initially see the wood from the trees.
The only option I can see initially to do all this is to :-
1) provide an edit string box (%rs) or edit box (%eb) for the user to input the text string (unformatted)
2) provide a set of buttons which 'activate' bold/u-line/°font/etc..... for a selected (marked) sub-string
3) record the selections made in an array (for EACH character seperately)
4) 'parse' the recorded array and generate the necessary commands to 'DRAW CHARACTERS' with the other commands around it for each character 1 by 1.
Maybethat's all just like in Excel where the contents of a cell in the command line at the top of the screen are always in DOS text format but when editted with the edit toolbar the text appears formatted in the cells.
All that seems a little 'heavy' just to format a string in a wauy a user wants to.
Any suggestions/guidelines for a best approach would be appreciated.
Thanks
John
PS - supplementary Q - for TEXT_UNDERLINE (for characters drawn on a drawing surface) , what thickness line does it use ? presumeably it''s in proportion to the font size, but is it user selectable/changeable also ?')
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Sep 15, 2014 11:26 am    Post subject: Reply with quote

For text underline it does it with a standard underline because it's a Windows font and not a stick (stroke) font.

My suggestion is that you keep a list of graphics elements including the text complete with their bounding coordinates on screen, where they can be clicked to select (also coordinates), and their specific features such as colour, type (text, filled polygon, unfilled polygon etc). On receiving a 'selection click', run through the list to choose which graphic element has been selected, and then draw it with some sort of highlight, e.g. a bounding box.

If the editable items are movable, then you will need to enable 'click and drag', if text strings are scalable you may need to draw 'handles' to allow the bounding box to be stretched. You can permit text editing in a pop up window which is probably simplest. If you want 'on screen' or 'in place' editing, you will need to do a graphics update after each keystroke, and this will cause the screen to flicker unless you have a fast computer: you only need to update an area equal to the larger of the original or new bounding boxes.

You will also need an 'end of editing' convention: this is easiest with the pop up window, because it coincides with window closure. You will also have to figure out a stack of changes if you need an 'undo-redo' facility.
In another thread we had some code for a resizable 'stretchy box' which was done in this thread:

"Some suggestions for future enhancements to Clearwin+"

and it might give you some ideas as how to implement editing in your graphics callback routine.

Eddie
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Tue Sep 16, 2014 9:33 am    Post subject: Reply with quote

Eddie, thanks for the initial input & suggestions.
Maybe you could further clarify a couple of things:

a) when you say 'keep a list of graphic elements.. etc...' do you mean just stored in the program code or in an actual 'list' e.g. via %lv, or %eb
I suspect after reading a little more maybe the latter is the way to go as it seems to allow more editing options, or maybe I’m mistaken ?

b) how to identify individual keystrokes/highlighted text ? my idea is to (try to) record the running state of the string being modified AND the 'status' of each character i.e. which font, font size, bold or not, etc... according to buttons pressed/selected from lists, etc.... on a toolbar menu
... so for example, there's a need to identify which individual characters in a string have been selected (highlighted) . That seems to favour the %eb approach which has that specific capability available via the items 8 and 9 in theEDIT_INFO structure (see p.110 of the .pdf Clearwin Manual) . I don’t think it’s available in the %lv format, but I may be wrong ??
The number and 'index' of characters of course will change as characters are added/deleted so there's the question of keeping track of all that too in the CallBack routine.

c) identifying when exactly to 'preview' i.e. 'DRAW CHARACTERS' is a decision to be made. As you say the drawing surface refresh could be done after each character 'modification'/and-or/toolbar button press , but more likely at user-specified (via a button click ?) moments since you may want to preview several times in the process of long editing while at the same time keeping refreshes to a minimum.
I wasn’t thinking of creating labels in their own ‘sub-drawing surface’ areas.
I didn’t realise a particular section of a drawing surface could be refreshed (which I think is what you were saying), I’d thought it had to be the complete drawing surface. That might be necessary anyway e.g. imagine user specifies a ‘large’ font which would encroach on the drawing of the circle for example, then it would be necessary to consider re-scaling not just the text but also maybe the other onject(s).


As for ‘undo’ facility thanks for reminding me of that little hand grenade (which can wait till I’ve got something basic worked out) 

Elastic bands too ….. thanks for re-directing me in the direction of that previous post (I’d already seen before), although I didn’t come across much else there particularly applicable I think (to my amateur eyes at least). My initial idea is to work with a single drawing surface and make sure there are no ‘clashes’ between any text and any other objects’ therein . Elastic bands can be a back-up solution.

Cheers
John
__________________________________________

An aside (for SilverFrost) ….. About CLEARWIN Documentation

As an aside a general comment here while researching this topic is that the CLEARWIN documentation isn't totally complete imo. Certainly not easy to find things in some cases.
e.g. Not all [Options] for example are always listed in the Format Code Reference Chpt. 21 , others are often contained in the previous chapters but it doesn't make it easy to find all possible options.
The Standard CallBack Functions anf Library Reference also appear sometimes to be ‘missing’ some entries which are referenced elsewhere either in individual %nn descriptions or in various other specific chapters describing in more detail some modules.
This is not so much a complaint as an onservation. I know it’s not easy to constantly keep documentation up to date, but it certainly is frustrating sometimes to discover sometimes possibilities that at first glance aren’t obvious.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Sep 16, 2014 10:53 am    Post subject: Reply with quote

John,

The 'list' would be a set of arrays (for a simple man like myself) or data structures containing the data to allow any element to be selected, modified and/or be redrawn, so yes, stored in the program.

When it comes to editing a text string with attributes for every character, then doing it in a string edit box in a popup window could save you a vast amount of programming. If you want to do it yourself then you need to get into the intricacies of such things as the EDIT_INFO structure. %lv and %bv etc give me heartburn ...

Your para c. has hit the nail on the head. If you do the editing on the surface you do need to update after each character: if you do it in a popup you only need to refresh when that window is closed. The routine is SET_UPDATE_RECTANGLE@, but unless you want to set clipping limits yourself, or your drawing is extremely complex, just redraw everything: Clearwin+ and Windows will do the clipping for you and only update in the selected rectangle. Only the update rectangle will flash, and clashes are sorted out automatically: text is probably the last to be drawn.

The reminder of the 'stretchy box' was a reminder that all of this has to be done in a graphics callback, and the first step is to decide how you select which object to edit (and show that it is selected). The stretchy box updates on screen, has no undo, and edits with the mouse. You may need to have a toolbar, and/or menu items, and/or accelerator shortcut keys for your specific functions as well as accepting keys and mouse edits!

I agree that the documentation is sometimes out of date, and/or minimalist. I have at various times printed out the full PDF documentation, and the .ENH file. The PDF documentation is years out of date, one or two things aren't even in the ENH file but only on the knowledgebase, and the CHM file doesn't always give you what you want either.

Eddie
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Tue Sep 16, 2014 12:07 pm    Post subject: Reply with quote

A simple string edit box wouldn't do the whole business I don't think because remember I want the user to be able t : change fonts and/or size and/or bold-italic-underline for different parts of the string, allow subsripts and superscripts, etc... A text string box would be needed for each part of the 'comment' to do that. I guess in the limit 1 box per character ! With an edit box the user could a) edit the characters there b) select the buttons for bold-underline-etc..... and the 'flags' for those characters set to the appropriate value for the appropriate property. Then when all is done, the code relative to the commands necessary to draw on the drawing surface called up.
Convoluted I know, but as we know, the degree of complexity goes up in exponential proportion to the degree of flexibility for the user ! Smile

I'll do a bit of forward planning now.
Maybe I'll descope my user options for editing/specifying the formats initially I don't know yet.
Come back to me if you have any other bright ideas , I'd appreciate it Eddie.

Oh and thanks for the SET_UPDATE_RECTANGLE@ tip, it's a good example of what I was talking about in my previous post ... something which is NITFM !!!
Of course we'll have to badger Paul about updating the whole documentation to be complete/fully cross-referenced and up to date !!!LOL
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Sep 16, 2014 4:27 pm    Post subject: Reply with quote

My last thoughts for today are to have a go with a graphics program and watch very carefully how it is done there. My favourite is CorelDraw!

If you want more than simple string editing, then do it in a popup window that instead of an editable string window has its own %gr box, and update that after every keystroke. The routine GET_TEXT_SIZE@ could be useful in this. CorelDraw! has such a thing after a text label has been selected if you press Ctrl-Shift_T.

Maybe every character should have qualifications stored as bits for B, I, u, subscript, superscript etc so you only need a byte extra per character (you have to be comfortable with bit-handling), but you'll need more than that to remember font changes.

I know I should get a life, but I have diligently read the ENH file for ideas, then in the FTN95.CHM I have read through the alphabetical lists of allowable format codes ('format code reference'), the alphabetical list of library routines ('library reference'). This has given me vague recollections along the lines of 'I know there's something about that in the ...' Finally, read the MS User Experience Guidelines.

Eddie
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Wed Sep 17, 2014 5:58 pm    Post subject: Reply with quote

Pop-up window ?
I've seen pop-up menus (%pm) but how do you get a pop-up window ?
... or do you just mean open a new %gr window from a menu ?
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Sep 17, 2014 8:26 pm    Post subject: Reply with quote

No, I meant start a new window. The ‘Edit text’ window in CorelDRAW! could be programmed with Clearwin+ like this, starting with:

Code:
I=WINIO@(‘%ca[Edit text] …


And the window probably needs a %ww with options nomaxminbox, toolwindow and fixed_size.

The next line contains a drop-down selection box with a list of font names, a drop-down box with font sizes, buttons for bold, italic, underline, then a drop down list box for justification options (left, centre, right) … all this lot looking like a toolbar. The buttons would be generated with %tb or %ib. It is clearly followed by a %nl, then a %gr which displays the text, followed by another %nl … then some buttons in a row:

Code:
I=WINIO@(%8bt[Options]%8bt[Import]%8bt[OK]%8bt[Cancel]%8bt[Help]’)


(Don't forget the ^ qualifiers to set up callbacks, and ~ for the buttons that are greyable)

If you do it the same way as CorelDRAW!, you would need callbacks for the drop-down selection boxes and the buttons in the top row.

The first two of the buttons (and the last one) in the final row of labelled buttons launch other dialog boxes, the others exit the window.In the %gr area, the cursor is turned to the I-beam text selector style, and left-click and click and drag are enabled to select text for editing – which is done in the calback for %gr..

Maybe I should have called it a ‘new dialog box’.

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group