Пример #1
0
Файл: game.c Проект: orodley/ttc
void new_level(Game *game)
{
    char *word = strdup(random_word(game->all_words_array, MAX_WORD_LENGTH));

    printf("word is %s\n", word);
    shuffle(word);
    printf("word is %s\n", word);

    game->anagrams = find_all_anagrams(game->all_words_tree, word);
    printf("%zu anagrams:\n", game->anagrams->count);

    WordList **anagrams_by_length = malloc(sizeof(*anagrams_by_length) *
                                           (MAX_WORD_LENGTH - 2));
    sort_words(anagrams_by_length, game->anagrams);
    for (size_t i = 0; i < MAX_WORD_LENGTH - 2; i++) {
        printf("%zu: %zu words\n", i + 3, anagrams_by_length[i]->count);

        for (size_t j = 0; j < anagrams_by_length[i]->count; j++)
            printf("\t%s\n", GET_WORD(anagrams_by_length[i], j));
    }

    game->anagrams_by_length = anagrams_by_length;

    game->column_sizes = compute_layout(game);

    game->guessed_words =
        make_word_list(game->anagrams->count, MAX_WORD_LENGTH + 1);

    SDL_Color white = { 0xFF, 0xFF, 0xFF, 0xFF };
    game->guessed_words_texture = render_empty_words(game, white);
    SDL_DestroyTexture(game->message_box);
    game->message_box = NULL;

    game->chars_entered = 0;

    memset(game->curr_input, 0, MAX_WORD_LENGTH + 1);
    memcpy(game->remaining_chars, word, MAX_WORD_LENGTH + 1);

    if (game->second_timer != 0)
        SDL_RemoveTimer(game->second_timer);
    game->second_timer = SDL_AddTimer(1000, timer_handler, game);
    game->time_left = 180;

    game->state = IN_LEVEL;
}
Пример #2
0
void
ish3_ProgressBar::add_control(Rollout *ro, HWND parent, HINSTANCE hInstance, int& current_y)
{
   caption = caption->eval();

   const TCHAR*   text = caption->eval()->to_string();

   // We'll hang onto these...
   parent_rollout = ro;
   control_ID = next_id();

   // Load in some values from the user, if they were given...
   Value* Vtmp = control_param(value);
   if(Vtmp==&unsupplied) value = 0;
   else
      value = Vtmp->to_int();

   // Check orientation parameter
   type = TYPE_HORIZ;
   Value* Ttmp = control_param(orient);
   if(Ttmp!=&unsupplied&&Ttmp==n_vertical) type = TYPE_VERT;

   // Get the colour of the progress slider
   Value* Ctmp = control_param(color);
   if(Ctmp==&unsupplied) colorPro = RGB(30,10,190);
   else
      colorPro = convertFrom(Ctmp->to_acolor());

   // Pass the inpho back to MXS to 
   // let it calculate final position
   layout_data pos;
   compute_layout(ro, &pos, current_y);

   progbar = CreateWindow(
                     PBAR_WINDOWCLASS,
                     text,
                     WS_VISIBLE | WS_CHILD | WS_GROUP,
                     pos.left, pos.top, pos.width, pos.height,    
                     parent, (HMENU)control_ID, g_hInst, this);
   DWORD err = GetLastError();

}
Пример #3
0
void AngleControl::add_control(Rollout *ro, HWND parent, HINSTANCE hInstance, int& current_y)
{
   caption = caption->eval();

   HWND  label;
   int      left, top, width, height;
   SIZE  size;
   const TCHAR *label_text = caption->eval()->to_string();

   parent_rollout = ro;
   control_ID = next_id();
   WORD label_id = next_id();

   Value *val;
   if((val = control_param(diameter)) != &unsupplied)
      m_diameter = val->to_int();
   else if((val = control_param(width)) != &unsupplied)
      m_diameter = val->to_int();
   else if((val = control_param(height)) != &unsupplied)
      m_diameter = val->to_int();
   else
      m_diameter = 64;

   val = control_param(degrees);
   if(val != &unsupplied)
      m_degrees = val->to_float();
   else
      m_degrees = 0.f;

   val = control_param(radians);
   if(val != &unsupplied)
      m_degrees = RadToDeg(val->to_float());

   val = control_param(range);
   if (val == &unsupplied)
   {
      m_min = -360.0f; m_max = 360.0f;
   }
   else if (is_point3(val))
   {
      Point3 p = val->to_point3();
      m_min = p.x; m_max = p.y; m_degrees = p.z;
   }
   else
      throw TypeError (MaxSDK::GetResourceStringAsMSTR(IDS_ANGLE_RANGE_MUST_BE_A_VECTOR), val);

   val = control_param(startDegrees);
   if(val != &unsupplied)
      SetStartDegrees(val->to_float());
   else
      SetStartDegrees(0.f);

   val = control_param(startRadians);
   if(val != &unsupplied)
      SetStartDegrees(RadToDeg(val->to_float()));

   val = control_param(dir);
   if(val != &unsupplied)
   {
      if (val != n_CW && val != n_CCW)
         throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_ANGLE_DIR_BAD_VALUE), val);
      m_dirCCW = val != n_CW;
   }

   val = control_param(bitmap);
   if(val != &unsupplied)
      SetBitmap(val);
   else
      SetColor(control_param(color));

   m_lButtonDown = FALSE;

   layout_data pos;
   compute_layout(ro, &pos, current_y);
   left = pos.left; top = pos.top;

   // place optional label
   int label_height = (_tcslen(label_text) != 0) ? ro->text_height + SPACING_BEFORE - 2 : 0;
   // LAM - defect 298613 - not creating the caption HWND was causing problems (whole screen redrawn
   // when control moved, setting caption text set wrong HWND). Now always create.
