mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
[ui] Make passage objects reusable
I had intended to do this for a while, but now that I want it for center print strings, it was time to make the change.
This commit is contained in:
parent
2a53047007
commit
1d51c05f90
3 changed files with 22 additions and 11 deletions
|
@ -49,7 +49,8 @@ typedef struct passage_s {
|
|||
struct hierarchy_s *hierarchy; ///< hierarchy of text objects
|
||||
} passage_t;
|
||||
|
||||
passage_t *Passage_ParseText (const char *text, struct ecs_registry_s *reg);
|
||||
void Passage_ParseText (passage_t *passage, const char *text);
|
||||
passage_t *Passage_New (struct ecs_registry_s *reg);
|
||||
void Passage_Delete (passage_t *passage);
|
||||
int Passage_IsSpace (const char *text) __attribute__((pure));
|
||||
|
||||
|
|
|
@ -99,16 +99,16 @@ add_entity (hierarchy_t *h, uint32_t parent)
|
|||
ref->index = i;
|
||||
}
|
||||
|
||||
VISIBLE passage_t *
|
||||
Passage_ParseText (const char *text, ecs_registry_t *reg)
|
||||
VISIBLE void
|
||||
Passage_ParseText (passage_t *passage, const char *text)
|
||||
{
|
||||
passage_t *passage = malloc (sizeof (passage_t));
|
||||
passage->text = text;
|
||||
passage->reg = reg;
|
||||
|
||||
if (!*text) {
|
||||
return passage;
|
||||
if (passage->hierarchy) {//FIXME just empty hierarchy
|
||||
Hierarchy_Delete (passage->hierarchy);
|
||||
}
|
||||
if (!*text) {
|
||||
return;
|
||||
}
|
||||
passage->text = text;
|
||||
|
||||
unsigned num_paragraphs = 1;
|
||||
unsigned num_text_objects = 1;
|
||||
|
@ -133,7 +133,7 @@ Passage_ParseText (const char *text, ecs_registry_t *reg)
|
|||
parsing_space = 0;
|
||||
}
|
||||
}
|
||||
passage->hierarchy = Hierarchy_New (reg, &passage_type, 0);
|
||||
passage->hierarchy = Hierarchy_New (passage->reg, &passage_type, 0);
|
||||
Hierarchy_Reserve (passage->hierarchy,
|
||||
1 + num_paragraphs + num_text_objects);
|
||||
#if 0
|
||||
|
@ -197,6 +197,15 @@ Passage_ParseText (const char *text, ecs_registry_t *reg)
|
|||
to->text, to->size, to->size, text + to->text);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
VISIBLE passage_t *
|
||||
Passage_New (ecs_registry_t *reg)
|
||||
{
|
||||
passage_t *passage = malloc (sizeof (passage_t));
|
||||
passage->text = 0;
|
||||
passage->reg = reg;
|
||||
passage->hierarchy = 0;
|
||||
return passage;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ main (void)
|
|||
ECS_RegisterComponents (registry, test_components, 1);
|
||||
registry->href_comp = test_href;
|
||||
|
||||
passage_t *passage = Passage_ParseText (test_text, registry);
|
||||
passage_t *passage = Passage_New (registry);
|
||||
Passage_ParseText (passage, test_text);
|
||||
if (passage->hierarchy->childCount[0] != 3) {
|
||||
ret = 1;
|
||||
printf ("incorrect number of paragraphs: %d\n",
|
||||
|
|
Loading…
Reference in a new issue