Class: Wads::WadsConfig
- Inherits:
-
Object
- Object
- Wads::WadsConfig
- Includes:
- Singleton
- Defined in:
- lib/wads/widgets.rb
Overview
WadsConfig is the one singleton that provides access to resources used throughput the application, including fonts, themes, and layouts.
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#window ⇒ Object
Returns the value of attribute window.
Instance Method Summary collapse
-
#circle(color) ⇒ Object
Get a Gosu images instance for the specified color, i.e.
- #create_circles ⇒ Object
- #create_layout(x, y, width, height, widget, layout_type = nil, args = {}) ⇒ Object
- #create_layout_for_widget(widget, layout_type = nil, args = {}) ⇒ Object
-
#current_theme ⇒ Object
Get a reference to the current theme.
-
#default_dimensions(widget_type) ⇒ Object
This method returns the default dimensions for the given widget type as a two value array of the form [width, height].
-
#get_default_theme ⇒ Object
Get the default theme which is white text on a black background that uses icons (primarily used in the Graph display widget currently).
- #get_logger ⇒ Object
- #get_window ⇒ Object
-
#set_current_theme(theme) ⇒ Object
Set the theme to be used by wads widgets.
- #set_default_layout(layout_type, layout_args = {}) ⇒ Object
-
#set_log_level(level) ⇒ Object
Wads uses the Ruby logger, and you can conrol the log level using this method.
- #set_window(w) ⇒ Object
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
276 277 278 |
# File 'lib/wads/widgets.rb', line 276 def logger @logger end |
#window ⇒ Object
Returns the value of attribute window.
277 278 279 |
# File 'lib/wads/widgets.rb', line 277 def window @window end |
Instance Method Details
#circle(color) ⇒ Object
Get a Gosu images instance for the specified color, i.e. COLOR_AQUA ir COLOR_BLUE
411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/wads/widgets.rb', line 411 def circle(color) create_circles if color.nil? return nil end img = @wads_image_circles[color] if img.nil? get_logger.error("ERROR: Did not find circle image with color #{color}") end img end |
#create_circles ⇒ Object
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/wads/widgets.rb', line 423 def create_circles return unless @wads_image_circles.nil? @wads_image_circle_aqua = Gosu::Image.new("./media/CircleAqua.png") @wads_image_circle_blue = Gosu::Image.new("./media/CircleBlue.png") @wads_image_circle_green = Gosu::Image.new("./media/CircleGreen.png") @wads_image_circle_purple = Gosu::Image.new("./media/CirclePurple.png") @wads_image_circle_red = Gosu::Image.new("./media/CircleRed.png") @wads_image_circle_yellow = Gosu::Image.new("./media/CircleYellow.png") @wads_image_circle_gray = Gosu::Image.new("./media/CircleGray.png") @wads_image_circle_white = Gosu::Image.new("./media/CircleWhite.png") @wads_image_circle_alpha = Gosu::Image.new("./media/CircleAlpha.png") @wads_image_circles = {} @wads_image_circles[COLOR_AQUA] = @wads_image_circle_aqua @wads_image_circles[COLOR_BLUE] = @wads_image_circle_blue @wads_image_circles[COLOR_GREEN] = @wads_image_circle_green @wads_image_circles[COLOR_PURPLE] = @wads_image_circle_purple @wads_image_circles[COLOR_RED] = @wads_image_circle_red @wads_image_circles[COLOR_YELLOW] = @wads_image_circle_yellow @wads_image_circles[COLOR_GRAY] = @wads_image_circle_gray @wads_image_circles[COLOR_WHITE] = @wads_image_circle_white @wads_image_circles[COLOR_ALPHA] = @wads_image_circle_alpha @wads_image_circles[4294956800] = @wads_image_circle_yellow @wads_image_circles[4281893349] = @wads_image_circle_blue @wads_image_circles[4294967295] = @wads_image_circle_gray @wads_image_circles[4286611584] = @wads_image_circle_gray @wads_image_circles[4282962380] = @wads_image_circle_aqua @wads_image_circles[4294939648] = @wads_image_circle_red @wads_image_circles[4292664540] = @wads_image_circle_white end |
#create_layout(x, y, width, height, widget, layout_type = nil, args = {}) ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/wads/widgets.rb', line 370 def create_layout(x, y, width, height, , layout_type = nil, args = {}) if layout_type.nil? if @default_layout_type.nil? layout_type = LAYOUT_VERTICAL_COLUMN else layout_type = @default_layout_type end end if not @default_layout_args.nil? if args.nil? args = @default_layout_args else args.merge(@default_layout_args) end end if layout_type == LAYOUT_VERTICAL_COLUMN return VerticalColumnLayout.new(x, y, width, height, , args) elsif layout_type == LAYOUT_TOP_MIDDLE_BOTTOM return TopMiddleBottomLayout.new(x, y, width, height, , args) elsif layout_type == LAYOUT_BORDER return BorderLayout.new(x, y, width, height, , args) elsif layout_type == LAYOUT_HEADER_CONTENT return HeaderContentLayout.new(x, y, width, height, , args) elsif layout_type == LAYOUT_CONTENT_FOOTER return ContentFooterLayout.new(x, y, width, height, , args) elsif layout_type == LAYOUT_EAST_WEST return EastWestLayout.new(x, y, width, height, , args) end raise "#{layout_type} is an unsupported layout type" end |
#create_layout_for_widget(widget, layout_type = nil, args = {}) ⇒ Object
366 367 368 |
# File 'lib/wads/widgets.rb', line 366 def (, layout_type = nil, args = {}) create_layout(.x, .y, .width, .height, , layout_type, args) end |
#current_theme ⇒ Object
Get a reference to the current theme. If one has not been set using set_current_theme(theme), the default theme will be used.
326 327 328 329 330 331 |
# File 'lib/wads/widgets.rb', line 326 def current_theme if @current_theme.nil? @current_theme = get_default_theme end @current_theme end |
#default_dimensions(widget_type) ⇒ Object
This method returns the default dimensions for the given widget type as a two value array of the form [width, height]. This helps the layout manager allocate space to widgets within a layout and container. The string value max tells the layout to use all available space in that dimension (either x or y)
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/wads/widgets.rb', line 347 def default_dimensions() if @default_dimensions.nil? @default_dimensions = {} @default_dimensions[ELEMENT_TEXT] = [100, 20] @default_dimensions[ELEMENT_TEXT_INPUT] = [100, 20] @default_dimensions[ELEMENT_IMAGE] = [100, 100] @default_dimensions[ELEMENT_TABLE] = ["max", "max"] @default_dimensions[ELEMENT_HORIZONTAL_PANEL] = ["max", 100] @default_dimensions[ELEMENT_VERTICAL_PANEL] = [100, "max"] @default_dimensions[ELEMENT_MAX_PANEL] = ["max", "max"] @default_dimensions[ELEMENT_DOCUMENT] = ["max", "max"] @default_dimensions[ELEMENT_GRAPH] = ["max", "max"] @default_dimensions[ELEMENT_BUTTON] = [100, 26] @default_dimensions[ELEMENT_GENERIC] = ["max", "max"] @default_dimensions[ELEMENT_PLOT] = ["max", "max"] end @default_dimensions[] end |
#get_default_theme ⇒ Object
Get the default theme which is white text on a black background that uses icons (primarily used in the Graph display widget currently)
308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/wads/widgets.rb', line 308 def get_default_theme if @default_theme.nil? @default_theme = GuiTheme.new(COLOR_WHITE, # text color COLOR_HEADER_BRIGHT_BLUE, # graphic elements COLOR_BORDER_BLUE, # border color COLOR_BLACK, # background COLOR_LIGHT_GRAY, # selected item true, # use icons Gosu::Font.new(22), # regular font Gosu::Font.new(38)) # large font end @default_theme end |
#get_logger ⇒ Object
279 280 281 282 283 284 |
# File 'lib/wads/widgets.rb', line 279 def get_logger if @logger.nil? @logger = Logger.new(STDOUT) end @logger end |
#get_window ⇒ Object
297 298 299 300 301 302 |
# File 'lib/wads/widgets.rb', line 297 def get_window if @window.nil? raise "The WadsConfig.instance.set_window(window) needs to be invoked first" end @window end |
#set_current_theme(theme) ⇒ Object
Set the theme to be used by wads widgets
336 337 338 |
# File 'lib/wads/widgets.rb', line 336 def set_current_theme(theme) @current_theme = theme end |
#set_default_layout(layout_type, layout_args = {}) ⇒ Object
403 404 405 406 |
# File 'lib/wads/widgets.rb', line 403 def set_default_layout(layout_type, layout_args = {}) @default_layout_type = layout_type @default_layout_args = layout_args end |
#set_log_level(level) ⇒ Object
Wads uses the Ruby logger, and you can conrol the log level using this method. Valid values are ‘debug’, ‘info’, ‘warn’, ‘error’
289 290 291 |
# File 'lib/wads/widgets.rb', line 289 def set_log_level(level) get_logger.level = level end |
#set_window(w) ⇒ Object
293 294 295 |
# File 'lib/wads/widgets.rb', line 293 def set_window(w) @window = w end |