~swag/armagetronad/0.2.9-sty+ct+ap-fork

« back to all changes in this revision

Viewing changes to src/tools/tColor.cpp

  • Committer: SwagTron
  • Date: 2019-03-05 07:13:03 UTC
  • Revision ID: swagtron-20190305071303-5m4cn9hs6h8ydsgf
- Ported toggle from 0.4. Seems kind of hacky. Had to add another FindConfigItem of type tConfItemBase due to tab completion using the previous tString function. Plan to change this later, but I really needed the toggle function. Tried to cast the two, but that did not work out. Seemed like the bug-less option for the time being. Those unfamiliar with this function, you can now toggle boolean commands (Ex. toggle text_out)

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
// minimal tolerated values of font color before a white background is rendered
48
48
static REAL sr_minR = .5, sr_minG = .5, sr_minB =.5, sr_minTotal = .7;
49
 
tConfItem< REAL > sr_minRConf( "FONT_MIN_R", sr_minR );
50
 
tConfItem< REAL > sr_minGConf( "FONT_MIN_G", sr_minG );
51
 
tConfItem< REAL > sr_minBConf( "FONT_MIN_B", sr_minB );
52
 
tConfItem< REAL > sr_minTotalConf( "FONT_MIN_TOTAL", sr_minTotal );
 
49
tSettingItem< REAL > sr_minRConf( "FONT_MIN_R", sr_minR );
 
50
tSettingItem< REAL > sr_minGConf( "FONT_MIN_G", sr_minG );
 
51
tSettingItem< REAL > sr_minBConf( "FONT_MIN_B", sr_minB );
 
52
tSettingItem< REAL > sr_minTotalConf( "FONT_MIN_TOTAL", sr_minTotal );
53
53
 
54
54
// *******************************************************************************************
55
55
// *
158
158
    r_ = CTR( hex_to_int( c[2] ) *16 + hex_to_int( c[3] ) );
159
159
    g_ = CTR( hex_to_int( c[4] ) *16 + hex_to_int( c[5] ) );
160
160
    b_ = CTR( hex_to_int( c[6] ) *16 + hex_to_int( c[7] ) );
161
 
}
162
 
 
163
 
// strict checking: accept only 0-9 and a-f.  Network aware config item is in nNetwork.cpp.
164
 
bool st_verifyColorCodeStrictly = 0;
165
 
 
166
 
static bool st_verifyColorChar( int c )
167
 
{
168
 
    if( st_verifyColorCodeStrictly )
169
 
    {
170
 
        // really check for valid hexcodes
171
 
        return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
172
 
    }
173
 
    else
174
 
    {
175
 
        // be content with ASCII.
176
 
        return (0 < c) && (c <= 0x7f);
177
 
    }
178
 
}
179
 
 
180
 
// *******************************************************************************************
181
 
// *
182
 
// *    VerifyColorCode
183
 
// *
184
 
// *******************************************************************************************
185
 
//!
186
 
//!             @param  c       Color code string to read the color from
187
 
//!
188
 
// *******************************************************************************************
189
 
 
190
 
bool tColor::VerifyColorCode( const char * c )
191
 
{
192
 
    for( int i = 2; i < 8; ++i )
193
 
    {
194
 
        if ( !st_verifyColorChar(c[i]) )
195
 
        {
196
 
            return false;
197
 
        }
198
 
    }
199
 
    return true;
200
 
}
201
 
 
202
 
// *******************************************************************************************
203
 
// *
204
 
// *    VerifyColorCode
205
 
// *
206
 
// *******************************************************************************************
207
 
//!
208
 
//!             @param  c       Color code string to read the color from
209
 
//!
210
 
// *******************************************************************************************
211
 
 
212
 
bool tColor::VerifyColorCode( const wchar_t * c )
213
 
{
214
 
    for( int i = 2; i < 8; ++i )
215
 
    {
216
 
        if ( !st_verifyColorChar(c[i]) )
217
 
        {
218
 
            return false;
219
 
        }
220
 
    }
221
 
    return true;
 
161
}
 
162
 
 
163
// strict checking: accept only 0-9 and a-f.  Network aware config item is in nNetwork.cpp.
 
164
bool st_verifyColorCodeStrictly = 0;
 
165
 
 
166
static bool st_verifyColorChar( int c )
 
167
{
 
168
    if( st_verifyColorCodeStrictly )
 
169
    {
 
170
        // really check for valid hexcodes
 
171
        return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
 
172
    }
 
173
    else
 
174
    {
 
175
        // be content with ASCII.
 
176
        return (0 < c) && (c <= 0x7f);
 
177
    }
 
178
}
 
179
 
 
180
// *******************************************************************************************
 
181
// *
 
182
// *    VerifyColorCode
 
183
// *
 
184
// *******************************************************************************************
 
185
//!
 
186
//!             @param  c       Color code string to read the color from
 
187
//!
 
188
// *******************************************************************************************
 
189
 
 
190
bool tColor::VerifyColorCode( const char * c )
 
191
{
 
192
    for( int i = 2; i < 8; ++i )
 
193
    {
 
194
        if ( !st_verifyColorChar(c[i]) )
 
195
        {
 
196
            return false;
 
197
        }
 
198
    }
 
199
    return true;
 
200
}
 
201
 
 
202
// *******************************************************************************************
 
203
// *
 
204
// *    VerifyColorCode
 
205
// *
 
206
// *******************************************************************************************
 
207
//!
 
208
//!             @param  c       Color code string to read the color from
 
209
//!
 
210
// *******************************************************************************************
 
211
 
 
212
bool tColor::VerifyColorCode( const wchar_t * c )
 
213
{
 
214
    for( int i = 2; i < 8; ++i )
 
215
    {
 
216
        if ( !st_verifyColorChar(c[i]) )
 
217
        {
 
218
            return false;
 
219
        }
 
220
    }
 
221
    return true;
222
222
}
223
223
 
224
224
// *******************************************************************************************