# texteff.cpp

Go to the documentation of this file.

    00001 /* $Id: texteff.cpp 24068 2012-03-25 19:30:05Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "texteff.hpp"
    00014 #include "transparency.h"
    00015 #include "strings_func.h"
    00016 #include "core/smallvec_type.hpp"
    00017 #include "viewport_func.h"
    00018 #include "settings_type.h"
    00019
    00021 struct TextEffect : public ViewportSign {
    00022   uint64 params_1;
    00023   StringID string_id;
    00024   uint8 duration;
    00025   TextEffectMode mode;
    00026
    00028   void Reset()
    00029   {
    00030     this->MarkDirty();
    00031     this->width_normal = 0;
    00032     this->string_id = INVALID_STRING_ID;
    00033   }
    00034 };
    00035
    00036 static SmallVector<struct TextEffect, 32> _text_effects;
    00037
    00038 /* Text Effects */
    00039 TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode)
    00040 {
    00041   if (_game_mode == GM_MENU) return INVALID_TE_ID;
    00042
    00043   TextEffectID i;
    00044   for (i = 0; i < _text_effects.Length(); i++) {
    00045     if (_text_effects[i].string_id == INVALID_STRING_ID) break;
    00046   }
    00047   if (i == _text_effects.Length()) _text_effects.Append();
    00048
    00049   TextEffect *te = _text_effects.Get(i);
    00050
    00051   /* Start defining this object */
    00052   te->string_id = msg;
    00053   te->duration = duration;
    00054   te->params_1 = GetDParam(0);
    00055   te->mode = mode;
    00056
    00057   /* Make sure we only dirty the new area */
    00058   te->width_normal = 0;
    00059   te->UpdatePosition(center, y, msg);
    00060
    00061   return i;
    00062 }
    00063
    00064 void UpdateTextEffect(TextEffectID te_id, StringID msg)
    00065 {
    00066   /* Update details */
    00067   TextEffect *te = _text_effects.Get(te_id);
    00068   if (msg == te->string_id && GetDParam(0) == te->params_1) return;
    00069   te->string_id = msg;
    00070   te->params_1 = GetDParam(0);
    00071
    00072   te->UpdatePosition(te->center, te->top, msg);
    00073 }
    00074
    00075 void RemoveTextEffect(TextEffectID te_id)
    00076 {
    00077   _text_effects[te_id].Reset();
    00078 }
    00079
    00080 void MoveAllTextEffects()
    00081 {
    00082   const TextEffect *end = _text_effects.End();
    00083   for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
    00084     if (te->string_id == INVALID_STRING_ID) continue;
    00085     if (te->mode != TE_RISING) continue;
    00086
    00087     if (te->duration-- == 0) {
    00088       te->Reset();
    00089       continue;
    00090     }
    00091
    00092     te->MarkDirty(ZOOM_LVL_OUT_8X);
    00093     te->top -= ZOOM_LVL_BASE;
    00094     te->MarkDirty(ZOOM_LVL_OUT_8X);
    00095   }
    00096 }
    00097
    00098 void InitTextEffects()
    00099 {
    00100   _text_effects.Reset();
    00101 }
    00102
    00103 void DrawTextEffects(DrawPixelInfo *dpi)
    00104 {
    00105   /* Don't draw the text effects when zoomed out a lot */
    00106   if (dpi->zoom > ZOOM_LVL_OUT_8X) return;
    00107
    00108   const TextEffect *end = _text_effects.End();
    00109   for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
    00110     if (te->string_id == INVALID_STRING_ID) continue;
    00111     if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
    00112       ViewportAddString(dpi, ZOOM_LVL_OUT_8X, te, te->string_id, te->string_id - 1, 0, te->params_1);
    00113     }
    00114   }
    00115 }