source: tags/ms_r16q2/EDIT4/ED4_text_terminals.cxx

Last change on this file was 14929, checked in by westram, 8 years ago
  • inline AW_find_active_color_group
  • provide AW_color_groups_active
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.3 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : ED4_text_terminals.cxx                            //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include <ed4_extern.hxx>
12
13#include "ed4_class.hxx"
14#include "ed4_awars.hxx"
15#include "ed4_edit_string.hxx"
16#include "ed4_block.hxx"
17#include "ed4_nds.hxx"
18#include "ed4_visualizeSAI.hxx"
19#include "ed4_ProteinViewer.hxx"
20#include "ed4_protein_2nd_structure.hxx"
21#include "ed4_seq_colors.hxx"
22
23#include <aw_preset.hxx>
24#include <aw_awar.hxx>
25
26#include <AW_helix.hxx>
27#include <aw_msg.hxx>
28#include <aw_root.hxx>
29
30#include <st_window.hxx>
31#include <arbdbt.h>
32#include <ad_colorset.h>
33
34#include <iostream>
35
36inline void ensure_buffer(char*& buffer, size_t& buffer_size, size_t needed) {
37    if (needed>buffer_size) {
38        delete [] buffer;
39        buffer_size = needed+10;
40        buffer      = new char[buffer_size];
41
42        memset(buffer, ' ', buffer_size-1);
43        buffer[buffer_size-1] = 0;
44    }
45}
46
47ED4_returncode ED4_consensus_sequence_terminal::draw() {
48    static char   *buffer      = 0;
49    static size_t  buffer_size = 0;
50
51    AW_pos x, y;
52    calc_world_coords(&x, &y);
53    current_ed4w()->world_to_win_coords(&x, &y);
54
55    PosRange index_range = calc_update_interval();
56    if (index_range.is_empty()) return ED4_R_OK;
57
58    AW_pos text_x = x + CHARACTEROFFSET; // don't change
59    AW_pos text_y = y + SEQ_TERM_TEXT_YOFFSET;
60
61    buffer_size = 0;
62
63    if (index_range.is_unlimited()) {
64        e4_assert(MAXSEQUENCECHARACTERLENGTH == 0); // allow missing update interval when no seqdata is present (yet)
65
66        const char *no_data = "No consensus data";
67        size_t      len     = strlen(no_data);
68        ensure_buffer(buffer, buffer_size, len+1);
69        memcpy(buffer, no_data, len);
70
71        index_range = ExplicitRange(index_range, buffer_size-1);
72    }
73    else {
74        const ED4_remap *rm = ED4_ROOT->root_group_man->remap();
75       
76        index_range = rm->clip_screen_range(index_range);
77        if (index_range.is_empty()) return ED4_R_OK;
78
79        ExplicitRange seq_range = ExplicitRange(rm->screen_to_sequence(index_range), MAXSEQUENCECHARACTERLENGTH);
80        index_range             = rm->sequence_to_screen(seq_range);
81
82        char *cons = 0;
83        if (!seq_range.is_empty()) {
84            cons = GB_give_buffer(seq_range.size()+1);
85            get_char_table().build_consensus_string_to(cons, seq_range, ED4_ROOT->get_consensus_params());
86        }
87
88        ensure_buffer(buffer, buffer_size, index_range.end()+1);
89
90        ED4_reference *ref            = ED4_ROOT->reference;
91        bool           only_show_diff = ref->only_show_diff_for(this);
92
93        for (int pos = index_range.start(); pos <= index_range.end(); ++pos) {
94            int seq_pos = rm->screen_to_sequence(pos);
95            if (seq_pos<0) {
96                buffer[pos] = ' ';
97            }
98            else {
99                char c      = cons[seq_pos-seq_range.start()];
100                buffer[pos] = only_show_diff ? ref->convert(c, seq_pos) : c;
101                e4_assert(buffer[pos]);
102            }
103        }
104    }
105
106    if (buffer_size) {
107        current_device()->set_vertical_font_overlap(true);
108        current_device()->text(ED4_G_SEQUENCES, buffer, text_x, text_y, 0, AW_SCREEN, index_range.end()+1);
109        current_device()->set_vertical_font_overlap(false);
110    }
111
112    return (ED4_R_OK);
113}
114
115struct ShowHelix_cd {
116    AW_helix *helix;
117    int       real_sequence_length;
118};
119
120static bool ED4_show_helix_on_device(AW_device *device, int gc, const char *opt_string, size_t /*opt_string_size*/, size_t start, size_t size,
121                                     AW_pos x, AW_pos y, AW_pos /*opt_ascent*/, AW_pos /*opt_descent*/,
122                                     AW_CL cduser) // , AW_CL real_sequence_length, AW_CL cd2)
123{
124    ShowHelix_cd    *cd     = (ShowHelix_cd*)cduser;
125    AW_helix        *helix  = cd->helix;
126    const ED4_remap *rm     = ED4_ROOT->root_group_man->remap();
127    char            *buffer = GB_give_buffer(size+1);
128    long             i, j, k;
129
130    size = std::min(rm->get_max_screen_pos(), size);
131
132    for (k=0; size_t(k)<size; k++) {
133        i = rm->screen_to_sequence(k+start);
134
135        BI_PAIR_TYPE pairType = helix->pairtype(i);
136        if (pairType == HELIX_NONE) {
137            buffer[k] = ' ';
138        }
139        else {
140            j             = helix->opposite_position(i);
141            char pairchar = j<cd->real_sequence_length ? opt_string[j] : '.';
142            buffer[k]     = helix->get_symbol(opt_string[i], pairchar, pairType);
143        }
144    }
145    buffer[size] = 0;
146    return device->text(gc, buffer, x, y);
147}
148
149static bool ED4_show_protein_match_on_device(AW_device *device, int gc, const char *protstruct, size_t /* protstruct_len */, size_t start, size_t size,
150                                             AW_pos x, AW_pos y, AW_pos /* opt_ascent */, AW_pos /* opt_descent */,
151                                             AW_CL cl_protstruct) // , AW_CL /* real_sequence_length */, AW_CL cd2)
152{
153    /*! \brief Calls ED4_pfold_calculate_secstruct_match() for the visible area in the
154     *         editor to compute the protein secondary structure match and outputs the
155     *         result to the device.
156     *  \param[in] protstruct    The protein structure (primary or secondary) that should be compared to \a cl_protstruct
157     *  \param[in] cl_protstruct The reference protein secondary structure SAI
158     */
159
160    GB_ERROR error = 0;
161    // TODO: proper use of ED4_remap?
162    const ED4_remap *rm = ED4_ROOT->root_group_man->remap();
163    char *buffer = GB_give_buffer(size+1);
164    if (!buffer) {
165        error = GB_export_error("Out of memory.");
166    }
167    else {
168        error = ED4_pfold_calculate_secstruct_match((const unsigned char *)cl_protstruct,
169                                                    (const unsigned char *)protstruct,
170                                                    rm->screen_to_sequence(start),
171                                                    rm->screen_to_sequence(start + size),
172                                                    buffer,
173                                                    (PFOLD_MATCH_METHOD)ED4_ROOT->aw_root->awar(PFOLD_AWAR_MATCH_METHOD)->read_int());
174    }
175    if (error) {
176        aw_message(error);
177        return false;
178    }
179   
180    buffer[size] = 0;
181    return device->text(gc, buffer, x, y);
182}
183
184ED4_returncode ED4_orf_terminal::draw() {
185    // draw aminoacid ORFs below the DNA sequence
186
187    static int    color_is_used[ED4_G_DRAG];
188    static char **colored_strings        = 0;
189    static int    len_of_colored_strings = 0;
190
191    AW_device *device = current_device();
192
193    // @@@ DRY calculation of index-range to-be-updated (done in several draw functions)
194    AW_pos world_x, world_y;
195    calc_world_coords(&world_x, &world_y);
196    current_ed4w()->world_to_win_coords(&world_x, &world_y);
197
198    AW_pos text_x = world_x + CHARACTEROFFSET; // don't change
199    AW_pos text_y = world_y + SEQ_TERM_TEXT_YOFFSET;
200
201    const ED4_remap *rm = ED4_ROOT->root_group_man->remap();
202
203    ExplicitRange index_range = rm->clip_screen_range(calc_update_interval());
204    {
205        int max_seq_len = aaSeqLen;
206        int max_seq_pos = rm->sequence_to_screen(max_seq_len-1);
207        index_range     = ExplicitRange(PosRange(index_range), max_seq_pos);
208    }
209
210    if (index_range.is_empty()) {
211        const char *no_data = "No sequence data";
212        size_t      len     = strlen(no_data);
213
214        device->text(ED4_G_STANDARD, no_data, text_x, text_y, 0, AW_SCREEN, len);
215        return ED4_R_OK;
216    }
217
218    if (index_range.end() >= len_of_colored_strings) {
219        len_of_colored_strings = index_range.end() + 256;
220        if (!colored_strings) {
221            colored_strings = (char **)GB_calloc(sizeof(char *), ED4_G_DRAG);
222        }
223        int i;
224        for (i=0; i<ED4_G_DRAG; i++) {
225            freeset(colored_strings[i], (char *)malloc(sizeof(char) * (len_of_colored_strings+1)));
226            memset(colored_strings[i], ' ', len_of_colored_strings);
227            colored_strings[i][len_of_colored_strings] = 0;
228        }
229    }
230
231    int seq_end = rm->screen_to_sequence(index_range.end());
232
233    // mark all strings as unused
234    memset(color_is_used, 0, sizeof(color_is_used));
235
236    int iDisplayMode = ED4_ROOT->aw_root->awar(AWAR_PROTVIEW_DISPLAY_OPTIONS)->read_int();
237    {
238        const unsigned char *aaSequence_u = (const unsigned char *)aaSequence;
239        const unsigned char *aaColor_u    = (const unsigned char *)aaColor;
240
241        if (iDisplayMode == PV_AA_NAME || iDisplayMode == PV_AA_CODE) {
242            // transform strings, compress if needed
243            ED4_reference *ref = ED4_ROOT->reference;
244            ref->expand_to_length(seq_end);
245
246            char *char_2_char = ED4_ROOT->sequence_colors->char_2_char_aa;
247            char *char_2_gc   = ED4_ROOT->sequence_colors->char_2_gc_aa;
248
249            if (iDisplayMode == PV_AA_NAME) {
250                for (int scr_pos=index_range.start(); scr_pos <= index_range.end(); scr_pos++) {
251                    int           seq_pos = rm->screen_to_sequence(scr_pos);
252                    unsigned char c       = aaSequence_u[seq_pos];
253                    unsigned char cc      = aaColor_u[seq_pos];
254                    int           gc      = char_2_gc[safeCharIndex(cc)];
255
256                    color_is_used[gc] = scr_pos+1;
257                    colored_strings[gc][scr_pos] = char_2_char[safeCharIndex(c)];
258                }
259            }
260            else {
261                for (int scr_pos=index_range.start(); scr_pos <= index_range.end(); scr_pos++) {
262                    int  seq_pos = rm->screen_to_sequence(scr_pos);
263                    char c       = aaSequence_u[seq_pos];
264                    int  gc      = char_2_gc[safeCharIndex(c)];
265
266                    color_is_used[gc] = scr_pos+1;
267                    colored_strings[gc][scr_pos] = char_2_char[safeCharIndex(c)];
268                }
269            }
270        }
271
272        // paint background
273        if ((iDisplayMode == PV_AA_CODE) || (iDisplayMode == PV_AA_BOX)) {
274            AW_pos     width        = ED4_ROOT->font_group.get_width(ED4_G_HELIX);
275            const int  real_left    = index_range.start();
276            const int  real_right   = index_range.end();
277            AW_pos     x2           = text_x + width*real_left;
278            AW_pos     y1           = world_y;
279            AW_pos     y2           = text_y+1;
280            AW_pos     height       = y2-y1+1;
281            int        color        = ED4_G_STANDARD;
282            char      *char_2_gc_aa = ED4_ROOT->sequence_colors->char_2_gc_aa;
283
284            for (int i = real_left; i <= real_right; i++, x2 += width) {
285                int  new_pos = rm->screen_to_sequence(i); // getting the real position of the base in the sequence
286                char base    = aaSequence_u[new_pos];
287
288                if (isupper(base) || (base=='*')) {
289                    AW_pos x1  = x2-width; // store current x pos to x1
290                    x2 += width*2; // add 2 char width to x2
291                    i  += 2; // jump two pos
292
293                    int gcChar =  char_2_gc_aa[safeCharIndex(base)];
294                    if ((gcChar>=0) && (gcChar<ED4_G_DRAG)) {
295                        color = gcChar;
296                        if (iDisplayMode == PV_AA_BOX) {
297                            device->box(color, AW::FillStyle::SOLID, x1, y1, width*3, height);
298                        }
299                        else {
300                            double    rad_x    = width*1.5;
301                            double    rad_y    = height*0.7;
302                            double    center_x = x1+rad_x;
303                            const int DRAW_DEG = 62;
304
305                            device->arc(ED4_G_SEQUENCES, AW::FillStyle::EMPTY, center_x, y1, rad_x, rad_y,   0,  DRAW_DEG);
306                            device->arc(ED4_G_SEQUENCES, AW::FillStyle::EMPTY, center_x, y1, rad_x, rad_y, 180, -DRAW_DEG);
307                        }
308                    }
309                }
310            }
311        }
312    }
313
314    if ((iDisplayMode == PV_AA_NAME) || (iDisplayMode == PV_AA_CODE)) {
315        device->set_vertical_font_overlap(true);
316        // output strings
317        for (int gc = 0; gc < ED4_G_DRAG; gc++) {
318            if (color_is_used[gc] && (int)strlen(colored_strings[gc]) >= color_is_used[gc]) {
319                device->text(gc, colored_strings[gc], text_x, text_y, 0, AW_SCREEN, color_is_used [gc]);
320                memset(colored_strings[gc] + index_range.start(), ' ', index_range.size()); // clear string
321            }
322        }
323        device->set_vertical_font_overlap(false);
324    }
325
326    return (ED4_R_OK);
327}
328
329ED4_returncode ED4_sequence_terminal::draw() {
330    static int    color_is_used[ED4_G_DRAG];
331    static char **colored_strings        = 0;
332    static int    len_of_colored_strings = 0;
333
334#if defined(TRACE_REFRESH)
335    fprintf(stderr, "ED4_sequence_terminal::draw for id='%s'\n", id); fflush(stderr);
336#endif
337
338    AW_device *device = current_device();
339
340    int max_seq_len;
341    resolve_pointer_to_char_pntr(&max_seq_len);
342    e4_assert(max_seq_len>0);
343
344    AW_pos world_x, world_y;
345    calc_world_coords(&world_x, &world_y);
346    current_ed4w()->world_to_win_coords(&world_x, &world_y);
347
348    AW_pos text_x = world_x + CHARACTEROFFSET;    // don't change
349    AW_pos text_y = world_y + SEQ_TERM_TEXT_YOFFSET;
350
351    const ED4_remap *rm = ED4_ROOT->root_group_man->remap();
352
353    ExplicitRange index_range = rm->clip_screen_range(calc_update_interval());
354    if (index_range.is_empty()) return ED4_R_OK;
355
356    int left  = index_range.start(); // @@@ do similar to ED4_orf_terminal::draw here
357    int right = index_range.end();
358
359    {
360        int max_seq_pos = rm->sequence_to_screen(max_seq_len-1);
361
362        if (right>max_seq_len) right = max_seq_pos;
363        if (left>right) {
364            const char *no_data = "No sequence data";
365            size_t      len     = strlen(no_data);
366
367            device->text(ED4_G_STANDARD, no_data, text_x, text_y, 0, AW_SCREEN, len);
368            return ED4_R_OK;
369        }
370    }
371
372    if (right >= len_of_colored_strings) {
373        len_of_colored_strings = right + 256;
374        if (!colored_strings) {
375            colored_strings = (char **)GB_calloc(sizeof(char *), ED4_G_DRAG);
376        }
377        int i;
378        for (i=0; i<ED4_G_DRAG; i++) {
379            freeset(colored_strings[i], (char *)malloc(sizeof(char) * (len_of_colored_strings+1)));
380            memset(colored_strings[i], ' ', len_of_colored_strings);
381            colored_strings[i][len_of_colored_strings] = 0;
382        }
383    }
384
385    int seq_start = rm->screen_to_sequence(left); // real start of sequence
386    int seq_end = rm->screen_to_sequence(right);
387
388    // mark all strings as unused
389    memset(color_is_used, 0, sizeof(color_is_used));
390
391    // transform strings, compress if needed
392    {
393        ED4_reference *ref        = ED4_ROOT->reference;
394        unsigned char *db_pointer = (unsigned char *)resolve_pointer_to_string_copy();
395
396        ref->expand_to_length(seq_end);
397
398        GB_alignment_type aliType = GetAliType();
399        char *char_2_char = (aliType && (aliType==GB_AT_AA)) ? ED4_ROOT->sequence_colors->char_2_char_aa : ED4_ROOT->sequence_colors->char_2_char;
400        char *char_2_gc   = (aliType && (aliType==GB_AT_AA)) ? ED4_ROOT->sequence_colors->char_2_gc_aa : ED4_ROOT->sequence_colors->char_2_gc;
401
402        bool only_show_diff = ref->only_show_diff_for(this);
403        for (int scr_pos=left; scr_pos <= right; scr_pos++) {
404            int seq_pos = rm->screen_to_sequence(scr_pos);
405            int c = db_pointer[seq_pos];
406            int gc = char_2_gc[c];
407
408            color_is_used[gc] = scr_pos+1;
409            colored_strings[gc][scr_pos] = char_2_char[only_show_diff ? ref->convert(c, seq_pos) : c];
410        }
411
412        free(db_pointer);
413    }
414
415    // Set background
416
417    {
418        GB_transaction       ta(GLOBAL_gb_main);
419        ST_ML_Color         *statColors   = 0;
420        char                *searchColors = results().buildColorString(this, seq_start, seq_end); // defined in ED4_SearchResults class : ED4_search.cxx
421        ED4_species_manager *spec_man     = get_parent(ED4_L_SPECIES)->to_species_manager();
422        int                  color_group  = AW_color_groups_active() ? GBT_get_color_group(spec_man->get_species_pointer()) : 0;
423
424        PosRange selection;
425        int      is_selected = ED4_get_selected_range(this, selection);
426        int      is_marked   = GB_read_flag(spec_man->get_species_pointer());
427
428        if (species_name &&
429            ED4_ROOT->column_stat_activated &&
430            (st_ml_node || (st_ml_node = STAT_find_node_by_name(ED4_ROOT->st_ml, this->species_name))))
431            {
432                statColors = STAT_get_color_string(ED4_ROOT->st_ml, 0, st_ml_node, seq_start, seq_end);
433            }
434
435        const char *saiColors = 0;
436
437        if (species_name                       &&
438            ED4_ROOT->visualizeSAI             &&
439            spec_man->get_type() != ED4_SP_SAI &&
440            (is_marked || ED4_ROOT->visualizeSAI_allSpecies))
441        {
442            saiColors = ED4_getSaiColorString(ED4_ROOT->aw_root, seq_start, seq_end);
443        }
444
445        if (statColors || searchColors || is_marked || is_selected || color_group || saiColors) {
446            int    i;
447            AW_pos width      = ED4_ROOT->font_group.get_width(ED4_G_HELIX);
448            int    real_left  = left;
449            int    real_right = right;
450            AW_pos x2         = text_x + width*real_left;
451            AW_pos old_x      = x2;
452            AW_pos y1         = world_y;
453            AW_pos y2         = text_y+1;
454            AW_pos height     = y2-y1+1;
455            int    old_color  = ED4_G_STANDARD;
456            int    color      = ED4_G_STANDARD;
457
458            if (is_selected && selection.is_unlimited()) {
459                selection = ExplicitRange(selection, rm->screen_to_sequence(real_right));
460            }
461
462            for (i = real_left; i <= real_right; i++, x2 += width) {
463                int new_pos = rm->screen_to_sequence(i);  // getting the real position of the base in the sequence
464
465                // Note: if you change background color priorities,
466                // please update help in ../HELP_SOURCE/oldhelp/e4_background_priority.hlp@COLOR_PRIORITY
467
468                if (searchColors && searchColors[new_pos]) {
469                    color = searchColors[new_pos];
470                }
471                else if (is_selected && selection.contains(new_pos)) {
472                    color = ED4_G_SELECTED;
473                }
474                else if (statColors) {
475                    color = statColors[new_pos] + ED4_G_CBACK_0;
476                    if (color > ED4_G_CBACK_9) color = ED4_G_CBACK_9;
477                }
478                else if (saiColors) {
479                    color = saiColors[new_pos];
480                    if (color < ED4_G_CBACK_0 || color > ED4_G_CBACK_9)  color = ED4_G_STANDARD;
481                }
482                else if (is_marked) {
483                    color = ED4_G_MARKED;
484                }
485                else if (color_group) {
486                    color = ED4_G_FIRST_COLOR_GROUP+color_group-1;
487                }
488                else {
489                    color = ED4_G_STANDARD;
490                }
491
492                if (color != old_color) {   // draw till oldcolor
493                    if (x2>old_x) {
494                        if (old_color!=ED4_G_STANDARD) {
495                            device->box(old_color, AW::FillStyle::SOLID, old_x, y1, x2-old_x, height); // paints the search pattern background
496                        }
497                    }
498                    old_x = x2;
499                    old_color = color;
500                }
501            }
502
503            if (x2>old_x) {
504                if (color!=ED4_G_STANDARD) {
505                    device->box(color, AW::FillStyle::SOLID, old_x, y1, x2-old_x, height);
506                }
507            }
508        }
509    }
510
511    device->set_vertical_font_overlap(true);
512
513    if (shall_display_secstruct_info) {
514        if (ED4_ROOT->helix->is_enabled()) {
515            // output helix
516            int   db_len;
517            char *db_pointer = resolve_pointer_to_string_copy(&db_len);
518
519            e4_assert(size_t(db_len) == ED4_ROOT->helix->size());
520            ShowHelix_cd  cd         = { ED4_ROOT->helix, max_seq_len };
521            device->text_overlay(ED4_G_HELIX,
522                                 (char *)db_pointer, db_len,
523                                 AW::Position(text_x,  text_y + ED4_ROOT->helix_spacing), 0.0,  AW_ALL_DEVICES_UNSCALED,
524                                 (AW_CL)&cd, 1.0, 1.0, ED4_show_helix_on_device);
525            free(db_pointer);
526        }
527
528        if (ED4_ROOT->protstruct) {
529            // output protein structure match
530            ED4_species_manager *spec_man = get_parent(ED4_L_SPECIES)->to_species_manager();
531            if (spec_man->get_type() != ED4_SP_SAI && ED4_ROOT->aw_root->awar(PFOLD_AWAR_ENABLE)->read_int()) {  // should do a remap
532                int   db_len;
533                char *protstruct = resolve_pointer_to_string_copy(&db_len);
534               
535                if (protstruct) {
536                    device->text_overlay(ED4_G_HELIX,
537                                         protstruct, db_len,
538                                         AW::Position(text_x,  text_y + ED4_ROOT->helix_spacing),  0.0,  AW_ALL_DEVICES_UNSCALED,
539                                         (AW_CL)ED4_ROOT->protstruct, 1.0, 1.0, ED4_show_protein_match_on_device);
540                    free(protstruct);
541                }
542            }
543        }
544    }
545    // output strings
546    {
547        int gc;
548        for (gc = 0; gc < ED4_G_DRAG; gc++) {
549            if (!color_is_used[gc]) continue;
550            device->text(gc, colored_strings[gc], text_x, text_y, 0, AW_SCREEN, color_is_used[gc]);
551            memset(colored_strings[gc] + left, ' ', right-left+1); // clear string
552        }
553    }
554
555    device->set_vertical_font_overlap(false);
556
557    return (ED4_R_OK);
558}
559
560
561ED4_returncode ED4_sequence_info_terminal::draw() {
562    AW_pos x, y;
563    calc_world_coords(&x, &y);
564    current_ed4w()->world_to_win_coords(&x, &y);
565
566    AW_pos text_x = x + CHARACTEROFFSET; // don't change
567    AW_pos text_y = y+INFO_TERM_TEXT_YOFFSET;
568
569    char    buffer[10];
570    GBDATA *gbdata = data();
571
572    if (gbdata) {
573        GB_push_transaction(gbdata);
574        buffer[0] = '0' + GB_read_security_write(gbdata);
575        GB_pop_transaction(gbdata);
576    }
577    else {
578        buffer[0] = ' ';
579    }
580    strncpy(&buffer[1], this->id, 8);
581    buffer[9] = 0;
582
583    if (containing_species_manager()->is_selected()) {
584        current_device()->box(ED4_G_SELECTED, AW::FillStyle::SOLID, x, y, extension.size[WIDTH], text_y-y+1);
585    }
586
587    current_device()->set_vertical_font_overlap(true);
588    current_device()->text(ED4_G_STANDARD, buffer, text_x, text_y, 0, AW_SCREEN, 0);
589    current_device()->set_vertical_font_overlap(false);
590
591    return (ED4_R_OK);
592
593}
594
595// ---------------------------
596//      ED4_text_terminal
597
598ED4_returncode ED4_text_terminal::Show(int IF_ASSERTION_USED(refresh_all), int is_cleared)
599{
600    e4_assert(update_info.refresh || refresh_all);
601    current_device()->push_clip_scale();
602    if (adjust_clipping_rectangle()) {
603        if (update_info.clear_at_refresh && !is_cleared) {
604            clear_background();
605        }
606        draw();
607    }
608    current_device()->pop_clip_scale();
609
610    return ED4_R_OK;
611}
612
613ED4_returncode ED4_text_terminal::draw() {
614    AW_pos x, y;
615    calc_world_coords(&x, &y);
616    current_ed4w()->world_to_win_coords(&x, &y);
617
618    AW_pos text_x = x + CHARACTEROFFSET; // don't change
619    AW_pos text_y = y + INFO_TERM_TEXT_YOFFSET;
620
621    current_device()->set_vertical_font_overlap(true);
622
623    if (is_species_name_terminal()) {
624        GB_CSTR real_name      = to_species_name_terminal()->get_displayed_text();
625        int     width_of_char;
626        int     height_of_char = -1;
627        bool    paint_box      = inside_species_seq_manager();
628        bool    is_marked      = false;
629
630        if (paint_box) {
631            ED4_species_manager *species_man = get_parent(ED4_L_SPECIES)->to_species_manager();
632            GBDATA *gbd = species_man->get_species_pointer();
633
634            if (gbd) {
635                GB_transaction ta(gbd);
636                is_marked = GB_read_flag(gbd);
637            }
638
639            width_of_char = ED4_ROOT->font_group.get_width(ED4_G_STANDARD);
640            height_of_char = ED4_ROOT->font_group.get_height(ED4_G_STANDARD);
641#define MIN_MARK_BOX_SIZE 8
642            if (width_of_char<MIN_MARK_BOX_SIZE) width_of_char = MIN_MARK_BOX_SIZE;
643            if (height_of_char<MIN_MARK_BOX_SIZE) height_of_char = MIN_MARK_BOX_SIZE;
644#undef MIN_MARK_BOX_SIZE
645        }
646        else {
647            width_of_char = 0;
648        }
649
650        if (containing_species_manager()->is_selected()) {
651            current_device()->box(ED4_G_SELECTED, AW::FillStyle::SOLID, x, y, extension.size[WIDTH], text_y-y+1);
652        }
653        current_device()->text(ED4_G_STANDARD, real_name, text_x+width_of_char, text_y, 0, AW_SCREEN, 0);
654
655        if (paint_box) {
656            int xsize = (width_of_char*6)/10;
657            int ysize = (height_of_char*6)/10;
658            int xoff  = xsize>>1;
659            int yoff  = 0;
660            int bx    = int(text_x+xoff);
661            int by    = int(text_y-(yoff+ysize));
662
663            current_device()->box(ED4_G_STANDARD, AW::FillStyle::SOLID, bx, by, xsize, ysize);
664            if (!is_marked && xsize>2 && ysize>2) {
665                current_device()->clear_part(bx+1, by+1, xsize-2, ysize-2, AW_ALL_DEVICES);
666            }
667        }
668    }
669    else {
670        char *db_pointer = resolve_pointer_to_string_copy();
671
672        if (is_sequence_info_terminal()) {
673            current_device()->text(ED4_G_STANDARD, db_pointer, text_x, text_y, 0, AW_SCREEN, 4);
674        }
675        else if (is_pure_text_terminal()) { // normal text (i.e. remark)
676            text_y += (SEQ_TERM_TEXT_YOFFSET-INFO_TERM_TEXT_YOFFSET);
677            current_device()->text(ED4_G_SEQUENCES, db_pointer, text_x, text_y, 0, AW_SCREEN, 0);
678        }
679        else {
680            e4_assert(0); // unknown terminal type
681        }
682
683        free(db_pointer);
684    }
685    current_device()->set_vertical_font_overlap(false);
686
687    return (ED4_R_OK);
688}
689
690ED4_text_terminal::ED4_text_terminal(const ED4_objspec& spec_, GB_CSTR temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) :
691    ED4_terminal(spec_, temp_id, x, y, width, height, temp_parent)
692{
693}
694
Note: See TracBrowser for help on using the repository browser.