# texteff.cpp

Go to the documentation of this file.

    00001 /* $Id: texteff.cpp 18636 2009-12-25 23:22:41Z smatz $ */
    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 "openttd.h"
    00014 #include "strings_type.h"
    00015 #include "texteff.hpp"
    00016 #include "core/bitmath_func.hpp"
    00017 #include "transparency.h"
    00018 #include "strings_func.h"
    00019 #include "core/alloc_func.hpp"
    00020 #include "core/smallvec_type.hpp"
    00021 #include "viewport_func.h"
    00022 #include "settings_type.h"
    00023
    00025 struct TextEffect : public ViewportSign{
    00026   uint64 params_1;
    00027   StringID string_id;
    00028   uint8 duration;
    00029   TextEffectMode mode;
    00030
    00032   void Reset()
    00033   {
    00034     this->MarkDirty();
    00035     this->width_normal = 0;
    00036     this->string_id = INVALID_STRING_ID;
    00037   }
    00038 };
    00039
    00040 static SmallVector<struct TextEffect, 32> _text_effects;
    00041
    00042 /* Text Effects */
    00043 TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode)
    00044 {
    00045   if (_game_mode == GM_MENU) return INVALID_TE_ID;
    00046
    00047   TextEffectID i;
    00048   for (i = 0; i < _text_effects.Length(); i++) {
    00049     if (_text_effects[i].string_id == INVALID_STRING_ID) break;
    00050   }
    00051   if (i == _text_effects.Length()) _text_effects.Append();
    00052
    00053   TextEffect *te = _text_effects.Get(i);
    00054
    00055   /* Start defining this object */
    00056   te->string_id = msg;
    00057   te->duration = duration;
    00058   te->params_1 = GetDParam(0);
    00059   te->mode = mode;
    00060
    00061   /* Make sure we only dirty the new area */
    00062   te->width_normal = 0;
    00063   te->UpdatePosition(center, y, msg);
    00064
    00065   return i;
    00066 }
    00067
    00068 void UpdateTextEffect(TextEffectID te_id, StringID msg)
    00069 {
    00070   /* Update details */
    00071   TextEffect *te = _text_effects.Get(te_id);
    00072   te->string_id = msg;
    00073   te->params_1 = GetDParam(0);
    00074
    00075   te->UpdatePosition(te->center, te->top, msg);
    00076 }
    00077
    00078 void RemoveTextEffect(TextEffectID te_id)
    00079 {
    00080   _text_effects[te_id].Reset();
    00081 }
    00082
    00083 void MoveAllTextEffects()
    00084 {
    00085   const TextEffect *end = _text_effects.End();
    00086   for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
    00087     if (te->string_id == INVALID_STRING_ID) continue;
    00088     if (te->mode != TE_RISING) continue;
    00089
    00090     if (te->duration-- == 0) {
    00091       te->Reset();
    00092       continue;
    00093     }
    00094
    00095     te->MarkDirty();
    00096     te->top--;
    00097     te->MarkDirty();
    00098   }
    00099 }
    00100
    00101 void InitTextEffects()
    00102 {
    00103   _text_effects.Reset();
    00104 }
    00105
    00106 void DrawTextEffects(DrawPixelInfo *dpi)
    00107 {
    00108   /* Don't draw the text effects when zoomed out a lot */
    00109   if (dpi->zoom > ZOOM_LVL_OUT_2X) return;
    00110
    00111   const TextEffect *end = _text_effects.End();
    00112   for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
    00113     if (te->string_id == INVALID_STRING_ID) continue;
    00114     if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
    00115       ViewportAddString(dpi, ZOOM_LVL_OUT_2X, te, te->string_id, te->string_id - 1, 0, te->params_1);
    00116     }
    00117   }
    00118 }