// if (label_height != 0)
// {
      DLGetTextExtent(ro->rollout_dc, label_text, &size);   
      width = min(size.cx, pos.width); height = ro->text_height;
      label = CreateWindow(_T("STATIC"),
                        label_text,
                        WS_VISIBLE | WS_CHILD | WS_GROUP,
                        left, top, width, height,    
                        parent, (HMENU)label_id, hInstance, NULL);
// }

   // place angle box
   top = pos.top + label_height;
   width = pos.width;

   m_hWnd = CreateWindow(
      ANGLECTRL_WINDOWCLASS,
      TEXT(""),
      WS_VISIBLE | WS_CHILD | WS_GROUP,
      pos.left, top, width, m_diameter,    
      parent, (HMENU)control_ID, g_hInst, this);

   m_hToolTip = CreateWindow(
      TOOLTIPS_CLASS,
      TEXT(""), WS_POPUP,
      CW_USEDEFAULT, CW_USEDEFAULT,
      CW_USEDEFAULT, CW_USEDEFAULT,
      m_hWnd, (HMENU)NULL, g_hInst, NULL);

   SendMessage(label, WM_SETFONT, (WPARAM)ro->font, 0L);
   SendMessage(m_hToolTip, TTM_ADDTOOL, 0, (LPARAM)GetToolInfo());
}
Пример #4
0
void s_write(screen_t *s, const wcstring &left_prompt, const wcstring &right_prompt,
             const wcstring &commandline, size_t explicit_len,
             const std::vector<highlight_spec_t> &colors, const std::vector<int> &indent,
             size_t cursor_pos, const page_rendering_t &pager, bool cursor_is_within_pager) {
    screen_data_t::cursor_t cursor_arr;

    // Turn the command line into the explicit portion and the autosuggestion.
    const wcstring explicit_command_line = commandline.substr(0, explicit_len);
    const wcstring autosuggestion = commandline.substr(explicit_len);

    // If we are using a dumb terminal, don't try any fancy stuff, just print out the text.
    // right_prompt not supported.
    if (is_dumb()) {
        const std::string prompt_narrow = wcs2string(left_prompt);
        const std::string command_line_narrow = wcs2string(explicit_command_line);

        write_loop(STDOUT_FILENO, "\r", 1);
        write_loop(STDOUT_FILENO, prompt_narrow.c_str(), prompt_narrow.size());
        write_loop(STDOUT_FILENO, command_line_narrow.c_str(), command_line_narrow.size());

        return;
    }

    s_check_status(s);
    const size_t screen_width = common_get_width();

    // Completely ignore impossibly small screens.
    if (screen_width < 4) {
        return;
    }

    // Compute a layout.
    const screen_layout_t layout = compute_layout(s, screen_width, left_prompt, right_prompt,
                                                  explicit_command_line, autosuggestion, indent);

    // Determine whether, if we have an autosuggestion, it was truncated.
    s->autosuggestion_is_truncated =
        !autosuggestion.empty() && autosuggestion != layout.autosuggestion;

    // Clear the desired screen.
    s->desired.resize(0);
    s->desired.cursor.x = s->desired.cursor.y = 0;

    // Append spaces for the left prompt.
    for (size_t i = 0; i < layout.left_prompt_space; i++) {
        s_desired_append_char(s, L' ', highlight_spec_t{}, 0, layout.left_prompt_space);
    }

    // If overflowing, give the prompt its own line to improve the situation.
    size_t first_line_prompt_space = layout.left_prompt_space;
    if (layout.prompts_get_own_line) {
        s_desired_append_char(s, L'\n', highlight_spec_t{}, 0, 0);
        first_line_prompt_space = 0;
    }

    // Reconstruct the command line.
    wcstring effective_commandline = explicit_command_line + layout.autosuggestion;

    // Output the command line.
    size_t i;
    for (i = 0; i < effective_commandline.size(); i++) {
        // Grab the current cursor's x,y position if this character matches the cursor's offset.
        if (!cursor_is_within_pager && i == cursor_pos) {
            cursor_arr = s->desired.cursor;
        }
        s_desired_append_char(s, effective_commandline.at(i), colors[i], indent[i],
                              first_line_prompt_space);
    }

    // Cursor may have been at the end too.
    if (!cursor_is_within_pager && i == cursor_pos) {
        cursor_arr = s->desired.cursor;
    }

    // Now that we've output everything, set the cursor to the position that we saved in the loop
    // above.
    s->desired.cursor = cursor_arr;

    if (cursor_is_within_pager) {
        s->desired.cursor.x = (int)cursor_pos;
        s->desired.cursor.y = (int)s->desired.line_count();
    }

    // Append pager_data (none if empty).
    s->desired.append_lines(pager.screen_data);

    s_update(s, layout.left_prompt, layout.right_prompt);
    s_save_status(s);
}
Пример #5
0
void s_write(screen_t *s,
             const wcstring &left_prompt,
             const wcstring &right_prompt,
             const wcstring &commandline,
             size_t explicit_len,
             const int *colors,
             const int *indent,
             size_t cursor_pos)
{
    screen_data_t::cursor_t cursor_arr;

    CHECK(s,);
    CHECK(indent,);

    /* Turn the command line into the explicit portion and the autosuggestion */
    const wcstring explicit_command_line = commandline.substr(0, explicit_len);
    const wcstring autosuggestion = commandline.substr(explicit_len);

    /*
      If we are using a dumb terminal, don't try any fancy stuff,
      just print out the text. right_prompt not supported.
     */
    if (is_dumb())
    {
        const std::string prompt_narrow = wcs2string(left_prompt);
        const std::string command_line_narrow = wcs2string(explicit_command_line);

        write_loop(STDOUT_FILENO, "\r", 1);
        write_loop(STDOUT_FILENO, prompt_narrow.c_str(), prompt_narrow.size());
        write_loop(STDOUT_FILENO, command_line_narrow.c_str(), command_line_narrow.size());

        return;
    }

    s_check_status(s);
    const size_t screen_width = common_get_width();

    /* Completely ignore impossibly small screens */
    if (screen_width < 4)
    {
        return;
    }

    /* Compute a layout */
    const screen_layout_t layout = compute_layout(s, screen_width, left_prompt, right_prompt, explicit_command_line, autosuggestion, indent);

    /* Determine whether, if we have an autosuggestion, it was truncated */
    s->autosuggestion_is_truncated = ! autosuggestion.empty() && autosuggestion != layout.autosuggestion;

    /* Clear the desired screen */
    s->desired.resize(0);
    s->desired.cursor.x = s->desired.cursor.y = 0;

    /* Append spaces for the left prompt */
    for (size_t i=0; i < layout.left_prompt_space; i++)
    {
        s_desired_append_char(s, L' ', 0, 0, layout.left_prompt_space);
    }

    /* If overflowing, give the prompt its own line to improve the situation. */
    size_t first_line_prompt_space = layout.left_prompt_space;
    if (layout.prompts_get_own_line)
    {
        s_desired_append_char(s, L'\n', 0, 0, 0);
        first_line_prompt_space = 0;
    }

    /* Reconstruct the command line */
    wcstring effective_commandline = explicit_command_line + layout.autosuggestion;

    /* Output the command line */
    size_t i;
    for (i=0; i < effective_commandline.size(); i++)
    {
        int color = colors[i];

        if (i == cursor_pos)
        {
            color = 0;
        }

        if (i == cursor_pos)
        {
            cursor_arr = s->desired.cursor;
        }

        s_desired_append_char(s, effective_commandline.at(i), color, indent[i], first_line_prompt_space);
    }
    if (i == cursor_pos)
    {
        cursor_arr = s->desired.cursor;
    }

    s->desired.cursor = cursor_arr;
    s_update(s, layout.left_prompt.c_str(), layout.right_prompt.c_str());
    s_save_status(s);
}
Пример #6
0
 void Button_base::text_changed()
 {
     compute_label_bounds();
     compute_layout(bounds());
     invalidate();
 }